Merge pull request #444 from andreika-git/stepper

stepperDirectionPin Mode
This commit is contained in:
rusefi 2017-06-13 14:55:18 -04:00 committed by GitHub
commit b74b43adfa
3 changed files with 14 additions and 15 deletions

View File

@ -315,9 +315,9 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) {
static void initIdleHardware() { static void initIdleHardware() {
if (boardConfiguration->useStepperIdle) { if (boardConfiguration->useStepperIdle) {
iacMotor.initialize(boardConfiguration->idle.stepperStepPin, boardConfiguration->idle.stepperDirectionPin, iacMotor.initialize(boardConfiguration->idle.stepperStepPin, boardConfiguration->idle.stepperDirectionPin,
engineConfiguration->idleStepperReactionTime, engineConfiguration->idleStepperTotalSteps, engineConfiguration->stepperDirectionPinMode, engineConfiguration->idleStepperReactionTime,
engineConfiguration->stepperEnablePin); engineConfiguration->idleStepperTotalSteps, engineConfiguration->stepperEnablePin);
} else { } else {
/** /**
* Start PWM for idleValvePin * Start PWM for idleValvePin

View File

@ -16,7 +16,7 @@ EXTERN_ENGINE;
static msg_t stThread(StepperMotor *motor) { static msg_t stThread(StepperMotor *motor) {
chRegSetThreadName("stepper"); chRegSetThreadName("stepper");
palWritePad(motor->directionPort, motor->directionPin, false); motor->directionPin.setValue(false);
/** /**
* let's park the motor in a known position to begin with * let's park the motor in a known position to begin with
@ -37,7 +37,7 @@ static msg_t stThread(StepperMotor *motor) {
continue; continue;
} }
bool isIncrementing = targetPosition > currentPosition; bool isIncrementing = targetPosition > currentPosition;
palWritePad(motor->directionPort, motor->directionPin, isIncrementing); motor->directionPin.setValue(isIncrementing);
if (isIncrementing) { if (isIncrementing) {
motor->currentPosition++; motor->currentPosition++;
} else { } else {
@ -57,8 +57,6 @@ static msg_t stThread(StepperMotor *motor) {
StepperMotor::StepperMotor() { StepperMotor::StepperMotor() {
currentPosition = 0; currentPosition = 0;
targetPosition = 0; targetPosition = 0;
directionPort = NULL;
directionPin = 0;
enablePort = NULL; enablePort = NULL;
enablePin = 0; enablePin = 0;
stepPort = NULL; stepPort = NULL;
@ -86,8 +84,8 @@ void StepperMotor::pulse() {
palWritePad(enablePort, enablePin, true); // disable stepper palWritePad(enablePort, enablePin, true); // disable stepper
} }
void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, float reactionTime, int totalSteps, void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin_output_mode_e directionPinMode,
brain_pin_e enablePin) { float reactionTime, int totalSteps, brain_pin_e enablePin) {
this->reactionTime = maxF(1, reactionTime); this->reactionTime = maxF(1, reactionTime);
this->totalSteps = maxI(3, totalSteps); this->totalSteps = maxI(3, totalSteps);
if (stepPin == GPIO_UNASSIGNED || directionPin == GPIO_UNASSIGNED) { if (stepPin == GPIO_UNASSIGNED || directionPin == GPIO_UNASSIGNED) {
@ -97,14 +95,13 @@ void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, flo
stepPort = getHwPort(stepPin); stepPort = getHwPort(stepPin);
this->stepPin = getHwPin(stepPin); this->stepPin = getHwPin(stepPin);
directionPort = getHwPort(directionPin); this->directionPinMode = directionPinMode;
this->directionPin = getHwPin(directionPin); this->directionPin.initPin("stepper dir", directionPin, &this->directionPinMode);
enablePort = getHwPort(enablePin); enablePort = getHwPort(enablePin);
this->enablePin = getHwPin(enablePin); this->enablePin = getHwPin(enablePin);
efiSetPadMode("stepper step", stepPin, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("stepper step", stepPin, PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("stepper dir", directionPin, PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("stepper enable", enablePin, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("stepper enable", enablePin, PAL_MODE_OUTPUT_PUSHPULL);
palWritePad(this->enablePort, enablePin, true); // disable stepper palWritePad(this->enablePort, enablePin, true); // disable stepper

View File

@ -8,18 +8,18 @@
#define STEPPER_H_ #define STEPPER_H_
#include "main.h" #include "main.h"
#include "efiGpio.h"
class StepperMotor { class StepperMotor {
public: public:
StepperMotor(); StepperMotor();
void initialize(brain_pin_e stepPin, brain_pin_e directionPin, float reactionTime, int totalSteps, void initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin_output_mode_e directionPinMode, float reactionTime, int totalSteps,
brain_pin_e enablePin); brain_pin_e enablePin);
void pulse(); void pulse();
void setTargetPosition(int targetPosition); void setTargetPosition(int targetPosition);
int getTargetPosition(); int getTargetPosition();
ioportid_t directionPort; OutputPin directionPin;
ioportmask_t directionPin;
int currentPosition; int currentPosition;
float reactionTime; float reactionTime;
int totalSteps; int totalSteps;
@ -31,6 +31,8 @@ private:
ioportid_t enablePort; ioportid_t enablePort;
ioportmask_t enablePin; ioportmask_t enablePin;
pin_output_mode_e directionPinMode;
THD_WORKING_AREA(stThreadStack, UTILITY_THREAD_STACK_SIZE); THD_WORKING_AREA(stThreadStack, UTILITY_THREAD_STACK_SIZE);
}; };