Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
GPIO Driver APIs

GPIO Driver APIs . More...

Topics

 Emulated GPIO
 Emulated GPIO backend API .
 
 MAX32-specific GPIO Flags
 MAX32-specific GPIO Flags .
 
 nPM1300-specific GPIO Flags
 nPM1300-specific GPIO Flags
 
 nPM6001-specific GPIO Flags
 nPM6001-specific GPIO Flags
 
 nRF-specific GPIO Flags
 nRF-specific GPIO Flags
 

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.
 
#define GPIO_DT_FLAGS_MASK   0x3F
 Mask for DT GPIO flags.
 
#define GPIO_INT_WAKEUP   (1 << 6)
 Configures GPIO interrupt to wakeup the system from low power mode.
 

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.
 

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 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). 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 GPIO_INT_MODE_ENABLE_ONLY and GPIO_INT_MODE_DISABLE_ONLY flags to enable and disable interrupts on the pin without changing any GPIO settings.

#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.
 

GPIO pin active level flags

#define GPIO_ACTIVE_LOW   (1 << 0)
 GPIO pin is active (has logical value '1') in low state.
 
#define GPIO_ACTIVE_HIGH   (0 << 0)
 GPIO pin is active (has logical value '1') in high state.
 

GPIO pin drive flags

#define GPIO_OPEN_DRAIN   (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN)
 Configures GPIO output in open drain mode (wired AND).
 
#define GPIO_OPEN_SOURCE   (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE)
 Configures GPIO output in open source mode (wired OR).
 

GPIO pin bias flags

#define GPIO_PULL_UP   (1 << 4)
 Enables GPIO pin pull-up.
 
#define GPIO_PULL_DOWN   (1 << 5)
 Enable GPIO pin pull-down.
 
#define STM32_GPIO_WKUP   (1 << 8)
 STM32 GPIO specific flags.
 

Detailed Description

GPIO Driver APIs .

GPIO Driver APIs .

Since
1.0
Version
1.0.0

Macro Definition Documentation

◆ GPIO_ACTIVE_HIGH

#define GPIO_ACTIVE_HIGH   (0 << 0)

#include <zephyr/dt-bindings/gpio/gpio.h>

GPIO pin is active (has logical value '1') in high state.

◆ GPIO_ACTIVE_LOW

#define GPIO_ACTIVE_LOW   (1 << 0)

#include <zephyr/dt-bindings/gpio/gpio.h>

GPIO pin is active (has logical value '1') in low state.

◆ GPIO_DISCONNECTED

#define GPIO_DISCONNECTED   0

#include <zephyr/drivers/gpio.h>

Disables pin for both input and output.

◆ GPIO_DT_FLAGS_MASK

#define GPIO_DT_FLAGS_MASK   0x3F

#include <zephyr/dt-bindings/gpio/gpio.h>

Mask for DT GPIO flags.

◆ GPIO_DT_INST_PORT_PIN_MASK_NGPIOS_EXC

#define GPIO_DT_INST_PORT_PIN_MASK_NGPIOS_EXC ( inst,
ngpios )

#include <zephyr/drivers/gpio.h>

Value:
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:3809
#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 a DT_DRV_COMPAT instance's "gpio-reserved-ranges" property and "ngpios" argument.

Parameters
instDT_DRV_COMPAT instance number
ngpiosnumber of GPIOs
Returns
the bitmask of allowed gpios
See also
GPIO_DT_NGPIOS_PORT_PIN_MASK_EXC()

◆ GPIO_DT_INST_RESERVED_RANGES

#define GPIO_DT_INST_RESERVED_RANGES ( inst)

#include <zephyr/drivers/gpio.h>

Value:
#define GPIO_DT_RESERVED_RANGES(node_id)
Makes a bitmask of reserved GPIOs from the "gpio-reserved-ranges" and "ngpios" DT properties values.
Definition gpio.h:583

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

Parameters
instDT_DRV_COMPAT instance number
Returns
the bitmask of reserved gpios
See also
GPIO_DT_RESERVED_RANGES()

◆ GPIO_DT_INST_RESERVED_RANGES_NGPIOS

#define GPIO_DT_INST_RESERVED_RANGES_NGPIOS ( inst,
ngpios )

#include <zephyr/drivers/gpio.h>

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.
Definition gpio.h:566

Makes a bitmask of reserved GPIOs from a DT_DRV_COMPAT instance's "gpio-reserved-ranges" property and "ngpios" argument.

Parameters
instDT_DRV_COMPAT instance number
Returns
the bitmask of reserved gpios
Parameters
ngpiosnumber of GPIOs
See also
GPIO_DT_RESERVED_RANGES()

◆ GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC

#define GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC ( node_id,
ngpios )

#include <zephyr/drivers/gpio.h>

Value:
COND_CODE_0(ngpios, \
(0), \
(COND_CODE_1(DT_NODE_HAS_PROP(node_id, gpio_reserved_ranges), \
((GENMASK64(ngpios - 1, 0) & \
~GPIO_DT_RESERVED_RANGES_NGPIOS(node_id, ngpios))), \
(GENMASK64(ngpios - 1, 0))) \
) \
))
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition devicetree.h:3684
uint32_t gpio_port_pins_t
Identifies a set of pins associated with a port.
Definition gpio.h:233
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195
#define GENMASK64(h, l)
Create a contiguous 64-bit bitmask starting at bit position l and ending at position h.
Definition util.h:86

