Skip to content

Commit

Permalink
gpio_config: add default value
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Aug 21, 2024
1 parent de56161 commit f3f49d3
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/driver/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "driver/timer.h"

typedef enum {
GPIO_INPUT,
GPIO_OUTPUT,
GPIO_INPUT,
GPIO_ANALOG,
GPIO_ALTERNATE,
} gpio_mode_t;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/driver/mcu/at32/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/driver/mcu/at32/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/driver/mcu/stm32/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/driver/mcu/stm32/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/driver/mcu/stm32/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/driver/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/driver/serial_4way_avr_bl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/driver/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/rx/unified_dsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f3f49d3

Please sign in to comment.