diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index f4fd526c78..c422487e46 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -387,6 +387,7 @@ static void setBit(const char *offsetStr, const char *bitStr, const char *valueS * this response is part of dev console API */ scheduleMsg(&logger, "bit @%d/%d is %d", offset, bit, value); + applyNewConfiguration(); } static void setShort(const int offset, const int value) { @@ -395,6 +396,7 @@ static void setShort(const int offset, const int value) { uint16_t *ptr = (uint16_t *) (&((char *) engineConfiguration)[offset]); *ptr = (uint16_t) value; getShort(offset); + applyNewConfiguration(); } static void getBit(int offset, int bit) { @@ -425,6 +427,7 @@ static void setInt(const int offset, const int value) { int *ptr = (int *) (&((char *) engineConfiguration)[offset]); *ptr = value; getInt(offset); + applyNewConfiguration(); } static void getFloat(int offset) { @@ -533,7 +536,6 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { #if (EFI_PROD_CODE && EFI_ENGINE_CONTROL) || defined(__DOXYGEN__) initInjectorCentral(); - initIgnitionCentral(); /** * This has to go after 'initInjectorCentral' and 'initInjectorCentral' in order to * properly detect un-assigned output pins diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index b86e169b04..dfce90de2d 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -43,14 +43,6 @@ static int is_injector_enabled[MAX_INJECTOR_COUNT]; extern engine_pins_s enginePins; -void initIgnitionCentral(void) { - for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { - NamedOutputPin *output = &enginePins.coils[i]; - outputPinRegisterExt2(output->name, output, boardConfiguration->ignitionPins[i], - &boardConfiguration->ignitionPinMode); - } -} - bool_t isRunningBenchTest(void) { return isRunningBench; } @@ -216,11 +208,40 @@ static msg_t benchThread(int param) { extern engine_configuration_s activeConfiguration; +static void unregister(brain_pin_e currentPin, OutputPin *output) { + if (currentPin == GPIO_UNASSIGNED) + return; + scheduleMsg(&logger, "unregistering %s", hwPortname(currentPin)); + unmarkPin(currentPin); + output->unregister(); +} + +void stopIgnitionPins(void) { + for (int i = 0; i < IGNITION_PIN_COUNT; i++) { + NamedOutputPin *output = &enginePins.injectors[i]; + brain_pin_e currentPin = activeConfiguration.bc.ignitionPins[i]; + if (engineConfiguration->bc.ignitionPins[i] != currentPin) { + unregister(currentPin, output); + } + } +} + void stopInjectionPins(void) { for (int i = 0; i < INJECTION_PIN_COUNT; i++) { NamedOutputPin *output = &enginePins.injectors[i]; - if (engineConfiguration->bc.injectionPins[i] != activeConfiguration.bc.injectionPins[i]) { -// unmarkPin + brain_pin_e currentPin = activeConfiguration.bc.injectionPins[i]; + if (engineConfiguration->bc.injectionPins[i] != currentPin) { + unregister(currentPin, output); + } + } +} + +void startIgnitionPins(void) { + for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { + NamedOutputPin *output = &enginePins.coils[i]; + if (boardConfiguration->ignitionPins[i] != activeConfiguration.bc.ignitionPins[i]) { + outputPinRegisterExt2(output->name, output, boardConfiguration->ignitionPins[i], + &boardConfiguration->ignitionPinMode); } } } @@ -245,7 +266,7 @@ void initInjectorCentral(void) { } startInjectionPins(); - + startIgnitionPins(); printStatus(); addConsoleActionII("injector", setInjectorEnabled); diff --git a/firmware/controllers/injector_central.h b/firmware/controllers/injector_central.h index d4a67e48df..13773dd282 100644 --- a/firmware/controllers/injector_central.h +++ b/firmware/controllers/injector_central.h @@ -17,7 +17,6 @@ void fanBench(void); void fuelPumpBench(void); void initInjectorCentral(void); -void initIgnitionCentral(void); bool_t isRunningBenchTest(void); int isInjectorEnabled(int cylinderId); void assertCylinderId(int cylinderId, const char *msg); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 4bddd7e95e..65053f8140 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -603,6 +603,7 @@ static void setIgnitionPin(const char *indexStr, const char *pinName) { } scheduleMsg(&logger, "setting ignition pin[%d] to %s please save&restart", index, hwPortname(pin)); boardConfiguration->ignitionPins[index] = pin; + applyNewConfiguration(); } static void setIndividualPin(const char *pinName, brain_pin_e *targetPin, const char *name) { @@ -613,6 +614,7 @@ static void setIndividualPin(const char *pinName, brain_pin_e *targetPin, const } scheduleMsg(&logger, "setting %s pin to %s please save&restart", name, hwPortname(pin)); *targetPin = pin; + applyNewConfiguration(); } // set_idle_pin none @@ -648,6 +650,7 @@ static void setInjectionPin(const char *indexStr, const char *pinName) { } scheduleMsg(&logger, "setting injection pin[%d] to %s please save&restart", index, hwPortname(pin)); boardConfiguration->injectionPins[index] = pin; + applyNewConfiguration(); } static void setTriggerInputPin(const char *indexStr, const char *pinName) { @@ -662,6 +665,7 @@ static void setTriggerInputPin(const char *indexStr, const char *pinName) { } scheduleMsg(&logger, "setting trigger pin[%d] to %s please save&restart", index, hwPortname(pin)); boardConfiguration->triggerInputPins[index] = pin; + applyNewConfiguration(); } static void setTriggerSimulatorMode(const char *indexStr, const char *modeCode) { @@ -687,6 +691,7 @@ static void setEgtCSPin(const char *indexStr, const char *pinName, board_configu } scheduleMsg(&logger, "setting EGT CS pin[%d] to %s please save&restart", index, hwPortname(pin)); boardConfiguration->max31855_cs[index] = pin; + applyNewConfiguration(); } static void setTriggerSimulatorPin(const char *indexStr, const char *pinName) { @@ -700,6 +705,7 @@ static void setTriggerSimulatorPin(const char *indexStr, const char *pinName) { } scheduleMsg(&logger, "setting trigger simulator pin[%d] to %s please save&restart", index, hwPortname(pin)); boardConfiguration->triggerSimulatorPins[index] = pin; + applyNewConfiguration(); } #if HAL_USE_ADC || defined(__DOXYGEN__) @@ -727,6 +733,7 @@ static void setAnalogInputPin(const char *sensorStr, const char *pinName) { engineConfiguration->tpsAdcChannel = channel; scheduleMsg(&logger, "setting TPS to %s/%d", pinName, channel); } + applyNewConfiguration(); } #endif diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index d73f7e6a43..ec3d40127d 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -51,8 +51,14 @@ bool_t OutputPin::getLogicValue() { return currentLogicValue; } +void OutputPin::unregister() { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + port = NULL; +#endif +} + void OutputPin::setDefaultPinState(pin_output_mode_e *outputMode) { -#if EFI_GPIO +#if EFI_GPIO || defined(__DOXYGEN__) pin_output_mode_e mode = *outputMode; assertOMode(mode); this->modePtr = outputMode; diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index 97d940e5b2..3385324a92 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -25,6 +25,7 @@ public: void setValue(int logicValue); void setDefaultPinState(pin_output_mode_e *defaultState); bool_t getLogicValue(); + void unregister(); #if EFI_PROD_CODE || defined(__DOXYGEN__) GPIO_TypeDef *port; int pin; diff --git a/java_console/ui/src/com/rusefi/ui/SettingsTab.java b/java_console/ui/src/com/rusefi/ui/SettingsTab.java index b9bd1534e9..7894f96de7 100644 --- a/java_console/ui/src/com/rusefi/ui/SettingsTab.java +++ b/java_console/ui/src/com/rusefi/ui/SettingsTab.java @@ -17,6 +17,7 @@ public class SettingsTab { panel.add(UiUtils.wrap(new EnumConfigField(Fields.triggerInputPins1, "trigger #1 input").getContent())); panel.add(UiUtils.wrap(new EnumConfigField(Fields.triggerInputPins2, "trigger #2 input").getContent())); // panel.add(UiUtils.wrap(new EnumConfigField(Fields.triggerInputPins3, "trigger #3 input").getContent())); + panel.add(UiUtils.wrap(new EnumConfigField(Fields.injector1, "injector #1").getContent())); panel.add(UiUtils.wrap(RecentCommands.createButton(new AtomicBoolean(), "writeconfig"))); }