Skip to content

Commit

Permalink
driverlib HWREG quick write alternative - not tested... yet
Browse files Browse the repository at this point in the history
  • Loading branch information
sq7bti committed Aug 27, 2014
1 parent 8c2bf8d commit 85a8ae5
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions iAccelStepper.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include "iAccelStepper.h"
#include "driverlib/timer.h"

static iAccelStepper* me[3];
#include "inc/hw_gpio.h"

#define portOutputRegister(x) (regtype)portBASERegister(x)
typedef volatile uint32_t regtype;
typedef uint8_t regsize;

static iAccelStepper* me[2];
static unsigned int ulPort_step[2];
static unsigned int ucPin_step[2];
static unsigned int ulPort_dir[2];
static unsigned int ucPin_dir[2];
static boolean direction[2];
static unsigned int all_instances;
static unsigned long ulPeriod;

Expand All @@ -17,16 +27,19 @@ void iAccelStepper::ISR(void) {

// prepare for the next period
computeNewSpeed();
digitalWrite(_pin[1], _direction);
if(direction[id] != _direction) {
direction[id] = _direction;
HWREG(ulPort_dir + (GPIO_O_DATA + (ucPin_dir[id]))) = _direction;
}

// switch off timer at the falling edge
if((_stepInterval == 0) || (abs(distanceToGo()) < 1)) {
TimerDisable(g_ulTIMERBase[id], TIMER_A);
running = false;
} else {
digitalWrite(_pin[0], true);
HWREG(ulPort_step + (GPIO_O_DATA + (ucPin_step[id]))) = true;
delayMicroseconds(ulPeriod);
digitalWrite(_pin[0], false);
HWREG(ulPort_step + (GPIO_O_DATA + (ucPin_step[id]))) = false;

TimerLoadSet(g_ulTIMERBase[id], TIMER_A, _stepInterval - ulPeriod);
TimerEnable(g_ulTIMERBase[id], TIMER_A);
Expand Down Expand Up @@ -66,6 +79,10 @@ void iAccelStepper::begin(uint8_t pin1, uint8_t pin2, uint8_t pin3)
me[id] = this;
running = false;
++all_instances;
ulPort_step[id] = portOutputRegister(digitalPinToPort(pin1));
ucPin_step[id] = digitalPinToBitMask(pin1);
ulPort_dir[id] = portOutputRegister(digitalPinToPort(pin2));
ucPin_dir[id] = digitalPinToBitMask(pin2);
}
}

Expand All @@ -83,7 +100,10 @@ void iAccelStepper::moveTo(long absolute)
// enable driver
// enableOutputs();
computeNewSpeed();
digitalWrite(_pin[1], _direction);
if(direction[id] != _direction) {
direction[id] = _direction;
HWREG(ulPort_dir + (GPIO_O_DATA + (ucPin_dir[id]))) = _direction;
}

if(_direction == DIRECTION_CW)
// Clockwise
Expand All @@ -92,9 +112,9 @@ void iAccelStepper::moveTo(long absolute)
// Anticlockwise
--_currentPos;

digitalWrite(_pin[0], true);
HWREG(ulPort_step + (GPIO_O_DATA + (ucPin_step[id]))) = true;
delayMicroseconds(ulPeriod);
digitalWrite(_pin[0], false);
HWREG(ulPort_step + (GPIO_O_DATA + (ucPin_step[id]))) = false;

TimerLoadSet(g_ulTIMERBase[id], TIMER_A, _stepInterval - ulPeriod);
TimerEnable(g_ulTIMERBase[id], TIMER_A);
Expand Down

0 comments on commit 85a8ae5

Please sign in to comment.