ETB using tle7209 fix #746
This commit is contained in:
parent
ba8b4e676c
commit
16cf6388b6
|
@ -89,6 +89,8 @@ void setMinimalPinsEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
CONFIGB(canTxPin) = GPIO_UNASSIGNED;
|
||||
CONFIGB(canRxPin) = GPIO_UNASSIGNED;
|
||||
CONFIGB(sdCardCsPin) = GPIO_UNASSIGNED;
|
||||
boardConfiguration->fanPin = GPIO_UNASSIGNED;
|
||||
CONFIGB(idle).solenoidPin = GPIO_UNASSIGNED;
|
||||
for (int i = 0;i<TRIGGER_INPUT_PIN_COUNT;i++) {
|
||||
CONFIGB(triggerInputPins)[i] = GPIO_UNASSIGNED;
|
||||
}
|
||||
|
@ -337,6 +339,7 @@ void setTle8888TestConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
boardConfiguration->is_enabled_spi_1 = true;
|
||||
engineConfiguration->debugMode = DBG_TLE8888;
|
||||
|
||||
engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_9; // PB1 // just any non-empty value for now
|
||||
// ETB #1 top one - closer to 121 connector
|
||||
// DIS PF12
|
||||
// EN PF13
|
||||
|
|
|
@ -96,6 +96,10 @@ static LoggingWithStorage logger("ETB");
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
class EtbControl;
|
||||
|
||||
static void applyEtbPinState(int stateIndex, EtbControl *etb) /* pwm_gen_callback */;
|
||||
|
||||
class EtbControl {
|
||||
public:
|
||||
EtbControl() : etbPwmUp("etbUp"), dcMotor(&etbPwmUp, &outputDirectionOpen, &outputDirectionClose) {}
|
||||
|
@ -104,18 +108,22 @@ public:
|
|||
OutputPin etbOutput;
|
||||
SimplePwm etbPwmUp;
|
||||
TwoPinDcMotor dcMotor;
|
||||
void start(brain_pin_e controlPin,
|
||||
void start(bool useTwoWires, brain_pin_e controlPin,
|
||||
brain_pin_e directionPin1,
|
||||
brain_pin_e directionPin2) {
|
||||
etbPwmUp.arg = this;
|
||||
dcMotor.useTwoWires = useTwoWires;
|
||||
if (!dcMotor.useTwoWires) {
|
||||
// this line used for PWM in case of three wire mode
|
||||
etbOutput.initPin("etb", controlPin);
|
||||
}
|
||||
int freq = maxI(100, engineConfiguration->etbFreq);
|
||||
// this line used for PWM
|
||||
startSimplePwmExt(&etbPwmUp, "etb1",
|
||||
startSimplePwm(&etbPwmUp, "etb1",
|
||||
&engine->executor,
|
||||
controlPin,
|
||||
&etbOutput,
|
||||
freq,
|
||||
0.80,
|
||||
(pwm_gen_callback*)applyPinState);
|
||||
(pwm_gen_callback*)applyEtbPinState);
|
||||
outputDirectionOpen.initPin("etb dir open", directionPin1);
|
||||
outputDirectionClose.initPin("etb dir close", directionPin2);
|
||||
}
|
||||
|
@ -372,7 +380,9 @@ void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *pre
|
|||
|
||||
void startETBPins(void) {
|
||||
|
||||
etb1.start(CONFIGB(etb1.controlPin1),
|
||||
etb1.start(
|
||||
CONFIG(etb1_use_two_wires),
|
||||
CONFIGB(etb1.controlPin1),
|
||||
CONFIGB(etb1.directionPin1),
|
||||
CONFIGB(etb1.directionPin2)
|
||||
);
|
||||
|
@ -433,6 +443,20 @@ void unregisterEtbPins() {
|
|||
|
||||
}
|
||||
|
||||
static void applyEtbPinState(int stateIndex, EtbControl *etb) /* pwm_gen_callback */ {
|
||||
efiAssertVoid(CUSTOM_ERR_6663, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex");
|
||||
int value = etb->etbPwmUp.multiWave.getChannelState(0, stateIndex);
|
||||
if (etb->dcMotor.useTwoWires) {
|
||||
OutputPin *output = etb->dcMotor.twoWireModeControl;
|
||||
if (output != NULL) {
|
||||
output->setValue(value);
|
||||
}
|
||||
} else {
|
||||
OutputPin *output = &etb->etbOutput;
|
||||
output->setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
void initElectronicThrottle(void) {
|
||||
addConsoleAction("ethinfo", showEthInfo);
|
||||
addConsoleAction("etbreset", etbReset);
|
||||
|
|
|
@ -68,6 +68,12 @@ bool TwoPinDcMotor::Set(float duty)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (isPositiveOrZero) {
|
||||
twoWireModeControl = m_dir1;
|
||||
} else {
|
||||
twoWireModeControl = m_dir2;
|
||||
}
|
||||
|
||||
m_dir1->setValue(isPositiveOrZero);
|
||||
m_dir2->setValue(!isPositiveOrZero);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ public:
|
|||
*/
|
||||
TwoPinDcMotor(SimplePwm* pwm, OutputPin* dir1, OutputPin* dir2);
|
||||
|
||||
bool useTwoWires = false;
|
||||
OutputPin* twoWireModeControl = NULL;
|
||||
virtual bool Set(float duty) override;
|
||||
float Get();
|
||||
void BrakeGnd();
|
||||
|
|
Loading…
Reference in New Issue