diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index ae958101f6..f91e5ac2dc 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -471,9 +471,13 @@ void commonInitEngineController() { initLaunchControl(); #endif -#if EFI_UNIT_TEST - engine->rpmCalculator.Register(); -#endif /* EFI_UNIT_TEST */ +#if EFI_SHAFT_POSITION_INPUT + /** + * there is an implicit dependency on the fact that 'tachometer' listener is the 1st listener - this case + * other listeners can access current RPM value + */ + initRpmCalculator(); +#endif /* EFI_SHAFT_POSITION_INPUT */ #if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || EFI_SIMULATOR || EFI_UNIT_TEST if (engineConfiguration->isEngineControlEnabled) { diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 21aee2c105..30772ba46a 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -381,6 +381,21 @@ void tdcMarkCallback( } } +void initRpmCalculator() { + +#if ! HW_CHECK_MODE + if (hasFirmwareError()) { + return; + } +#endif // HW_CHECK_MODE + + // Only register if not configured to read RPM over OBD2 + if (!engineConfiguration->consumeObdSensors) { + engine->rpmCalculator.Register(); + } + +} + /** * Schedules a callback 'angle' degree of crankshaft from now. * The callback would be executed once after the duration of time which diff --git a/firmware/controllers/engine_cycle/rpm_calculator.h b/firmware/controllers/engine_cycle/rpm_calculator.h index 8824ae2454..daf3dd2aaf 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.h +++ b/firmware/controllers/engine_cycle/rpm_calculator.h @@ -174,6 +174,10 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t trgEventIn void tdcMarkCallback( uint32_t trgEventIndex, efitick_t edgeTimestamp); +/** + * @brief Initialize RPM calculator + */ +void initRpmCalculator(); operation_mode_e lookupOperationMode(); #define getRevolutionCounter() (engine->rpmCalculator.getRevolutionCounterM()) diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input.cpp b/firmware/hw_layer/digital_input/trigger/trigger_input.cpp index 6c35aa243e..f08fcab84e 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input.cpp +++ b/firmware/hw_layer/digital_input/trigger/trigger_input.cpp @@ -183,20 +183,9 @@ void startTriggerDebugPins() { } void applyNewTriggerInputPins() { - if (hasFirmwareError()) { - return; - } - #if EFI_PROD_CODE // first we will turn off all the changed pins stopTriggerInputPins(); - if (engineConfiguration->triggerInputDebugPins[0] != activeConfiguration.triggerInputDebugPins[0]) { - engine->rpmCalculator.unregister(); - if (!hasFirmwareError() && engineConfiguration->triggerInputDebugPins[0] != Gpio::Unassigned) { - // if we do not have primary input channel maybe it's BCM mode and we inject RPM value via Lua? - engine->rpmCalculator.Register(); - } - } // then we will enable all the changed pins startTriggerInputPins(); #endif /* EFI_PROD_CODE */