Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
gpio.h File Reference

Public APIs for GPIO drivers. More...

#include <sys/__assert.h>
#include <sys/slist.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>
#include <dt-bindings/gpio/gpio.h>
#include <syscalls/gpio.h>

Go to the source code of this file.

Data Structures

struct  gpio_dt_spec
 Provides a type to hold GPIO information specified in devicetree. More...
 
struct  gpio_driver_config
 
struct  gpio_driver_data
 
struct  gpio_callback
 GPIO callback structure. More...
 

Macros

#define GPIO_INT_DEBOUNCE   (1U << 19)
 
#define GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)
 Static initializer for a gpio_dt_spec. More...
 
#define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value)
 Like GPIO_DT_SPEC_GET_BY_IDX(), with a fallback to a default value. More...
 
#define GPIO_DT_SPEC_GET(node_id, prop)    GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
 Equivalent to GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0). More...
 
#define GPIO_DT_SPEC_GET_OR(node_id, prop, default_value)    GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
 Equivalent to GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value). More...
 
#define GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx)    GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
 Static initializer for a gpio_dt_spec from a DT_DRV_COMPAT instance's GPIO property at an index. More...
 
#define GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value)    GPIO_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)
 Static initializer for a gpio_dt_spec from a DT_DRV_COMPAT instance's GPIO property at an index, with fallback. More...
 
#define GPIO_DT_SPEC_INST_GET(inst, prop)    GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
 Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0). More...
 
#define GPIO_DT_SPEC_INST_GET_OR(inst, prop, default_value)    GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
 Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value). More...
 
#define GPIO_MAX_PINS_PER_PORT   (sizeof(gpio_port_pins_t) * __CHAR_BIT__)
 Maximum number of pins that are supported by gpio_port_pins_t. More...
 
GPIO input/output configuration flags
#define GPIO_INPUT   (1U << 8)
 
#define GPIO_OUTPUT   (1U << 9)
 
#define GPIO_DISCONNECTED   0
 
#define GPIO_OUTPUT_LOW   (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW)
 
#define GPIO_OUTPUT_HIGH   (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH)
 
#define GPIO_OUTPUT_INACTIVE
 
#define GPIO_OUTPUT_ACTIVE
 
GPIO interrupt configuration flags

The GPIO_INT_* flags are used to specify how input GPIO pins will trigger interrupts. The interrupts can be sensitive to pin physical or logical level. Interrupts sensitive to pin logical level take into account GPIO_ACTIVE_LOW flag. If a pin was configured as Active Low, physical level low will be considered as logical level 1 (an active state), physical level high will be considered as logical level 0 (an inactive state).

#define GPIO_INT_DISABLE   (1U << 13)
 
#define GPIO_INT_EDGE_RISING
 
#define GPIO_INT_EDGE_FALLING
 
#define GPIO_INT_EDGE_BOTH
 
#define GPIO_INT_LEVEL_LOW
 
#define GPIO_INT_LEVEL_HIGH
 
#define GPIO_INT_EDGE_TO_INACTIVE
 
#define GPIO_INT_EDGE_TO_ACTIVE
 
#define GPIO_INT_LEVEL_INACTIVE
 
#define GPIO_INT_LEVEL_ACTIVE
 
GPIO drive strength flags

The GPIO_DS_* flags are used with gpio_pin_configure to specify the drive strength configuration of a GPIO pin.

The drive strength of individual pins can be configured independently for when the pin output is low and high.

The GPIO_DS_*_LOW enumerations define the drive strength of a pin when output is low.

The GPIO_DS_*_HIGH enumerations define the drive strength of a pin when output is high.

The interface supports two different drive strengths: DFLT - The lowest drive strength supported by the HW ALT - The highest drive strength supported by the HW

On hardware that supports only one standard drive strength, both DFLT and ALT have the same behavior.

#define GPIO_DS_DFLT_LOW   (0x0U << GPIO_DS_LOW_POS)
 
#define GPIO_DS_ALT_LOW   (0x1U << GPIO_DS_LOW_POS)
 
#define GPIO_DS_DFLT_HIGH   (0x0U << GPIO_DS_HIGH_POS)
 
#define GPIO_DS_ALT_HIGH   (0x1U << GPIO_DS_HIGH_POS)
 

Typedefs

typedef uint32_t gpio_port_pins_t
 Identifies a set of pins associated with a port. More...
 
