stepperDirectionPin Mode
This commit is contained in:
parent
3f61be1a3b
commit
68e761f6f0
|
@ -36,6 +36,11 @@
|
|||
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
|
||||
#include "allsensors.h"
|
||||
|
||||
#ifndef STEPPER_DIRECTION_PIN_MODE
|
||||
// todo: migrate this to boardConfiguration->idle.stepperDirectionPinMode
|
||||
#define STEPPER_DIRECTION_PIN_MODE OM_DEFAULT
|
||||
#endif /* STEPPER_DIRECTION_PIN_MODE */
|
||||
|
||||
static THD_WORKING_AREA(ivThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||
|
||||
static Logging *logger;
|
||||
|
@ -315,9 +320,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,
|
||||
STEPPER_DIRECTION_PIN_MODE, engineConfiguration->idleStepperReactionTime,
|
||||
engineConfiguration->idleStepperTotalSteps, engineConfiguration->stepperEnablePin);
|
||||
} else {
|
||||
/**
|
||||
* Start PWM for idleValvePin
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue