From 9aff6e3103cc0765841759f014157c937888b9b3 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 9 Nov 2020 21:10:48 -0500 Subject: [PATCH] Output pin init/deinit needs a linked list #1803 --- firmware/controllers/gauges/tachometer.cpp | 3 +-- firmware/controllers/system/efi_gpio.cpp | 25 +++++++++++----------- firmware/controllers/system/efi_gpio.h | 19 ++++++++++------ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/firmware/controllers/gauges/tachometer.cpp b/firmware/controllers/gauges/tachometer.cpp index 2f4c5f9270..6f44a092eb 100644 --- a/firmware/controllers/gauges/tachometer.cpp +++ b/firmware/controllers/gauges/tachometer.cpp @@ -71,10 +71,9 @@ void initTachometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return; } - startSimplePwmExt(&tachControl, + startSimplePwm(&tachControl, "Tachometer", &engine->executor, - CONFIG(tachOutputPin), &enginePins.tachOut, NAN, 0.1f); diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 6f20ffc2d0..e275315222 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -52,9 +52,13 @@ static const char *auxValveShortNames[] = { "a1", "a2"}; static RegisteredOutputPin * registeredOutputHead = nullptr; -RegisteredOutputPin::RegisteredOutputPin(const char *name, short pinOffset, +RegisteredNamedOutputPin::RegisteredNamedOutputPin(const char *name, short pinOffset, + short pinModeOffset) : RegisteredOutputPin(name, pinOffset, pinModeOffset) { +} + +RegisteredOutputPin::RegisteredOutputPin(const char *registrationName, short pinOffset, short pinModeOffset) { - this->name = name; + this->registrationName = registrationName; this->pinOffset = pinOffset; this->pinModeOffset = pinModeOffset; // adding into head of the list is so easy and since we do not care about order that's what we shall do @@ -81,7 +85,7 @@ void RegisteredOutputPin::init() { pin_output_mode_e *newMode = (pin_output_mode_e *) ((void *) (&((char*) engineConfiguration)[pinModeOffset])); if (isPinConfigurationChanged()) { - this->initPin(name, newPin, newMode); + this->initPin(registrationName, newPin, newMode); } #endif // EFI_PROD_CODE } @@ -114,8 +118,7 @@ EnginePins::EnginePins() : 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)), + tachOut("tachOut", CONFIG_PIN_OFFSETS(tachOutput)), triggerDecoderErrorPin("led: trigger debug", CONFIG_PIN_OFFSETS(triggerError)), hipCs("hipCs", CONFIG_PIN_OFFSETS(hip9011Cs)) { @@ -197,7 +200,6 @@ void EnginePins::unregisterPins() { unregisterEtbPins(); #endif /* EFI_ELECTRONIC_THROTTLE_BODY */ #if EFI_PROD_CODE - unregisterOutputIfPinOrModeChanged(tachOut, tachOutputPin, tachOutputPinMode); // todo: add pinMode unregisterOutputIfPinChanged(sdCsPin, sdCardCsPin); unregisterOutputIfPinChanged(accelerometerCs, LIS302DLCsPin); @@ -289,7 +291,10 @@ void EnginePins::startInjectionPins(void) { } NamedOutputPin::NamedOutputPin() : OutputPin() { - name = NULL; +} + +NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() { + this->name = name; } const char *NamedOutputPin::getName() const { @@ -297,11 +302,7 @@ const char *NamedOutputPin::getName() const { } const char *NamedOutputPin::getShortName() const { - return shortName == NULL ? name : shortName; -} - -NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() { - this->name = name; + return shortName == nullptr ? name : shortName; } void NamedOutputPin::setHigh() { diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index 9557542c90..0a8cb27483 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -86,7 +86,7 @@ private: /** * OutputPin which is reported on Engine Sniffer */ -class NamedOutputPin : public OutputPin { +class NamedOutputPin : public virtual OutputPin { public: NamedOutputPin(); explicit NamedOutputPin(const char *name); @@ -99,11 +99,11 @@ public: */ bool stop(); // todo: char pointer is a bit of a memory waste here, we can reduce RAM usage by software-based getName() method - const char *name; + const char *name = nullptr; /** * rusEfi Engine Sniffer protocol uses these short names to reduce bytes usage */ - const char *shortName = NULL; + const char *shortName = nullptr; }; class InjectorOutputPin final : public NamedOutputPin { @@ -134,19 +134,24 @@ public: /** * OutputPin with semi-automated init/deinit on configuration change */ -class RegisteredOutputPin : public OutputPin { +class RegisteredOutputPin : public virtual OutputPin { public: - RegisteredOutputPin(const char *name, short pinOffset, short pinModeOffset); + RegisteredOutputPin(const char *registrationName, short pinOffset, short pinModeOffset); void init(); void unregister(); RegisteredOutputPin *next; private: - const char *name; + const char *registrationName; short pinOffset; short pinModeOffset; bool isPinConfigurationChanged(); }; +class RegisteredNamedOutputPin : public RegisteredOutputPin, public NamedOutputPin { +public: + RegisteredNamedOutputPin(const char *name, short pinOffset, short pinModeOffset); +}; + class EnginePins { public: EnginePins(); @@ -187,7 +192,7 @@ public: */ RegisteredOutputPin checkEnginePin; - NamedOutputPin tachOut; + RegisteredNamedOutputPin tachOut; OutputPin fsioOutputs[FSIO_COMMAND_COUNT]; RegisteredOutputPin triggerDecoderErrorPin;