Makes a bitmask of allowed GPIOs from DT "gpio-reserved-ranges" property and "ngpios" argument.

This macro is paired with GPIO_DT_RESERVED_RANGES_NGPIOS(), however unlike the latter, it returns a bitmask of ALLOWED gpios.

Example devicetree fragment:

a {
compatible = "some,gpio-controller";
ngpios = <32>;
gpio-reserved-ranges = <0 8>, <9 5>, <15 16>;
};

Example usage:

struct some_config {
uint32_t port_pin_mask;
};
static const struct some_config dev_cfg = {
DT_LABEL(a), 32),
};
__UINT32_TYPE__ uint32_t
Definition stdint.h:90

This expands to:

struct some_config {
uint32_t port_pin_mask;
};
static const struct some_config dev_cfg = {
.port_pin_mask = 0x80004100,
// 0b1000 0000 0000 0000 0100 0001 00000 000
};
Parameters
node_idGPIO controller node identifier.
ngpiosnumber of GPIOs
Returns
the bitmask of allowed gpios

◆ GPIO_DT_RESERVED_RANGES

#define GPIO_DT_RESERVED_RANGES ( node_id)

#include <zephyr/drivers/gpio.h>

Value:
GPIO_DT_RESERVED_RANGES_NGPIOS(node_id, DT_PROP(node_id, ngpios))
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition devicetree.h:752

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

Parameters
node_idGPIO controller node identifier.
Returns
the bitmask of reserved gpios

◆ GPIO_DT_RESERVED_RANGES_NGPIOS

#define GPIO_DT_RESERVED_RANGES_NGPIOS ( node_id,
ngpios )

#include <zephyr/drivers/gpio.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, gpio_reserved_ranges), \
(GENMASK64(BITS_PER_LONG_LONG - 1, ngpios) \
| FOR_EACH_FIXED_ARG(Z_GPIO_GEN_RESERVED_RANGES_COND, \
(|), \
node_id, \
LIST_DROP_EMPTY(Z_SPARSE_LIST_ODD_NUMBERS))), \
(0)))
#define FOR_EACH_FIXED_ARG(F, sep, fixed_arg,...)
Call macro F on each provided argument, with an additional fixed argument as a parameter.
Definition util_macro.h:601
#define LIST_DROP_EMPTY(...)
Remove empty arguments from list.
Definition util_macro.h:331
#define BITS_PER_LONG_LONG
Number of bits in a long long int.
Definition util.h:73

Makes a bitmask of reserved GPIOs from DT "gpio-reserved-ranges" property and "ngpios" argument.

This macro returns the value as a bitmask of the "gpio-reserved-ranges" property. This property defines the disabled (or 'reserved') GPIOs in the range 0...ngpios-1 and is specified as an array of value's pairs that define the start offset and size of the reserved ranges.

For example, setting "gpio-reserved-ranges = <3 2>, <10 1>;" means that GPIO offsets 3, 4 and 10 cannot be used even if ngpios = <18>.

The implementation constraint is inherited from common DT limitations: a maximum of 64 pairs can be used (with result limited to bitsize of gpio_port_pins_t type).

NB: Due to the nature of C macros, some incorrect tuple definitions (for example, overlapping or out of range) will produce undefined results.

Also be aware that if ngpios is less than 32 (bit size of DT int type), then all unused MSBs outside the range defined by ngpios will be marked as reserved too.

Example devicetree fragment:

a {
compatible = "some,gpio-controller";
ngpios = <32>;
gpio-reserved-ranges = <0 4>, <5 3>, <9 5>, <11 2>, <15 2>,
<18 2>, <21 1>, <23 1>, <25 4>, <30 2>;
};
b {
compatible = "some,gpio-controller";
ngpios = <18>;
gpio-reserved-ranges = <3 2>, <10 1>;
};

Example usage:

struct some_config {
uint32_t ngpios;
uint32_t gpios_reserved;
};
static const struct some_config dev_cfg_a = {
.ngpios = DT_PROP_OR(DT_LABEL(a), ngpios, 0),
.gpios_reserved = GPIO_DT_RESERVED_RANGES_NGPIOS(DT_LABEL(a),
DT_PROP(DT_LABEL(a), ngpios)),
};
static const struct some_config dev_cfg_b = {
.ngpios = DT_PROP_OR(DT_LABEL(b), ngpios, 0),
.gpios_reserved = GPIO_DT_RESERVED_RANGES_NGPIOS(DT_LABEL(b),
DT_PROP(DT_LABEL(b), ngpios)),
};
#define DT_PROP_OR(node_id, prop, default_value)
Like DT_PROP(), but with a fallback to default_value.
Definition devicetree.h:914

This expands to:

struct some_config {
uint32_t ngpios;
uint32_t gpios_reserved;
};
static const struct some_config dev_cfg_a = {
.ngpios = 32,
.gpios_reserved = 0xdeadbeef,
// 0b1101 1110 1010 1101 1011 1110 1110 1111
static const struct some_config dev_cfg_b = {
.ngpios = 18,
.gpios_reserved = 0xfffc0418,
// 0b1111 1111 1111 1100 0000 0100 0001 1000
// unused MSBs were marked as reserved too
};
Parameters
node_idGPIO controller node identifier.
ngpiosnumber of GPIOs.
Returns
the bitmask of reserved gpios

◆ GPIO_DT_SPEC_GET

#define GPIO_DT_SPEC_GET ( node_id,
prop )

