diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index c8b9f8b1dd..7134745a67 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -915,6 +915,9 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ #endif // EFI_ENGINE_CONTROL switch (engineConfiguration->debugMode) { + case DBG_START_STOP: + tsOutputChannels->debugIntField1 = engine->startStopStateToggleCounter; + break; case DBG_AUX_TEMPERATURE: // // 68 tsOutputChannels->debugFloatField1 = engine->sensors.auxTemp1; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 502322661a..6076943b55 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -176,6 +176,11 @@ public: */ efitick_t stopEngineRequestTimeNt = 0; + + bool startStopState = false; + efitick_t startStopStateLastPushTime = 0; + int startStopStateToggleCounter = 0; + /** * This counter is incremented every time user adjusts ECU parameters online (either via rusEfi console or other * tuning software) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index d7d4b44566..509fa58c70 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -246,6 +246,20 @@ static void resetAccel(void) { } } +static void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + if (CONFIG(startStopButtonPin) != GPIO_UNASSIGNED) { +#if EFI_PROD_CODE + bool startStopState = efiReadPin(CONFIG(startStopButtonPin)); + + if (startStopState && !engine->startStopState) { + // we are here on transition from 0 to 1 + engine->startStopStateToggleCounter++; + } + engine->startStopState = startStopState; +#endif /* EFI_PROD_CODE */ + } +} + static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT efiAssertVoid(CUSTOM_ERR_6661, getCurrentRemainingStack() > 64, "lowStckOnEv"); @@ -253,6 +267,8 @@ static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { touchTimeCounter(); #endif /* EFI_PROD_CODE */ + slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE); + /** * Update engine RPM state if needed (check timeouts). */ diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 997956d8ba..3f9b766e5b 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -255,8 +255,9 @@ void turnOnHardware(Logging *sharedLogger) { void stopSpi(spi_device_e device) { #if HAL_USE_SPI - if (!isSpiInitialized[device]) + if (!isSpiInitialized[device]) { return; // not turned on + } isSpiInitialized[device] = false; brain_pin_markUnused(getSckPin(device)); brain_pin_markUnused(getMisoPin(device)); @@ -309,17 +310,21 @@ void applyNewHardwareSettings(void) { stopAuxPins(); #endif /* EFI_AUX_PID */ - if (isConfigurationChanged(is_enabled_spi_1)) + if (isConfigurationChanged(is_enabled_spi_1)) { stopSpi(SPI_DEVICE_1); + } - if (isConfigurationChanged(is_enabled_spi_2)) + if (isConfigurationChanged(is_enabled_spi_2)) { stopSpi(SPI_DEVICE_2); + } - if (isConfigurationChanged(is_enabled_spi_3)) + if (isConfigurationChanged(is_enabled_spi_3)) { stopSpi(SPI_DEVICE_3); + } - if (isConfigurationChanged(is_enabled_spi_4)) + if (isConfigurationChanged(is_enabled_spi_4)) { stopSpi(SPI_DEVICE_4); + } #if EFI_HD44780_LCD stopHD44780_pins(); @@ -328,8 +333,13 @@ void applyNewHardwareSettings(void) { #if EFI_BOOST_CONTROL stopBoostPin(); #endif - if (isPinOrModeChanged(clutchUpPin, clutchUpPinMode)) + if (isPinOrModeChanged(clutchUpPin, clutchUpPinMode)) { brain_pin_markUnused(activeConfiguration.clutchUpPin); + } + + if (isPinOrModeChanged(startStopButtonPin, startStopButtonMode)) { + brain_pin_markUnused(activeConfiguration.startStopButtonPin); + } enginePins.unregisterPins();