picofuse

gpio.h
Go to the documentation of this file.
1 
11 #pragma once
12 #include <stdbool.h>
13 #include <stdint.h>
14 
16 // TYPES
17 
22 typedef enum {
23  hw_gpio_none = 0,
24  hw_gpio_input,
25  hw_gpio_pullup,
26  hw_gpio_pulldown,
27  hw_gpio_output,
28  hw_gpio_spi,
29  hw_gpio_i2c,
30  hw_gpio_uart,
31  hw_gpio_pwm,
32  hw_gpio_adc,
33  hw_gpio_unknown,
35 
40 typedef enum {
41  hw_gpio_rising = (1 << 0),
42  hw_gpio_falling = (1 << 1),
44 
50 typedef struct hw_gpio_t hw_gpio_t;
51 
61 typedef void (*hw_gpio_callback_t)(uint8_t bank, uint8_t pin,
62  hw_gpio_event_t event, void *userdata);
63 
65 // LIFECYCLE
66 
80 hw_gpio_t *hw_gpio_init(uint8_t bank, uint8_t pin, hw_gpio_mode_t mode);
81 
88 void hw_gpio_deinit(hw_gpio_t *gpio);
89 
100 uint8_t hw_gpio_count(uint8_t bank);
101 
110 void hw_gpio_set_callback(hw_gpio_callback_t callback, void *userdata);
111 
114 // METHODS
116 
127 uint8_t hw_gpio_pin(const hw_gpio_t *gpio);
128 
137 uint8_t hw_gpio_bank(const hw_gpio_t *gpio);
138 
147 
155 void hw_gpio_set_mode(hw_gpio_t *gpio, hw_gpio_mode_t mode);
156 
165 bool hw_gpio_get(const hw_gpio_t *gpio);
166 
174 void hw_gpio_set(hw_gpio_t *gpio, bool value);
175 
hw_gpio_mode_t hw_gpio_get_mode(const hw_gpio_t *gpio)
Get the current mode configuration of a GPIO pin.
struct hw_gpio_t hw_gpio_t
GPIO logical pin structure.
Definition: gpio.h:50
hw_gpio_event_t
GPIO interrupt event flags.
Definition: gpio.h:40
uint8_t hw_gpio_pin(const hw_gpio_t *gpio)
Get the logical pin number for a GPIO handle.
hw_gpio_mode_t
GPIO mode flags for configuring GPIO pins.
Definition: gpio.h:22
void(* hw_gpio_callback_t)(uint8_t bank, uint8_t pin, hw_gpio_event_t event, void *userdata)
GPIO interrupt callback function pointer.
Definition: gpio.h:61
uint8_t hw_gpio_bank(const hw_gpio_t *gpio)
Get the GPIO bank number for a GPIO handle.
bool hw_gpio_get(const hw_gpio_t *gpio)
Read the current state of a GPIO pin.
void hw_gpio_deinit(hw_gpio_t *gpio)
Deinitialize and release a GPIO pin.
void hw_gpio_set_callback(hw_gpio_callback_t callback, void *userdata)
Set the global GPIO interrupt callback handler.
uint8_t hw_gpio_count(uint8_t bank)
Get the total number of available GPIO pins for a given bank.
void hw_gpio_set_mode(hw_gpio_t *gpio, hw_gpio_mode_t mode)
Set the current mode configuration of a GPIO pin.
void hw_gpio_set(hw_gpio_t *gpio, bool value)
Set the state of a GPIO pin.
hw_gpio_t * hw_gpio_init(uint8_t bank, uint8_t pin, hw_gpio_mode_t mode)
Initialize a GPIO pin with the specified mode.