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() {
if (boardConfiguration->useStepperIdle) {
iacMotor.initialize(boardConfiguration->idle.stepperStepPin, boardConfiguration->idle.stepperDirectionPin,
engineConfiguration->idleStepperReactionTime, engineConfiguration->idleStepperTotalSteps,
engineConfiguration->stepperEnablePin);
iacMotor.initialize(boardConfiguration->idle.stepperStepPin, boardConfiguration->idle.stepperDirectionPin,
engineConfiguration->stepperDirectionPinMode, engineConfiguration->idleStepperReactionTime,
engineConfiguration->idleStepperTotalSteps, engineConfiguration->stepperEnablePin);
} else {
/**
* Start PWM for idleValvePin

View File

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

View File

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