From 9f565721da99eb654bed2b2c373b61e62dc1a326 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 17 Sep 2020 19:35:43 -0400 Subject: [PATCH] Output pin config #1803 alternative to #1800 --- firmware/controllers/system/efi_gpio.cpp | 30 ++++++++++++++++++++---- firmware/controllers/system/efi_gpio.h | 20 ++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 3de755c4d3..ddc2629d80 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -50,7 +50,26 @@ static const char *injectorShortNames[] = { PROTOCOL_INJ1_SHORT_NAME, "i2", "i3" static const char *auxValveShortNames[] = { "a1", "a2"}; -EnginePins::EnginePins() { +static RegisteredOutputPin * firstRegisteredOutput = nullptr; + +RegisteredOutputPin::RegisteredOutputPin(const char *name, short pinOffset, + short pinModeOffset) { + this->name = name; + this->pinOffset = pinOffset; + this->pinModeOffset = pinModeOffset; +} + +void RegisteredOutputPin::unregister() { + // pin_output_mode_e newMode = *(pin_output_mode_e *) (((void *) engineConfiguration)[pinModeOffset]); +} + + +EnginePins::EnginePins() : + mainRelay("mainRelay", mainRelayPin_offset, mainRelayPinMode_offset), + starterControl("starterControl", starterControlPin_offset, starterControlPinMode_offset), + starterRelayDisable("starterRelayDisable", starterRelayDisablePin_offset, starterRelayDisableMode_offset), + fanRelay("fanRelay", fanPin_offset, fanPinMode_offset) +{ tachOut.name = PROTOCOL_TACH_NAME; static_assert(efi::size(sparkNames) >= IGNITION_PIN_COUNT, "Too many ignition pins"); @@ -127,7 +146,6 @@ void EnginePins::unregisterPins() { #endif /* EFI_ELECTRONIC_THROTTLE_BODY */ #if EFI_PROD_CODE unregisterOutputIfPinOrModeChanged(fuelPumpRelay, fuelPumpPin, fuelPumpPinMode); - unregisterOutputIfPinOrModeChanged(fanRelay, fanPin, fanPinMode); unregisterOutputIfPinOrModeChanged(acRelay, acRelayPin, acRelayPinMode); unregisterOutputIfPinOrModeChanged(hipCs, hip9011CsPin, hip9011CsPinMode); unregisterOutputIfPinOrModeChanged(triggerDecoderErrorPin, triggerErrorPin, triggerErrorPinMode); @@ -144,10 +162,12 @@ void EnginePins::unregisterPins() { unregisterOutputIfPinOrModeChanged(boostPin, boostControlPin, boostControlPinMode); unregisterOutputIfPinOrModeChanged(alternatorPin, alternatorControlPin, alternatorControlPinMode); - unregisterOutputIfPinOrModeChanged(mainRelay, mainRelayPin, mainRelayPinMode); - unregisterOutputIfPinOrModeChanged(starterRelayDisable, starterRelayDisablePin, starterRelayDisableMode); - unregisterOutputIfPinChanged(starterControl, starterControlPin); + RegisteredOutputPin * pin = firstRegisteredOutput; + while (pin != nullptr) { + pin->unregister(); + pin = pin->next; + } #endif /* EFI_PROD_CODE */ } diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index 891f9a69dc..c6ebf4acd7 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -128,6 +128,17 @@ public: bool outOfOrder; // https://sourceforge.net/p/rusefi/tickets/319/ }; +class RegisteredOutputPin : public OutputPin { +public: + RegisteredOutputPin(const char *name, short pinOffset, short pinModeOffset); + void unregister(); + RegisteredOutputPin *next; +private: + const char *name; + short pinOffset; + short pinModeOffset; +}; + class EnginePins { public: EnginePins(); @@ -140,14 +151,13 @@ public: void startAuxValves(); void stopInjectionPins(); void stopIgnitionPins(); - OutputPin mainRelay; - + RegisteredOutputPin mainRelay; // this one cranks engine - OutputPin starterControl; + RegisteredOutputPin starterControl; // this one prevents driver from cranknig engine - OutputPin starterRelayDisable; + RegisteredOutputPin starterRelayDisable; - OutputPin fanRelay; + RegisteredOutputPin fanRelay; // see acRelayPin OutputPin acRelay; OutputPin fuelPumpRelay;