diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index d3fa7ab140..b929ac66c6 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -72,13 +72,13 @@ static Logging *logger; void startSimultaniousInjection(Engine *engine) { for (int i = 0; i < engine->engineConfigurationPtr->specs.cylindersCount; i++) { - enginePins.injectors[i].setHigh(); + enginePins.injectors[i].open(); } } static void endSimultaniousInjectionOnlyTogglePins(Engine *engine) { for (int i = 0; i < engine->engineConfigurationPtr->specs.cylindersCount; i++) { - enginePins.injectors[i].setLow(); + enginePins.injectors[i].close(); } } @@ -93,14 +93,14 @@ void endSimultaniousInjection(InjectionEvent *event) { engine->injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX); } -static inline void turnInjectionPinHigh(InjectorOutputPin *output) { - output->overlappingCounter++; +void InjectorOutputPin::open() { + overlappingCounter++; #if FUEL_MATH_EXTREME_LOGGING - printf("turnInjectionPinHigh %s %d %d\r\n", output->name, output->overlappingCounter, (int)getTimeNowUs()); + printf("turnInjectionPinHigh %s %d %d\r\n", name, overlappingCounter, (int)getTimeNowUs()); #endif /* FUEL_MATH_EXTREME_LOGGING */ - if (output->overlappingCounter > 1) { + if (overlappingCounter > 1) { // /** // * #299 // * this is another kind of overlap which happens in case of a small duty cycle after a large duty cycle @@ -109,13 +109,7 @@ static inline void turnInjectionPinHigh(InjectorOutputPin *output) { printf("overlapping, no need to touch pin %s %d\r\n", output->name, (int)getTimeNowUs()); #endif /* FUEL_MATH_EXTREME_LOGGING */ } else { -#if FUEL_MATH_EXTREME_LOGGING - const char * w = output->currentLogicValue == true ? "err" : ""; -// scheduleMsg(&sharedLogger, "^ %spin=%s eventIndex %d %d", w, output->name, -// getRevolutionCounter(), getTimeNowUs()); -#endif /* FUEL_MATH_EXTREME_LOGGING */ - - output->setHigh(); + setHigh(); } } @@ -130,33 +124,24 @@ void turnInjectionPinHigh(InjectionEvent *event) { InjectorOutputPin *output = event->outputs[i]; if (output) { - turnInjectionPinHigh(output); + output->open(); } } } -static inline void turnInjectionPinLow(InjectorOutputPin *output) { +void InjectorOutputPin::close() { #if FUEL_MATH_EXTREME_LOGGING - printf("turnInjectionPinLow %s %d %d\r\n", output->name, output->overlappingCounter, (int)getTimeNowUs()); + printf("turnInjectionPinLow %s %d %d\r\n", name, overlappingCounter, (int)getTimeNowUs()); #endif /* FUEL_MATH_EXTREME_LOGGING */ - + overlappingCounter--; + if (overlappingCounter > 0) { #if FUEL_MATH_EXTREME_LOGGING - const char * w = output->currentLogicValue == false ? "err" : ""; - -// scheduleMsg(&sharedLogger, "- %spin=%s eventIndex %d %d", w, output->name, -// getRevolutionCounter(), getTimeNowUs()); + printf("was overlapping, no need to touch pin %s %d\r\n", name, (int)getTimeNowUs()); #endif /* FUEL_MATH_EXTREME_LOGGING */ - - output->overlappingCounter--; - if (output->overlappingCounter > 0) { -#if FUEL_MATH_EXTREME_LOGGING - printf("was overlapping, no need to touch pin %s %d\r\n", output->name, (int)getTimeNowUs()); -#endif /* FUEL_MATH_EXTREME_LOGGING */ - } else { - output->setLow(); - } - + } else { + setLow(); + } } void turnInjectionPinLow(InjectionEvent *event) { @@ -169,8 +154,8 @@ void turnInjectionPinLow(InjectionEvent *event) { event->isScheduled = false; for (int i = 0;ioutputs[i]; - if (output != NULL) { - turnInjectionPinLow(output); + if (output) { + output->close(); } } #if EFI_UNIT_TEST diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index 3113c91e80..8971e0cfa9 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -107,8 +107,14 @@ class InjectorOutputPin : public NamedOutputPin { public: InjectorOutputPin(); void reset(); + + void open(); + void close(); + // todo: re-implement this injectorIndex via address manipulation to reduce memory usage? int8_t injectorIndex; + +private: int8_t overlappingCounter; };