diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index b6f2bde7a9..4ff774e8af 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -93,53 +93,6 @@ void setSingleCoilDwell(engine_configuration_s *engineConfiguration) { #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) -static void addIgnitionEvent(angle_t localAdvance, angle_t dwellAngle, IgnitionEventList *list, IgnitionOutputPin *output DECLARE_ENGINE_PARAMETER_S) { - IgnitionEvent *event = list->add(); - - if (!isPinAssigned(output)) { - // todo: extact method for this index math - warning(CUSTOM_OBD_PIN_NOT_ASSIGNED, "no_pin_cl #%s", output->name); - } - event->output = output; - event->advance = localAdvance; - - findTriggerPosition(&event->dwellPosition, localAdvance - dwellAngle PASS_ENGINE_PARAMETER); - -#if EFI_UNIT_TEST || defined(__DOXYGEN__) - printf("addIgnitionEvent %s ind=%d\n", output->name, event->dwellPosition.eventIndex); - // scheduleMsg(logger, "addIgnitionEvent %s ind=%d", output->name, event->dwellPosition->eventIndex); -#endif /* FUEL_MATH_EXTREME_LOGGING */ - -} - -void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, - IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { - efiAssertVoid(engineConfiguration->specs.cylindersCount > 0, "cylindersCount"); - - list->reset(); - - for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { - // todo: clean up this implementation? does not look too nice as is. - - // change of sign here from 'before TDC' to 'after TDC' - angle_t localAdvance = -advance + ENGINE(angleExtra[i]); - int index = ENGINE(ignitionPin[i]); - int cylinderIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); - IgnitionOutputPin *output = &enginePins.coils[cylinderIndex]; - - addIgnitionEvent(localAdvance, dwellAngle, list, output PASS_ENGINE_PARAMETER); - - if (CONFIG(ignitionMode) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { - index += CONFIG(specs.cylindersCount) / 2; - cylinderIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); - output = &enginePins.coils[cylinderIndex]; - - addIgnitionEvent(localAdvance, dwellAngle, list, output PASS_ENGINE_PARAMETER); - } - - } -} - void FuelSchedule::registerInjectionEvent(int injectorIndex, float angle, angle_t injectionDuration, bool isSimultanious DECLARE_ENGINE_PARAMETER_S) { diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 606db3d3b7..9f9dc2112e 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -19,9 +19,6 @@ void setAlgorithm(engine_load_mode_e algo DECLARE_ENGINE_PARAMETER_S); void findTriggerPosition( event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_S); -void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, - IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S); - #if EFI_ENABLE_ASSERTS #define assertAngleRange(angle) if(angle > 10000000 || angle < -10000000) { firmwareError(OBD_PCM_Processor_Fault, "angle range");angle = 0;} #else diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 0ca9012735..6e0d577ed8 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -182,6 +182,53 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI } } +static void addIgnitionEvent(angle_t localAdvance, angle_t dwellAngle, IgnitionEventList *list, IgnitionOutputPin *output DECLARE_ENGINE_PARAMETER_S) { + IgnitionEvent *event = list->add(); + + if (!isPinAssigned(output)) { + // todo: extract method for this index math + warning(CUSTOM_OBD_PIN_NOT_ASSIGNED, "no_pin_cl #%s", output->name); + } + event->output = output; + event->advance = localAdvance; + + findTriggerPosition(&event->dwellPosition, localAdvance - dwellAngle PASS_ENGINE_PARAMETER); + +#if EFI_UNIT_TEST || defined(__DOXYGEN__) + printf("addIgnitionEvent %s ind=%d\n", output->name, event->dwellPosition.eventIndex); + // scheduleMsg(logger, "addIgnitionEvent %s ind=%d", output->name, event->dwellPosition->eventIndex); +#endif /* FUEL_MATH_EXTREME_LOGGING */ + +} + +static void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, + IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { + efiAssertVoid(engineConfiguration->specs.cylindersCount > 0, "cylindersCount"); + + list->reset(); + + for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { + // todo: clean up this implementation? does not look too nice as is. + + // change of sign here from 'before TDC' to 'after TDC' + angle_t localAdvance = -advance + ENGINE(angleExtra[i]); + int index = ENGINE(ignitionPin[i]); + int cylinderIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); + IgnitionOutputPin *output = &enginePins.coils[cylinderIndex]; + + addIgnitionEvent(localAdvance, dwellAngle, list, output PASS_ENGINE_PARAMETER); + + if (CONFIG(ignitionMode) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { + index += CONFIG(specs.cylindersCount) / 2; + cylinderIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); + output = &enginePins.coils[cylinderIndex]; + + addIgnitionEvent(localAdvance, dwellAngle, list, output PASS_ENGINE_PARAMETER); + } + + } +} + static ALWAYS_INLINE void prepareIgnitionSchedule(int rpm, int revolutionIndex DECLARE_ENGINE_PARAMETER_S) { engine->m.beforeIgnitionSch = GET_TIMESTAMP();