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;
}
startSimplePwmExt(&tachControl,
startSimplePwm(&tachControl,
"Tachometer",
&engine->executor,
CONFIG(tachOutputPin),
&enginePins.tachOut,
NAN, 0.1f);

View File

@ -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() {

View File

@ -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;