typedef uint32_t gpio_port_value_t
 Provides values for a set of pins associated with a port. More...
 
typedef uint8_t gpio_pin_t
 Provides a type to hold a GPIO pin index. More...
 
typedef uint8_t gpio_dt_flags_t
 Provides a type to hold GPIO devicetree flags. More...
 
typedef uint32_t gpio_flags_t
 Provides a type to hold GPIO configuration flags. More...
 
typedef void(* gpio_callback_handler_t) (const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins)
 Define the application callback handler function signature. More...
 

Functions

int gpio_pin_interrupt_configure (const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
 Configure pin interrupt. More...
 
static int gpio_pin_interrupt_configure_dt (const struct gpio_dt_spec *spec, gpio_flags_t flags)
 Configure pin interrupts from a gpio_dt_spec. More...
 
int gpio_pin_configure (const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
 Configure a single pin. More...
 
static int gpio_pin_configure_dt (const struct gpio_dt_spec *spec, gpio_flags_t extra_flags)
 Configure a single pin from a gpio_dt_spec and some extra flags. More...
 
int gpio_port_get_raw (const struct device *port, gpio_port_value_t *value)
 Get physical level of all input pins in a port. More...
 
static int gpio_port_get (const struct device *port, gpio_port_value_t *value)
 Get logical level of all input pins in a port. More...
 
int gpio_port_set_masked_raw (const struct device *port, gpio_port_pins_t mask, gpio_port_value_t value)
 Set physical level of output pins in a port. More...
 
static int gpio_port_set_masked (const struct device *port, gpio_port_pins_t mask, gpio_port_value_t value)
 Set logical level of output pins in a port. More...
 
int gpio_port_set_bits_raw (const struct device *port, gpio_port_pins_t pins)
 Set physical level of selected output pins to high. More...
 
static int gpio_port_set_bits (const struct device *port, gpio_port_pins_t pins)
 Set logical level of selected output pins to active. More...
 
int gpio_port_clear_bits_raw (const struct device *port, gpio_port_pins_t pins)
 Set physical level of selected output pins to low. More...
 
static int gpio_port_clear_bits (const struct device *port, gpio_port_pins_t pins)
 Set logical level of selected output pins to inactive. More...
 
int gpio_port_toggle_bits (const struct device *port, gpio_port_pins_t pins)
 Toggle level of selected output pins. More...
 
static int gpio_port_set_clr_bits_raw (const struct device *port, gpio_port_pins_t set_pins, gpio_port_pins_t clear_pins)
 Set physical level of selected output pins. More...
 
static int gpio_port_set_clr_bits (const struct device *port, gpio_port_pins_t set_pins, gpio_port_pins_t clear_pins)
 Set logical level of selected output pins. More...
 
static int gpio_pin_get_raw (const struct device *port, gpio_pin_t pin)
 Get physical level of an input pin. More...
 
static int gpio_pin_get (const struct device *port, gpio_pin_t pin)
 Get logical level of an input pin. More...
 
static int gpio_pin_get_dt (const struct gpio_dt_spec *spec)
 Get logical level of an input pin from a gpio_dt_spec. More...
 
static int gpio_pin_set_raw (const struct device *port, gpio_pin_t pin, int value)
 Set physical level of an output pin. More...
 
static int gpio_pin_set (const struct device *port, gpio_pin_t pin, int value)
 Set logical level of an output pin. More...
 
static int gpio_pin_set_dt (const struct gpio_dt_spec *spec, int value)
 Set logical level of a output pin from a gpio_dt_spec. More...
 
static int gpio_pin_toggle (const struct device *port, gpio_pin_t pin)
 Toggle pin level. More...
 
static int gpio_pin_toggle_dt (const struct gpio_dt_spec *spec)
 Toggle pin level from a gpio_dt_spec. More...
 
static void gpio_init_callback (struct gpio_callback *callback, gpio_callback_handler_t handler, gpio_port_pins_t pin_mask)
 Helper to initialize a struct gpio_callback properly. More...
 
static int gpio_add_callback (const struct device *port, struct gpio_callback *callback)
 Add an application callback. More...
 
static int gpio_remove_callback (const struct device *port, struct gpio_callback *callback)
 Remove an application callback. More...
 
int gpio_get_pending_int (const struct device *dev)
 Function to get pending interrupts. More...
 

Detailed Description

Public APIs for GPIO drivers.