From 4e3a5d088fd960d9ec941ff94caa6a3e4ae1cdd1 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 12 Jan 2015 22:03:39 -0600 Subject: [PATCH] auto-sync --- firmware/console/status_loop.cpp | 10 +-- .../controllers/algo/auto_generated_enums.cpp | 52 ------------ firmware/controllers/algo/engine.cpp | 4 +- firmware/controllers/algo/io_pins.h | 33 -------- firmware/controllers/algo/rusefi_types.h | 2 + firmware/controllers/core/fsio_impl.cpp | 81 ++++++++++++++----- firmware/controllers/engine_controller.cpp | 45 +++++------ firmware/controllers/injector_central.cpp | 17 ++-- firmware/controllers/lcd_controller.cpp | 66 +++++++-------- firmware/controllers/math/efitime.h | 1 - firmware/controllers/settings.cpp | 5 +- firmware/controllers/system/efiGpio.cpp | 44 ++-------- firmware/controllers/system/efiGpio.h | 17 ++-- firmware/hw_layer/io_pins.cpp | 15 ++-- 14 files changed, 162 insertions(+), 230 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 40b0225e96..ef91ac6380 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -64,7 +64,7 @@ #include "vehicle_speed.h" #endif -extern OutputPin outputs[IO_PIN_COUNT]; +extern engine_pins_s enginePins; // this 'true' value is needed for simulator static volatile bool fullLog = true; @@ -354,7 +354,7 @@ static void showFuelInfo2(float rpm, float engineLoad, Engine *engine) { scheduleMsg(&logger, "SD magic fuel %f", sdMath(engineConfiguration, 100, 100, 14.7, convertCelsiusToKelvin(20))); scheduleMsg(&logger2, "algo=%s/pump=%s", getEngine_load_mode_e(engineConfiguration->algorithm), - boolToString(getOutputPinValue(FUEL_PUMP_RELAY))); + boolToString(enginePins.fuelPumpRelay.getLogicValue())); scheduleMsg(&logger2, "cranking fuel: %f", getCrankingFuel(engine)); @@ -515,9 +515,9 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC tsOutputChannels->needBurn = getNeedToWriteConfiguration(); tsOutputChannels->hasSdCard = isSdCardAlive(); - tsOutputChannels->isFuelPumpOn = getOutputPinValue(FUEL_PUMP_RELAY); - tsOutputChannels->isFanOn = getOutputPinValue(FAN_RELAY); - tsOutputChannels->isO2HeaterOn = getOutputPinValue(O2_HEATER); + tsOutputChannels->isFuelPumpOn = enginePins.fuelPumpRelay.getLogicValue(); + tsOutputChannels->isFanOn = enginePins.fanRelay.getLogicValue(); + tsOutputChannels->isO2HeaterOn = enginePins.o2heater.getLogicValue(); tsOutputChannels->ignition_enabled = engineConfiguration->isIgnitionEnabled; tsOutputChannels->injection_enabled = engineConfiguration->isInjectionEnabled; tsOutputChannels->cylinder_cleanup_enabled = engineConfiguration->isCylinderCleanupEnabled; diff --git a/firmware/controllers/algo/auto_generated_enums.cpp b/firmware/controllers/algo/auto_generated_enums.cpp index 76c6053ae2..f4faaa33e1 100644 --- a/firmware/controllers/algo/auto_generated_enums.cpp +++ b/firmware/controllers/algo/auto_generated_enums.cpp @@ -5,46 +5,6 @@ #include "io_pins.h" const char *getIo_pin_e(io_pin_e value){ switch(value) { -case AC_RELAY: - return "AC_RELAY"; -case ALTERNATOR_SWITCH: - return "ALTERNATOR_SWITCH"; -case FAN_RELAY: - return "FAN_RELAY"; -case FUEL_PUMP_RELAY: - return "FUEL_PUMP_RELAY"; -case GPIO_0: - return "GPIO_0"; -case GPIO_1: - return "GPIO_1"; -case GPIO_10: - return "GPIO_10"; -case GPIO_11: - return "GPIO_11"; -case GPIO_12: - return "GPIO_12"; -case GPIO_13: - return "GPIO_13"; -case GPIO_14: - return "GPIO_14"; -case GPIO_15: - return "GPIO_15"; -case GPIO_2: - return "GPIO_2"; -case GPIO_3: - return "GPIO_3"; -case GPIO_4: - return "GPIO_4"; -case GPIO_5: - return "GPIO_5"; -case GPIO_6: - return "GPIO_6"; -case GPIO_7: - return "GPIO_7"; -case GPIO_8: - return "GPIO_8"; -case GPIO_9: - return "GPIO_9"; case INJECTOR_10_OUTPUT: return "INJECTOR_10_OUTPUT"; case INJECTOR_11_OUTPUT: @@ -71,10 +31,6 @@ case INJECTOR_9_OUTPUT: return "INJECTOR_9_OUTPUT"; case IO_INVALID: return "IO_INVALID"; -case MAIN_RELAY: - return "MAIN_RELAY"; -case O2_HEATER: - return "O2_HEATER"; case SPARKOUT_10_OUTPUT: return "SPARKOUT_10_OUTPUT"; case SPARKOUT_11_OUTPUT: @@ -99,14 +55,6 @@ case SPARKOUT_8_OUTPUT: return "SPARKOUT_8_OUTPUT"; case SPARKOUT_9_OUTPUT: return "SPARKOUT_9_OUTPUT"; -case SPI_CS_1: - return "SPI_CS_1"; -case SPI_CS_2: - return "SPI_CS_2"; -case SPI_CS_3: - return "SPI_CS_3"; -case SPI_CS_4: - return "SPI_CS_4"; } return NULL; } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 156686903b..b1a57bb61b 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -23,6 +23,8 @@ static Logging logger; +extern OutputPin outputs[IO_PIN_COUNT]; + EXTERN_ENGINE ; @@ -56,7 +58,7 @@ void Engine::init() { } static bool stopPin(io_pin_e pin) { - if (getOutputPinValue(pin)) { + if (outputs[(int)pin].getLogicValue()) { setOutputPinValue(pin, 0); scheduleMsg(&logger, "turning off %s", getPinName(pin)); return true; diff --git a/firmware/controllers/algo/io_pins.h b/firmware/controllers/algo/io_pins.h index 72e0c3e31b..ff4e1a433e 100644 --- a/firmware/controllers/algo/io_pins.h +++ b/firmware/controllers/algo/io_pins.h @@ -44,23 +44,6 @@ typedef enum { INJECTOR_11_OUTPUT, INJECTOR_12_OUTPUT, - GPIO_0, - GPIO_1, - GPIO_2, - GPIO_3, - GPIO_4, - GPIO_5, - GPIO_6, - GPIO_7, - GPIO_8, - GPIO_9, - GPIO_10, - GPIO_11, - GPIO_12, - GPIO_13, - GPIO_14, - GPIO_15, - IO_INVALID, /** @@ -94,22 +77,6 @@ typedef enum { // LED_HUGE_19, // LED_HUGE_20, - FUEL_PUMP_RELAY, - FAN_RELAY, - O2_HEATER, - AC_RELAY, - - SPI_CS_1, - SPI_CS_2, - SPI_CS_3, - SPI_CS_4, - - MAIN_RELAY, - - /** - * This output pin is used to turn alternator on or off - */ - ALTERNATOR_SWITCH, } io_pin_e; diff --git a/firmware/controllers/algo/rusefi_types.h b/firmware/controllers/algo/rusefi_types.h index bcfe072f3f..00878af964 100644 --- a/firmware/controllers/algo/rusefi_types.h +++ b/firmware/controllers/algo/rusefi_types.h @@ -7,6 +7,8 @@ #ifndef CONTROLLERS_ALGO_RUSEFI_TYPES_H_ #define CONTROLLERS_ALGO_RUSEFI_TYPES_H_ +#include + /** * integer time in milliseconds * 32 bit 4B / 1000 = 4M seconds = 1111.11 hours = 46 days. diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 76fde04a9b..ff9ed4d5be 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -32,6 +32,8 @@ static LENameOrdinalPair leFsioSsetting(LE_METHOD_FSIO_SETTING, "fsio_setting"); #define LE_EVAL_POOL_SIZE 32 +extern engine_pins_s enginePins; + static LECalculator evalCalc; static LEElement evalPoolElements[LE_EVAL_POOL_SIZE]; static LEElementPool evalPool(evalPoolElements, LE_EVAL_POOL_SIZE); @@ -62,7 +64,7 @@ float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { efiAssert(engine!=NULL, "getLEValue", NAN); switch (action) { case LE_METHOD_FAN: - return getOutputPinValue(FAN_RELAY); + return enginePins.fanRelay.getLogicValue(); case LE_METHOD_AC_TOGGLE: return getAcToggle(engine); case LE_METHOD_COOLANT: @@ -147,6 +149,48 @@ static SimplePwm fsioPwm[LE_COMMAND_COUNT] CCM_OPTIONAL; static LECalculator calc; extern LEElement * fsioLogics[LE_COMMAND_COUNT]; +extern OutputPin outputs[IO_PIN_COUNT]; + +// that's crazy, but what's an alternative? we need const char *, a shared buffer would not work for pin repository +static const char *getGpioPinName(int index) { +switch (index) { +case 0: + return "GPIO_0"; +case 1: + return "GPIO_1"; +case 10: + return "GPIO_10"; +case 11: + return "GPIO_11"; +case 12: + return "GPIO_12"; +case 13: + return "GPIO_13"; +case 14: + return "GPIO_14"; +case 15: + return "GPIO_15"; +case 2: + return "GPIO_2"; +case 3: + return "GPIO_3"; +case 4: + return "GPIO_4"; +case 5: + return "GPIO_5"; +case 6: + return "GPIO_6"; +case 7: + return "GPIO_7"; +case 8: + return "GPIO_8"; +case 9: + return "GPIO_9"; +} +return NULL; +} + +static OutputPin fsioPins[LE_COMMAND_COUNT]; static void handleFsio(Engine *engine, int index) { if (boardConfiguration->fsioPins[index] == GPIO_UNASSIGNED) @@ -154,8 +198,6 @@ static void handleFsio(Engine *engine, int index) { bool_t isPwmMode = boardConfiguration->fsioFrequency[index] != 0; - io_pin_e pin = (io_pin_e) ((int) GPIO_0 + index); - float fvalue = calc.getValue2(fsioLogics[index], engine); engine->engineConfiguration2->fsioLastValue[index] = fvalue; @@ -163,23 +205,23 @@ static void handleFsio(Engine *engine, int index) { fsioPwm[index].setSimplePwmDutyCycle(fvalue); } else { int value = (int) fvalue; - if (value != getOutputPinValue(pin)) { + if (value != fsioPins[index].getLogicValue()) { // scheduleMsg(&logger, "setting %s %s", getIo_pin_e(pin), boolToString(value)); - setOutputPinValue(pin, value); + fsioPins[index].setValue(value); } } } -static void setPinState(io_pin_e ioPin, LEElement *element, Engine *engine) { +static void setPinState(const char * msg, OutputPin *pin, LEElement *element, Engine *engine) { if (element == NULL) { - warning(OBD_PCM_Processor_Fault, "invalid expression for %s", getIo_pin_e(ioPin)); + warning(OBD_PCM_Processor_Fault, "invalid expression for %s", msg); } else { int value = calc.getValue2(element, engine); - if (value != getOutputPinValue(ioPin)) { + if (value != pin->getLogicValue()) { if (isRunningBenchTest()) return; // let's not mess with bench testing - scheduleMsg(&logger, "setting %s %s", getIo_pin_e(ioPin), boolToString(value)); - setOutputPinValue(ioPin, value); + scheduleMsg(&logger, "setting %s %s", msg, boolToString(value)); + pin->setValue(value); } } } @@ -286,7 +328,7 @@ void runFsio(void) { #if EFI_FUEL_PUMP if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED && engineConfiguration->isFuelPumpEnabled) { - setPinState(FUEL_PUMP_RELAY, fuelPumpLogic, engine); + setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic, engine); } #endif @@ -294,18 +336,21 @@ void runFsio(void) { * main relay is always on if ECU is on, that's a good enough initial implementation */ if (boardConfiguration->mainRelayPin != GPIO_UNASSIGNED) - setOutputPinValue(MAIN_RELAY, 1); + enginePins.mainRelay.setValue(true); + + enginePins.o2heater.setValue(engine->rpmCalculator.isRunning()); + if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) { - setPinState(AC_RELAY, acRelayLogic, engine); + setPinState("A/C", &enginePins.acRelay, acRelayLogic, engine); } if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) { - setPinState(ALTERNATOR_SWITCH, alternatorLogic, engine); + setPinState("alternator", &enginePins.alternatorField, alternatorLogic, engine); } if (boardConfiguration->fanPin != GPIO_UNASSIGNED) { -// setPinState(FAN_RELAY, radiatorFanLogic, engine); + setPinState("fan", &enginePins.fanRelay, radiatorFanLogic, engine); } } @@ -333,13 +378,13 @@ void initFsioImpl(Engine *engine) { if (brainPin != GPIO_UNASSIGNED) { //mySetPadMode2("user-defined", boardConfiguration->gpioPins[i], PAL_STM32_MODE_OUTPUT); - io_pin_e pin = (io_pin_e) ((int) GPIO_0 + i); + int frequency = boardConfiguration->fsioFrequency[i]; if (frequency == 0) { - outputPinRegisterExt2(getPinName(pin), &outputs[(int)pin], boardConfiguration->fsioPins[i], &defa); + outputPinRegisterExt2(getGpioPinName(i), &fsioPins[i], boardConfiguration->fsioPins[i], &defa); } else { - startSimplePwmExt(&fsioPwm[i], "FSIO", brainPin, &outputs[(int)pin], frequency, 0.5f, applyPinState); + startSimplePwmExt(&fsioPwm[i], "FSIO", brainPin, &fsioPins[i], frequency, 0.5f, applyPinState); } } } diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 6431070b28..591fd5be98 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -132,26 +132,26 @@ static void updateErrorCodes(void) { OBD_Engine_Coolant_Temperature_Circuit_Malfunction); } -static void fanRelayControl(void) { - if (boardConfiguration->fanPin == GPIO_UNASSIGNED) - return; - - int isCurrentlyOn = getOutputPinValue(FAN_RELAY); - int newValue; - if (isCurrentlyOn) { - // if the fan is already on, we keep it on till the 'fanOff' temperature - newValue = getCoolantTemperature(engine) > engineConfiguration->fanOffTemperature; - } else { - newValue = getCoolantTemperature(engine) > engineConfiguration->fanOnTemperature; - } - - if (isCurrentlyOn != newValue) { - if (isRunningBenchTest()) - return; // let's not mess with bench testing - scheduleMsg(&logger, "FAN relay: %s", newValue ? "ON" : "OFF"); - setOutputPinValue(FAN_RELAY, newValue); - } -} +//static void fanRelayControl(void) { +// if (boardConfiguration->fanPin == GPIO_UNASSIGNED) +// return; +// +// int isCurrentlyOn = getLogicPinValue(&en); +// int newValue; +// if (isCurrentlyOn) { +// // if the fan is already on, we keep it on till the 'fanOff' temperature +// newValue = getCoolantTemperature(engine) > engineConfiguration->fanOffTemperature; +// } else { +// newValue = getCoolantTemperature(engine) > engineConfiguration->fanOnTemperature; +// } +// +// if (isCurrentlyOn != newValue) { +// if (isRunningBenchTest()) +// return; // let's not mess with bench testing +// scheduleMsg(&logger, "FAN relay: %s", newValue ? "ON" : "OFF"); +// setOutputPinValue(FAN_RELAY, newValue); +// } +//} Overflow64Counter halTime; @@ -205,13 +205,8 @@ static void onEvenyGeneralMilliseconds(Engine *engine) { updateErrorCodes(); - // todo: migrate this to flex logic - fanRelayControl(); - cylinderCleanupControl(engine); - setOutputPinValue(O2_HEATER, engine->rpmCalculator.isRunning()); - // schedule next invocation chVTSetAny(&everyMsTimer, boardConfiguration->generalPeriodicThreadPeriod * TICKS_IN_MS, (vtfunc_t) &onEvenyGeneralMilliseconds, engine); diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index 233720b4b9..71360cbe6d 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -43,6 +43,7 @@ static bool_t isRunningBench = false; static int is_injector_enabled[MAX_INJECTOR_COUNT]; extern OutputPin outputs[IO_PIN_COUNT]; +extern engine_pins_s enginePins; void initIgnitionCentral(void) { for (int i = 0; i < engineConfiguration->cylindersCount; i++) { @@ -90,7 +91,7 @@ static void setInjectorEnabled(int id, int value) { printStatus(); } -static void runBench(brain_pin_e brainPin, io_pin_e pin, float delayMs, float onTimeMs, float offTimeMs, int count) { +static void runBench(brain_pin_e brainPin, OutputPin *output, float delayMs, float onTimeMs, float offTimeMs, int count) { scheduleMsg(&logger, "Running bench: ON_TIME=%f ms OFF_TIME=%fms Counter=%d", onTimeMs, offTimeMs, count); scheduleMsg(&logger, "output on %s", hwPortname(brainPin)); @@ -99,8 +100,6 @@ static void runBench(brain_pin_e brainPin, io_pin_e pin, float delayMs, float on chThdSleep(delaySt); } - OutputPin *output = &outputs[(int)pin]; - isRunningBench = true; for (int i = 0; i < count; i++) { output->setValue(true); @@ -121,10 +120,10 @@ static float offTime; static float delayMs; static int count; static brain_pin_e brainPin; -static io_pin_e pinX; +static OutputPin* pinX; static void pinbench(const char *delayStr, const char *onTimeStr, const char *offTimeStr, const char *countStr, - io_pin_e pinParam, brain_pin_e brainPinParam) { + OutputPin* pinParam, brain_pin_e brainPinParam) { delayMs = atoff(delayStr); onTime = atoff(onTimeStr); offTime = atoff(offTimeStr); @@ -148,12 +147,12 @@ static void fuelbench2(const char *delayStr, const char *indexStr, const char * } brain_pin_e b = boardConfiguration->injectionPins[index - 1]; io_pin_e p = (io_pin_e) ((int) INJECTOR_1_OUTPUT - 1 + index); - pinbench(delayStr, onTimeStr, offTimeStr, countStr, p, b); + pinbench(delayStr, onTimeStr, offTimeStr, countStr, &outputs[(int)p], b); } void fanBench(void) { brainPin = boardConfiguration->fanPin; - pinX = FAN_RELAY; + pinX = &enginePins.fanRelay; delayMs = 0; onTime = 3000; @@ -177,7 +176,7 @@ void milBench(void) { void fuelPumpBench(void) { brainPin = boardConfiguration->fuelPumpPin; - pinX = FUEL_PUMP_RELAY; + pinX = &enginePins.fuelPumpRelay; delayMs = 0; onTime = 3000; @@ -204,7 +203,7 @@ static void sparkbench2(const char *delayStr, const char *indexStr, const char * } brain_pin_e b = boardConfiguration->ignitionPins[index - 1]; io_pin_e p = (io_pin_e) ((int) SPARKOUT_1_OUTPUT - 1 + index); - pinbench(delayStr, onTimeStr, offTimeStr, countStr, p, b); + pinbench(delayStr, onTimeStr, offTimeStr, countStr, &outputs[(int)p], b); } /** diff --git a/firmware/controllers/lcd_controller.cpp b/firmware/controllers/lcd_controller.cpp index 7bd8f4401c..f2efbe0e87 100644 --- a/firmware/controllers/lcd_controller.cpp +++ b/firmware/controllers/lcd_controller.cpp @@ -115,32 +115,32 @@ static const char* ignitionModeStr[] = { "1C", "IND", "WS" }; static const char* injectionModeStr[] = { "Sim", "Seq", "Bch" }; static const char* idleModeStr[] = { "I:A", "I:M" }; -static const char *getPinShortName(io_pin_e pin) { - switch (pin) { - case ALTERNATOR_SWITCH: - return "AL"; - case FUEL_PUMP_RELAY: - return "FP"; - case FAN_RELAY: - return "FN"; - case O2_HEATER: - return "O2H"; - default: - firmwareError("No short name for %d", (int) pin); - return ""; - } -} +//static const char *getPinShortName(io_pin_e pin) { +// switch (pin) { +// case ALTERNATOR_SWITCH: +// return "AL"; +// case FUEL_PUMP_RELAY: +// return "FP"; +// case FAN_RELAY: +// return "FN"; +// case O2_HEATER: +// return "O2H"; +// default: +// firmwareError("No short name for %d", (int) pin); +// return ""; +// } +//} -char * appendPinStatus(char *buffer, io_pin_e pin) { - char *ptr = appendStr(buffer, getPinShortName(pin)); - int state = getOutputPinValue(pin); - // todo: should we handle INITIAL_PIN_STATE? - if (state) { - return appendStr(ptr, ":Y "); - } else { - return appendStr(ptr, ":n "); - } -} +//char * appendPinStatus(char *buffer, io_pin_e pin) { +// char *ptr = appendStr(buffer, getPinShortName(pin)); +// int state = getOutputPinValue(pin); +// // todo: should we handle INITIAL_PIN_STATE? +// if (state) { +// return appendStr(ptr, ":Y "); +// } else { +// return appendStr(ptr, ":n "); +// } +//} static char * prepareInfoLine(engine_configuration_s *engineConfiguration, char *buffer) { char *ptr = buffer; @@ -158,14 +158,14 @@ static char * prepareInfoLine(engine_configuration_s *engineConfiguration, char return ptr; } -static char * prepareStatusLine(char *buffer) { - char *ptr = buffer; - - ptr = appendPinStatus(ptr, FUEL_PUMP_RELAY); - ptr = appendPinStatus(ptr, FAN_RELAY); - ptr = appendPinStatus(ptr, O2_HEATER); - return ptr; -} +//static char * prepareStatusLine(char *buffer) { +// char *ptr = buffer; +// +// ptr = appendPinStatus(ptr, FUEL_PUMP_RELAY); +// ptr = appendPinStatus(ptr, FAN_RELAY); +// ptr = appendPinStatus(ptr, O2_HEATER); +// return ptr; +//} static char buffer[MAX_LCD_WIDTH + 4]; static char dateBuffer[30]; diff --git a/firmware/controllers/math/efitime.h b/firmware/controllers/math/efitime.h index 05454fdc2a..6c36e02977 100644 --- a/firmware/controllers/math/efitime.h +++ b/firmware/controllers/math/efitime.h @@ -10,7 +10,6 @@ #ifndef EFITIME_H_ #define EFITIME_H_ -#include #include "efifeatures.h" #include "rusefi_types.h" diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index a15d6d98a8..07b8fdb16c 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -37,6 +37,7 @@ static Logging logger; static char LOGGING_BUFFER[1000]; extern int maxNesting; +extern engine_pins_s enginePins; /* static void printIntArray(int array[], int size) { @@ -329,10 +330,10 @@ static void printTemperatureInfo(void) { scheduleMsg(&logger, "IAT sensing error"); } - scheduleMsg(&logger, "fan=%s @ %s", boolToString(getOutputPinValue(FAN_RELAY)), + scheduleMsg(&logger, "fan=%s @ %s", boolToString(enginePins.fanRelay.getLogicValue()), hwPortname(boardConfiguration->fanPin)); - scheduleMsg(&logger, "A/C relay=%s @ %s", boolToString(getOutputPinValue(AC_RELAY)), + scheduleMsg(&logger, "A/C relay=%s @ %s", boolToString(enginePins.acRelay.getLogicValue()), hwPortname(boardConfiguration->acRelayPin)); diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index 579fd915a2..5f6eb56537 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -14,10 +14,7 @@ pin_output_mode_e OUTPUT_MODE_DEFAULT = OM_DEFAULT; // todo: clean this mess, this should become 'static'/private OutputPin outputs[IO_PIN_COUNT]; - -int getOutputPinValue(io_pin_e pin) { - return getLogicPinValue(&outputs[pin]); -} +engine_pins_s enginePins; const char *namedPinsArray[NAMED_PIN_COUNT] = { "spa1", "spa2", "spa3", "spa4", "spa5", "spa6", "spa7", "spa8", "spa9", "spa10", "spa11", "spa12", "inj1", "inj2", "inj3", "inj4", "inj5", "inj6", "inj7", "inj8", "inj9", @@ -52,38 +49,6 @@ const char *getPinName(io_pin_e io_pin) { case INJECTOR_12_OUTPUT: return namedPinsArray[io_pin]; - case GPIO_0: - return "gpio0"; - case GPIO_1: - return "gpio1"; - case GPIO_2: - return "gpio2"; - case GPIO_3: - return "gpio3"; - case GPIO_4: - return "gpio4"; - case GPIO_5: - return "gpio5"; - case GPIO_6: - return "gpio6"; - case GPIO_7: - return "gpio7"; - case GPIO_8: - return "gpio8"; - case GPIO_9: - return "gpio9"; - case GPIO_10: - return "gpio10"; - case GPIO_11: - return "gpio11"; - case GPIO_12: - return "gpio12"; - case GPIO_13: - return "gpio13"; - case GPIO_14: - return "gpio14"; - case GPIO_15: - return "gpio15"; default: return "Pin needs name"; } @@ -97,6 +62,10 @@ void OutputPin::setValue(int logicValue) { doSetOutputPinValue2(this, logicValue); } +bool_t OutputPin::getLogicValue() { + return currentLogicValue; +} + void OutputPin::setDefaultPinState(pin_output_mode_e *outputMode) { #if EFI_GPIO pin_output_mode_e mode = *outputMode; @@ -106,9 +75,6 @@ void OutputPin::setDefaultPinState(pin_output_mode_e *outputMode) { setValue(false); // initial state } - -extern uint32_t dbgStart; -extern uint32_t dbgDurr; /** * @brief Sets the value according to current electrical settings * diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index a1690495bb..610cf47143 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -23,6 +23,7 @@ public: OutputPin(); void setValue(int logicValue); void setDefaultPinState(pin_output_mode_e *defaultState); + bool_t getLogicValue(); #if EFI_PROD_CODE GPIO_TypeDef *port; int pin; @@ -35,6 +36,15 @@ public: int currentLogicValue; }; +typedef struct { + OutputPin mainRelay; + OutputPin fanRelay; + OutputPin acRelay; + OutputPin fuelPumpRelay; + OutputPin o2heater; + OutputPin alternatorField; +} engine_pins_s; + /** * it's a macro to be sure that stack is not used * @return 0 for OM_DEFAULT and OM_OPENDRAIN @@ -49,8 +59,6 @@ public: */ #define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN) -#define getLogicPinValue(outputPin) ((outputPin)->currentLogicValue) - /** * Sets the value of the pin. On this layer the value is assigned as is, without any conversion. */ @@ -59,7 +67,7 @@ public: #define setPinValue(outputPin, electricalValue, logicValue) \ { \ - if (getLogicPinValue(outputPin) != (logicValue)) { \ + if ((outputPin)->currentLogicValue != (logicValue)) { \ palWritePad((outputPin)->port, (outputPin)->pin, (electricalValue)); \ (outputPin)->currentLogicValue = (logicValue); \ } \ @@ -67,7 +75,7 @@ public: #else /* EFI_PROD_CODE */ #define setPinValue(outputPin, electricalValue, logicValue) \ { \ - if (getLogicPinValue(outputPin) != (logicValue)) { \ + if ((outputPin)->currentLogicValue != (logicValue)) { \ (outputPin)->currentLogicValue = (logicValue); \ } \ } @@ -84,7 +92,6 @@ extern "C" { #endif /* __cplusplus */ -int getOutputPinValue(io_pin_e pin); void setOutputPinValue(io_pin_e pin, int logicValue); const char *getPinName(io_pin_e io_pin); diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index 7e4d50f9df..cbb509e143 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -28,6 +28,7 @@ static Logging logger; static OutputPin sdCsPin; extern OutputPin outputs[IO_PIN_COUNT]; +extern engine_pins_s enginePins; #if defined(STM32F4XX) static GPIO_TypeDef *PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH }; @@ -103,7 +104,7 @@ static void getPinValue(const char *name) { return; } OutputPin * outputPin = &outputs[pin]; - int value = getLogicPinValue(outputPin); + int value = outputPin->getLogicValue(); scheduleMsg(&logger, "pin_value %s %d", name, value); } @@ -132,13 +133,13 @@ void initOutputPins(void) { #endif // todo: should we move this code closer to the fuel pump logic? - outputPinRegisterExt2("fuel pump relay", &outputs[(int)FUEL_PUMP_RELAY], boardConfiguration->fuelPumpPin, &DEFAULT_OUTPUT); + outputPinRegisterExt2("fuel pump relay", &enginePins.fuelPumpRelay, boardConfiguration->fuelPumpPin, &DEFAULT_OUTPUT); - outputPinRegisterExt2("main relay", &outputs[(int)MAIN_RELAY], boardConfiguration->mainRelayPin, &boardConfiguration->mainRelayPinMode); + outputPinRegisterExt2("main relay", &enginePins.mainRelay, boardConfiguration->mainRelayPin, &boardConfiguration->mainRelayPinMode); - outputPinRegisterExt2("fan relay", &outputs[(int)FAN_RELAY], boardConfiguration->fanPin, &DEFAULT_OUTPUT); - outputPinRegisterExt2("o2 heater", &outputs[(int)O2_HEATER], boardConfiguration->o2heaterPin, &DEFAULT_OUTPUT); - outputPinRegisterExt2("A/C relay", &outputs[(int)AC_RELAY], boardConfiguration->acRelayPin, &boardConfiguration->acRelayPinMode); + 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); // digit 1 /* @@ -180,7 +181,7 @@ static io_pin_e TO_BE_TURNED_OFF_ON_ERROR[] = { SPARKOUT_1_OUTPUT, SPARKOUT_2_OU INJECTOR_1_OUTPUT, INJECTOR_2_OUTPUT, INJECTOR_3_OUTPUT, INJECTOR_4_OUTPUT, INJECTOR_5_OUTPUT, INJECTOR_6_OUTPUT, INJECTOR_7_OUTPUT, INJECTOR_8_OUTPUT, INJECTOR_9_OUTPUT, INJECTOR_10_OUTPUT, - INJECTOR_11_OUTPUT, INJECTOR_12_OUTPUT, FUEL_PUMP_RELAY }; + INJECTOR_11_OUTPUT, INJECTOR_12_OUTPUT }; /** * This method is part of fatal error handling.