Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gpio_utils.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <errno.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/slist.h>

Go to the source code of this file.

Macros

#define GPIO_PORT_PIN_MASK_FROM_NGPIOS(ngpios)
 
#define GPIO_PORT_PIN_MASK_FROM_DT_NODE(node_id)
 Makes a bitmask of allowed GPIOs from the "gpio-reserved-ranges" and "ngpios" DT properties values.
 
#define GPIO_PORT_PIN_MASK_FROM_DT_INST(inst)
 Make a bitmask of allowed GPIOs from a DT_DRV_COMPAT instance's GPIO "gpio-reserved-ranges" and "ngpios" DT properties values.
 

Functions

static int gpio_manage_callback (sys_slist_t *callbacks, struct gpio_callback *callback, bool set)
 Generic function to insert or remove a callback from a callback list.
 
static void gpio_fire_callbacks (sys_slist_t *list, const struct device *port, uint32_t pins)
 Generic function to go through and fire callback from a callback list.
 

Macro Definition Documentation

◆ GPIO_PORT_PIN_MASK_FROM_DT_INST

#define GPIO_PORT_PIN_MASK_FROM_DT_INST ( inst)
Value:
#define GPIO_PORT_PIN_MASK_FROM_DT_NODE(node_id)
Makes a bitmask of allowed GPIOs from the "gpio-reserved-ranges" and "ngpios" DT properties values.
Definition gpio_utils.h:35
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:3809

Make a bitmask of allowed GPIOs from a DT_DRV_COMPAT instance's GPIO "gpio-reserved-ranges" and "ngpios" DT properties values.

Parameters
instDT_DRV_COMPAT instance number
Returns
the bitmask of allowed gpios
See also
GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC()

◆ GPIO_PORT_PIN_MASK_FROM_DT_NODE

#define GPIO_PORT_PIN_MASK_FROM_DT_NODE ( node_id)
Value:
GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC(node_id, DT_PROP(node_id, ngpios))
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition devicetree.h:752
#define GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC(node_id, ngpios)
Makes a bitmask of allowed GPIOs from DT "gpio-reserved-ranges" property and "ngpios" argument.
Definition gpio.h:657

Makes a bitmask of allowed GPIOs from the "gpio-reserved-ranges" and "ngpios" DT properties values.

Parameters
node_idGPIO controller node identifier.
Returns
the bitmask of allowed gpios
See also
GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC()

◆ GPIO_PORT_PIN_MASK_FROM_NGPIOS

#define GPIO_PORT_PIN_MASK_FROM_NGPIOS ( ngpios)
Value:
((gpio_port_pins_t)(((uint64_t)1 << (ngpios)) - 1U))
uint32_t gpio_port_pins_t
Identifies a set of pins associated with a port.
Definition gpio.h:233
__UINT64_TYPE__ uint64_t
Definition stdint.h:91

Function Documentation

◆ gpio_fire_callbacks()

static void gpio_fire_callbacks ( sys_slist_t * list,
const struct device * port,
uint32_t pins )
inlinestatic

Generic function to go through and fire callback from a callback list.

Parameters
listA pointer on the gpio callback list
portA pointer on the gpio driver instance
pinsThe actual pin mask that triggered the interrupt

◆ gpio_manage_callback()

static int gpio_manage_callback ( sys_slist_t * callbacks,
struct gpio_callback * callback,
bool set )
inlinestatic

Generic function to insert or remove a callback from a callback list.

Parameters
callbacksA pointer to the original list of callbacks (can be NULL)
callbackA pointer of the callback to insert or remove from the list
setA boolean indicating insertion or removal of the callback
Returns
0 on success, negative errno otherwise.