#include <zephyr/drivers/gpio.h>

Value:
GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
#define GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)
Static initializer for a gpio_dt_spec.
Definition gpio.h:331

Equivalent to GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0).

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
Returns
static initializer for a struct gpio_dt_spec for the property
See also
GPIO_DT_SPEC_GET_BY_IDX()

◆ GPIO_DT_SPEC_GET_BY_IDX

#define GPIO_DT_SPEC_GET_BY_IDX ( node_id,
prop,
idx )

#include <zephyr/drivers/gpio.h>

Value:
{ \
.port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
.pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
.dt_flags = DT_GPIO_FLAGS_BY_IDX(node_id, prop, idx), \
}
#define DEVICE_DT_GET(node_id)
Get a device reference from a devicetree node identifier.
Definition device.h:255
#define DT_GPIO_FLAGS_BY_IDX(node_id, gpio_pha, idx)
Get a GPIO specifier's flags cell at an index.
Definition gpio.h:165
#define DT_GPIO_PIN_BY_IDX(node_id, gpio_pha, idx)
Get a GPIO specifier's pin cell at an index.
Definition gpio.h:109
#define DT_GPIO_CTLR_BY_IDX(node_id, gpio_pha, idx)
Get the node identifier for the controller phandle from a gpio phandle-array property at an index.
Definition gpio.h:53

Static initializer for a gpio_dt_spec.

This returns a static initializer for a gpio_dt_spec structure given a devicetree node identifier, a property specifying a GPIO and an index.

Example devicetree fragment:

 n: node {
    foo-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>,
                <&gpio1 2 GPIO_ACTIVE_LOW>;
 }

Example usage:

 const struct gpio_dt_spec spec = GPIO_DT_SPEC_GET_BY_IDX(DT_NODELABEL(n),
                                                     foo_gpios, 1);
 // Initializes 'spec' to:
 // {
 //         .port = DEVICE_DT_GET(DT_NODELABEL(gpio1)),
 //         .pin = 2,
 //         .dt_flags = GPIO_ACTIVE_LOW
 // }

The 'gpio' field must still be checked for readiness, e.g. using device_is_ready(). It is an error to use this macro unless the node exists, has the given property, and that property specifies a GPIO controller, pin number, and flags as shown above.

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
idxlogical index into "prop"
Returns
static initializer for a struct gpio_dt_spec for the property

◆ GPIO_DT_SPEC_GET_BY_IDX_OR

#define GPIO_DT_SPEC_GET_BY_IDX_OR ( node_id,
prop,
idx,
default_value )

#include <zephyr/drivers/gpio.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
(GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
(default_value))

Like GPIO_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.

If the devicetree node identifier 'node_id' refers to a node with a property 'prop', this expands to GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx). The default_value parameter is not expanded in this case.

Otherwise, this expands to default_value.

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
idxlogical index into "prop"
default_valuefallback value to expand to
Returns
static initializer for a struct gpio_dt_spec for the property, or default_value if the node or property do not exist

◆ GPIO_DT_SPEC_GET_OR

#define GPIO_DT_SPEC_GET_OR ( node_id,
prop,
default_value )

#include <zephyr/drivers/gpio.h>

Value:
GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
#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.
Definition gpio.h:355

Equivalent to GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value).

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
default_valuefallback value to expand to
Returns
static initializer for a struct gpio_dt_spec for the property
See also
GPIO_DT_SPEC_GET_BY_IDX_OR()

◆ GPIO_DT_SPEC_INST_GET

#define GPIO_DT_SPEC_INST_GET ( inst,
prop )

#include <zephyr/drivers/gpio.h>

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.
Definition gpio.h:394

Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0).

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
Returns
static initializer for a struct gpio_dt_spec for the property
See also
GPIO_DT_SPEC_INST_GET_BY_IDX()

◆ GPIO_DT_SPEC_INST_GET_BY_IDX

#define GPIO_DT_SPEC_INST_GET_BY_IDX ( inst,
prop,
idx )

#include <zephyr/drivers/gpio.h>

Value:

Static initializer for a gpio_dt_spec from a DT_DRV_COMPAT instance's GPIO property at an index.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
idxlogical index into "prop"
Returns
static initializer for a struct gpio_dt_spec for the property
See also
GPIO_DT_SPEC_GET_BY_IDX()

◆ GPIO_DT_SPEC_INST_GET_BY_IDX_OR

#define GPIO_DT_SPEC_INST_GET_BY_IDX_OR ( inst,
prop,
idx,
default_value )

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)), \
(default_value))
#define DT_PROP_HAS_IDX(node_id, prop, idx)
Is index idx valid for an array type property?
Definition devicetree.h:826

Static initializer for a gpio_dt_spec from a DT_DRV_COMPAT instance's GPIO property at an index, with fallback.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
idxlogical index into "prop"
default_valuefallback value to expand to
Returns
static initializer for a struct gpio_dt_spec for the property
See also
GPIO_DT_SPEC_GET_BY_IDX()

