Output pin init/deinit needs a linked list #1803

This commit is contained in:
rusefillc 2020-11-09 21:10:48 -05:00
parent 5c857571ec
commit 9aff6e3103
3 changed files with 26 additions and 21 deletions

View File

@ -71,10 +71,9 @@ void initTachometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return; return;
} }
startSimplePwmExt(&tachControl, startSimplePwm(&tachControl,
"Tachometer", "Tachometer",
&engine->executor, &engine->executor,
CONFIG(tachOutputPin),
&enginePins.tachOut, &enginePins.tachOut,
NAN, 0.1f); NAN, 0.1f);

View File

@ -52,9 +52,13 @@ static const char *auxValveShortNames[] = { "a1", "a2"};
static RegisteredOutputPin * registeredOutputHead = nullptr; 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) { short pinModeOffset) {
this->name = name; this->registrationName = registrationName;
this->pinOffset = pinOffset; this->pinOffset = pinOffset;
this->pinModeOffset = pinModeOffset; 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 // 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])); pin_output_mode_e *newMode = (pin_output_mode_e *) ((void *) (&((char*) engineConfiguration)[pinModeOffset]));
if (isPinConfigurationChanged()) { if (isPinConfigurationChanged()) {
this->initPin(name, newPin, newMode); this->initPin(registrationName, newPin, newMode);
} }
#endif // EFI_PROD_CODE #endif // EFI_PROD_CODE
} }
@ -114,8 +118,7 @@ EnginePins::EnginePins() :
secondIdleSolenoidPin("Idle Valve#2", CONFIG_OFFSET(secondSolenoidPin), idle_solenoidPinMode_offset), secondIdleSolenoidPin("Idle Valve#2", CONFIG_OFFSET(secondSolenoidPin), idle_solenoidPinMode_offset),
alternatorPin("Alternator control", CONFIG_PIN_OFFSETS(alternatorControl)), alternatorPin("Alternator control", CONFIG_PIN_OFFSETS(alternatorControl)),
checkEnginePin("checkEnginePin", CONFIG_PIN_OFFSETS(malfunctionIndicator)), 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)), triggerDecoderErrorPin("led: trigger debug", CONFIG_PIN_OFFSETS(triggerError)),
hipCs("hipCs", CONFIG_PIN_OFFSETS(hip9011Cs)) hipCs("hipCs", CONFIG_PIN_OFFSETS(hip9011Cs))
{ {
@ -197,7 +200,6 @@ void EnginePins::unregisterPins() {
unregisterEtbPins(); unregisterEtbPins();
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */ #endif /* EFI_ELECTRONIC_THROTTLE_BODY */
#if EFI_PROD_CODE #if EFI_PROD_CODE
unregisterOutputIfPinOrModeChanged(tachOut, tachOutputPin, tachOutputPinMode);
// todo: add pinMode // todo: add pinMode
unregisterOutputIfPinChanged(sdCsPin, sdCardCsPin); unregisterOutputIfPinChanged(sdCsPin, sdCardCsPin);
unregisterOutputIfPinChanged(accelerometerCs, LIS302DLCsPin); unregisterOutputIfPinChanged(accelerometerCs, LIS302DLCsPin);
@ -289,7 +291,10 @@ void EnginePins::startInjectionPins(void) {
} }
NamedOutputPin::NamedOutputPin() : OutputPin() { NamedOutputPin::NamedOutputPin() : OutputPin() {
name = NULL; }
NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() {
this->name = name;
} }
const char *NamedOutputPin::getName() const { const char *NamedOutputPin::getName() const {
@ -297,11 +302,7 @@ const char *NamedOutputPin::getName() const {
} }
const char *NamedOutputPin::getShortName() const { const char *NamedOutputPin::getShortName() const {
return shortName == NULL ? name : shortName; return shortName == nullptr ? name : shortName;
}
NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() {
this->name = name;
} }
void NamedOutputPin::setHigh() { void NamedOutputPin::setHigh() {

View File

@ -86,7 +86,7 @@ private:
/** /**
* OutputPin which is reported on Engine Sniffer * OutputPin which is reported on Engine Sniffer
*/ */
class NamedOutputPin : public OutputPin { class NamedOutputPin : public virtual OutputPin {
public: public:
NamedOutputPin(); NamedOutputPin();
explicit NamedOutputPin(const char *name); explicit NamedOutputPin(const char *name);
@ -99,11 +99,11 @@ public:
*/ */
bool stop(); bool stop();
// todo: char pointer is a bit of a memory waste here, we can reduce RAM usage by software-based getName() method // 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 * 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 { class InjectorOutputPin final : public NamedOutputPin {
@ -134,19 +134,24 @@ public:
/** /**
* OutputPin with semi-automated init/deinit on configuration change * OutputPin with semi-automated init/deinit on configuration change
*/ */
class RegisteredOutputPin : public OutputPin { class RegisteredOutputPin : public virtual OutputPin {
public: public:
RegisteredOutputPin(const char *name, short pinOffset, short pinModeOffset); RegisteredOutputPin(const char *registrationName, short pinOffset, short pinModeOffset);
void init(); void init();
void unregister(); void unregister();
RegisteredOutputPin *next; RegisteredOutputPin *next;
private: private:
const char *name; const char *registrationName;
short pinOffset; short pinOffset;
short pinModeOffset; short pinModeOffset;
bool isPinConfigurationChanged(); bool isPinConfigurationChanged();
}; };
class RegisteredNamedOutputPin : public RegisteredOutputPin, public NamedOutputPin {
public:
RegisteredNamedOutputPin(const char *name, short pinOffset, short pinModeOffset);
};
class EnginePins { class EnginePins {
public: public:
EnginePins(); EnginePins();
@ -187,7 +192,7 @@ public:
*/ */
RegisteredOutputPin checkEnginePin; RegisteredOutputPin checkEnginePin;
NamedOutputPin tachOut; RegisteredNamedOutputPin tachOut;
OutputPin fsioOutputs[FSIO_COMMAND_COUNT]; OutputPin fsioOutputs[FSIO_COMMAND_COUNT];
RegisteredOutputPin triggerDecoderErrorPin; RegisteredOutputPin triggerDecoderErrorPin;