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