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 2052b9e commit 83236ef
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/driver/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/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: 1 addition & 1 deletion src/driver/at32/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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: 1 addition & 1 deletion src/driver/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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 @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/driver/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ void spi_txn_finish(spi_ports_t port) {

spi_dev[port].dma_done = true;
spi_txn_continue_port(port);
}
}
2 changes: 2 additions & 0 deletions src/driver/stm32/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/driver/stm32/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/driver/stm32/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/io/buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -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;
Expand Down

0 comments on commit 83236ef

Please sign in to comment.