diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 06ec5164b4..88602d9c66 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -675,7 +675,6 @@ typedef enum __attribute__ ((__packed__)) { HPFP_CAM_EX2 = 4, } hpfp_cam_e; - #if __cplusplus #include @@ -695,4 +694,16 @@ enum class TsCalMode : uint8_t { PedalMin = 12, PedalMax = 13, }; + +enum class GearControllerMode : uint8_t { + None = 0, + ButtonShift = 1, +}; + +enum class TransmissionControllerMode : uint8_t { + None = 0, + SimpleTransmissionController = 1, + Gm4l6x = 2, +}; + #endif // __cplusplus diff --git a/firmware/controllers/buttonshift.cpp b/firmware/controllers/buttonshift.cpp index 6498c93db9..515cf428c0 100644 --- a/firmware/controllers/buttonshift.cpp +++ b/firmware/controllers/buttonshift.cpp @@ -12,7 +12,6 @@ ButtonShiftController buttonShiftController; - ButtonShiftController::ButtonShiftController() : debounceUp("gear_up"), debounceDown("gear_down") @@ -81,8 +80,6 @@ void ButtonShiftController::update() { GearControllerBase::update(); } - -void initButtonShift() { - buttonShiftController.init(); - engine->gearController = &buttonShiftController; +ButtonShiftController* getButtonShiftController() { + return &buttonShiftController; } diff --git a/firmware/controllers/buttonshift.h b/firmware/controllers/buttonshift.h index 6896d66aa6..496e782e46 100644 --- a/firmware/controllers/buttonshift.h +++ b/firmware/controllers/buttonshift.h @@ -15,11 +15,12 @@ class ButtonShiftController: public GearControllerBase { public: ButtonShiftController(); - void update() override; - void init() override; + void update() override; + void init() override; + GearControllerMode mode = GearControllerMode::ButtonShift; private: - ButtonDebounce debounceUp; - ButtonDebounce debounceDown; + ButtonDebounce debounceUp; + ButtonDebounce debounceDown; }; -void initButtonShift(); +ButtonShiftController* getButtonShiftController(); diff --git a/firmware/controllers/controllers.mk b/firmware/controllers/controllers.mk index 578837df9e..2480390194 100644 --- a/firmware/controllers/controllers.mk +++ b/firmware/controllers/controllers.mk @@ -63,6 +63,7 @@ CONTROLLERS_SRC_CPP = \ $(CONTROLLERS_DIR)/gear_controller.cpp \ $(CONTROLLERS_DIR)/start_stop.cpp \ $(CONTROLLERS_DIR)/simple_tcu.cpp \ + $(CONTROLLERS_DIR)/tc_4l6x.cpp \ $(CONTROLLERS_DIR)/limp_manager.cpp \ CONTROLLERS_INC=\ diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 4602764302..41ae2e6a98 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -224,7 +224,12 @@ static void doPeriodicSlowCallback() { engine->periodicSlowCallback(); #endif /* if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */ - if (engineConfiguration->tcuEnabled) { + if (engineConfiguration->tcuEnabled && engineConfiguration->gearControllerMode != GearControllerMode::None) { + if (engine->gearController == NULL) { + initGearController(); + } else if (engine->gearController->mode != engineConfiguration->gearControllerMode) { + initGearController(); + } engine->gearController->update(); } } @@ -513,7 +518,7 @@ void commonInitEngineController() { startIdleThread(); #endif /* EFI_IDLE_CONTROL */ - initButtonShift(); + initGearController(); initButtonDebounce(); initStartStopButton(); diff --git a/firmware/controllers/gear_controller.cpp b/firmware/controllers/gear_controller.cpp index 0a9b429683..39688cccc3 100644 --- a/firmware/controllers/gear_controller.cpp +++ b/firmware/controllers/gear_controller.cpp @@ -3,15 +3,35 @@ #include "gear_controller.h" void GearControllerBase::init() { - transmissionController.init(); + initTransmissionController(); +} + +void GearControllerBase::initTransmissionController() { + switch (engineConfiguration->transmissionControllerMode) { + case TransmissionControllerMode::SimpleTransmissionController : + transmissionController = getSimpleTransmissionController(); + break; + case TransmissionControllerMode::Gm4l6x : + transmissionController = getGm4l6xTransmissionController(); + break; + default : + transmissionController = NULL; + return; + } + transmissionController->init(); } void GearControllerBase::update() { - // We are responsible for telling the transmission controller - // what gear we want. - transmissionController.update(getDesiredGear()); - // Post state to TS - postState(); + if (transmissionController == NULL) { + initTransmissionController(); + } else if (transmissionController->mode != engineConfiguration->transmissionControllerMode) { + initTransmissionController(); + } + // We are responsible for telling the transmission controller + // what gear we want. + transmissionController->update(getDesiredGear()); + // Post state to TS + postState(); } gear_e GearControllerBase::getDesiredGear() const { @@ -28,3 +48,15 @@ void GearControllerBase::postState() { engine->outputChannels.tcuDesiredGear = getDesiredGear(); #endif } + +void initGearController() { + switch (engineConfiguration->gearControllerMode) { + case GearControllerMode::ButtonShift : + engine->gearController = getButtonShiftController(); + break; + default : + engine->gearController = NULL; + return; + } + engine->gearController->init(); +} diff --git a/firmware/controllers/gear_controller.h b/firmware/controllers/gear_controller.h index 85830cfa1e..59b4b0080f 100644 --- a/firmware/controllers/gear_controller.h +++ b/firmware/controllers/gear_controller.h @@ -6,18 +6,23 @@ #include "engine_configuration_generated_structures.h" #include "globalaccess.h" #include "simple_tcu.h" +#include "tc_4l6x.h" class GearControllerBase { public: - virtual void update(); - gear_e getDesiredGear() const; - virtual void init(); + virtual void update(); + gear_e getDesiredGear() const; + virtual void init(); + GearControllerMode mode = GearControllerMode::None; private: - gear_e desiredGear = NEUTRAL; + gear_e desiredGear = NEUTRAL; protected: - gear_e setDesiredGear(gear_e); + gear_e setDesiredGear(gear_e); + void initTransmissionController(); private: - void postState(); - SimpleTransmissionController transmissionController; + void postState(); + TransmissionControllerBase *transmissionController; }; + +void initGearController(); diff --git a/firmware/controllers/simple_tcu.cpp b/firmware/controllers/simple_tcu.cpp index e4fce18b85..62957613c2 100644 --- a/firmware/controllers/simple_tcu.cpp +++ b/firmware/controllers/simple_tcu.cpp @@ -2,6 +2,8 @@ #include "simple_tcu.h" +SimpleTransmissionController simpleTransmissionController; + void SimpleTransmissionController::init() { for (size_t i = 0; i < efi::size(engineConfiguration->tcu_solenoid); i++) { enginePins.tcuSolenoids[i].initPin("Transmission Solenoid", engineConfiguration->tcu_solenoid[i], &engineConfiguration->tcu_solenoid_mode[i]); @@ -27,3 +29,7 @@ void SimpleTransmissionController::update(gear_e gear) { } #endif } + +SimpleTransmissionController* getSimpleTransmissionController() { + return &simpleTransmissionController; +} diff --git a/firmware/controllers/simple_tcu.h b/firmware/controllers/simple_tcu.h index ceba866afd..852465cae0 100644 --- a/firmware/controllers/simple_tcu.h +++ b/firmware/controllers/simple_tcu.h @@ -1,9 +1,14 @@ #pragma once +#define SIMPLE_TRANSMISSION_CONTROLLER + #include "tcu.h" class SimpleTransmissionController: public TransmissionControllerBase { public: - void update(gear_e); - void init(); + void update(gear_e); + void init(); + TransmissionControllerMode mode = TransmissionControllerMode::SimpleTransmissionController; }; + +SimpleTransmissionController* getSimpleTransmissionController(); diff --git a/firmware/controllers/tc_4l6x.cpp b/firmware/controllers/tc_4l6x.cpp new file mode 100644 index 0000000000..a81da87f56 --- /dev/null +++ b/firmware/controllers/tc_4l6x.cpp @@ -0,0 +1,35 @@ +#include "pch.h" + +#include "tc_4l6x.h" + +Gm4l6xTransmissionController gm4l6xTransmissionController; + +void Gm4l6xTransmissionController::init() { + for (size_t i = 0; i < efi::size(engineConfiguration->tcu_solenoid); i++) { + enginePins.tcuSolenoids[i].initPin("Transmission Solenoid", engineConfiguration->tcu_solenoid[i], &engineConfiguration->tcu_solenoid_mode[i]); + } +} + +void Gm4l6xTransmissionController::update(gear_e gear) { + for (size_t i = 0; i < efi::size(engineConfiguration->tcu_solenoid); i++) { +#if ! EFI_UNIT_TEST + enginePins.tcuSolenoids[i].setValue(config->tcuSolenoidTable[static_cast(gear) + 1][i]); +#endif + } + setCurrentGear(gear); + postState(); + +#if EFI_TUNER_STUDIO + if (engineConfiguration->debugMode == DBG_TCU) { + engine->outputChannels.debugIntField1 = config->tcuSolenoidTable[static_cast(gear) + 1][0]; + engine->outputChannels.debugIntField2 = config->tcuSolenoidTable[static_cast(gear) + 1][1]; + engine->outputChannels.debugIntField3 = config->tcuSolenoidTable[static_cast(gear) + 1][2]; + engine->outputChannels.debugIntField4 = config->tcuSolenoidTable[static_cast(gear) + 1][3]; + engine->outputChannels.debugIntField5 = config->tcuSolenoidTable[static_cast(gear) + 1][4]; + } +#endif +} + +Gm4l6xTransmissionController* getGm4l6xTransmissionController() { + return &gm4l6xTransmissionController; +} diff --git a/firmware/controllers/tc_4l6x.h b/firmware/controllers/tc_4l6x.h new file mode 100644 index 0000000000..5350d36cb4 --- /dev/null +++ b/firmware/controllers/tc_4l6x.h @@ -0,0 +1,12 @@ +#pragma once + +#include "tcu.h" + +class Gm4l6xTransmissionController: public TransmissionControllerBase { +public: + void update(gear_e); + void init(); + TransmissionControllerMode mode = TransmissionControllerMode::Gm4l6x; +}; + +Gm4l6xTransmissionController* getGm4l6xTransmissionController(); diff --git a/firmware/controllers/tcu.cpp b/firmware/controllers/tcu.cpp index ab1ada52cc..2d660c89fc 100644 --- a/firmware/controllers/tcu.cpp +++ b/firmware/controllers/tcu.cpp @@ -10,6 +10,9 @@ #include "tcu.h" +void TransmissionControllerBase::init() { +} + void TransmissionControllerBase::update(gear_e gear) { setCurrentGear(gear); postState(); diff --git a/firmware/controllers/tcu.h b/firmware/controllers/tcu.h index f060d5c956..786fddd2ad 100644 --- a/firmware/controllers/tcu.h +++ b/firmware/controllers/tcu.h @@ -15,12 +15,13 @@ class TransmissionControllerBase { public: - void update(gear_e); - void init(); - gear_e getCurrentGear() const; + void update(gear_e); + void init(); + gear_e getCurrentGear() const; + TransmissionControllerMode mode = TransmissionControllerMode::None; private: - gear_e currentGear = NEUTRAL; + gear_e currentGear = NEUTRAL; protected: - gear_e setCurrentGear(gear_e); - void postState(); + gear_e setCurrentGear(gear_e); + void postState(); }; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index e05fcb582c..171d307e6e 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1179,7 +1179,6 @@ int16_t tps2Max;Full throttle#2. tpsMax value as 10 bit ADC value. Not Voltage!\ brain_input_pin_e[2 iterate] auxSpeedSensorInputPin; uint8_t totalGearsCount;;"", 1, 0, 1, @@GEARS_COUNT@@, 0 uint8_t unused16962;;"", 1, 0, 0, 1, 0 - uint32_t uartConsoleSerialSpeed;Band rate for primary TTL;"BPs", 1, 0, 0, 1000000, 0 float tpsDecelEnleanmentThreshold;For decel we simply multiply delta of TPS and tFor decel we do not use table?!;"roc", 1, 0, 0, 200, 1 float tpsDecelEnleanmentMultiplier;Magic multiplier, we multiply delta of TPS and get fuel squirt duration;"coeff", 1, 0, 0, 200, 2 @@ -1519,7 +1518,13 @@ uint8_t[TORQUE_CURVE_SIZE x TORQUE_CURVE_SIZE] autoscale torqueTable;;"Nm", 10, uint16_t[TORQUE_CURVE_SIZE] torqueRpmBins;;"RPM", 1, 0, 0, 65000, 0 uint16_t[TORQUE_CURVE_SIZE] torqueLoadBins;;"Load", 1, 0, 0, 65000, 0 -uint8_t[2] unused4750;;"",0,0,0,0,0 +#define gear_controller_e_enum "None", "Button Shift" + custom GearControllerMode 1 bits, U08, @OFFSET@, [0:1], @@gear_controller_e_enum@@ + GearControllerMode gearControllerMode + +#define transmission_controller_e_enum "None", "Simple Transmission", "GM 4L6X" + custom TransmissionControllerMode 1 bits, U08, @OFFSET@, [0:1], @@transmission_controller_e_enum@@ + TransmissionControllerMode transmissionControllerMode linear_sensor_s auxLinear1 linear_sensor_s auxLinear2 diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 809f15d31b..9b29fd0a55 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -3404,6 +3404,8 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" dialog = transmissionPanel field = "TCU Enabled" tcuEnabled + field = "Gear Controller" gearControllerMode + field = "Transmission Controller" transmissionControllerMode dialog = solenoidPanel, "Shift Solenoids" field = "Solenoid 1 Pin" tcu_solenoid1, { tcuEnabled }