diff options
Diffstat (limited to 'include/kern/gpio/gpio_manager.h')
-rw-r--r-- | include/kern/gpio/gpio_manager.h | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/include/kern/gpio/gpio_manager.h b/include/kern/gpio/gpio_manager.h index 922a423..cb61059 100644 --- a/include/kern/gpio/gpio_manager.h +++ b/include/kern/gpio/gpio_manager.h @@ -1,8 +1,8 @@ #ifndef KERN_GPIO_GPIO_MANAGE_H_ #define KERN_GPIO_GPIO_MANAGE_H_ -#include "kern/common.h" #include "arch/stm32l4xxx/peripherals/gpio.h" +#include "kern/common.h" #define GPIO_ERROR_IN_USE 1 #define GPIO_ERROR_INVALID_PIN_FOR_ALTERNATE_FUNCTION 2 @@ -10,8 +10,7 @@ typedef enum { /* Creates vaules GPIO_PIN_<port><num> i.e. GPIO_PIN_A0 */ -#define PORT(p, pn) \ - GPIO_PIN_P ## p ## pn, +#define PORT(p, pn) GPIO_PIN_P##p##pn, #include "arch/stm32l4xxx/peripherals/tables/stm32l432xx/gpio/port_table.inc" #undef PORT @@ -20,16 +19,14 @@ typedef enum { /* Alternate functions. */ typedef enum { -#define AFN(fn, ...) \ - GPIO_ALTERNATE_FUNCTION_ ## fn, +#define AFN(fn, ...) GPIO_ALTERNATE_FUNCTION_##fn, #include "arch/stm32l4xxx/peripherals/tables/stm32l432xx/gpio/afn_table.inc" #undef AFN GPIO_ALTERNATE_FUNCTION_EVENTOUT, } gpio_alternate_function_t; #define gpio_pin_for_alternate_function(af) ((af) / 16) -#define gpio_pin_out_of_range(pin) \ - ((pin) < 0 || (pin) >= N_GPIO_PINS) +#define gpio_pin_out_of_range(pin) ((pin) < 0 || (pin) >= N_GPIO_PINS) typedef enum { GPIO_PORT_A, @@ -83,41 +80,43 @@ typedef enum { inline static gpio_port_t get_port_for_pin(gpio_pin_t pin) { switch (pin) { -#define PORT(p, pn) \ - case GPIO_PIN_P ## p ## pn: return GPIO_PORT_ ## p; +#define PORT(p, pn) \ + case GPIO_PIN_P##p##pn: \ + return GPIO_PORT_##p; #include "arch/stm32l4xxx/peripherals/tables/stm32l432xx/gpio/port_table.inc" #undef PORT - case N_GPIO_PINS: return N_GPIO_PORTS; + case N_GPIO_PINS: + return N_GPIO_PORTS; } /* Should be unreachable. */ } -#define DEFAULT_GPIO_OPTS_OUTPUT \ - (gpio_pin_opts_t) { \ - .mode = GPIO_MODE_OUTPUT, \ - .pull_dir = GPIO_PULL_DIR_DOWN, \ - .output_opts.speed = GPIO_OUTPUT_SPEED_MEDIUM, \ - .output_opts.type = GPIO_OUTPUT_TYPE_PUSH_PULL, \ +#define DEFAULT_GPIO_OPTS_OUTPUT \ + (gpio_pin_opts_t) \ + { \ + .mode = GPIO_MODE_OUTPUT, .pull_dir = GPIO_PULL_DIR_DOWN, \ + .output_opts.speed = GPIO_OUTPUT_SPEED_MEDIUM, \ + .output_opts.type = GPIO_OUTPUT_TYPE_PUSH_PULL, \ } -#define DEFAULT_GPIO_OPTS_INPUT \ - (gpio_pin_opts_t) { \ - .mode = GPIO_MODE_OUTPUT, \ - .pull_dir = GPIO_PULL_DIR_DOWN, \ +#define DEFAULT_GPIO_OPTS_INPUT \ + (gpio_pin_opts_t) \ + { \ + .mode = GPIO_MODE_INPUT, .pull_dir = GPIO_PULL_DIR_DOWN, \ } typedef struct { - gpio_mode_t mode; - gpio_pull_dir_t pull_dir; + gpio_mode_t mode; + gpio_pull_dir_t pull_dir; union { struct { } input_opts; struct { - gpio_output_speed_t speed; - gpio_output_type_t type; + gpio_output_speed_t speed; + gpio_output_type_t type; } output_opts; struct { @@ -171,9 +170,7 @@ gpio_reserved_pin_t reserve_gpio_pin( * */ gpio_reserved_pin_t gpio_enable_alternate_function( - gpio_alternate_function_t fn, - gpio_pin_t hint, - int* error_out); + gpio_alternate_function_t fn, gpio_pin_t hint, int* error_out); /* * Releases the GPIO pin so it can be reserved again in the future. @@ -184,4 +181,9 @@ gpio_reserved_pin_t gpio_enable_alternate_function( */ void release_gpio_pin(gpio_reserved_pin_t gpio_pin); +/* + * Returns whether the GPIO pin has high or low input. + */ +bool get_gpio_pin_input_state(gpio_reserved_pin_t pin); + #endif /* KERN_GPIO_GPIO_MANAGE_H_ */ |