diff --git a/firmware/config/boards/microrusefi/board_configuration.cpp b/firmware/config/boards/microrusefi/board_configuration.cpp index 27b5f539fa..485d4a0d4c 100644 --- a/firmware/config/boards/microrusefi/board_configuration.cpp +++ b/firmware/config/boards/microrusefi/board_configuration.cpp @@ -109,25 +109,15 @@ static void setupEtb() { engineConfiguration->etbIo[0].controlPin1 = GPIOC_7; // DIR pin engineConfiguration->etbIo[0].directionPin1 = GPIOA_8; - - // set_fsio_output_pin 7 PC8 -#if EFI_FSIO - // set_rpn_expression 8 "1" - // disable ETB by default - setFsio(7, GPIOC_8, "1" PASS_CONFIG_PARAMETER_SUFFIX); - // enable ETB - // set_rpn_expression 8 "0" - //setFsio(7, GPIOC_8, "0" PASS_CONFIG_PARAMETER_SUFFIX); -#endif /* EFI_FSIO */ - + // Disable pin + engineConfiguration->etbIo[0].disablePin = GPIOC_8; + // Unused + engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED; // set_analog_input_pin pps PA7 // EFI_ADC_7: "31 - AN volt 3" - PA7 // engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_7; - // Unused - engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED; - // we only have pwm/dir, no dira/dirb engineConfiguration->etb_use_two_wires = false; diff --git a/firmware/config/boards/proteus/board_configuration.cpp b/firmware/config/boards/proteus/board_configuration.cpp index fcf989bae5..6851b41977 100644 --- a/firmware/config/boards/proteus/board_configuration.cpp +++ b/firmware/config/boards/proteus/board_configuration.cpp @@ -86,6 +86,8 @@ static void setupEtb() { engineConfiguration->etbIo[0].controlPin1 = GPIOD_12; // DIR pin engineConfiguration->etbIo[0].directionPin1 = GPIOD_10; + // Disable pin + engineConfiguration->etbIo[0].disablePin = GPIOD_11; // Unused engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED; @@ -94,15 +96,11 @@ static void setupEtb() { engineConfiguration->etbIo[1].controlPin1 = GPIOD_13; // DIR pin engineConfiguration->etbIo[1].directionPin1 = GPIOD_9; + // Disable pin + engineConfiguration->etbIo[1].disablePin = GPIOD_8; // Unused engineConfiguration->etbIo[1].directionPin2 = GPIO_UNASSIGNED; -#if EFI_FSIO - // disable ETB by default - setFsio(7, GPIOD_8, "1" PASS_CONFIG_PARAMETER_SUFFIX); - setFsio(8, GPIOD_11, "1" PASS_CONFIG_PARAMETER_SUFFIX); -#endif /* EFI_FSIO */ - // we only have pwm/dir, no dira/dirb engineConfiguration->etb_use_two_wires = false; engineConfiguration->etbFreq = 800; diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index 346da06eea..455a90e8de 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -349,11 +349,11 @@ void setTle8888TestConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { // SF PF11 #if defined(STM32_HAS_GPIOF) && STM32_HAS_GPIOF #if EFI_FSIO - setFsio(12, GPIOF_12, "0" PASS_CONFIG_PARAMETER_SUFFIX); setFsio(14, GPIOF_13, "1" PASS_CONFIG_PARAMETER_SUFFIX); #endif /* EFI_FSIO */ CONFIG(etbIo[0].directionPin1) = GPIOF_15; CONFIG(etbIo[0].directionPin2) = GPIOF_14; + CONFIG(etbIo[0].disablePin) = GPIOF_12; #endif /* STM32_HAS_GPIOF */ CONFIG(etb_use_two_wires) = true; engineConfiguration->isHip9011Enabled = false; @@ -365,11 +365,11 @@ void setTle8888TestConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { // IN2 PE4 // SF PE3 #if EFI_FSIO - setFsio(13, GPIOE_5, "0" PASS_CONFIG_PARAMETER_SUFFIX); setFsio(15, GPIOE_6, "1" PASS_CONFIG_PARAMETER_SUFFIX); #endif CONFIG(etbIo[0].directionPin1) = GPIOE_2; CONFIG(etbIo[0].directionPin2) = GPIOE_4; + CONFIG(etbIo[0].disablePin) = GPIOE_5; engineConfiguration->tps1_1AdcChannel = EFI_ADC_3; // PA3 diff --git a/firmware/config/engines/me7pnp.cpp b/firmware/config/engines/me7pnp.cpp index fb81730801..4806296a98 100644 --- a/firmware/config/engines/me7pnp.cpp +++ b/firmware/config/engines/me7pnp.cpp @@ -134,7 +134,6 @@ void vag_18_Turbo(DECLARE_CONFIG_PARAMETER_SIGNATURE) { #if EFI_FSIO #if defined(STM32_HAS_GPIOF) && STM32_HAS_GPIOF - setFsio (12, GPIOF_12, "0" PASS_CONFIG_PARAMETER_SUFFIX); setFsio (14, GPIOF_13, "1" PASS_CONFIG_PARAMETER_SUFFIX); #endif /* STM32_HAS_GPIOF */ setFsioExt (3, GPIOE_0, "0.15 90 coolant 120 min max 90 - 30 / 0.8 * +", 25 PASS_CONFIG_PARAMETER_SUFFIX); @@ -144,15 +143,16 @@ void vag_18_Turbo(DECLARE_CONFIG_PARAMETER_SIGNATURE) { #if defined(STM32_HAS_GPIOF) && STM32_HAS_GPIOF CONFIG(etbIo[0].directionPin1) = GPIOF_15; CONFIG(etbIo[0].directionPin2) = GPIOF_14; + CONFIG(etbIo[0].disablePin) = GPIOF_12; #endif /* STM32_HAS_GPIOF */ engineConfiguration->isHip9011Enabled = false; #if EFI_FSIO - setFsio (13, GPIOE_5, "0" PASS_CONFIG_PARAMETER_SUFFIX); setFsio (15, GPIOE_6, "1" PASS_CONFIG_PARAMETER_SUFFIX); #endif CONFIG(etbIo[1].directionPin1) = GPIOE_2; CONFIG(etbIo[1].directionPin2) = GPIOE_4; + CONFIG(etbIo[1].disablePin) = GPIOE_5; engineConfiguration->etb.pFactor = 1.07; engineConfiguration->etb.iFactor = 0.18; diff --git a/firmware/controllers/actuators/dc_motors.cpp b/firmware/controllers/actuators/dc_motors.cpp index 950cac040a..ca9222299b 100644 --- a/firmware/controllers/actuators/dc_motors.cpp +++ b/firmware/controllers/actuators/dc_motors.cpp @@ -24,6 +24,7 @@ private: OutputPin m_pinEnable; OutputPin m_pinDir1; OutputPin m_pinDir2; + OutputPin m_disablePin; SimplePwm m_pwmEnable; SimplePwm m_pwmDir1; @@ -32,7 +33,7 @@ private: SimplePwm etbPwmUp; public: - EtbHardware() : etbPwmUp("etbUp"), dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2) {} + EtbHardware() : etbPwmUp("etbUp"), dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2, &m_disablePin) {} TwoPinDcMotor dcMotor; @@ -47,10 +48,14 @@ public: // since we have pointer magic here we cannot simply have value parameter brain_pin_e pinDir1, brain_pin_e pinDir2, + brain_pin_e pinDisable, ExecutorInterface* executor, int frequency) { dcMotor.setType(useTwoWires ? TwoPinDcMotor::ControlType::PwmDirectionPins : TwoPinDcMotor::ControlType::PwmEnablePin); + // Configure the disable pin first - ensure things are in a safe state + m_disablePin.initPin("ETB Disable", pinDisable); + m_pinEnable.initPin("ETB Enable", pinEnable); m_pinDir1.initPin("ETB Dir 1", pinDir1); m_pinDir2.initPin("ETB Dir 2", pinDir2); @@ -96,6 +101,7 @@ DcMotor* initDcMotor(size_t index DECLARE_ENGINE_PARAMETER_SUFFIX) io.controlPin1, io.directionPin1, io.directionPin2, + io.disablePin, &ENGINE(executor), CONFIG(etbFreq) ); diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index d7445c9d38..1bb0fd2cb3 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -160,7 +160,7 @@ void EtbController::PeriodicTask() { } if (startupPositionError) { - m_motor->set(0); + m_motor->disable(); return; } @@ -175,21 +175,21 @@ void EtbController::PeriodicTask() { } if (engineConfiguration->pauseEtbControl) { - m_motor->set(0); + m_motor->disable(); return; } auto pedalPosition = Sensor::get(SensorType::AcceleratorPedal); if (!pedalPosition.Valid) { - m_motor->set(0); + m_motor->disable(); return; } SensorResult actualThrottlePosition = Sensor::get(indexToTpsSensor(m_myIndex)); if (!actualThrottlePosition.Valid) { - m_motor->set(0); + m_motor->disable(); return; } @@ -239,6 +239,7 @@ void EtbController::PeriodicTask() { currentEtbDuty = engine->engineState.etbFeedForward + m_pid.getOutput(targetPosition, actualThrottlePosition.Value); + m_motor->enable(); m_motor->set(ETB_PERCENT_TO_DUTY(currentEtbDuty)); if (engineConfiguration->isVerboseETB) { diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index b3c6eae0c5..742d06da30 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -695,7 +695,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) // help to notice when RAM usage goes up - if a code change adds to RAM usage these variables would fail // linking process which is the way to raise the alarm #ifndef RAM_UNUSED_SIZE -#define RAM_UNUSED_SIZE 13850 +#define RAM_UNUSED_SIZE 13800 #endif #ifndef CCM_UNUSED_SIZE #define CCM_UNUSED_SIZE 4100 diff --git a/firmware/controllers/system/dc_motor.cpp b/firmware/controllers/system/dc_motor.cpp index 2b3db71ef8..af9832f713 100644 --- a/firmware/controllers/system/dc_motor.cpp +++ b/firmware/controllers/system/dc_motor.cpp @@ -7,13 +7,31 @@ */ #include "dc_motor.h" +#include "efi_gpio.h" #include "pwm_generator_logic.h" -TwoPinDcMotor::TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2) +TwoPinDcMotor::TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2, OutputPin* disablePin) : m_enable(enable) , m_dir1(dir1) , m_dir2(dir2) + , m_disable(disablePin) { + disable(); +} + +void TwoPinDcMotor::enable() { + if (m_disable) { + m_disable->setValue(false); + } +} + +void TwoPinDcMotor::disable() { + if (m_disable) { + m_disable->setValue(true); + } + + // Also set the duty to zero + set(0); } bool TwoPinDcMotor::isOpenDirection() const { diff --git a/firmware/controllers/system/dc_motor.h b/firmware/controllers/system/dc_motor.h index c5d5237e78..47c2905af8 100644 --- a/firmware/controllers/system/dc_motor.h +++ b/firmware/controllers/system/dc_motor.h @@ -32,10 +32,14 @@ public: */ virtual float get() const = 0; + virtual void disable() = 0; + virtual void enable() = 0; + virtual bool isOpenDirection() const = 0; }; class SimplePwm; +class OutputPin; /** * @brief Represents a DC motor controller (H-bridge) with some combination of PWM and on/off control pins. @@ -70,6 +74,7 @@ private: SimplePwm* const m_enable; SimplePwm* const m_dir1; SimplePwm* const m_dir2; + OutputPin* const m_disable; float m_value = 0; ControlType m_type; @@ -79,11 +84,14 @@ public: * @param dir1 Enable 1 or direction 1 pin. Gets set high to rotate forward. * @param dir2 Enable 2 or direction 2 pin. Gets set high to rotate backward. */ - TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2); + TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2, OutputPin* disable); virtual bool set(float duty) override; float get() const override; bool isOpenDirection() const override; + void enable(); + void disable(); + void setType(ControlType type) { m_type = type; } }; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 9a3e320d63..39d73a5fb6 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -525,7 +525,7 @@ struct etb_io brain_pin_e directionPin1; brain_pin_e directionPin2; brain_pin_e controlPin1; - uint8_t pad; + brain_pin_e disablePin; end_struct idle_hardware_s idle; diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 0913e10ac2..a081e0634d 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1773,10 +1773,12 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00" field = "Fuel Pump Pin", fuelPumpPin field = "ETB#1 Dir #1", etbIo1_directionPin1 @@if_ts_show_etb_pins field = "ETB#1 Dir #2", etbIo1_directionPin2 @@if_ts_show_etb_pins - field = "ETB#1 Control #1", etbIo1_controlPin1 @@if_ts_show_etb_pins + field = "ETB#1 Control #1", etbIo1_controlPin1 @@if_ts_show_etb_pins + field = "ETB#1 Disable", etbIo1_disablePin @@if_ts_show_etb_pins field = "ETB#2 Dir #1", etbIo2_directionPin1 @@if_ts_show_etb_pins field = "ETB#2 Dir #2", etbIo2_directionPin2 @@if_ts_show_etb_pins field = "ETB#2 Control #1", etbIo2_controlPin1 @@if_ts_show_etb_pins + field = "ETB#2 Disable", etbIo2_disablePin @@if_ts_show_etb_pins field = "SD CS Pin", sdCardCsPin @@if_ts_show_sd_card field = "MIL / Check Engine Pin", malfunctionIndicatorPin field = "Aux Pin #1", auxPidPins1 @@ -2055,9 +2057,11 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00" field = "No1 Direction #1", etbIo1_directionPin1 field = "No1 Direction #2", etbIo1_directionPin2 field = "No1 Control #1", etbIo1_controlPin1, { etb_use_two_wires == 0 } + field = "No1 Disable", etbIo1_disablePin field = "No2 Direction #1", etbIo2_directionPin1 field = "No2 Direction #2", etbIo2_directionPin2 field = "No2 Control #1", etbIo2_controlPin1, { etb_use_two_wires == 0} + field = "No2 Disable", etbIo2_disablePin dialog = idleStepperHw, "Stepper Hardware" field = "Idle Stepper Step Pin", idle_stepperStepPin