Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
GPIO Driver APIs. More...
Modules | |
Emulated GPIO | |
Emulated GPIO backend API. | |
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... | |
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... | |
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 | |
#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 The drive strength of individual pins can be configured independently for when the pin output is low and high. The The The interface supports two different drive strengths: On hardware that supports only one standard drive strength, both | |
#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) |
GPIO pin active level flags | |
#define | GPIO_ACTIVE_LOW (1 << 0) |
#define | GPIO_ACTIVE_HIGH (0 << 0) |
GPIO pin drive flags | |
#define | GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN) |
#define | GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE) |
GPIO pin bias flags | |
#define | GPIO_PULL_UP (1 << 4) |
#define | GPIO_PULL_DOWN (1 << 5) |
GPIO pin voltage flags | |
The voltage flags are a Zephyr specific extension of the standard GPIO flags specified by the Linux GPIO binding. Only applicable if SoC allows to configure pin voltage per individual pin. | |
#define | GPIO_VOLTAGE_DEFAULT (0U << GPIO_VOLTAGE_POS) |
#define | GPIO_VOLTAGE_1P8 (1U << GPIO_VOLTAGE_POS) |
#define | GPIO_VOLTAGE_3P3 (2U << GPIO_VOLTAGE_POS) |
#define | GPIO_VOLTAGE_5P0 (3U << GPIO_VOLTAGE_POS) |
GPIO Driver APIs.
#define GPIO_ACTIVE_HIGH (0 << 0) |
#include <include/dt-bindings/gpio/gpio.h>
GPIO pin is active (has logical value '1') in high state.
#define GPIO_ACTIVE_LOW (1 << 0) |
#include <include/dt-bindings/gpio/gpio.h>
GPIO pin is active (has logical value '1') in low state.
#define GPIO_DISCONNECTED 0 |
#include <include/drivers/gpio.h>
Disables pin for both input and output.
#define GPIO_DS_ALT_HIGH (0x1U << GPIO_DS_HIGH_POS) |
#include <include/drivers/gpio.h>
Alternative drive strength when GPIO pin output is high. For hardware that does not support configurable drive strengths use the default drive strength.
#define GPIO_DS_ALT_LOW (0x1U << GPIO_DS_LOW_POS) |
#include <include/drivers/gpio.h>
Alternative drive strength when GPIO pin output is low. For hardware that does not support configurable drive strength use the default drive strength.
#define GPIO_DS_DFLT_HIGH (0x0U << GPIO_DS_HIGH_POS) |
#include <include/drivers/gpio.h>
Default drive strength when GPIO pin output is high.
#define GPIO_DS_DFLT_LOW (0x0U << GPIO_DS_LOW_POS) |
#include <include/drivers/gpio.h>
Default drive strength standard when GPIO pin output is low.
#define GPIO_DT_SPEC_GET | ( | node_id, | |
prop | |||
) | GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0) |
#include <include/drivers/gpio.h>
Equivalent to GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0).
node_id | devicetree node identifier |
prop | lowercase-and-underscores property name |
#define GPIO_DT_SPEC_GET_BY_IDX | ( | node_id, | |
prop, | |||
idx | |||
) |
#include <include/drivers/gpio.h>
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.
node_id | devicetree node identifier |
prop | lowercase-and-underscores property name |
idx | logical index into "prop" |
#define GPIO_DT_SPEC_GET_BY_IDX_OR | ( | node_id, | |
prop, | |||
idx, | |||
default_value | |||
) |
#include <include/drivers/gpio.h>
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
.
node_id | devicetree node identifier |
prop | lowercase-and-underscores property name |
idx | logical index into "prop" |
default_value | fallback value to expand to |
#define GPIO_DT_SPEC_GET_OR | ( | node_id, | |
prop, | |||
default_value | |||
) | GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value) |
#include <include/drivers/gpio.h>
Equivalent to GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value).
node_id | devicetree node identifier |
prop | lowercase-and-underscores property name |
default_value | fallback value to expand to |
#define GPIO_DT_SPEC_INST_GET | ( | inst, | |
prop | |||
) | GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0) |
#include <include/drivers/gpio.h>
Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0).
inst | DT_DRV_COMPAT instance number |
prop | lowercase-and-underscores property name |
#define GPIO_DT_SPEC_INST_GET_BY_IDX | ( | inst, | |
prop, | |||
idx | |||
) | GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx) |
#include <include/drivers/gpio.h>
Static initializer for a gpio_dt_spec
from a DT_DRV_COMPAT instance's GPIO property at an index.
inst | DT_DRV_COMPAT instance number |
prop | lowercase-and-underscores property name |
idx | logical index into "prop" |
#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) |
#include <include/drivers/gpio.h>
Static initializer for a gpio_dt_spec
from a DT_DRV_COMPAT instance's GPIO property at an index, with fallback.
inst | DT_DRV_COMPAT instance number |
prop | lowercase-and-underscores property name |
idx | logical index into "prop" |
default_value | fallback value to expand to |
#define GPIO_DT_SPEC_INST_GET_OR | ( | inst, | |
prop, | |||
default_value | |||
) | GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value) |
#include <include/drivers/gpio.h>
Equivalent to GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value).
inst | DT_DRV_COMPAT instance number |
prop | lowercase-and-underscores property name |
default_value | fallback value to expand to |
#define GPIO_INPUT (1U << 8) |
#include <include/drivers/gpio.h>
Enables pin as input.
#define GPIO_INT_DEBOUNCE (1U << 19) |
#include <include/drivers/gpio.h>
Enable GPIO pin debounce.
#define GPIO_INT_DISABLE (1U << 13) |
#include <include/drivers/gpio.h>
Disables GPIO pin interrupt.
#define GPIO_INT_EDGE_BOTH |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin rising or falling edge and enables it.
#define GPIO_INT_EDGE_FALLING |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin falling edge and enables it.
#define GPIO_INT_EDGE_RISING |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin rising edge and enables it.
#define GPIO_INT_EDGE_TO_ACTIVE |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin state change to logical level 1 and enables it.
#define GPIO_INT_EDGE_TO_INACTIVE |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin state change to logical level 0 and enables it.
#define GPIO_INT_LEVEL_ACTIVE |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin logical level 1 and enables it.
#define GPIO_INT_LEVEL_HIGH |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin physical level high and enables it.
#define GPIO_INT_LEVEL_INACTIVE |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin logical level 0 and enables it.
#define GPIO_INT_LEVEL_LOW |
#include <include/drivers/gpio.h>
Configures GPIO interrupt to be triggered on pin physical level low and enables it.
#define GPIO_MAX_PINS_PER_PORT (sizeof(gpio_port_pins_t) * __CHAR_BIT__) |
#include <include/drivers/gpio.h>
Maximum number of pins that are supported by gpio_port_pins_t
.
#define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN) |
#include <include/dt-bindings/gpio/gpio.h>
Configures GPIO output in open drain mode (wired AND).
#define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE) |
#include <include/dt-bindings/gpio/gpio.h>
Configures GPIO output in open source mode (wired OR).
#define GPIO_OUTPUT (1U << 9) |
#include <include/drivers/gpio.h>
Enables pin as output, no change to the output state.
#define GPIO_OUTPUT_ACTIVE |
#include <include/drivers/gpio.h>
Configures GPIO pin as output and initializes it to a logic 1.
#define GPIO_OUTPUT_HIGH (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH) |
#include <include/drivers/gpio.h>
Configures GPIO pin as output and initializes it to a high state.
#define GPIO_OUTPUT_INACTIVE |
#include <include/drivers/gpio.h>
Configures GPIO pin as output and initializes it to a logic 0.
#define GPIO_OUTPUT_LOW (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW) |
#include <include/drivers/gpio.h>
Configures GPIO pin as output and initializes it to a low state.
#define GPIO_PULL_DOWN (1 << 5) |
#include <include/dt-bindings/gpio/gpio.h>
Enable GPIO pin pull-down.
#define GPIO_PULL_UP (1 << 4) |
#include <include/dt-bindings/gpio/gpio.h>
Enables GPIO pin pull-up.
#define GPIO_VOLTAGE_1P8 (1U << GPIO_VOLTAGE_POS) |
#include <include/dt-bindings/gpio/gpio.h>
Set pin voltage level at 1.8 V
#define GPIO_VOLTAGE_3P3 (2U << GPIO_VOLTAGE_POS) |
#include <include/dt-bindings/gpio/gpio.h>
Set pin voltage level at 3.3 V
#define GPIO_VOLTAGE_5P0 (3U << GPIO_VOLTAGE_POS) |
#include <include/dt-bindings/gpio/gpio.h>
Set pin voltage level at 5.0 V
#define GPIO_VOLTAGE_DEFAULT (0U << GPIO_VOLTAGE_POS) |
#include <include/dt-bindings/gpio/gpio.h>
Set pin at the default voltage level
gpio_callback_handler_t |
#include <include/drivers/gpio.h>
Define the application callback handler function signature.
port | Device struct for the GPIO device. |
cb | Original struct gpio_callback owning this handler |
pins | Mask 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.
typedef uint8_t gpio_dt_flags_t |
#include <include/drivers/gpio.h>
Provides a type to hold GPIO devicetree flags.
All GPIO flags that can be expressed in devicetree fit in the low 8 bits of the full flags field, so use a reduced-size type to record that part of a GPIOS property.
typedef uint32_t gpio_flags_t |
#include <include/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.
typedef uint8_t gpio_pin_t |
#include <include/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.
typedef uint32_t gpio_port_pins_t |
#include <include/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.
typedef uint32_t gpio_port_value_t |
#include <include/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.
|
inlinestatic |
#include <include/drivers/gpio.h>
Add an application callback.
port | Pointer to the device structure for the driver instance. |
callback | A valid Application's callback structure pointer. |
Note: enables to add as many callback as needed on the same port.
int gpio_get_pending_int | ( | const struct device * | dev | ) |
#include <include/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.
dev | Pointer to the device structure for the driver instance. |
status | != 0 if at least one gpio interrupt is pending. |
0 | if no gpio interrupt is pending. |
|
inlinestatic |
#include <include/drivers/gpio.h>
Helper to initialize a struct gpio_callback properly.
callback | A valid Application's callback structure pointer. |
handler | A valid handler function pointer. |
pin_mask | A bit mask of relevant pins for the handler |
int gpio_pin_configure | ( | const struct device * | port, |
gpio_pin_t | pin, | ||
gpio_flags_t | flags | ||
) |
#include <include/drivers/gpio.h>
Configure a single pin.
port | Pointer to device structure for the driver instance. |
pin | Pin number to configure. |
flags | Flags for pin configuration: 'GPIO input/output configuration flags', 'GPIO drive strength flags', 'GPIO pin drive flags', 'GPIO pin bias flags', GPIO_INT_DEBOUNCE. |
0 | If successful. |
-ENOTSUP | if any of the configuration options is not supported (unless otherwise directed by flag documentation). |
-EINVAL | Invalid argument. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/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);
spec | GPIO specification from devicetree |
extra_flags | additional flags |
|
inlinestatic |
#include <include/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().
port | Pointer to the device structure for the driver instance. |
pin | Pin number. |
1 | If pin logical value is 1 / active. |
0 | If pin logical value is 0 / inactive. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/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);
spec | GPIO specification from devicetree |
|
inlinestatic |
#include <include/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.
port | Pointer to the device structure for the driver instance. |
pin | Pin number. |
1 | If pin physical level is high. |
0 | If pin physical level is low. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
int gpio_pin_interrupt_configure | ( | const struct device * | port, |
gpio_pin_t | pin, | ||
gpio_flags_t | flags | ||
) |
#include <include/drivers/gpio.h>
Configure pin interrupt.
port | Pointer to device structure for the driver instance. |
pin | Pin number. |
flags | Interrupt configuration flags as defined by GPIO_INT_*. |
0 | If successful. |
-ENOTSUP | If any of the configuration options is not supported (unless otherwise directed by flag documentation). |
-EINVAL | Invalid argument. |
-EBUSY | Interrupt line required to configure pin interrupt is already in use. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/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.
spec | GPIO specification from devicetree |
flags | interrupt configuration flags |
|
inlinestatic |
#include <include/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().
port | Pointer to the device structure for the driver instance. |
pin | Pin number. |
value | Value assigned to the pin. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/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);
spec | GPIO specification from devicetree |
value | Value assigned to the pin. |
|
inlinestatic |
#include <include/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.
port | Pointer to the device structure for the driver instance. |
pin | Pin number. |
value | Value assigned to the pin. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/drivers/gpio.h>
Toggle pin level.
port | Pointer to the device structure for the driver instance. |
pin | Pin number. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/drivers/gpio.h>
Toggle pin level from a gpio_dt_spec
.
This is equivalent to:
gpio_pin_toggle(spec->port, spec->pin);
spec | GPIO specification from devicetree |
|
inlinestatic |
#include <include/drivers/gpio.h>
Set logical level of selected output pins to inactive.
port | Pointer to the device structure for the driver instance. |
pins | Value indicating which pins will be modified. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
int gpio_port_clear_bits_raw | ( | const struct device * | port, |
gpio_port_pins_t | pins | ||
) |
#include <include/drivers/gpio.h>
Set physical level of selected output pins to low.
port | Pointer to the device structure for the driver instance. |
pins | Value indicating which pins will be modified. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/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.
port | Pointer to the device structure for the driver instance. |
value | Pointer to a variable where pin values will be stored. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
int gpio_port_get_raw | ( | const struct device * | port, |
gpio_port_value_t * | value | ||
) |
#include <include/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.
port | Pointer to the device structure for the driver instance. |
value | Pointer to a variable where pin values will be stored. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/drivers/gpio.h>
Set logical level of selected output pins to active.
port | Pointer to the device structure for the driver instance. |
pins | Value indicating which pins will be modified. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
int gpio_port_set_bits_raw | ( | const struct device * | port, |
gpio_port_pins_t | pins | ||
) |
#include <include/drivers/gpio.h>
Set physical level of selected output pins to high.
port | Pointer to the device structure for the driver instance. |
pins | Value indicating which pins will be modified. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/drivers/gpio.h>
Set logical level of selected output pins.
port | Pointer to the device structure for the driver instance. |
set_pins | Value indicating which pins will be set to active. |
clear_pins | Value indicating which pins will be set to inactive. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/drivers/gpio.h>
Set physical level of selected output pins.
port | Pointer to the device structure for the driver instance. |
set_pins | Value indicating which pins will be set to high. |
clear_pins | Value indicating which pins will be set to low. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/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.
port | Pointer to the device structure for the driver instance. |
mask | Mask indicating which pins will be modified. |
value | Value assigned to the output pins. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
int gpio_port_set_masked_raw | ( | const struct device * | port, |
gpio_port_pins_t | mask, | ||
gpio_port_value_t | value | ||
) |
#include <include/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.
port | Pointer to the device structure for the driver instance. |
mask | Mask indicating which pins will be modified. |
value | Value assigned to the output pins. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
int gpio_port_toggle_bits | ( | const struct device * | port, |
gpio_port_pins_t | pins | ||
) |
#include <include/drivers/gpio.h>
Toggle level of selected output pins.
port | Pointer to the device structure for the driver instance. |
pins | Value indicating which pins will be modified. |
0 | If successful. |
-EIO | I/O error when accessing an external GPIO chip. |
-EWOULDBLOCK | if operation would block. |
|
inlinestatic |
#include <include/drivers/gpio.h>
Remove an application callback.
port | Pointer to the device structure for the driver instance. |
callback | A valid application's callback structure pointer. |
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().