From 17e05402edc7094e004f0d54c472fbd817802631 Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 21 Apr 2017 17:14:14 -0400 Subject: [PATCH] refactoring - reducing GPIO complexity --- firmware/controllers/system/efiGpio.cpp | 35 ++++++++++--------------- firmware/hw_layer/io_pins.cpp | 1 - 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index ecb915b8b2..acba3fbd02 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -231,12 +231,19 @@ void initOutputPins(void) { #if EFI_GPIO_HARDWARE || defined(__DOXYGEN__) -/** - * This method is used for digital GPIO pins only, for peripheral pins see mySetPadMode - */ -static void outputPinRegisterExt(const char *msg, OutputPin *output, ioportid_t port, uint32_t pin, - pin_output_mode_e *outputMode) { -#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__) +void initPrimaryPins(void) { + outputPinRegisterExt2("led: ERROR status", &enginePins.errorLedPin, LED_ERROR_BRAIN_PIN, &DEFAULT_OUTPUT); +} + +void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode) { + if (brainPin == GPIO_UNASSIGNED) + return; + ioportid_t port = getHwPort(brainPin); + int pin = getHwPin(brainPin); + + /** + * This method is used for digital GPIO pins only, for peripheral pins see mySetPadMode + */ if (port == GPIO_NULL) { // that's for GRIO_NONE output->port = port; @@ -245,25 +252,11 @@ static void outputPinRegisterExt(const char *msg, OutputPin *output, ioportid_t assertOMode(*outputMode); iomode_t mode = (*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) ? - PAL_MODE_OUTPUT_PUSHPULL : PAL_MODE_OUTPUT_OPENDRAIN; + PAL_MODE_OUTPUT_PUSHPULL : PAL_MODE_OUTPUT_OPENDRAIN; initOutputPinExt(msg, output, port, pin, mode); output->setDefaultPinState(outputMode); -#endif /* EFI_GPIO_HARDWARE */ -} - -void initPrimaryPins(void) { - outputPinRegisterExt2("led: ERROR status", &enginePins.errorLedPin, LED_ERROR_BRAIN_PIN, &DEFAULT_OUTPUT); -} - -void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode) { - if (brainPin == GPIO_UNASSIGNED) - return; - ioportid_t hwPort = getHwPort(brainPin); - int hwPin = getHwPin(brainPin); - - outputPinRegisterExt(msg, output, hwPort, hwPin, outputMode); } /** diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index f43596620f..904cd7cd80 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -53,7 +53,6 @@ ioportmask_t getHwPin(brain_pin_e brainPin) { return brainPin % PORT_SIZE; } - /** * @brief Initialize the hardware output pin while also assigning it a logical name */