From f3f49d30bd75a7623b3f1059881e64314a249c67 Mon Sep 17 00:00:00 2001 From: bkleiner Date: Thu, 22 Aug 2024 00:24:35 +0200 Subject: [PATCH] gpio_config: add default value --- src/driver/gpio.h | 9 ++++++++- src/driver/mcu/at32/adc.c | 2 ++ src/driver/mcu/at32/gpio.c | 8 ++++---- src/driver/mcu/stm32/adc.c | 2 ++ src/driver/mcu/stm32/serial.c | 2 +- src/driver/mcu/stm32/spi.c | 2 +- src/driver/serial.c | 2 +- src/driver/serial_4way_avr_bl.c | 4 ++-- src/driver/spi.c | 2 +- src/rx/unified_dsm.c | 2 +- 10 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/driver/gpio.h b/src/driver/gpio.h index 5b2649469..a9390582d 100644 --- a/src/driver/gpio.h +++ b/src/driver/gpio.h @@ -5,8 +5,8 @@ #include "driver/timer.h" typedef enum { - GPIO_INPUT, GPIO_OUTPUT, + GPIO_INPUT, GPIO_ANALOG, GPIO_ALTERNATE, } gpio_mode_t; @@ -50,6 +50,13 @@ extern const gpio_pin_def_t gpio_pin_defs[PINS_MAX]; extern const gpio_af_t gpio_pin_afs[]; extern const uint32_t GPIO_AF_MAX; +#define gpio_config_default() { \ + .mode = GPIO_OUTPUT, \ + .output = GPIO_PUSHPULL, \ + .drive = GPIO_DRIVE_NORMAL, \ + .pull = GPIO_NO_PULL, \ +} + void gpio_ports_init(); void gpio_pin_init(gpio_pins_t pin, gpio_config_t config); diff --git a/src/driver/mcu/at32/adc.c b/src/driver/mcu/at32/adc.c index 3d6c06e6a..762b35317 100644 --- a/src/driver/mcu/at32/adc.c +++ b/src/driver/mcu/at32/adc.c @@ -54,6 +54,8 @@ static void adc_init_pin(adc_chan_t chan, gpio_pins_t pin) { if (adc_pins[chan].pin != PIN_NONE) { gpio_config_t gpio_init; gpio_init.mode = GPIO_ANALOG; + gpio_init.output = GPIO_OPENDRAIN; + gpio_init.output = GPIO_DRIVE_NORMAL; gpio_init.pull = GPIO_NO_PULL; gpio_pin_init(pin, gpio_init); } diff --git a/src/driver/mcu/at32/gpio.c b/src/driver/mcu/at32/gpio.c index 3b02125a0..2de7a6b0f 100644 --- a/src/driver/mcu/at32/gpio.c +++ b/src/driver/mcu/at32/gpio.c @@ -5,24 +5,24 @@ #include "driver/rcc.h" #include "driver/timer.h" -static const uint32_t mode_map[] = { +static const gpio_mode_type mode_map[] = { [GPIO_INPUT] = GPIO_MODE_INPUT, [GPIO_OUTPUT] = GPIO_MODE_OUTPUT, [GPIO_ANALOG] = GPIO_MODE_ANALOG, [GPIO_ALTERNATE] = GPIO_MODE_MUX, }; -static const uint32_t output_map[] = { +static const gpio_output_type output_map[] = { [GPIO_PUSHPULL] = GPIO_OUTPUT_PUSH_PULL, [GPIO_OPENDRAIN] = GPIO_OUTPUT_OPEN_DRAIN, }; -static const uint32_t speed_map[] = { +static const gpio_drive_type speed_map[] = { [GPIO_DRIVE_NORMAL] = GPIO_DRIVE_STRENGTH_MODERATE, [GPIO_DRIVE_HIGH] = GPIO_DRIVE_STRENGTH_STRONGER, }; -static const uint32_t pull_map[] = { +static const gpio_pull_type pull_map[] = { [GPIO_NO_PULL] = GPIO_PULL_NONE, [GPIO_UP_PULL] = GPIO_PULL_UP, [GPIO_DOWN_PULL] = GPIO_PULL_DOWN, diff --git a/src/driver/mcu/stm32/adc.c b/src/driver/mcu/stm32/adc.c index d4e847e22..a3e8c79ee 100644 --- a/src/driver/mcu/stm32/adc.c +++ b/src/driver/mcu/stm32/adc.c @@ -100,6 +100,8 @@ static void adc_init_pin(adc_chan_t chan, gpio_pins_t pin) { if (adc_pins[chan].pin != PIN_NONE) { gpio_config_t gpio_init; gpio_init.mode = GPIO_ANALOG; + gpio_init.output = GPIO_OPENDRAIN; + gpio_init.output = GPIO_DRIVE_NORMAL; gpio_init.pull = GPIO_NO_PULL; gpio_pin_init(pin, gpio_init); } diff --git a/src/driver/mcu/stm32/serial.c b/src/driver/mcu/stm32/serial.c index 5fd285898..27226f573 100644 --- a/src/driver/mcu/stm32/serial.c +++ b/src/driver/mcu/stm32/serial.c @@ -89,7 +89,7 @@ void handle_usart_invert(serial_ports_t port, bool invert) { } // Inverter control line, set high - gpio_config_t gpio_init; + gpio_config_t gpio_init = gpio_config_default(); gpio_init.mode = GPIO_OUTPUT; gpio_init.output = GPIO_PUSHPULL; gpio_init.pull = GPIO_NO_PULL; diff --git a/src/driver/mcu/stm32/spi.c b/src/driver/mcu/stm32/spi.c index cb3dd3a22..4aaf3f63b 100644 --- a/src/driver/mcu/stm32/spi.c +++ b/src/driver/mcu/stm32/spi.c @@ -155,7 +155,7 @@ void spi_reconfigure(spi_bus_device_t *bus) { if (config->mode != bus->mode) { config->mode = bus->mode; - gpio_config_t gpio_init; + gpio_config_t gpio_init = gpio_config_default(); gpio_init.mode = GPIO_ALTERNATE; gpio_init.drive = GPIO_DRIVE_HIGH; gpio_init.output = GPIO_PUSHPULL; diff --git a/src/driver/serial.c b/src/driver/serial.c index 3618aae24..a898b75c4 100644 --- a/src/driver/serial.c +++ b/src/driver/serial.c @@ -40,7 +40,7 @@ static bool serial_hard_pin_init(serial_port_t *serial, serial_port_config_t con bool swap = false; - gpio_config_t gpio_init; + gpio_config_t gpio_init = gpio_config_default(); gpio_init.mode = GPIO_ALTERNATE; gpio_init.drive = GPIO_DRIVE_HIGH; if (config.half_duplex) { diff --git a/src/driver/serial_4way_avr_bl.c b/src/driver/serial_4way_avr_bl.c index 73eaa5681..7090f5476 100644 --- a/src/driver/serial_4way_avr_bl.c +++ b/src/driver/serial_4way_avr_bl.c @@ -55,7 +55,7 @@ static void esc_set_low(gpio_pins_t pin) { } static void esc_set_input(gpio_pins_t pin) { - gpio_config_t gpio_init = {0}; + gpio_config_t gpio_init = gpio_config_default(); gpio_init.mode = GPIO_INPUT; gpio_init.output = GPIO_OPENDRAIN; gpio_init.pull = GPIO_UP_PULL; @@ -64,7 +64,7 @@ static void esc_set_input(gpio_pins_t pin) { } static void esc_set_output(gpio_pins_t pin) { - gpio_config_t gpio_init = {0}; + gpio_config_t gpio_init = gpio_config_default(); gpio_init.mode = GPIO_OUTPUT; gpio_init.output = GPIO_PUSHPULL; gpio_init.pull = GPIO_NO_PULL; diff --git a/src/driver/spi.c b/src/driver/spi.c index 64914525b..1e280985b 100644 --- a/src/driver/spi.c +++ b/src/driver/spi.c @@ -195,7 +195,7 @@ void spi_txn_finish(spi_ports_t port) { static void spi_init_pins(spi_ports_t port) { const target_spi_port_t *dev = &target.spi_ports[port]; - gpio_config_t gpio_init; + gpio_config_t gpio_init = gpio_config_default(); gpio_init.mode = GPIO_ALTERNATE; gpio_init.drive = GPIO_DRIVE_HIGH; diff --git a/src/rx/unified_dsm.c b/src/rx/unified_dsm.c index 8e848bbb5..21932a63e 100644 --- a/src/rx/unified_dsm.c +++ b/src/rx/unified_dsm.c @@ -162,7 +162,7 @@ void rx_spektrum_bind() { if (bind_storage.bind_saved == 0) { const gpio_pins_t spectrum_bind_pin = target.serial_ports[profile.serial.rx].rx; - gpio_config_t gpio_init; + gpio_config_t gpio_init = gpio_config_default(); gpio_init.mode = GPIO_OUTPUT; gpio_init.output = GPIO_PUSHPULL; gpio_init.pull = GPIO_NO_PULL;