refactoring - reducing GPIO complexity

This commit is contained in:
rusefi 2017-04-21 18:11:36 -04:00
parent 6938538fac
commit 6f9ff11213
13 changed files with 40 additions and 51 deletions

View File

@ -546,17 +546,15 @@ static THD_WORKING_AREA(blinkingStack, 128);
static OutputPin *leds[] = { &enginePins.warningPin, &enginePins.runningPin, &enginePins.checkEnginePin,
&enginePins.errorLedPin, &enginePins.communicationPin, &enginePins.checkEnginePin };
extern pin_output_mode_e DEFAULT_OUTPUT;
static void initStatusLeds(void) {
enginePins.communicationPin.initPin("led: comm status", engineConfiguration->communicationPin, &DEFAULT_OUTPUT);
enginePins.communicationPin.initPin("led: comm status", engineConfiguration->communicationPin);
// we initialize this here so that we can blink it on start-up
enginePins.checkEnginePin.initPin("MalfunctionIndicator", boardConfiguration->malfunctionIndicatorPin, &DEFAULT_OUTPUT);
enginePins.checkEnginePin.initPin("MalfunctionIndicator", boardConfiguration->malfunctionIndicatorPin);
#if EFI_WARNING_LED || defined(__DOXYGEN__)
enginePins.warningPin.initPin("led: warning status", LED_WARNING_BRAIN_PIN, &DEFAULT_OUTPUT);
enginePins.runningPin.initPin("led: running status", engineConfiguration->runningPin, &DEFAULT_OUTPUT);
enginePins.warningPin.initPin("led: warning status", LED_WARNING_BRAIN_PIN);
enginePins.runningPin.initPin("led: running status", engineConfiguration->runningPin);
#endif /* EFI_WARNING_LED */
}

View File

