From 5ac535c5e502884e5eac888ffb2ae1f43c7bed0c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sat, 2 May 2020 14:54:28 -0700 Subject: [PATCH] Support 4 h-bridges (#1392) * update dc motor api * add more etbio * get out of two arrays * hand generate enough * forgot engine param * ram Co-authored-by: Matthew Kennedy --- firmware/controllers/actuators/dc_motors.cpp | 26 ++++++++++++------- firmware/controllers/actuators/dc_motors.h | 2 +- .../actuators/electronic_throttle.cpp | 2 +- .../controllers/actuators/idle_thread.cpp | 4 +-- firmware/controllers/engine_controller.cpp | 2 +- firmware/integration/rusefi_config.txt | 4 ++- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/firmware/controllers/actuators/dc_motors.cpp b/firmware/controllers/actuators/dc_motors.cpp index 27e666b9cb..6773b6e558 100644 --- a/firmware/controllers/actuators/dc_motors.cpp +++ b/firmware/controllers/actuators/dc_motors.cpp @@ -30,10 +30,8 @@ private: SimplePwm m_pwmDir1; SimplePwm m_pwmDir2; - SimplePwm etbPwmUp; - public: - EtbHardware() : etbPwmUp("etbUp"), dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2, &m_disablePin) {} + EtbHardware() : dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2, &m_disablePin) {} TwoPinDcMotor dcMotor; @@ -45,7 +43,6 @@ public: void start(bool useTwoWires, brain_pin_e pinEnable, - // since we have pointer magic here we cannot simply have value parameter brain_pin_e pinDir1, brain_pin_e pinDir2, brain_pin_e pinDisable, @@ -89,15 +86,26 @@ public: } }; -static EtbHardware etbHardware[ETB_COUNT]; +static EtbHardware etbHardware[ETB_COUNT * 2]; -DcMotor* initDcMotor(size_t index DECLARE_ENGINE_PARAMETER_SUFFIX) -{ - const auto& io = engineConfiguration->etbIo[index]; +// We needed more H-bridge configs - so the IO configs are split +// across two arrays of settings to preserve config compatibility +const etb_io& getConfigForMotor(size_t index DECLARE_ENGINE_PARAMETER_SUFFIX) { + size_t firstSize = efi::size(engineConfiguration->etbIo); + + if (index < firstSize) { + return engineConfiguration->etbIo[index]; + } + + return engineConfiguration->etbIo2[index - firstSize]; +} + +DcMotor* initDcMotor(size_t index, bool useTwoWires DECLARE_ENGINE_PARAMETER_SUFFIX) { + const auto& io = getConfigForMotor(index PASS_ENGINE_PARAMETER_SUFFIX); auto& hw = etbHardware[index]; hw.start( - CONFIG(etb_use_two_wires), + useTwoWires, io.controlPin1, io.directionPin1, io.directionPin2, diff --git a/firmware/controllers/actuators/dc_motors.h b/firmware/controllers/actuators/dc_motors.h index 0d9cfd4100..f587331805 100644 --- a/firmware/controllers/actuators/dc_motors.h +++ b/firmware/controllers/actuators/dc_motors.h @@ -13,7 +13,7 @@ class DcMotor; class Logger; -DcMotor* initDcMotor(size_t index DECLARE_ENGINE_PARAMETER_SUFFIX); +DcMotor* initDcMotor(size_t index, bool useTwoWires DECLARE_ENGINE_PARAMETER_SUFFIX); // Manual control of motors for use by console commands void setDcMotorFrequency(size_t index, int hz); diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 2b0b399fba..4dad7da054 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -682,7 +682,7 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1; for (int i = 0 ; i < engine->etbActualCount; i++) { - auto motor = initDcMotor(i PASS_ENGINE_PARAMETER_SUFFIX); + auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX); // If this motor is actually set up, init the etb if (motor) diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index fa168795ae..df3afa96dc 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -595,8 +595,8 @@ void initIdleHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) { StepperHw* hw; if (CONFIG(useHbridges)) { - auto motorA = initDcMotor(0 PASS_ENGINE_PARAMETER_SUFFIX); - auto motorB = initDcMotor(1 PASS_ENGINE_PARAMETER_SUFFIX); + auto motorA = initDcMotor(2, /*useTwoWires*/ true PASS_ENGINE_PARAMETER_SUFFIX); + auto motorB = initDcMotor(3, /*useTwoWires*/ true PASS_ENGINE_PARAMETER_SUFFIX); if (motorA && motorB) { iacHbridgeHw.initialize( diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 2d4e423736..d4fe11b572 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -691,7 +691,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 14300 +#define RAM_UNUSED_SIZE 13600 #endif #ifndef CCM_UNUSED_SIZE #define CCM_UNUSED_SIZE 2900 diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 37911cd8a1..42ebe2ee44 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -880,7 +880,9 @@ custom maf_sensor_type_e 4 bits, S32, @OFFSET@, [0:7], @@maf_sensor_type_e_enum@ stft_s stft - int[94] unusedAtOldBoardConfigurationEnd; + etb_io[ETB_COUNT iterate] etbIo2 + + int[92] unusedAtOldBoardConfigurationEnd; bit vvtDisplayInverted bit fuelClosedLoopCorrectionEnabled;+Enables lambda sensor closed loop feedback for fuelling.