Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gpio_emul.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Friedt Professional Engineering Services, Inc
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11
12#ifndef ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_EMUL_H_
13#define ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_EMUL_H_
14
15#include <zephyr/types.h>
16#include <zephyr/drivers/gpio.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
46
58 gpio_port_value_t values);
59
70static inline int gpio_emul_input_set(const struct device *port, gpio_pin_t pin,
71 int value)
72{
73 return gpio_emul_input_set_masked(port, BIT(pin), value ? BIT(pin) : 0);
74}
75
88static inline int gpio_emul_input_set_dt(const struct gpio_dt_spec *spec, int value)
89{
90 return gpio_emul_input_set(spec->port, spec->pin, value);
91}
92
104 gpio_port_value_t *values);
105
115static inline int gpio_emul_output_get(const struct device *port, gpio_pin_t pin)
116{
117 int ret;
118 gpio_port_value_t values;
119
120 ret = gpio_emul_output_get_masked(port, BIT(pin), &values);
121 if (ret == 0) {
122 ret = (values & BIT(pin)) ? 1 : 0;
123 }
124
125 return ret;
126}
127
139static inline int gpio_emul_output_get_dt(const struct gpio_dt_spec *spec)
140{
141 return gpio_emul_output_get(spec->port, spec->pin);
142}
143
157
172static inline int gpio_emul_flags_get_dt(const struct gpio_dt_spec *spec, gpio_flags_t *flags)
173{
174 return gpio_emul_flags_get(spec->port, spec->pin, flags);
175}
176
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_EMUL_H_ */
Main header file for GPIO driver API.
static int gpio_emul_input_set(const struct device *port, gpio_pin_t pin, int value)
Modify the value of one emulated GPIO input pin.
Definition gpio_emul.h:70
static int gpio_emul_output_get_dt(const struct gpio_dt_spec *spec)
Read the value of one emulated GPIO output pin from a gpio_dt_spec.
Definition gpio_emul.h:139
static int gpio_emul_flags_get_dt(const struct gpio_dt_spec *spec, gpio_flags_t *flags)
Get flags for a given emulated GPIO pin from a gpio_dt_spec.
Definition gpio_emul.h:172
int gpio_emul_flags_get(const struct device *port, gpio_pin_t pin, gpio_flags_t *flags)
Get flags for a given emulated GPIO pin.
static int gpio_emul_output_get(const struct device *port, gpio_pin_t pin)
Read the value of one emulated GPIO output pin.
Definition gpio_emul.h:115
int gpio_emul_output_get_masked(const struct device *port, gpio_port_pins_t pins, gpio_port_value_t *values)
Read the value of one or more emulated GPIO output pins.
int gpio_emul_input_set_masked(const struct device *port, gpio_port_pins_t pins, gpio_port_value_t values)
Modify the values of one or more emulated GPIO input pins.
static int gpio_emul_input_set_dt(const struct gpio_dt_spec *spec, int value)
Modify the value of one emulated GPIO input pin from a gpio_dt_spec.
Definition gpio_emul.h:88
uint8_t gpio_pin_t
Provides a type to hold a GPIO pin index.
Definition gpio.h:262
uint32_t gpio_flags_t
Provides a type to hold GPIO configuration flags.
Definition gpio.h:282
uint32_t gpio_port_pins_t
Identifies a set of pins associated with a port.
Definition gpio.h:241
uint32_t gpio_port_value_t
Provides values for a set of pins associated with a port.
Definition gpio.h:254
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
flags
Definition parser.h:97
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
const struct device * port
GPIO device controlling the pin.
Definition gpio.h:298
gpio_pin_t pin
The pin's number on the device.
Definition gpio.h:300