◆ GPIO_DT_SPEC_INST_GET_OR

#define GPIO_DT_SPEC_INST_GET_OR ( inst,
prop,
default_value )

#include <zephyr/drivers/gpio.h>

Value:
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
#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,...
Definition gpio.h:408

Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value).

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
default_valuefallback value to expand to
Returns
static initializer for a struct gpio_dt_spec for the property
See also
GPIO_DT_SPEC_INST_GET_BY_IDX()

◆ GPIO_INPUT

#define GPIO_INPUT   (1U << 16)

#include <zephyr/drivers/gpio.h>

Enables pin as input.

◆ GPIO_INT_DISABLE

#define GPIO_INT_DISABLE   (1U << 21)

#include <zephyr/drivers/gpio.h>

Disables GPIO pin interrupt.

◆ GPIO_INT_EDGE_BOTH

#define GPIO_INT_EDGE_BOTH

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_EDGE | \
GPIO_INT_LOW_0 | \
GPIO_INT_HIGH_1)

Configures GPIO interrupt to be triggered on pin rising or falling edge and enables it.

◆ GPIO_INT_EDGE_FALLING

#define GPIO_INT_EDGE_FALLING

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_EDGE | \
GPIO_INT_LOW_0)

Configures GPIO interrupt to be triggered on pin falling edge and enables it.

◆ GPIO_INT_EDGE_RISING

#define GPIO_INT_EDGE_RISING

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_EDGE | \
GPIO_INT_HIGH_1)

Configures GPIO interrupt to be triggered on pin rising edge and enables it.

◆ GPIO_INT_EDGE_TO_ACTIVE

#define GPIO_INT_EDGE_TO_ACTIVE

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_LEVELS_LOGICAL | \
GPIO_INT_EDGE | \
GPIO_INT_HIGH_1)

Configures GPIO interrupt to be triggered on pin state change to logical level 1 and enables it.

◆ GPIO_INT_EDGE_TO_INACTIVE

#define GPIO_INT_EDGE_TO_INACTIVE

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_LEVELS_LOGICAL | \
GPIO_INT_EDGE | \
GPIO_INT_LOW_0)

Configures GPIO interrupt to be triggered on pin state change to logical level 0 and enables it.

◆ GPIO_INT_LEVEL_ACTIVE

#define GPIO_INT_LEVEL_ACTIVE

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_LEVELS_LOGICAL | \
GPIO_INT_HIGH_1)

Configures GPIO interrupt to be triggered on pin logical level 1 and enables it.

◆ GPIO_INT_LEVEL_HIGH

#define GPIO_INT_LEVEL_HIGH

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_HIGH_1)

Configures GPIO interrupt to be triggered on pin physical level high and enables it.

◆ GPIO_INT_LEVEL_INACTIVE

#define GPIO_INT_LEVEL_INACTIVE

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_LEVELS_LOGICAL | \
GPIO_INT_LOW_0)

Configures GPIO interrupt to be triggered on pin logical level 0 and enables it.

◆ GPIO_INT_LEVEL_LOW

#define GPIO_INT_LEVEL_LOW

#include <zephyr/drivers/gpio.h>

Value:
(GPIO_INT_ENABLE | \
GPIO_INT_LOW_0)

Configures GPIO interrupt to be triggered on pin physical level low and enables it.

◆ GPIO_INT_WAKEUP

#define GPIO_INT_WAKEUP   (1 << 6)

#include <zephyr/dt-bindings/gpio/gpio.h>

Configures GPIO interrupt to wakeup the system from low power mode.

◆ GPIO_MAX_PINS_PER_PORT

#define GPIO_MAX_PINS_PER_PORT   (sizeof(gpio_port_pins_t) * __CHAR_BIT__)

#include <zephyr/drivers/gpio.h>

Maximum number of pins that are supported by gpio_port_pins_t.

◆ GPIO_OPEN_DRAIN

#define GPIO_OPEN_DRAIN   (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN)

#include <zephyr/dt-bindings/gpio/gpio.h>

Configures GPIO output in open drain mode (wired AND).

Note
'Open Drain' mode also known as 'Open Collector' is an output configuration which behaves like a switch that is either connected to ground or disconnected.

◆ GPIO_OPEN_SOURCE

#define GPIO_OPEN_SOURCE   (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE)

#include <zephyr/dt-bindings/gpio/gpio.h>

Configures GPIO output in open source mode (wired OR).

Note
'Open Source' is a term used by software engineers to describe output mode opposite to 'Open Drain'. It behaves like a switch that is either connected to power supply or disconnected. There exist no corresponding hardware schematic and the term is generally unknown to hardware engineers.

◆ GPIO_OUTPUT

#define GPIO_OUTPUT   (1U << 17)

#include <zephyr/drivers/gpio.h>

Enables pin as output, no change to the output state.

◆ GPIO_OUTPUT_ACTIVE

#define GPIO_OUTPUT_ACTIVE

#include <zephyr/drivers/gpio.h>

Value:
GPIO_OUTPUT_INIT_HIGH | \
GPIO_OUTPUT_INIT_LOGICAL)
#define GPIO_OUTPUT
Enables pin as output, no change to the output state.
Definition gpio.h:50

Configures GPIO pin as output and initializes it to a logic 1.

