diff --git a/firmware/controllers/algo/engine_configuration_defaults.h b/firmware/controllers/algo/engine_configuration_defaults.h index 2417d1111e..bc9918c597 100644 --- a/firmware/controllers/algo/engine_configuration_defaults.h +++ b/firmware/controllers/algo/engine_configuration_defaults.h @@ -27,7 +27,9 @@ namespace engine_configuration_defaults { /* Other Sensor Inputs: */ constexpr switch_input_pin_e CLUTCH_DOWN_PIN = Gpio::Unassigned; - constexpr bool CLUTCH_DOWN_PIN_INVERTED = false; + constexpr bool CLUTCH_DOWN_PIN_INVERTED = false; + constexpr switch_input_pin_e CLUTCH_UP_PIN = Gpio::Unassigned; + constexpr bool CLUTCH_UP_PIN_INVERTED = false; /* Launch Control: */ constexpr switch_input_pin_e LAUNCH_ACTIVATE_PIN = Gpio::Unassigned; diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index a2559975e4..6086024fd2 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -605,6 +605,7 @@ typedef enum __attribute__ ((__packed__)) { TORQUE_REDUCTION_BUTTON = 0, LAUNCH_BUTTON = 1, TORQUE_REDUCTION_CLUTCH_DOWN_SWITCH = 2, + TORQUE_REDUCTION_CLUTCH_UP_SWITCH = 3, } torqueReductionActivationMode_e; typedef enum __attribute__ ((__packed__)) { diff --git a/firmware/controllers/algo/shift_torque_reduction_controller.cpp b/firmware/controllers/algo/shift_torque_reduction_controller.cpp index c599849325..8e6a27cf67 100644 --- a/firmware/controllers/algo/shift_torque_reduction_controller.cpp +++ b/firmware/controllers/algo/shift_torque_reduction_controller.cpp @@ -59,6 +59,14 @@ void ShiftTorqueReductionController::updateTriggerPinState() { ); break; } + case TORQUE_REDUCTION_CLUTCH_UP_SWITCH: { + updateTriggerPinState( + engineConfiguration->clutchUpPin, + engineConfiguration->clutchUpPinInverted, + engine->engineState.lua.clutchUpState + ); + break; + } default: { break; // we shouldn't be here! } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 8594505a8e..2ae9f3f0cb 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1445,7 +1445,7 @@ float tChargeAirDecrLimit;Maximum allowed rate of decrease allowed for the estim pin_input_mode_e torqueReductionTriggerPinMode; - #define torqueReductionActivationMode_e_enum "Torque Reduction Button", "Launch Button", "Clutch Down Switch" + #define torqueReductionActivationMode_e_enum "Torque Reduction Button", "Launch Button", "Clutch Down Switch", "Clutch Up Switch" custom torqueReductionActivationMode_e 1 bits, S08, @OFFSET@, [0:1], @@torqueReductionActivationMode_e_enum@@ torqueReductionActivationMode_e torqueReductionActivationMode; diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index 7c74f17b70..d9b78e1e2e 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -5011,11 +5011,17 @@ dialog = tcuControls, "Transmission Settings" field = "Clutch Down Inverted", clutchDownPinInverted, {clutchDownPin != 0} field = "Clutch Down Mode", clutchDownPinMode, {clutchDownPin != 0} + dialog = ClutchUpDialog, "Clutch Up" + field = "Clutch Up", clutchUpPin + field = "Clutch Up Inverted", clutchUpPinInverted, {clutchUpPin != 0} + field = "Clutch Up Mode", clutchUpPinMode, {clutchUpPin != 0} + dialog = TorqueReductionActivationModeDialog, "Activation", yAxis field = "Activation Mode", torqueReductionActivationMode panel = TorqueReductionButtonDialog, {torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_BUTTON@@} panel = LaunchButtonDialog, {torqueReductionActivationMode == @@torqueReductionActivationMode_e_LAUNCH_BUTTON@@} panel = ClutchDownDialog, {torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_CLUTCH_DOWN_SWITCH@@} + panel = ClutchUpDialog, {torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_CLUTCH_UP_SWITCH@@} dialog = TorqueReductionSettings, "Settings" field = "Limit Torque Reduction Time", limitTorqueReductionTime @@ -5028,7 +5034,7 @@ dialog = tcuControls, "Transmission Settings" dialog = ShiftTorqueReductionSettingsDialog, "", yAxis field = "Enable Shift Torque Reduction", torqueReductionEnabled panel = TorqueReductionActivationModeDialog, {torqueReductionEnabled == 1} - panel = TorqueReductionSettings, {torqueReductionEnabled == 1 && ((torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_BUTTON@@) || (torqueReductionActivationMode == @@torqueReductionActivationMode_e_LAUNCH_BUTTON@@ && launchActivatePin != 0) || (torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_CLUTCH_DOWN_SWITCH@@))} + panel = TorqueReductionSettings, {torqueReductionEnabled == 1 && ((torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_BUTTON@@) || (torqueReductionActivationMode == @@torqueReductionActivationMode_e_LAUNCH_BUTTON@@ && launchActivatePin != 0) || (torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_CLUTCH_DOWN_SWITCH@@) || (torqueReductionActivationMode == @@torqueReductionActivationMode_e_TORQUE_REDUCTION_CLUTCH_UP_SWITCH@@))} dialog = ShiftTorqueReductionDialog, "", border panel = ShiftTorqueReductionSettingsDialog, West diff --git a/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_params.h b/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_params.h index 508102ced7..d577876836 100644 --- a/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_params.h +++ b/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_params.h @@ -12,6 +12,8 @@ enum class TestSwitchPin { LAUNCH, CLUTCH_DOWN, LUA_CLUTCH_DOWN, + CLUTCH_UP, + LUA_CLUTCH_UP, }; struct ShiftTorqueReductionSwitchParams { diff --git a/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.cpp b/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.cpp index fd9d9f5886..552f52ca65 100644 --- a/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.cpp +++ b/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.cpp @@ -10,7 +10,8 @@ const EngineConfig ShiftTorqueReductionSwitchTestBase::TEST_ENGINE_CONFIG = Engi .setTorqueReductionEnabled(true) .setTorqueReductionTriggerPin(TEST_TORQUE_REDUCTION_BUTTON_PIN) .setLaunchActivatePin(TEST_LAUNCH_BUTTON_PIN) - .setClutchDownPin(TEST_CLUTCH_DOWN_PIN); + .setClutchDownPin(TEST_CLUTCH_DOWN_PIN) + .setClutchUpPin(TEST_CLUTCH_UP_PIN); void ShiftTorqueReductionSwitchTestBase::SetUp() { TestBase::SetUp(); @@ -56,6 +57,14 @@ void ShiftTorqueReductionSwitchTestBase::setPinState(const TestSwitchPin pin, co getTestLuaScriptExecutor().setClutchDownState(state); break; } + case TestSwitchPin::CLUTCH_UP: { + setMockState(TEST_CLUTCH_UP_PIN, state);; + break; + } + case TestSwitchPin::LUA_CLUTCH_UP: { + getTestLuaScriptExecutor().setClutchUpState(state); + break; + } default: { FAIL() << "Unexpected pin:" << static_cast(pin); break; diff --git a/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.h b/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.h index 100956c4af..40229c5b3a 100644 --- a/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.h +++ b/unit_tests/tests/shift_torque_reduction/shift_torque_reduction_switch_test_base.h @@ -17,6 +17,7 @@ protected: static constexpr switch_input_pin_e TEST_TORQUE_REDUCTION_BUTTON_PIN = Gpio::F15; static constexpr switch_input_pin_e TEST_LAUNCH_BUTTON_PIN = Gpio::G15; static constexpr switch_input_pin_e TEST_CLUTCH_DOWN_PIN = Gpio::E15; + static constexpr switch_input_pin_e TEST_CLUTCH_UP_PIN = Gpio::D15; void SetUp() override; diff --git a/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_inverted_switch.cpp b/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_inverted_switch.cpp index f52f1bf2ce..de08e98cff 100644 --- a/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_inverted_switch.cpp +++ b/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_inverted_switch.cpp @@ -59,6 +59,14 @@ namespace { .setClutchDownPinInverted(true), /* expectedIsTorqueReductionTriggerPinValid = */ true, /* description = */ "CLUTCH_DOWN" + }, + ShiftTorqueReductionSwitchParams { + /* inputPin = */ TestSwitchPin::CLUTCH_UP, + /* config = */ ShiftTorqueReductionSwitchTestBase::TEST_ENGINE_CONFIG.clone() + .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_CLUTCH_UP_SWITCH) + .setClutchUpPinInverted(true), + /* expectedIsTorqueReductionTriggerPinValid = */ true, + /* description = */ "CLUTCH_UP" } ) ); diff --git a/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_switch.cpp b/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_switch.cpp index 2e34b00cec..1b0bd1dfd9 100644 --- a/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_switch.cpp +++ b/unit_tests/tests/shift_torque_reduction/test_shift_torque_reduction_switch.cpp @@ -22,6 +22,8 @@ namespace { TestSwitchPin::LAUNCH, TestSwitchPin::CLUTCH_DOWN, TestSwitchPin::LUA_CLUTCH_DOWN, + TestSwitchPin::CLUTCH_UP, + TestSwitchPin::LUA_CLUTCH_UP, }; const bool expectedIsTorqueReductionTriggerPinValid = engine->shiftTorqueReductionController.isTorqueReductionTriggerPinValid; @@ -171,6 +173,47 @@ namespace { .setClutchDownPinInverted(true), /* expectedIsTorqueReductionTriggerPinValid = */ false, /* description = */ "LUA_CLUTCH_DOWN (pinInverted = true)" + }, + ShiftTorqueReductionSwitchParams { + /* inputPin = */ TestSwitchPin::CLUTCH_UP, + /* config = */ ShiftTorqueReductionSwitchTestBase::TEST_ENGINE_CONFIG.clone() + .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_CLUTCH_UP_SWITCH), + /* expectedIsTorqueReductionTriggerPinValid = */ true, + /* description = */ "CLUTCH_UP" + }, + ShiftTorqueReductionSwitchParams { + /* inputPin = */ TestSwitchPin::CLUTCH_UP, + /* config = */ ShiftTorqueReductionSwitchTestBase::TEST_ENGINE_CONFIG.clone() + .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_CLUTCH_UP_SWITCH) + .setClutchUpPinInverted(false), + /* expectedIsTorqueReductionTriggerPinValid = */ true, + /* description = */ "CLUTCH_UP (pinInverted = false)" + }, + ShiftTorqueReductionSwitchParams { + /* inputPin = */ TestSwitchPin::LUA_CLUTCH_UP, + /* config = */ ShiftTorqueReductionSwitchTestBase::TEST_ENGINE_CONFIG.clone() + .setClutchUpPin(Gpio::Unassigned) + .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_CLUTCH_UP_SWITCH), + /* expectedIsTorqueReductionTriggerPinValid = */ false, + /* description = */ "LUA_CLUTCH_UP" + }, + ShiftTorqueReductionSwitchParams { + /* inputPin = */ TestSwitchPin::LUA_CLUTCH_UP, + /* config = */ ShiftTorqueReductionSwitchTestBase::TEST_ENGINE_CONFIG.clone() + .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_CLUTCH_UP_SWITCH) + .setClutchUpPin(Gpio::Unassigned) + .setClutchUpPinInverted(false), + /* expectedIsTorqueReductionTriggerPinValid = */ false, + /* description = */ "LUA_CLUTCH_UP (pinInverted = false)" + }, + ShiftTorqueReductionSwitchParams { + /* inputPin = */ TestSwitchPin::LUA_CLUTCH_UP, + /* config = */ ShiftTorqueReductionSwitchTestBase::TEST_ENGINE_CONFIG.clone() + .setTorqueReductionActivationMode(torqueReductionActivationMode_e::TORQUE_REDUCTION_CLUTCH_UP_SWITCH) + .setClutchUpPin(Gpio::Unassigned) + .setClutchUpPinInverted(true), + /* expectedIsTorqueReductionTriggerPinValid = */ false, + /* description = */ "LUA_CLUTCH_UP (pinInverted = true)" } ) ); diff --git a/unit_tests/tests/util/engine_config.cpp b/unit_tests/tests/util/engine_config.cpp index 784ac84cb5..084331d5c2 100644 --- a/unit_tests/tests/util/engine_config.cpp +++ b/unit_tests/tests/util/engine_config.cpp @@ -16,8 +16,18 @@ EngineConfig EngineConfig::setClutchDownPin(const std::optional value) { - m_clutchDownPinInverted = value; - return *this; + m_clutchDownPinInverted = value; + return *this; +} + +EngineConfig EngineConfig::setClutchUpPin(const std::optional value) { + m_clutchUpPin = value; + return *this; +} + +EngineConfig EngineConfig::setClutchUpPinInverted(const std::optional value) { + m_clutchUpPinInverted = value; + return *this; } EngineConfig EngineConfig::setLaunchActivatePin(const std::optional value) { diff --git a/unit_tests/tests/util/engine_config.h b/unit_tests/tests/util/engine_config.h index aed73280c9..4ec319369f 100644 --- a/unit_tests/tests/util/engine_config.h +++ b/unit_tests/tests/util/engine_config.h @@ -12,7 +12,9 @@ public: // Other Sensor Inputs std::optional getClutchDownPin() const { return m_clutchDownPin; } - std::optional getClutchDownPinInverted() const { return m_clutchDownPinInverted; } + std::optional getClutchDownPinInverted() const { return m_clutchDownPinInverted; } + std::optional getClutchUpPin() const { return m_clutchUpPin; } + std::optional getClutchUpPinInverted() const { return m_clutchUpPinInverted; } // Launch Control std::optional getLaunchActivatePin() const { return m_launchActivatePin; } @@ -89,7 +91,9 @@ public: // Other Sensor Inputs EngineConfig setClutchDownPin(std::optional value); - EngineConfig setClutchDownPinInverted(std::optional value); + EngineConfig setClutchDownPinInverted(std::optional value); + EngineConfig setClutchUpPin(std::optional value); + EngineConfig setClutchUpPinInverted(std::optional value); // Launch Control EngineConfig setLaunchActivatePin(std::optional value); @@ -158,7 +162,9 @@ public: private: // Other Sensor Inputs std::optional m_clutchDownPin; - std::optional m_clutchDownPinInverted; + std::optional m_clutchDownPinInverted; + std::optional m_clutchUpPin; + std::optional m_clutchUpPinInverted; // Launch Control std::optional m_launchActivatePin; diff --git a/unit_tests/tests/util/test_base.hpp b/unit_tests/tests/util/test_base.hpp index 5f68c8796e..97e4dc1ba8 100644 --- a/unit_tests/tests/util/test_base.hpp +++ b/unit_tests/tests/util/test_base.hpp @@ -39,6 +39,8 @@ void TestBase::setUpEngineConfiguration(const EngineConfig& config) { // Other Sensor Inputs getTestEngineConfiguration().configureClutchDownPin(config.getClutchDownPin()); getTestEngineConfiguration().configureClutchDownPinInverted(config.getClutchDownPinInverted()); + getTestEngineConfiguration().configureClutchUpPin(config.getClutchUpPin()); + getTestEngineConfiguration().configureClutchUpPinInverted(config.getClutchUpPinInverted()); // Launch Control getTestEngineConfiguration().configureLaunchActivatePin(config.getLaunchActivatePin()); diff --git a/unit_tests/tests/util/test_engine_configuration.cpp b/unit_tests/tests/util/test_engine_configuration.cpp index 7975eb699d..d73a4fc989 100644 --- a/unit_tests/tests/util/test_engine_configuration.cpp +++ b/unit_tests/tests/util/test_engine_configuration.cpp @@ -24,14 +24,36 @@ void TestEngineConfiguration::configureClutchDownPin(const std::optional pinInverted) { - if (pinInverted.has_value()) { - engineConfiguration->clutchDownPinInverted = pinInverted.value(); - } else { - ASSERT_EQ( - engineConfiguration->clutchDownPinInverted, - engine_configuration_defaults::CLUTCH_DOWN_PIN_INVERTED - ); // check default value - } + if (pinInverted.has_value()) { + engineConfiguration->clutchDownPinInverted = pinInverted.value(); + } else { + ASSERT_EQ( + engineConfiguration->clutchDownPinInverted, + engine_configuration_defaults::CLUTCH_DOWN_PIN_INVERTED + ); // check default value + } +} + +void TestEngineConfiguration::configureClutchUpPin(const std::optional pin) { + if (pin.has_value()) { + engineConfiguration->clutchUpPin = pin.value(); + } else { + ASSERT_EQ( + engineConfiguration->clutchUpPin, + engine_configuration_defaults::CLUTCH_UP_PIN + ); // check default value + } +} + +void TestEngineConfiguration::configureClutchUpPinInverted(const std::optional pinInverted) { + if (pinInverted.has_value()) { + engineConfiguration->clutchUpPinInverted = pinInverted.value(); + } else { + ASSERT_EQ( + engineConfiguration->clutchUpPinInverted, + engine_configuration_defaults::CLUTCH_UP_PIN_INVERTED + ); // check default value + } } void TestEngineConfiguration::configureLaunchControlEnabled(const std::optional launchControlEnabled) { diff --git a/unit_tests/tests/util/test_engine_configuration.h b/unit_tests/tests/util/test_engine_configuration.h index fae79fef74..da662a1c4b 100644 --- a/unit_tests/tests/util/test_engine_configuration.h +++ b/unit_tests/tests/util/test_engine_configuration.h @@ -12,7 +12,9 @@ public: // Other Sensor Inputs void configureClutchDownPin(std::optional pin); - void configureClutchDownPinInverted(std::optional pinInverted); + void configureClutchDownPinInverted(std::optional pinInverted); + void configureClutchUpPin(std::optional pin); + void configureClutchUpPinInverted(std::optional pinInverted); // Launch Control Settings void configureLaunchControlEnabled(std::optional launchControlEnabled); diff --git a/unit_tests/tests/util/test_lua_script_executor.cpp b/unit_tests/tests/util/test_lua_script_executor.cpp index 7c0c28bd8b..2d3c74c22f 100644 --- a/unit_tests/tests/util/test_lua_script_executor.cpp +++ b/unit_tests/tests/util/test_lua_script_executor.cpp @@ -25,6 +25,10 @@ void TestLuaScriptExecutor::setClutchDownState(const bool state) { executeFormattedLuaScript("setClutchDownState(%s);", toLuaBoolean(state)); } +void TestLuaScriptExecutor::setClutchUpState(const bool state) { + executeFormattedLuaScript("setClutchUpState(%s);", toLuaBoolean(state)); +} + void TestLuaScriptExecutor::setTorqueReductionState(const bool state) { executeFormattedLuaScript("setTorqueReductionState(%s);", toLuaBoolean(state)); } diff --git a/unit_tests/tests/util/test_lua_script_executor.h b/unit_tests/tests/util/test_lua_script_executor.h index f2c397284a..8c520027b6 100644 --- a/unit_tests/tests/util/test_lua_script_executor.h +++ b/unit_tests/tests/util/test_lua_script_executor.h @@ -9,6 +9,7 @@ public: static TestLuaScriptExecutor& getInstance(); void setClutchDownState(bool state); + void setClutchUpState(bool state); void setTorqueReductionState(bool state); void setSparkSkipRatio(float sparkSkipRatio); void setSparkHardSkipRatio(float sparkSkipRatio);