From e7b1b80ce9a7af353fd33ec608c9408456bcb30f Mon Sep 17 00:00:00 2001 From: rusefillc Date: Thu, 5 Nov 2020 17:23:09 -0500 Subject: [PATCH] Output pin init/deinit needs a linked list #1803 --- firmware/controllers/system/efi_gpio.cpp | 48 ++++++++++++++++++------ firmware/controllers/system/efi_gpio.h | 2 + 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 8f31294966..869a88f69a 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -62,15 +62,34 @@ RegisteredOutputPin::RegisteredOutputPin(const char *name, short pinOffset, registeredOutputHead = this; } -void RegisteredOutputPin::unregister() { +bool RegisteredOutputPin::isPinConfigurationChanged() { #if EFI_PROD_CODE brain_pin_e curPin = *(brain_pin_e *) ((void *) (&((char*)&activeConfiguration)[pinOffset])); brain_pin_e newPin = *(brain_pin_e *) ((void *) (&((char*) engineConfiguration)[pinOffset])); pin_output_mode_e curMode = *(pin_output_mode_e *) ((void *) (&((char*)&activeConfiguration)[pinModeOffset])); pin_output_mode_e newMode = *(pin_output_mode_e *) ((void *) (&((char*) engineConfiguration)[pinModeOffset])); + return curPin != newPin || curMode != newMode; +#else + return false; +#endif // EFI_PROD_CODE +} - if (curPin != newPin || curMode != newMode) { +void RegisteredOutputPin::init() { +#if EFI_PROD_CODE + brain_pin_e newPin = *(brain_pin_e *) ((void *) (&((char*) engineConfiguration)[pinOffset])); + pin_output_mode_e newMode = *(pin_output_mode_e *) ((void *) (&((char*) engineConfiguration)[pinModeOffset])); + + if (isPinConfigurationChanged()) { + + } +#endif // EFI_PROD_CODE +} + +void RegisteredOutputPin::unregister() { +#if EFI_PROD_CODE + brain_pin_e curPin = *(brain_pin_e *) ((void *) (&((char*)&activeConfiguration)[pinOffset])); + if (isPinConfigurationChanged()) { unregisterOutput(curPin); } #endif // EFI_PROD_CODE @@ -83,21 +102,21 @@ void RegisteredOutputPin::unregister() { EnginePins::EnginePins() : - mainRelay("mainRelay", CONFIG_PIN_OFFSETS(mainRelay)), + mainRelay("Main relay", CONFIG_PIN_OFFSETS(mainRelay)), hpfpValve("hpfpValve", CONFIG_PIN_OFFSETS(hpfpValve)), starterControl("starterControl", CONFIG_PIN_OFFSETS(starterControl)), starterRelayDisable("starterRelayDisable", CONFIG_PIN_OFFSETS(starterRelayDisable)), - fanRelay("fanRelay", CONFIG_PIN_OFFSETS(fan)), - acRelay("acRelay", CONFIG_PIN_OFFSETS(acRelay)), - fuelPumpRelay("fuelPump", CONFIG_PIN_OFFSETS(fuelPump)), - boostPin("boostPin", CONFIG_PIN_OFFSETS(boostControl)), - idleSolenoidPin("idleSolenoid", idle_solenoidPin_offset, idle_solenoidPinMode_offset), - secondIdleSolenoidPin("secondIdleSolenoid", CONFIG_OFFSET(secondSolenoidPin), idle_solenoidPinMode_offset), - alternatorPin("alternatorPin", CONFIG_PIN_OFFSETS(alternatorControl)), + fanRelay("Fan", CONFIG_PIN_OFFSETS(fan)), + acRelay("A/C relay", CONFIG_PIN_OFFSETS(acRelay)), + fuelPumpRelay("Fuel pump", CONFIG_PIN_OFFSETS(fuelPump)), + boostPin("Boost", CONFIG_PIN_OFFSETS(boostControl)), + idleSolenoidPin("Idle Valve", idle_solenoidPin_offset, idle_solenoidPinMode_offset), + secondIdleSolenoidPin("Idle Valve#2", CONFIG_OFFSET(secondSolenoidPin), idle_solenoidPinMode_offset), + alternatorPin("Alternator control", CONFIG_PIN_OFFSETS(alternatorControl)), checkEnginePin("checkEnginePin", CONFIG_PIN_OFFSETS(malfunctionIndicator)), // todo: NamedOutputPin vs RegisteredOutputPin // tachOut("tachOut", CONFIG_PIN_OFFSETS(tachOutput)), - triggerDecoderErrorPin("triggerDecoderErrorPin", CONFIG_PIN_OFFSETS(triggerError)), + triggerDecoderErrorPin("led: trigger debug", CONFIG_PIN_OFFSETS(triggerError)), hipCs("hipCs", CONFIG_PIN_OFFSETS(hip9011Cs)) { tachOut.name = PROTOCOL_TACH_NAME; @@ -212,6 +231,13 @@ void EnginePins::startPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) { starterControl.initPin("Starter control", CONFIG(starterControlPin)); #endif /* EFI_ENGINE_CONTROL */ + RegisteredOutputPin * pin = registeredOutputHead; + while (pin != nullptr) { + pin->init(); + pin = pin->next; + } + + initIfPinOrModeChanged(mainRelay, "Main relay", mainRelayPin, mainRelayPinMode); initIfPinOrModeChanged(fanRelay, "Fan", fanPin, fanPinMode); diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index 59bac68b88..fafcb0803c 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -132,12 +132,14 @@ public: class RegisteredOutputPin : public OutputPin { public: RegisteredOutputPin(const char *name, short pinOffset, short pinModeOffset); + void init(); void unregister(); RegisteredOutputPin *next; private: const char *name; short pinOffset; short pinModeOffset; + bool isPinConfigurationChanged(); }; class EnginePins {