◆ GPIO_OUTPUT_HIGH

#define GPIO_OUTPUT_HIGH   (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH)

#include <zephyr/drivers/gpio.h>

Configures GPIO pin as output and initializes it to a high state.

◆ GPIO_OUTPUT_INACTIVE

#define GPIO_OUTPUT_INACTIVE

#include <zephyr/drivers/gpio.h>

Value:
GPIO_OUTPUT_INIT_LOW | \
GPIO_OUTPUT_INIT_LOGICAL)

Configures GPIO pin as output and initializes it to a logic 0.

◆ GPIO_OUTPUT_LOW

#define GPIO_OUTPUT_LOW   (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW)

#include <zephyr/drivers/gpio.h>

Configures GPIO pin as output and initializes it to a low state.

◆ GPIO_PULL_DOWN

#define GPIO_PULL_DOWN   (1 << 5)

#include <zephyr/dt-bindings/gpio/gpio.h>

Enable GPIO pin pull-down.

◆ GPIO_PULL_UP

#define GPIO_PULL_UP   (1 << 4)

#include <zephyr/dt-bindings/gpio/gpio.h>

Enables GPIO pin pull-up.

◆ STM32_GPIO_WKUP

#define STM32_GPIO_WKUP   (1 << 8)

#include <zephyr/dt-bindings/gpio/stm32-gpio.h>

STM32 GPIO specific flags.

The driver flags are encoded in the 8 upper bits of gpio_dt_flags_t as follows:

  • Bit 8: Configure a GPIO pin to power on the system after Poweroff. Configures a GPIO pin to power on the system after Poweroff. This flag is reserved to GPIO pins that are associated with wake-up pins in STM32 PWR devicetree node, through the property "wkup-gpios".

Typedef Documentation

◆ gpio_callback_handler_t

typedef void(* gpio_callback_handler_t) (const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins)

#include <zephyr/drivers/gpio.h>

Define the application callback handler function signature.

Parameters
portDevice struct for the GPIO device.
cbOriginal struct gpio_callback owning this handler
pinsMask of pins that triggers the callback handler

Note: cb pointer can be used to retrieve private data through CONTAINER_OF() if original struct gpio_callback is stored in another private structure.

◆ gpio_dt_flags_t

#include <zephyr/drivers/gpio.h>

Provides a type to hold GPIO devicetree flags.

All GPIO flags that can be expressed in devicetree fit in the low 16 bits of the full flags field, so use a reduced-size type to record that part of a GPIOS property.

The lower 8 bits are used for standard flags. The upper 8 bits are reserved for SoC specific flags.

◆ gpio_flags_t

#include <zephyr/drivers/gpio.h>

Provides a type to hold GPIO configuration flags.

This type is sufficient to hold all flags used to control GPIO configuration, whether pin or interrupt.

◆ gpio_pin_t

#include <zephyr/drivers/gpio.h>

Provides a type to hold a GPIO pin index.

This reduced-size type is sufficient to record a pin number, e.g. from a devicetree GPIOS property.

◆ gpio_port_pins_t

#include <zephyr/drivers/gpio.h>

Identifies a set of pins associated with a port.

The pin with index n is present in the set if and only if the bit identified by (1U << n) is set.

◆ gpio_port_value_t

#include <zephyr/drivers/gpio.h>

Provides values for a set of pins associated with a port.

The value for a pin with index n is high (physical mode) or active (logical mode) if and only if the bit identified by (1U << n) is set. Otherwise the value for the pin is low (physical mode) or inactive (logical mode).

Values of this type are often paired with a gpio_port_pins_t value that specifies which encoded pin values are valid for the operation.

Function Documentation

◆ gpio_add_callback()

static int gpio_add_callback ( const struct device * port,
struct gpio_callback * callback )
inlinestatic

#include <zephyr/drivers/gpio.h>

Add an application callback.

Parameters
portPointer to the device structure for the driver instance.
callbackA valid Application's callback structure pointer.
Return values
0If successful
-ENOSYSIf driver does not implement the operation
-errnoOther negative errno code on failure.
Note
Callbacks may be added to the device from within a callback handler invocation, but whether they are invoked for the current GPIO event is not specified.

Note: enables to add as many callback as needed on the same port.

◆ gpio_add_callback_dt()

static int gpio_add_callback_dt ( const struct gpio_dt_spec * spec,
struct gpio_callback * callback )
inlinestatic

#include <zephyr/drivers/gpio.h>

Add an application callback.

This is equivalent to:

gpio_add_callback(spec->port, callback);
Parameters
specGPIO specification from devicetree.
callbackA valid application's callback structure pointer.
Returns
a value from gpio_add_callback().

◆ gpio_get_pending_int()

int gpio_get_pending_int ( const struct device * dev)

#include <zephyr/drivers/gpio.h>

Function to get pending interrupts.

The purpose of this function is to return the interrupt status register for the device. This is especially useful when waking up from low power states to check the wake up source.

Parameters
devPointer to the device structure for the driver instance.
Return values
status!= 0 if at least one gpio interrupt is pending.
0if no gpio interrupt is pending.
-ENOSYSIf driver does not implement the operation

◆ gpio_init_callback()

