General Purpose Input/Output (GPIO) interface for hardware platforms.
More...
|
| 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.
|
| |
| enum | hw_gpio_event_t { hw_gpio_rising = (1 << 0),
hw_gpio_falling = (1 << 1)
} |
| | GPIO interrupt event flags.
|
| |
General Purpose Input/Output (GPIO) interface for hardware platforms.
This module provides functions to initialize GPIO pins, set their modes, and handle interrupts.
◆ hw_gpio_callback_t
| typedef void(* hw_gpio_callback_t) (uint8_t bank, uint8_t pin, hw_gpio_event_t event, void *userdata) |
GPIO interrupt callback function pointer.
- Parameters
-
| bank | The GPIO bank number that triggered the event. |
| pin | The logical pin number that triggered the event. |
| event | The type of GPIO event that occurred. |
| userdata | User-defined data pointer passed when setting the callback. |
Definition at line 61 of file gpio.h.
◆ hw_gpio_bank()
| uint8_t hw_gpio_bank |
( |
const hw_gpio_t * |
gpio | ) |
|
Get the GPIO bank number for a GPIO handle.
- Parameters
-
| gpio | Pointer to the GPIO structure. |
- Returns
- The GPIO bank number. Always
0 on Pico, which only has one bank.
◆ hw_gpio_count()
| uint8_t hw_gpio_count |
( |
uint8_t |
bank | ) |
|
Get the total number of available GPIO pins for a given bank.
- Parameters
-
| bank | The GPIO bank number to query. |
- Returns
- The number of GPIO pins available on the hardware platform, or
0 if bank doesn't exist - or, on backends that can't always determine this (e.g. an FTDI device with no known pin count for its chip type), because the count is simply unknown.
◆ hw_gpio_deinit()
Deinitialize and release a GPIO pin.
- Parameters
-
| gpio | Pointer to the GPIO structure to deinitialize. |
◆ hw_gpio_get()
Read the current state of a GPIO pin.
- Parameters
-
| gpio | Pointer to the GPIO structure. |
- Return values
-
| true | The pin is high. |
| false | The pin is low. |
◆ hw_gpio_get_mode()
Get the current mode configuration of a GPIO pin.
- Parameters
-
| gpio | Pointer to the GPIO structure. |
- Returns
- The current GPIO mode configuration.
◆ hw_gpio_init()
Initialize a GPIO pin with the specified mode.
- Parameters
-
| bank | The GPIO bank number to which the pin belongs. |
| pin | The logical GPIO pin number to initialize. |
| mode | The GPIO mode configuration. |
- Returns
- A pointer to the initialized GPIO structure, or
NULL if initialization fails.
◆ hw_gpio_pin()
| uint8_t hw_gpio_pin |
( |
const hw_gpio_t * |
gpio | ) |
|
Get the logical pin number for a GPIO handle.
- Parameters
-
| gpio | Pointer to the GPIO structure. |
- Returns
- The logical GPIO pin number.
◆ hw_gpio_set()
| void hw_gpio_set |
( |
hw_gpio_t * |
gpio, |
|
|
bool |
value |
|
) |
| |
Set the state of a GPIO pin.
- Parameters
-
| gpio | Pointer to the GPIO structure. |
| value | true to set the pin high, false to set it low. |
◆ hw_gpio_set_callback()
Set the global GPIO interrupt callback handler.
- Parameters
-
| callback | Pointer to the callback function, or NULL to disable interrupt handling. |
| userdata | User-defined data pointer to pass to the callback. |
◆ hw_gpio_set_mode()
Set the current mode configuration of a GPIO pin.
- Parameters
-
| gpio | Pointer to the GPIO structure. |
| mode | The new GPIO mode configuration to set. |