@ -25,7 +25,6 @@ EXTERN_ENGINE
static Logging *logger;
extern pin_output_mode_e DEFAULT_OUTPUT;
int alternatorPidResetCounter = 0;
static SimplePwm alternatorControl;
@ -172,8 +171,7 @@ void initAlternatorCtrl(Logging *sharedLogger) {
return;
if (boardConfiguration->onOffAlternatorLogic) {
outputPinRegisterExt2("on/off alternator", &enginePins.alternatorPin, boardConfiguration->alternatorControlPin,
&DEFAULT_OUTPUT);
enginePins.alternatorPin.initPin("on/off alternator", boardConfiguration->alternatorControlPin);
} else {
startSimplePwmExt(&alternatorControl, "Alternator control", boardConfiguration->alternatorControlPin,

View File

@ -504,7 +504,7 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) {
if (brainPin != GPIO_UNASSIGNED) {
int frequency = boardConfiguration->fsioFrequency[i];
if (frequency == 0) {
outputPinRegisterExt2(getGpioPinName(i), &enginePins.fsioOutputs[i], boardConfiguration->fsioPins[i], &defa);
enginePins.fsioOutputs[i].initPin(getGpioPinName(i), boardConfiguration->fsioPins[i], &defa);
} else {
startSimplePwmExt(&fsioPwm[i], "FSIOpwm", brainPin, &enginePins.fsioOutputs[i], frequency, 0.5f, applyPinState);
}

View File

@ -43,7 +43,6 @@
#include "pwm_generator.h"
#define ETB_FREQ 400
extern pin_output_mode_e DEFAULT_OUTPUT;
static LoggingWithStorage logger("ETB");
/**
@ -171,8 +170,8 @@ void startETBPins(void) {
0.80,
applyPinState);
outputPinRegisterExt2("etb dir open", &outputDirectionOpen, boardConfiguration->etbDirectionPin1, &DEFAULT_OUTPUT);
outputPinRegisterExt2("etb dir close", &outputDirectionClose, boardConfiguration->etbDirectionPin2, &DEFAULT_OUTPUT);
outputDirectionOpen.initPin("etb dir open", boardConfiguration->etbDirectionPin1);
outputDirectionClose.initPin("etb dir close", boardConfiguration->etbDirectionPin2);
}
void initElectronicThrottle(void) {

View File

@ -251,13 +251,13 @@ void startIgnitionPins(void) {
NamedOutputPin *output = &enginePins.coils[i];
// todo: we need to check if mode has changed
if (boardConfiguration->ignitionPins[i] != activeConfiguration.bc.ignitionPins[i]) {
outputPinRegisterExt2(output->name, output, boardConfiguration->ignitionPins[i],
output->initPin(output->name, boardConfiguration->ignitionPins[i],
&boardConfiguration->ignitionPinMode);
}
}
// todo: we need to check if mode has changed
if (engineConfiguration->dizzySparkOutputPin != activeConfiguration.dizzySparkOutputPin) {
outputPinRegisterExt2("dizzy tach", &enginePins.dizzyOutput, engineConfiguration->dizzySparkOutputPin,
enginePins.dizzyOutput.initPin("dizzy tach", engineConfiguration->dizzySparkOutputPin,
&engineConfiguration->dizzySparkOutputPinMode);
}
@ -270,7 +270,7 @@ void startInjectionPins(void) {
// todo: we need to check if mode has changed
if (engineConfiguration->bc.injectionPins[i] != activeConfiguration.bc.injectionPins[i]) {
outputPinRegisterExt2(output->name, output, boardConfiguration->injectionPins[i],
output->initPin(output->name, boardConfiguration->injectionPins[i],
&boardConfiguration->injectionPinMode);
}
}

View File

@ -20,7 +20,7 @@ EXTERN_ENGINE;
EnginePins enginePins;
extern LoggingWithStorage sharedLogger;
static pin_output_mode_e OUTPUT_MODE_DEFAULT = OM_DEFAULT;
static pin_output_mode_e DEFAULT_OUTPUT = OM_DEFAULT;
static const char *sparkNames[IGNITION_PIN_COUNT] = { "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8",
"c9", "cA", "cB", "cD"};
@ -125,7 +125,7 @@ void IgnitionOutputPin::reset() {
}
OutputPin::OutputPin() {
modePtr = &OUTPUT_MODE_DEFAULT;
modePtr = &DEFAULT_OUTPUT;
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
port = NULL;
pin = 0;
@ -173,9 +173,6 @@ void OutputPin::setDefaultPinState(pin_output_mode_e *outputMode) {
setValue(false); // initial state
}
pin_output_mode_e DEFAULT_OUTPUT = OM_DEFAULT;
pin_output_mode_e OPENDRAIN_OUTPUT = OM_OPENDRAIN;
void initOutputPins(void) {
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
/**
@ -186,17 +183,17 @@ void initOutputPins(void) {
// memset(&outputs, 0, sizeof(outputs));
#if HAL_USE_SPI || defined(__DOXYGEN__)
outputPinRegisterExt2("spi CS5", &enginePins.sdCsPin, boardConfiguration->sdCardCsPin, &DEFAULT_OUTPUT);
enginePins.sdCsPin.initPin("spi CS5", boardConfiguration->sdCardCsPin);
#endif /* HAL_USE_SPI */
// todo: should we move this code closer to the fuel pump logic?
outputPinRegisterExt2("fuel pump relay", &enginePins.fuelPumpRelay, boardConfiguration->fuelPumpPin, &DEFAULT_OUTPUT);
enginePins.fuelPumpRelay.initPin("fuel pump relay", boardConfiguration->fuelPumpPin);
outputPinRegisterExt2("main relay", &enginePins.mainRelay, boardConfiguration->mainRelayPin, &boardConfiguration->mainRelayPinMode);
enginePins.mainRelay.initPin("main relay", boardConfiguration->mainRelayPin, &boardConfiguration->mainRelayPinMode);
outputPinRegisterExt2("fan relay", &enginePins.fanRelay, boardConfiguration->fanPin, &DEFAULT_OUTPUT);
outputPinRegisterExt2("o2 heater", &enginePins.o2heater, boardConfiguration->o2heaterPin, &DEFAULT_OUTPUT);
outputPinRegisterExt2("A/C relay", &enginePins.acRelay, boardConfiguration->acRelayPin, &boardConfiguration->acRelayPinMode);
enginePins.fanRelay.initPin("fan relay", boardConfiguration->fanPin);
enginePins.o2heater.initPin("o2 heater", boardConfiguration->o2heaterPin);
enginePins.acRelay.initPin("A/C relay", boardConfiguration->acRelayPin, &boardConfiguration->acRelayPinMode);
// digit 1
/*
@ -229,11 +226,11 @@ void initOutputPins(void) {
#endif /* EFI_GPIO_HARDWARE */
}
void OutputPin::initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e *outputMode) {
outputPinRegisterExt2(msg, this, brainPin, outputMode);
void OutputPin::initPin(const char *msg, brain_pin_e brainPin) {
initPin(msg, brainPin, &DEFAULT_OUTPUT);
}
void outputPinRegisterExt2(const char *msg, OutputPin *outputPin, brain_pin_e brainPin, pin_output_mode_e *outputMode) {
void OutputPin::initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e *outputMode) {
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
if (brainPin == GPIO_UNASSIGNED)
return;
@ -245,7 +242,7 @@ void outputPinRegisterExt2(const char *msg, OutputPin *outputPin, brain_pin_e br
*/
if (port == GPIO_NULL) {
// that's for GRIO_NONE
outputPin->port = port;
this->port = port;
return;
}
@ -256,29 +253,29 @@ void outputPinRegisterExt2(const char *msg, OutputPin *outputPin, brain_pin_e br
/**
* @brief Initialize the hardware output pin while also assigning it a logical name
*/
if (outputPin->port != NULL && (outputPin->port != port || outputPin->pin != pin)) {
if (this->port != NULL && (this->port != port || this->pin != pin)) {
/**
* here we check if another physical pin is already assigned to this logical output
*/
// todo: need to clear '&outputs' in io_pins.c
warning(CUSTOM_OBD_PIN_CONFLICT, "outputPin [%s] already assigned to %x%d", msg, outputPin->port, outputPin->pin);
warning(CUSTOM_OBD_PIN_CONFLICT, "outputPin [%s] already assigned to %x%d", msg, this->port, this->pin);
engine->withError = true;
return;
}
outputPin->currentLogicValue = INITIAL_PIN_STATE;
outputPin->port = port;
outputPin->pin = pin;
this->currentLogicValue = INITIAL_PIN_STATE;
this->port = port;
this->pin = pin;
mySetPadMode(msg, port, pin, mode);
outputPin->setDefaultPinState(outputMode);
setDefaultPinState(outputMode);
#endif /* EFI_GPIO_HARDWARE */
}
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
void initPrimaryPins(void) {
outputPinRegisterExt2("led: ERROR status", &enginePins.errorLedPin, LED_ERROR_BRAIN_PIN, &DEFAULT_OUTPUT);
enginePins.errorLedPin.initPin("led: ERROR status", LED_ERROR_BRAIN_PIN);
}
/**

View File

@ -33,6 +33,7 @@ public:
bool getLogicValue();
void unregister();
bool isPinAssigned();
void initPin(const char *msg, brain_pin_e brainPin);
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e *outputMode);
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
@ -143,8 +144,6 @@ public:
void turnPinHigh(NamedOutputPin *output);
void turnPinLow(NamedOutputPin *output);
void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode);
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
ioportmask_t getHwPin(brain_pin_e brainPin);

View File

@ -35,7 +35,7 @@ void initTachometer(void) {
return;
}
outputPinRegisterExt2("analog tach output", &enginePins.tachOut, boardConfiguration->tachOutputPin, &boardConfiguration->tachOutputPinMode);
enginePins.tachOut.initPin("analog tach output", boardConfiguration->tachOutputPin, &boardConfiguration->tachOutputPinMode);
addTriggerEventListener(tachSignalCallback, "tach", engine);
}

View File

@ -727,7 +727,7 @@ void initTriggerDecoderLogger(Logging *sharedLogger) {
void initTriggerDecoder(void) {
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
outputPinRegisterExt2("trg_err", &enginePins.triggerDecoderErrorPin, boardConfiguration->triggerErrorPin,
enginePins.triggerDecoderErrorPin.initPin("trg_err", boardConfiguration->triggerErrorPin,
&boardConfiguration->triggerErrorPinMode);
#endif /* EFI_GPIO_HARDWARE */
}

View File

@ -41,13 +41,13 @@ void initTriggerEmulator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) {
#if EFI_PROD_CODE
// todo: refactor, make this a loop
outputPinRegisterExt2("trg emulator ch1", triggerSignal.outputPins[0], boardConfiguration->triggerSimulatorPins[0],
triggerSignal.outputPins[0]->initPin("trg emulator ch1", boardConfiguration->triggerSimulatorPins[0],
&boardConfiguration->triggerSimulatorPinModes[0]);
outputPinRegisterExt2("trg emulator ch2", triggerSignal.outputPins[1], boardConfiguration->triggerSimulatorPins[1],
triggerSignal.outputPins[1]->initPin("trg emulator ch2", boardConfiguration->triggerSimulatorPins[1],
&boardConfiguration->triggerSimulatorPinModes[1]);
outputPinRegisterExt2("trg emulator ch3", triggerSignal.outputPins[2], boardConfiguration->triggerSimulatorPins[2],
triggerSignal.outputPins[2]->initPin("trg emulator ch3", boardConfiguration->triggerSimulatorPins[2],
&boardConfiguration->triggerSimulatorPinModes[2]);
#endif /* EFI_PROD_CODE */

View File

@ -437,9 +437,9 @@ void initHip9011(Logging *sharedLogger) {
hipSpiCfg.ssport = getHwPort(boardConfiguration->hip9011CsPin);
hipSpiCfg.sspad = getHwPin(boardConfiguration->hip9011CsPin);
outputPinRegisterExt2("hip int/hold", &intHold, boardConfiguration->hip9011IntHoldPin,
intHold.initPin("hip int/hold", boardConfiguration->hip9011IntHoldPin,
&boardConfiguration->hip9011IntHoldPinMode);
outputPinRegisterExt2("hip CS", &enginePins.hipCs, boardConfiguration->hip9011CsPin,
enginePins.hipCs.initPin("hip CS", boardConfiguration->hip9011CsPin,
&boardConfiguration->hip9011CsPinMode);
scheduleMsg(logger, "Starting HIP9011/TPIC8101 driver");

View File

@ -50,12 +50,10 @@ void startSimplePwm(PwmConfig *state, const char *msg, OutputPin *output, float
state->weComplexInit(msg, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
}
extern pin_output_mode_e DEFAULT_OUTPUT;
void startSimplePwmExt(PwmConfig *state, const char *msg, brain_pin_e brainPin, OutputPin *output, float frequency,
float dutyCycle, pwm_gen_callback *stateChangeCallback) {
outputPinRegisterExt2(msg, output, brainPin, &DEFAULT_OUTPUT);
output->initPin(msg, brainPin);
startSimplePwm(state, msg, output, frequency, dutyCycle, stateChangeCallback);
}

View File

@ -110,7 +110,7 @@ void initCJ125(Logging *sharedLogger) {
driver = getSpiDevice(engineConfiguration->cj125SpiDevice);
outputPinRegisterExt2("cj125 CS", &cj125Cs, boardConfiguration->cj125CsPin,
cj125Cs.initPin("cj125 CS", boardConfiguration->cj125CsPin,
&engineConfiguration->cj125CsPinMode);
if (boardConfiguration->wboHeaterPin != GPIO_UNASSIGNED) {