diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index c4ee5e6b44..7127458f04 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -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;iis_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 diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 6db80faf0d..f4d8f24a25 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -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); diff --git a/firmware/controllers/system/dc_motor.cpp b/firmware/controllers/system/dc_motor.cpp index 425a20bb52..541d98bc19 100644 --- a/firmware/controllers/system/dc_motor.cpp +++ b/firmware/controllers/system/dc_motor.cpp @@ -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); } diff --git a/firmware/controllers/system/dc_motor.h b/firmware/controllers/system/dc_motor.h index 9ba747f6f5..5d724255f2 100644 --- a/firmware/controllers/system/dc_motor.h +++ b/firmware/controllers/system/dc_motor.h @@ -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();