picofuse

Typedefs | Enumerations

General Purpose Input/Output (GPIO) interface for hardware platforms. More...

Collaboration diagram for GPIO:

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.
 
enum  hw_gpio_event_t { hw_gpio_rising = (1 << 0), hw_gpio_falling = (1 << 1) }
 GPIO interrupt event flags.
 

Lifecycle

hw_gpio_thw_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_deinit (hw_gpio_t *gpio)
 Deinitialize and release a GPIO pin. More...
 
uint8_t hw_gpio_count (uint8_t bank)
 Get the total number of available GPIO pins for a given bank. More...
 
void hw_gpio_set_callback (hw_gpio_callback_t callback, void *userdata)
 Set the global GPIO interrupt callback handler. More...
 

Methods

uint8_t hw_gpio_pin (const hw_gpio_t *gpio)
 Get the logical pin number for a GPIO handle. More...
 
uint8_t hw_gpio_bank (const hw_gpio_t *gpio)
 Get the GPIO bank number for a GPIO handle. More...
 
hw_gpio_mode_t hw_gpio_get_mode (const 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 (const 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...
 

Detailed Description

General Purpose Input/Output (GPIO) interface for hardware platforms.

This module provides functions to initialize GPIO pins, set their modes, and handle interrupts.

Typedef Documentation

◆ 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
bankThe GPIO bank number that triggered the event.
pinThe logical pin number that triggered the event.
eventThe type of GPIO event that occurred.
userdataUser-defined data pointer passed when setting the callback.

Definition at line 61 of file gpio.h.

Function Documentation

◆ hw_gpio_bank()

uint8_t hw_gpio_bank ( const hw_gpio_t gpio)

Get the GPIO bank number for a GPIO handle.

Parameters
gpioPointer 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
bankThe 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()

void hw_gpio_deinit ( hw_gpio_t gpio)

Deinitialize and release a GPIO pin.

Parameters
gpioPointer to the GPIO structure to deinitialize.

◆ hw_gpio_get()

bool hw_gpio_get ( const hw_gpio_t gpio)

Read the current state of a GPIO pin.

Parameters
gpioPointer to the GPIO structure.
Return values
trueThe pin is high.
falseThe pin is low.

◆ hw_gpio_get_mode()

hw_gpio_mode_t hw_gpio_get_mode ( const hw_gpio_t gpio)

Get the current mode configuration of a GPIO pin.

Parameters
gpioPointer to the GPIO structure.
Returns
The current GPIO mode configuration.

◆ hw_gpio_init()

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.

Parameters
bankThe GPIO bank number to which the pin belongs.
pinThe logical GPIO pin number to initialize.
modeThe 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
gpioPointer 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
gpioPointer to the GPIO structure.
valuetrue to set the pin high, false to set it low.

◆ hw_gpio_set_callback()

void hw_gpio_set_callback ( hw_gpio_callback_t  callback,
void *  userdata 
)

Set the global GPIO interrupt callback handler.

Parameters
callbackPointer to the callback function, or NULL to disable interrupt handling.
userdataUser-defined data pointer to pass to the callback.

◆ hw_gpio_set_mode()

void hw_gpio_set_mode ( hw_gpio_t gpio,
hw_gpio_mode_t  mode 
)

Set the current mode configuration of a GPIO pin.

Parameters
gpioPointer to the GPIO structure.
modeThe new GPIO mode configuration to set.