From 014cae25dbc0a0cfde18c47419344c2bd0aee076 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 16 Nov 2020 20:07:12 -0500 Subject: [PATCH] DC not ETB refactoring --- firmware/controllers/actuators/dc_motors.cpp | 17 ++--------------- firmware/controllers/actuators/dc_motors.h | 2 +- .../actuators/electronic_throttle.cpp | 2 +- .../controllers/actuators/idle_hardware.cpp | 4 ++-- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/firmware/controllers/actuators/dc_motors.cpp b/firmware/controllers/actuators/dc_motors.cpp index 70cea0706a..bfb8008c54 100644 --- a/firmware/controllers/actuators/dc_motors.cpp +++ b/firmware/controllers/actuators/dc_motors.cpp @@ -94,22 +94,9 @@ public: } }; -static DcHardware dcHardware[ETB_COUNT * 2]; +static DcHardware dcHardware[ETB_COUNT + DC_PER_STEPPER]; -// We needed more H-bridge configs - so the IO configs are split -// across two arrays of settings to preserve config compatibility -const dc_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->stepperDcIo[index - firstSize]; -} - -DcMotor* initDcMotor(size_t index, bool useTwoWires DECLARE_ENGINE_PARAMETER_SUFFIX) { - const auto& io = getConfigForMotor(index PASS_ENGINE_PARAMETER_SUFFIX); +DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires DECLARE_ENGINE_PARAMETER_SUFFIX) { auto& hw = dcHardware[index]; hw.start( diff --git a/firmware/controllers/actuators/dc_motors.h b/firmware/controllers/actuators/dc_motors.h index 2c8d209e6d..8210fbb212 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, bool useTwoWires DECLARE_ENGINE_PARAMETER_SUFFIX); +DcMotor* initDcMotor(const dc_io& io, 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 497f4b12e9..690663e1a0 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -841,7 +841,7 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { bool anyEtbConfigured = false; for (int i = 0 ; i < ETB_COUNT; i++) { - auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX); + auto motor = initDcMotor(engineConfiguration->etbIo[i], 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_hardware.cpp b/firmware/controllers/actuators/idle_hardware.cpp index fb8136b0a7..f19f98536c 100644 --- a/firmware/controllers/actuators/idle_hardware.cpp +++ b/firmware/controllers/actuators/idle_hardware.cpp @@ -139,8 +139,8 @@ void initIdleHardware(Logging* sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { StepperHw* hw; if (CONFIG(useHbridges)) { - auto motorA = initDcMotor(2, /*useTwoWires*/ true PASS_ENGINE_PARAMETER_SUFFIX); - auto motorB = initDcMotor(3, /*useTwoWires*/ true PASS_ENGINE_PARAMETER_SUFFIX); + auto motorA = initDcMotor(engineConfiguration->stepperDcIo[0], 2, /*useTwoWires*/ true PASS_ENGINE_PARAMETER_SUFFIX); + auto motorB = initDcMotor(engineConfiguration->stepperDcIo[1], 3, /*useTwoWires*/ true PASS_ENGINE_PARAMETER_SUFFIX); if (motorA && motorB) { iacHbridgeHw.initialize(