Zephyr API 3.6.99
|
Public APIs for GPIO drivers. More...
#include <errno.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/slist.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <zephyr/device.h>
#include <zephyr/dt-bindings/gpio/gpio.h>
#include <zephyr/syscalls/gpio.h>
Go to the source code of this file.
Data Structures | |
struct | gpio_dt_spec |
Container for GPIO pin information specified in devicetree. More... | |
struct | gpio_driver_config |
This structure is common to all GPIO drivers and is expected to be the first element in the object pointed to by the config field in the device structure. More... | |
struct | gpio_driver_data |
This structure is common to all GPIO drivers and is expected to be the first element in the driver's struct driver_data declaration. More... | |
struct | gpio_callback |
GPIO callback structure. More... | |
Macros | |
#define | GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx) |
Static initializer for a gpio_dt_spec . | |
#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. | |
#define | GPIO_DT_SPEC_GET(node_id, prop) |
Equivalent to GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0). | |
#define | GPIO_DT_SPEC_GET_OR(node_id, prop, default_value) |
Equivalent to GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value). | |
#define | GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) |
Static initializer for a gpio_dt_spec from a DT_DRV_COMPAT instance's GPIO property at an index. | |
#define | GPIO_DT_SPEC_INST_GET_BY_IDX_OR(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. | |
#define | GPIO_DT_SPEC_INST_GET(inst, prop) |
Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0). | |
#define | GPIO_DT_SPEC_INST_GET_OR(inst, prop, default_value) |
Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value). | |
#define | GPIO_DT_RESERVED_RANGES_NGPIOS(node_id, ngpios) |
Makes a bitmask of reserved GPIOs from DT "gpio-reserved-ranges" property and "ngpios" argument. | |
#define | GPIO_DT_RESERVED_RANGES(node_id) |
Makes a bitmask of reserved GPIOs from the "gpio-reserved-ranges" and "ngpios" DT properties values. | |
#define | GPIO_DT_INST_RESERVED_RANGES_NGPIOS(inst, ngpios) |
Makes a bitmask of reserved GPIOs from a DT_DRV_COMPAT instance's "gpio-reserved-ranges" property and "ngpios" argument. | |
#define | GPIO_DT_INST_RESERVED_RANGES(inst) |
Make a bitmask of reserved GPIOs from a DT_DRV_COMPAT instance's GPIO "gpio-reserved-ranges" and "ngpios" properties. | |
#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. | |
#define | GPIO_DT_INST_PORT_PIN_MASK_NGPIOS_EXC(inst, ngpios) |
Makes a bitmask of allowed GPIOs from a DT_DRV_COMPAT instance's "gpio-reserved-ranges" property and "ngpios" argument. | |
#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 . | |
GPIO input/output configuration flags | |
#define | GPIO_INPUT (1U << 16) |
Enables pin as input. | |
#define | GPIO_OUTPUT (1U << 17) |
Enables pin as output, no change to the output state. | |
#define | GPIO_DISCONNECTED 0 |
Disables pin for both input and output. | |
#define | GPIO_OUTPUT_LOW (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW) |
Configures GPIO pin as output and initializes it to a low state. | |
#define | GPIO_OUTPUT_HIGH (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH) |
Configures GPIO pin as output and initializes it to a high state. | |
#define | GPIO_OUTPUT_INACTIVE |
Configures GPIO pin as output and initializes it to a logic 0. | |
#define | GPIO_OUTPUT_ACTIVE |
Configures GPIO pin as output and initializes it to a logic 1. | |
GPIO interrupt configuration flags | |
The 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). The GPIO controller should reset the interrupt status, such as clearing the pending bit, etc, when configuring the interrupt triggering properties. Applications should use the | |
#define | GPIO_INT_DISABLE (1U << 21) |
Disables GPIO pin interrupt. | |
#define | GPIO_INT_EDGE_RISING |
Configures GPIO interrupt to be triggered on pin rising edge and enables it. | |
#define | GPIO_INT_EDGE_FALLING |
Configures GPIO interrupt to be triggered on pin falling edge and enables it. | |
#define | GPIO_INT_EDGE_BOTH |
Configures GPIO interrupt to be triggered on pin rising or falling edge and enables it. | |
#define | GPIO_INT_LEVEL_LOW |
Configures GPIO interrupt to be triggered on pin physical level low and enables it. | |
#define | GPIO_INT_LEVEL_HIGH |
Configures GPIO interrupt to be triggered on pin physical level high and enables it. | |
#define | GPIO_INT_EDGE_TO_INACTIVE |
Configures GPIO interrupt to be triggered on pin state change to logical level 0 and enables it. | |
#define | GPIO_INT_EDGE_TO_ACTIVE |
Configures GPIO interrupt to be triggered on pin state change to logical level 1 and enables it. | |
#define | GPIO_INT_LEVEL_INACTIVE |
Configures GPIO interrupt to be triggered on pin logical level 0 and enables it. | |
#define | GPIO_INT_LEVEL_ACTIVE |
Configures GPIO interrupt to be triggered on pin logical level 1 and enables it. | |
Typedefs | |
typedef uint32_t | gpio_port_pins_t |
Identifies a set of pins associated with a port. | |
typedef uint32_t | gpio_port_value_t |
Provides values for a set of pins associated with a port. | |
typedef uint8_t | gpio_pin_t |
Provides a type to hold a GPIO pin index. | |
typedef uint16_t | gpio_dt_flags_t |
Provides a type to hold GPIO devicetree flags. | |
typedef uint32_t | gpio_flags_t |
Provides a type to hold GPIO configuration flags. | |
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. | |
Functions | |
static bool | gpio_is_ready_dt (const struct gpio_dt_spec *spec) |
Validate that GPIO port is ready. | |
int | gpio_pin_interrupt_configure (const struct device *port, gpio_pin_t pin, gpio_flags_t flags) |
Configure pin interrupt. | |
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 . | |
int | gpio_pin_configure (const struct device *port, gpio_pin_t pin, gpio_flags_t flags) |
Configure a single pin. | |
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. | |
int | gpio_port_get_direction (const struct device *port, gpio_port_pins_t map, gpio_port_pins_t *inputs, gpio_port_pins_t *outputs) |
Get direction of select pins in a port. | |
static int | gpio_pin_is_input (const struct device *port, gpio_pin_t pin) |
Check if pin is configured for input. | |
static int | gpio_pin_is_input_dt (const struct gpio_dt_spec *spec) |
Check if a single pin from gpio_dt_spec is configured for input. | |
static int | gpio_pin_is_output (const struct device *port, gpio_pin_t pin) |
Check if pin is configured for output. | |
static int | gpio_pin_is_output_dt (const struct gpio_dt_spec *spec) |
Check if a single pin from gpio_dt_spec is configured for output. | |
int | gpio_pin_get_config (const struct device *port, gpio_pin_t pin, gpio_flags_t *flags) |
Get a configuration of a single pin. | |
static int | gpio_pin_get_config_dt (const struct gpio_dt_spec *spec, gpio_flags_t *flags) |
Get a configuration of a single pin from a gpio_dt_spec . | |
int | gpio_port_get_raw (const struct device *port, gpio_port_value_t *value) |
Get physical level of all input pins in a port. | |
static int | gpio_port_get (const struct device *port, gpio_port_value_t *value) |
Get logical level of all input pins in a port. | |
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. | |
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. | |
int | gpio_port_set_bits_raw (const struct device *port, gpio_port_pins_t pins) |
Set physical level of selected output pins to high. | |
static int | gpio_port_set_bits (const struct device *port, gpio_port_pins_t pins) |
Set logical level of selected output pins to active. | |
int | gpio_port_clear_bits_raw (const struct device *port, gpio_port_pins_t pins) |
Set physical level of selected output pins to low. | |
static int | gpio_port_clear_bits (const struct device *port, gpio_port_pins_t pins) |
Set logical level of selected output pins to inactive. | |
int | gpio_port_toggle_bits (const struct device *port, gpio_port_pins_t pins) |
Toggle level of selected output pins. | |
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. | |
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. | |
static int | gpio_pin_get_raw (const struct device *port, gpio_pin_t pin) |
Get physical level of an input pin. | |
static int | gpio_pin_get (const struct device *port, gpio_pin_t pin) |
Get logical level of an input pin. | |
static int | gpio_pin_get_dt (const struct gpio_dt_spec *spec) |
Get logical level of an input pin from a gpio_dt_spec . | |
static int | gpio_pin_set_raw (const struct device *port, gpio_pin_t pin, int value) |
Set physical level of an output pin. | |
static int | gpio_pin_set (const struct device *port, gpio_pin_t pin, int value) |
Set logical level of an output pin. | |
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 . | |
static int | gpio_pin_toggle (const struct device *port, gpio_pin_t pin) |
Toggle pin level. | |
static int | gpio_pin_toggle_dt (const struct gpio_dt_spec *spec) |
Toggle pin level from a gpio_dt_spec . | |
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. | |
static int | gpio_add_callback (const struct device *port, struct gpio_callback *callback) |
Add an application callback. | |
static int | gpio_add_callback_dt (const struct gpio_dt_spec *spec, struct gpio_callback *callback) |
Add an application callback. | |
static int | gpio_remove_callback (const struct device *port, struct gpio_callback *callback) |
Remove an application callback. | |
static int | gpio_remove_callback_dt (const struct gpio_dt_spec *spec, struct gpio_callback *callback) |
Remove an application callback. | |
int | gpio_get_pending_int (const struct device *dev) |
Function to get pending interrupts. | |
Public APIs for GPIO drivers.