static void gpio_init_callback ( struct gpio_callback * callback,
gpio_callback_handler_t handler,
gpio_port_pins_t pin_mask )
inlinestatic

#include <zephyr/drivers/gpio.h>

Helper to initialize a struct gpio_callback properly.

Parameters
callbackA valid Application's callback structure pointer.
handlerA valid handler function pointer.
pin_maskA bit mask of relevant pins for the handler

◆ gpio_is_ready_dt()

static bool gpio_is_ready_dt ( const struct gpio_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/gpio.h>

Validate that GPIO port is ready.

Parameters
specGPIO specification from devicetree
Return values
trueif the GPIO spec is ready for use.
falseif the GPIO spec is not ready for use.

◆ gpio_pin_configure()

int gpio_pin_configure ( const struct device * port,
gpio_pin_t pin,
gpio_flags_t flags )

#include <zephyr/drivers/gpio.h>

Configure a single pin.

Parameters
portPointer to device structure for the driver instance.
pinPin number to configure.
flagsFlags for pin configuration: 'GPIO input/output configuration flags', 'GPIO pin drive flags', 'GPIO pin bias flags'.
Return values
0If successful.
-ENOTSUPif any of the configuration options is not supported (unless otherwise directed by flag documentation).
-EINVALInvalid argument.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_configure_dt()

static int gpio_pin_configure_dt ( const struct gpio_dt_spec * spec,
gpio_flags_t extra_flags )
inlinestatic

#include <zephyr/drivers/gpio.h>

Configure a single pin from a gpio_dt_spec and some extra flags.

This is equivalent to:

gpio_pin_configure(spec->port, spec->pin, spec->dt_flags | extra_flags);
Parameters
specGPIO specification from devicetree
extra_flagsadditional flags
Returns
a value from gpio_pin_configure()

◆ gpio_pin_get()

static int gpio_pin_get ( const struct device * port,
gpio_pin_t pin )
inlinestatic

#include <zephyr/drivers/gpio.h>

Get logical level of an input pin.

Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag. If pin is configured as Active High, a low physical level will be interpreted as logical value 0. If pin is configured as Active Low, a low physical level will be interpreted as logical value 1.

Note: If pin is configured as Active High, the default, gpio_pin_get() function is equivalent to gpio_pin_get_raw().

Parameters
portPointer to the device structure for the driver instance.
pinPin number.
Return values
1If pin logical value is 1 / active.
0If pin logical value is 0 / inactive.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_get_config()

int gpio_pin_get_config ( const struct device * port,
gpio_pin_t pin,
gpio_flags_t * flags )

#include <zephyr/drivers/gpio.h>

Get a configuration of a single pin.

Parameters
portPointer to device structure for the driver instance.
pinPin number which configuration is get.
flagsPointer to variable in which the current configuration will be stored if function is successful.
Return values
0If successful.
-ENOSYSif getting current pin configuration is not implemented by the driver.
-EINVALInvalid argument.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_get_config_dt()

static int gpio_pin_get_config_dt ( const struct gpio_dt_spec * spec,
gpio_flags_t * flags )
inlinestatic

#include <zephyr/drivers/gpio.h>

Get a configuration of a single pin from a gpio_dt_spec.

This is equivalent to:

gpio_pin_get_config(spec->port, spec->pin, flags);
Parameters
specGPIO specification from devicetree
flagsPointer to variable in which the current configuration will be stored if function is successful.
Returns
a value from gpio_pin_configure()

◆ gpio_pin_get_dt()

static int gpio_pin_get_dt ( const struct gpio_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/gpio.h>

Get logical level of an input pin from a gpio_dt_spec.

This is equivalent to:

gpio_pin_get(spec->port, spec->pin);
Parameters
specGPIO specification from devicetree
Returns
a value from gpio_pin_get()

◆ gpio_pin_get_raw()

static int gpio_pin_get_raw ( const struct device * port,
gpio_pin_t pin )
inlinestatic

#include <zephyr/drivers/gpio.h>

Get physical level of an input pin.

A low physical level on the pin will be interpreted as value 0. A high physical level will be interpreted as value 1. This function ignores GPIO_ACTIVE_LOW flag.

Parameters
portPointer to the device structure for the driver instance.
pinPin number.
Return values
1If pin physical level is high.
0If pin physical level is low.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_interrupt_configure()

int gpio_pin_interrupt_configure ( const struct device * port,
gpio_pin_t pin,
gpio_flags_t flags )

#include <zephyr/drivers/gpio.h>

Configure pin interrupt.

Note
This function can also be used to configure interrupts on pins not controlled directly by the GPIO module. That is, pins which are routed to other modules such as I2C, SPI, UART.
Parameters
portPointer to device structure for the driver instance.
pinPin number.
flagsInterrupt configuration flags as defined by GPIO_INT_*.
Return values
0If successful.
-ENOSYSIf the operation is not implemented by the driver.
-ENOTSUPIf any of the configuration options is not supported (unless otherwise directed by flag documentation).
-EINVALInvalid argument.
-EBUSYInterrupt line required to configure pin interrupt is already in use.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_interrupt_configure_dt()

static int gpio_pin_interrupt_configure_dt ( const struct gpio_dt_spec * spec,
gpio_flags_t flags )
inlinestatic

#include <zephyr/drivers/gpio.h>

Configure pin interrupts from a gpio_dt_spec.

This is equivalent to:

gpio_pin_interrupt_configure(spec->port, spec->pin, flags);

The spec->dt_flags value is not used.

Parameters
specGPIO specification from devicetree
flagsinterrupt configuration flags
Returns
a value from gpio_pin_interrupt_configure()

◆ gpio_pin_is_input()

static int gpio_pin_is_input ( const struct device * port,
gpio_pin_t pin )
inlinestatic

#include <zephyr/drivers/gpio.h>

Check if pin is configured for input.

Parameters
portPointer to device structure for the driver instance.
pinPin number to query the direction of
Return values
1if pin is configured as GPIO_INPUT.
0if pin is not configured as GPIO_INPUT.
-ENOSYSif the underlying driver does not support this call.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_is_input_dt()

static int gpio_pin_is_input_dt ( const struct gpio_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/gpio.h>

Check if a single pin from gpio_dt_spec is configured for input.

This is equivalent to:

gpio_pin_is_input(spec->port, spec->pin);
Parameters
specGPIO specification from devicetree.
Returns
A value from gpio_pin_is_input().

◆ gpio_pin_is_output()

static int gpio_pin_is_output ( const struct device * port,
gpio_pin_t pin )
inlinestatic

#include <zephyr/drivers/gpio.h>

Check if pin is configured for output.

Parameters
portPointer to device structure for the driver instance.
pinPin number to query the direction of
Return values
1if pin is configured as GPIO_OUTPUT.
0if pin is not configured as GPIO_OUTPUT.
-ENOSYSif the underlying driver does not support this call.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_is_output_dt()

static int gpio_pin_is_output_dt ( const struct gpio_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/gpio.h>

Check if a single pin from gpio_dt_spec is configured for output.

This is equivalent to:

gpio_pin_is_output(spec->port, spec->pin);
Parameters
specGPIO specification from devicetree.
Returns
A value from gpio_pin_is_output().

◆ gpio_pin_set()

static int gpio_pin_set ( const struct device * port,
gpio_pin_t pin,
int value )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set logical level of an output pin.

Set logical level of an output pin taking into account GPIO_ACTIVE_LOW flag. Value 0 sets the pin in logical 0 / inactive state. Any value other than 0 sets the pin in logical 1 / active state. If pin is configured as Active High, the default, setting it in inactive state will force the pin to a low physical level. If pin is configured as Active Low, setting it in inactive state will force the pin to a high physical level.

Note: If pin is configured as Active High, gpio_pin_set() function is equivalent to gpio_pin_set_raw().

Parameters
portPointer to the device structure for the driver instance.
pinPin number.
valueValue assigned to the pin.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_set_dt()

static int gpio_pin_set_dt ( const struct gpio_dt_spec * spec,
int value )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set logical level of a output pin from a gpio_dt_spec.

This is equivalent to:

gpio_pin_set(spec->port, spec->pin, value);
Parameters
specGPIO specification from devicetree
valueValue assigned to the pin.
Returns
a value from gpio_pin_set()

◆ gpio_pin_set_raw()

static int gpio_pin_set_raw ( const struct device * port,
gpio_pin_t pin,
int value )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set physical level of an output pin.

Writing value 0 to the pin will set it to a low physical level. Writing any value other than 0 will set it to a high physical level. This function ignores GPIO_ACTIVE_LOW flag.

Parameters
portPointer to the device structure for the driver instance.
pinPin number.
valueValue assigned to the pin.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_toggle()

static int gpio_pin_toggle ( const struct device * port,
gpio_pin_t pin )
inlinestatic

#include <zephyr/drivers/gpio.h>

Toggle pin level.

Parameters
portPointer to the device structure for the driver instance.
pinPin number.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_pin_toggle_dt()

static int gpio_pin_toggle_dt ( const struct gpio_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/gpio.h>

Toggle pin level from a gpio_dt_spec.

This is equivalent to:

gpio_pin_toggle(spec->port, spec->pin);
Parameters
specGPIO specification from devicetree
Returns
a value from gpio_pin_toggle()

◆ gpio_port_clear_bits()

static int gpio_port_clear_bits ( const struct device * port,
gpio_port_pins_t pins )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set logical level of selected output pins to inactive.

Parameters
portPointer to the device structure for the driver instance.
pinsValue indicating which pins will be modified.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_clear_bits_raw()

int gpio_port_clear_bits_raw ( const struct device * port,
gpio_port_pins_t pins )

#include <zephyr/drivers/gpio.h>

Set physical level of selected output pins to low.

Parameters
portPointer to the device structure for the driver instance.
pinsValue indicating which pins will be modified.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_get()

static int gpio_port_get ( const struct device * port,
gpio_port_value_t * value )
inlinestatic

#include <zephyr/drivers/gpio.h>

Get logical level of all input pins in a port.

Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag. If pin is configured as Active High, a low physical level will be interpreted as logical value 0. If pin is configured as Active Low, a low physical level will be interpreted as logical value 1.

Value of a pin with index n will be represented by bit n in the returned port value.

Parameters
portPointer to the device structure for the driver instance.
valuePointer to a variable where pin values will be stored.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_get_direction()

int gpio_port_get_direction ( const struct device * port,
gpio_port_pins_t map,
gpio_port_pins_t * inputs,
gpio_port_pins_t * outputs )

#include <zephyr/drivers/gpio.h>

Get direction of select pins in a port.

Retrieve direction of each pin specified in map.

If inputs or outputs is NULL, then this function does not get the respective input or output direction information.

Parameters
portPointer to the device structure for the driver instance.
mapBitmap of pin directions to query.
inputsPointer to a variable where input directions will be stored.
outputsPointer to a variable where output directions will be stored.
Return values
0If successful.
-ENOSYSif the underlying driver does not support this call.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_get_raw()

int gpio_port_get_raw ( const struct device * port,
gpio_port_value_t * value )

#include <zephyr/drivers/gpio.h>

Get physical level of all input pins in a port.

A low physical level on the pin will be interpreted as value 0. A high physical level will be interpreted as value 1. This function ignores GPIO_ACTIVE_LOW flag.

Value of a pin with index n will be represented by bit n in the returned port value.

Parameters
portPointer to the device structure for the driver instance.
valuePointer to a variable where pin values will be stored.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_set_bits()

static int gpio_port_set_bits ( const struct device * port,
gpio_port_pins_t pins )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set logical level of selected output pins to active.

Parameters
portPointer to the device structure for the driver instance.
pinsValue indicating which pins will be modified.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_set_bits_raw()

int gpio_port_set_bits_raw ( const struct device * port,
gpio_port_pins_t pins )

#include <zephyr/drivers/gpio.h>

Set physical level of selected output pins to high.

Parameters
portPointer to the device structure for the driver instance.
pinsValue indicating which pins will be modified.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_set_clr_bits()

static int gpio_port_set_clr_bits ( const struct device * port,
gpio_port_pins_t set_pins,
gpio_port_pins_t clear_pins )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set logical level of selected output pins.

Parameters
portPointer to the device structure for the driver instance.
set_pinsValue indicating which pins will be set to active.
clear_pinsValue indicating which pins will be set to inactive.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_set_clr_bits_raw()

static int gpio_port_set_clr_bits_raw ( const struct device * port,
gpio_port_pins_t set_pins,
gpio_port_pins_t clear_pins )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set physical level of selected output pins.

Parameters
portPointer to the device structure for the driver instance.
set_pinsValue indicating which pins will be set to high.
clear_pinsValue indicating which pins will be set to low.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_set_masked()

static int gpio_port_set_masked ( const struct device * port,
gpio_port_pins_t mask,
gpio_port_value_t value )
inlinestatic

#include <zephyr/drivers/gpio.h>

Set logical level of output pins in a port.

Set logical level of an output pin taking into account GPIO_ACTIVE_LOW flag. Value 0 sets the pin in logical 0 / inactive state. Value 1 sets the pin in logical 1 / active state. If pin is configured as Active High, the default, setting it in inactive state will force the pin to a low physical level. If pin is configured as Active Low, setting it in inactive state will force the pin to a high physical level.

Pin with index n is represented by bit n in mask and value parameter.

Parameters
portPointer to the device structure for the driver instance.
maskMask indicating which pins will be modified.
valueValue assigned to the output pins.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_set_masked_raw()

int gpio_port_set_masked_raw ( const struct device * port,
gpio_port_pins_t mask,
gpio_port_value_t value )

#include <zephyr/drivers/gpio.h>

Set physical level of output pins in a port.

Writing value 0 to the pin will set it to a low physical level. Writing value 1 will set it to a high physical level. This function ignores GPIO_ACTIVE_LOW flag.

Pin with index n is represented by bit n in mask and value parameter.

Parameters
portPointer to the device structure for the driver instance.
maskMask indicating which pins will be modified.
valueValue assigned to the output pins.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_port_toggle_bits()

int gpio_port_toggle_bits ( const struct device * port,
gpio_port_pins_t pins )

#include <zephyr/drivers/gpio.h>

Toggle level of selected output pins.

Parameters
portPointer to the device structure for the driver instance.
pinsValue indicating which pins will be modified.
Return values
0If successful.
-EIOI/O error when accessing an external GPIO chip.
-EWOULDBLOCKif operation would block.

◆ gpio_remove_callback()

static int gpio_remove_callback ( const struct device * port,
struct gpio_callback * callback )
inlinestatic

#include <zephyr/drivers/gpio.h>

Remove an application callback.

Parameters
portPointer to the device structure for the driver instance.
callbackA valid application's callback structure pointer.
Return values
0If successful
-ENOSYSIf driver does not implement the operation
-errnoOther negative errno code on failure.
Warning
It is explicitly permitted, within a callback handler, to remove the registration for the callback that is running, i.e. callback. Attempts to remove other registrations on the same device may result in undefined behavior, including failure to invoke callbacks that remain registered and unintended invocation of removed callbacks.

Note: enables to remove as many callbacks as added through gpio_add_callback().

◆ gpio_remove_callback_dt()

static int gpio_remove_callback_dt ( const struct gpio_dt_spec * spec,
struct gpio_callback * callback )
inlinestatic

#include <zephyr/drivers/gpio.h>

Remove an application callback.

This is equivalent to:

gpio_remove_callback(spec->port, callback);
Parameters
specGPIO specification from devicetree.
callbackA valid application's callback structure pointer.
Returns
a value from gpio_remove_callback().