General Purpose Input/Output (GPIO) interface for hardware platforms. More...
|
Data Structures | |
| struct | hw_gpio_t |
| GPIO logical pin structure. More... | |
Macros | |
| #define | HW_GPIO_MAX_COUNT 64 |
| Maximum number of GPIO pins. More... | |
Typedefs | |
| typedef struct hw_gpio_t | hw_gpio_t |
| GPIO logical pin structure. | |
| typedef void(* | hw_gpio_callback_t) (uint8_t bank, uint8_t pin, hw_gpio_event_t event, void *userdata) |
| GPIO interrupt callback function pointer. More... | |
Enumerations | |
| enum | hw_gpio_mode_t { HW_GPIO_NONE = 0, HW_GPIO_INPUT, HW_GPIO_PULLUP, HW_GPIO_PULLDOWN, HW_GPIO_OUTPUT, HW_GPIO_SPI, HW_GPIO_I2C, HW_GPIO_UART, HW_GPIO_PWM, HW_GPIO_ADC, HW_GPIO_UNKNOWN } |
| GPIO mode flags for configuring GPIO pins. More... | |
| enum | hw_gpio_event_t { HW_GPIO_RISING = (1 << 0), HW_GPIO_FALLING = (1 << 1) } |
| GPIO mode flags for configuring GPIO pins. More... | |
Functions | |
| uint8_t | hw_gpio_count (uint8_t bank) |
| Get the total number of available GPIO pins for a given bank. More... | |
| static bool | hw_gpio_valid (hw_gpio_t *gpio) |
| Validate the GPIO pin. More... | |
| void | hw_gpio_set_callback (hw_gpio_callback_t callback, void *userdata) |
| Set the global GPIO interrupt callback handler. More... | |
| 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. More... | |
| void | hw_gpio_finalize (hw_gpio_t *gpio) |
| Finalize and release a GPIO pin. More... | |
| hw_gpio_mode_t | hw_gpio_get_mode (hw_gpio_t *gpio) |
| Get the current mode configuration of a GPIO pin. More... | |
| void | hw_gpio_set_mode (hw_gpio_t *gpio, hw_gpio_mode_t mode) |
| Set the current mode configuration of a GPIO pin. More... | |
| bool | hw_gpio_get (hw_gpio_t *gpio) |
| Read the current state of a GPIO pin. More... | |
| void | hw_gpio_set (hw_gpio_t *gpio, bool value) |
| Set the state of a GPIO pin. More... | |
General Purpose Input/Output (GPIO) interface for hardware platforms.
This module provides functions to initialize GPIO pins, set their modes, and handle interrupts.
| #define HW_GPIO_MAX_COUNT 64 |
| typedef void(* hw_gpio_callback_t) (uint8_t bank, uint8_t pin, hw_gpio_event_t event, void *userdata) |
GPIO interrupt callback function pointer.
| pin | The logical pin number that triggered the event. |
| event | The type of GPIO event that occurred (rising or falling edge). |
| userdata | User-defined data pointer passed when setting the callback. |
This callback function is called when a GPIO interrupt occurs on a pin that has been configured for interrupt detection. The callback is executed in interrupt context, so it should be kept short and avoid blocking operations.
| enum hw_gpio_event_t |
| enum hw_gpio_mode_t |
GPIO mode flags for configuring GPIO pins.
| Enumerator | |
|---|---|
| HW_GPIO_NONE | No GPIO mode set. |
| HW_GPIO_INPUT | GPIO pin floating input. |
| HW_GPIO_PULLUP | GPIO pin input with pull-up resistor. |
| HW_GPIO_PULLDOWN | GPIO pin input with pull-down resistor. |
| HW_GPIO_OUTPUT | GPIO pin configured as output. |
| HW_GPIO_SPI | GPIO pin configured for SPI. |
| HW_GPIO_I2C | GPIO pin configured for I2C. |
| HW_GPIO_UART | GPIO pin configured for UART. |
| HW_GPIO_PWM | GPIO pin configured for PWM. |
| HW_GPIO_ADC | GPIO pin configured for analog input. |
| HW_GPIO_UNKNOWN | GPIO pin mode is not implemented. |
Definition at line 32 of file gpio.h.
| uint8_t hw_gpio_count | ( | uint8_t | bank | ) |
Get the total number of available GPIO pins for a given bank.
| bank | The GPIO bank number to query (0-based). |
Returns the number of logical GPIO pins that can be used in the system. These are usually numbered from 0 to hw_gpio_count() - 1. If zero is returned, it indicates that GPIO functionality is not available, or the specified bank does not exist.
It will never return more than HW_GPIO_MAX_COUNT as this is a hard limit on the number of supported GPIO pins.
| void hw_gpio_finalize | ( | hw_gpio_t * | gpio | ) |
| bool hw_gpio_get | ( | hw_gpio_t * | gpio | ) |
| hw_gpio_mode_t hw_gpio_get_mode | ( | hw_gpio_t * | gpio | ) |
| 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.
| bank | The GPIO bank number to which the pin belongs (0-based). |
| pin | The logical GPIO pin number to initialize. |
| mode | The GPIO mode configuration (input, output, pull-up, etc.). |
| void hw_gpio_set | ( | hw_gpio_t * | gpio, |
| bool | value | ||
| ) |
| void hw_gpio_set_callback | ( | hw_gpio_callback_t | callback, |
| void * | userdata | ||
| ) |
Set the global GPIO interrupt callback handler.
| callback | Pointer to the callback function to handle GPIO interrupts, or NULL to disable interrupt handling. |
| userdata | User-defined data pointer to pass to the callback. |
This function registers a global callback handler that will be invoked whenever a GPIO interrupt occurs on any pin that has been configured for interrupt detection. Only one callback can be active at a time.
| void hw_gpio_set_mode | ( | hw_gpio_t * | gpio, |
| hw_gpio_mode_t | mode | ||
| ) |
|
inlinestatic |