diff --git a/src/driver/at32/adc.c b/src/driver/at32/adc.c index 8be05fd2f..54a566065 100644 --- a/src/driver/at32/adc.c +++ b/src/driver/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/at32/gpio.c b/src/driver/at32/gpio.c index 3b02125a0..2de7a6b0f 100644 --- a/src/driver/at32/gpio.c +++ b/src/driver/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/at32/spi.c b/src/driver/at32/spi.c index d3fd7d8d2..adc70c16a 100644 --- a/src/driver/at32/spi.c +++ b/src/driver/at32/spi.c @@ -188,7 +188,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/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/serial.c b/src/driver/serial.c index 220b54ddf..6475b3bdf 100644 --- a/src/driver/serial.c +++ b/src/driver/serial.c @@ -38,7 +38,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 b1ad50554..0c30d6614 100644 --- a/src/driver/serial_4way_avr_bl.c +++ b/src/driver/serial_4way_avr_bl.c @@ -53,7 +53,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; @@ -62,7 +62,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 e650c5873..e7d698a81 100644 --- a/src/driver/spi.c +++ b/src/driver/spi.c @@ -187,4 +187,4 @@ void spi_txn_finish(spi_ports_t port) { spi_dev[port].dma_done = true; spi_txn_continue_port(port); -} \ No newline at end of file +} diff --git a/src/driver/stm32/adc.c b/src/driver/stm32/adc.c index 6220ab227..ed8c976a0 100644 --- a/src/driver/stm32/adc.c +++ b/src/driver/stm32/adc.c @@ -87,6 +87,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/stm32/serial.c b/src/driver/stm32/serial.c index 50905c22b..65167f1c2 100644 --- a/src/driver/stm32/serial.c +++ b/src/driver/stm32/serial.c @@ -87,7 +87,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/stm32/spi.c b/src/driver/stm32/spi.c index 13d9782d5..9b475a773 100644 --- a/src/driver/stm32/spi.c +++ b/src/driver/stm32/spi.c @@ -169,7 +169,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/io/buzzer.c b/src/io/buzzer.c index d2e3f5bd4..1cfe7348d 100644 --- a/src/io/buzzer.c +++ b/src/io/buzzer.c @@ -36,7 +36,7 @@ void buzzer_init() { return; } - 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/rx/unified_dsm.c b/src/rx/unified_dsm.c index 70414b123..ec4244815 100644 --- a/src/rx/unified_dsm.c +++ b/src/rx/unified_dsm.c @@ -160,7 +160,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;