objc

gpio.h
Go to the documentation of this file.
1 
13 #pragma once
14 #include <stdbool.h>
15 #include <stdint.h>
16 
18 // TYPES
19 
26 #define HW_GPIO_MAX_COUNT 50
27 
32 typedef enum {
45 
50 typedef enum {
51  HW_GPIO_RISING = (1 << 0),
52  HW_GPIO_FALLING = (1 << 1),
54 
60 typedef struct hw_gpio_t {
61  uint64_t mask;
62  uint8_t pin;
63 } hw_gpio_t;
64 
80 typedef void (*hw_gpio_callback_t)(uint8_t pin, hw_gpio_event_t event,
81  void *userdata);
82 
84 // LIFECYCLE
85 
98 uint8_t hw_gpio_count(void);
99 
108 static inline bool hw_gpio_valid(hw_gpio_t *gpio) {
109  return gpio && gpio->mask > 0;
110 }
111 
125 void hw_gpio_set_callback(hw_gpio_callback_t callback, void *userdata);
126 
136 hw_gpio_t hw_gpio_init(uint8_t pin, hw_gpio_mode_t mode);
137 
145 void hw_gpio_finalize(hw_gpio_t *gpio);
146 
154 
164 void hw_gpio_set_mode(hw_gpio_t *gpio, hw_gpio_mode_t mode);
165 
174 bool hw_gpio_get(hw_gpio_t *gpio);
175 
185 void hw_gpio_set(hw_gpio_t *gpio, bool value);
GPIO pin configured for PWM.
Definition: gpio.h:41
GPIO pin floating input.
Definition: gpio.h:34
hw_gpio_event_t
GPIO mode flags for configuring GPIO pins.
Definition: gpio.h:50
void(* hw_gpio_callback_t)(uint8_t pin, hw_gpio_event_t event, void *userdata)
GPIO interrupt callback function pointer.
Definition: gpio.h:80
GPIO pin input with pull-down resistor.
Definition: gpio.h:36
No GPIO mode set.
Definition: gpio.h:33
hw_gpio_t hw_gpio_init(uint8_t pin, hw_gpio_mode_t mode)
Initialize a GPIO pin with the specified mode.
GPIO pin configured as output.
Definition: gpio.h:37
uint8_t pin
GPIO logical pin number.
Definition: gpio.h:62
GPIO pin configured for I2C.
Definition: gpio.h:39
GPIO pin falling edge interrupt.
Definition: gpio.h:52
hw_gpio_mode_t
GPIO mode flags for configuring GPIO pins.
Definition: gpio.h:32
uint8_t hw_gpio_count(void)
Get the total number of available GPIO pins.
bool hw_gpio_get(hw_gpio_t *gpio)
Read the current state of a GPIO pin.
uint64_t mask
GPIO pin mask for multiple pins.
Definition: gpio.h:61
static bool hw_gpio_valid(hw_gpio_t *gpio)
Validate the GPIO pin.
Definition: gpio.h:108
GPIO pin rising edge interrupt.
Definition: gpio.h:51
GPIO pin configured for analog input.
Definition: gpio.h:42
GPIO pin mode is not implemented.
Definition: gpio.h:43
GPIO pin configured for SPI.
Definition: gpio.h:38
void hw_gpio_finalize(hw_gpio_t *gpio)
Finalize and release a GPIO pin.
GPIO pin configured for UART.
Definition: gpio.h:40
hw_gpio_mode_t hw_gpio_get_mode(hw_gpio_t *gpio)
Get the current mode configuration of a GPIO pin.
void hw_gpio_set_callback(hw_gpio_callback_t callback, void *userdata)
Set the global GPIO interrupt callback handler.
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.
GPIO logical pin structure.
Definition: gpio.h:60
struct hw_gpio_t hw_gpio_t
GPIO logical pin structure.
GPIO pin input with pull-up resistor.
Definition: gpio.h:35