Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019-2020 Nordic Semiconductor ASA
3 * Copyright (c) 2019 Piotr Mienkowski
4 * Copyright (c) 2017 ARM Ltd
5 * Copyright (c) 2015-2016 Intel Corporation.
6 *
7 * SPDX-License-Identifier: Apache-2.0
8 */
9
15
16#ifndef ZEPHYR_INCLUDE_DRIVERS_GPIO_H_
17#define ZEPHYR_INCLUDE_DRIVERS_GPIO_H_
18
19#include <errno.h>
20
21#include <zephyr/sys/__assert.h>
22#include <zephyr/sys/slist.h>
24
25#include <zephyr/types.h>
26#include <stddef.h>
27#include <zephyr/device.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
48
53
55#define GPIO_INPUT BIT(16)
56
58#define GPIO_OUTPUT BIT(17)
59
61#define GPIO_DISCONNECTED 0
62
64
65/* Initializes output to a low state. */
66#define GPIO_OUTPUT_INIT_LOW BIT(18)
67
68/* Initializes output to a high state. */
69#define GPIO_OUTPUT_INIT_HIGH BIT(19)
70
71/* Initializes output based on logic level */
72#define GPIO_OUTPUT_INIT_LOGICAL BIT(20)
73
75
77#define GPIO_OUTPUT_LOW (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW)
79#define GPIO_OUTPUT_HIGH (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH)
81#define GPIO_OUTPUT_INACTIVE (GPIO_OUTPUT | \
82 GPIO_OUTPUT_INIT_LOW | \
83 GPIO_OUTPUT_INIT_LOGICAL)
84
85#define GPIO_OUTPUT_ACTIVE (GPIO_OUTPUT | \
86 GPIO_OUTPUT_INIT_HIGH | \
87 GPIO_OUTPUT_INIT_LOGICAL)
88
90
106
108#define GPIO_INT_DISABLE BIT(21)
109
111
112/* Enables GPIO pin interrupt. */
113#define GPIO_INT_ENABLE BIT(22)
114
115/* GPIO interrupt is sensitive to logical levels.
116 *
117 * This is a component flag that should be combined with other
118 * `GPIO_INT_*` flags to produce a meaningful configuration.
119 */
120#define GPIO_INT_LEVELS_LOGICAL BIT(23)
121
122/* GPIO interrupt is edge sensitive.
123 *
124 * Note: by default interrupts are level sensitive.
125 *
126 * This is a component flag that should be combined with other
127 * `GPIO_INT_*` flags to produce a meaningful configuration.
128 */
129#define GPIO_INT_EDGE BIT(24)
130
131/* Trigger detection when input state is (or transitions to) physical low or
132 * logical 0 level.
133 *
134 * This is a component flag that should be combined with other
135 * `GPIO_INT_*` flags to produce a meaningful configuration.
136 */
137#define GPIO_INT_LOW_0 BIT(25)
138
139/* Trigger detection on input state is (or transitions to) physical high or
140 * logical 1 level.
141 *
142 * This is a component flag that should be combined with other
143 * `GPIO_INT_*` flags to produce a meaningful configuration.
144 */
145#define GPIO_INT_HIGH_1 BIT(26)
146
147#ifdef CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT
148/* Disable/Enable interrupt functionality without changing other interrupt
149 * related register, such as clearing the pending register.
150 *
151 * This is a component flag that should be combined with `GPIO_INT_ENABLE` or
152 * `GPIO_INT_DISABLE` flags to produce a meaningful configuration.
153 */
154#define GPIO_INT_ENABLE_DISABLE_ONLY BIT(27)
155#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
156
157#define GPIO_INT_MASK (GPIO_INT_DISABLE | \
158 GPIO_INT_ENABLE | \
159 GPIO_INT_LEVELS_LOGICAL | \
160 GPIO_INT_EDGE | \
161 GPIO_INT_LOW_0 | \
162 GPIO_INT_HIGH_1)
163
165
168#define GPIO_INT_EDGE_RISING (GPIO_INT_ENABLE | \
169 GPIO_INT_EDGE | \
170 GPIO_INT_HIGH_1)
171
175#define GPIO_INT_EDGE_FALLING (GPIO_INT_ENABLE | \
176 GPIO_INT_EDGE | \
177 GPIO_INT_LOW_0)
178
182#define GPIO_INT_EDGE_BOTH (GPIO_INT_ENABLE | \
183 GPIO_INT_EDGE | \
184 GPIO_INT_LOW_0 | \
185 GPIO_INT_HIGH_1)
186
190#define GPIO_INT_LEVEL_LOW (GPIO_INT_ENABLE | \
191 GPIO_INT_LOW_0)
192
196#define GPIO_INT_LEVEL_HIGH (GPIO_INT_ENABLE | \
197 GPIO_INT_HIGH_1)
198
202#define GPIO_INT_EDGE_TO_INACTIVE (GPIO_INT_ENABLE | \
203 GPIO_INT_LEVELS_LOGICAL | \
204 GPIO_INT_EDGE | \
205 GPIO_INT_LOW_0)
206
210#define GPIO_INT_EDGE_TO_ACTIVE (GPIO_INT_ENABLE | \
211 GPIO_INT_LEVELS_LOGICAL | \
212 GPIO_INT_EDGE | \
213 GPIO_INT_HIGH_1)
214
218#define GPIO_INT_LEVEL_INACTIVE (GPIO_INT_ENABLE | \
219 GPIO_INT_LEVELS_LOGICAL | \
220 GPIO_INT_LOW_0)
221
225#define GPIO_INT_LEVEL_ACTIVE (GPIO_INT_ENABLE | \
226 GPIO_INT_LEVELS_LOGICAL | \
227 GPIO_INT_HIGH_1)
228
230
232#define GPIO_DIR_MASK (GPIO_INPUT | GPIO_OUTPUT)
234
242
255
263
275
283
304
339#define GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx) \
340 { \
341 .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
342 .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
343 .dt_flags = DT_GPIO_FLAGS_BY_IDX(node_id, prop, idx), \
344 }
345
363#define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
364 COND_CODE_1(DT_PROP_HAS_IDX(node_id, prop, idx), \
365 (GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
366 (default_value))
367
376#define GPIO_DT_SPEC_GET(node_id, prop) \
377 GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
378
389#define GPIO_DT_SPEC_GET_OR(node_id, prop, default_value) \
390 GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
391
402#define GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
403 GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
404
416#define GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value) \
417 COND_CODE_1(DT_PROP_HAS_IDX(DT_DRV_INST(inst), prop, idx), \
418 (GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)), \
419 (default_value))
420
429#define GPIO_DT_SPEC_INST_GET(inst, prop) \
430 GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
431
442#define GPIO_DT_SPEC_INST_GET_OR(inst, prop, default_value) \
443 GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
444
445/*
446 * @cond INTERNAL_HIDDEN
447 */
448
459#define Z_GPIO_GEN_BITMASK_COND(node_id, prop, off_idx, sz_idx) \
460 COND_CODE_1(DT_PROP_HAS_IDX(node_id, prop, off_idx), \
461 (COND_CODE_0(DT_PROP_BY_IDX(node_id, prop, sz_idx), \
462 (0), \
463 (GENMASK64(DT_PROP_BY_IDX(node_id, prop, off_idx) + \
464 DT_PROP_BY_IDX(node_id, prop, sz_idx) - 1, \
465 DT_PROP_BY_IDX(node_id, prop, off_idx)))) \
466 ), (0))
467
475#define Z_GPIO_GEN_RESERVED_RANGES_COND(odd_it, node_id) \
476 COND_CODE_1(DT_PROP_HAS_IDX(node_id, gpio_reserved_ranges, odd_it), \
477 (Z_GPIO_GEN_BITMASK_COND(node_id, \
478 gpio_reserved_ranges, \
479 GET_ARG_N(odd_it, Z_SPARSE_LIST_EVEN_NUMBERS), \
480 odd_it)), \
481 (0))
482
486
574#define GPIO_DT_RESERVED_RANGES_NGPIOS(node_id, ngpios) \
575 ((gpio_port_pins_t) \
576 COND_CODE_1(DT_NODE_HAS_PROP(node_id, gpio_reserved_ranges), \
577 (GENMASK64(BITS_PER_LONG_LONG - 1, ngpios) \
578 | FOR_EACH_FIXED_ARG(Z_GPIO_GEN_RESERVED_RANGES_COND, \
579 (|), \
580 node_id, \
581 LIST_DROP_EMPTY(Z_SPARSE_LIST_ODD_NUMBERS))), \
582 (0)))
583
591#define GPIO_DT_RESERVED_RANGES(node_id) \
592 GPIO_DT_RESERVED_RANGES_NGPIOS(node_id, DT_PROP(node_id, ngpios))
593
603#define GPIO_DT_INST_RESERVED_RANGES_NGPIOS(inst, ngpios) \
604 GPIO_DT_RESERVED_RANGES_NGPIOS(DT_DRV_INST(inst), ngpios)
605
614#define GPIO_DT_INST_RESERVED_RANGES(inst) \
615 GPIO_DT_RESERVED_RANGES(DT_DRV_INST(inst))
616
665#define GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC(node_id, ngpios) \
666 ((gpio_port_pins_t) \
667 COND_CODE_0(ngpios, \
668 (0), \
669 (COND_CODE_1(DT_NODE_HAS_PROP(node_id, gpio_reserved_ranges), \
670 ((GENMASK64(ngpios - 1, 0) & \
671 ~GPIO_DT_RESERVED_RANGES_NGPIOS(node_id, ngpios))), \
672 (GENMASK64(ngpios - 1, 0))) \
673 ) \
674 ))
675
685#define GPIO_DT_INST_PORT_PIN_MASK_NGPIOS_EXC(inst, ngpios) \
686 GPIO_DT_PORT_PIN_MASK_NGPIOS_EXC(DT_DRV_INST(inst), ngpios)
687
691#define GPIO_MAX_PINS_PER_PORT (sizeof(gpio_port_pins_t) * __CHAR_BIT__)
692
706
719
720struct gpio_callback;
721
733typedef void (*gpio_callback_handler_t)(const struct device *port,
734 struct gpio_callback *cb,
735 gpio_port_pins_t pins);
736
764
769
781 GPIO_INT_MODE_LEVEL = GPIO_INT_ENABLE,
783 GPIO_INT_MODE_EDGE = GPIO_INT_ENABLE | GPIO_INT_EDGE,
784#if defined(CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT) || defined(__DOXYGEN__)
789 GPIO_INT_MODE_DISABLE_ONLY = GPIO_INT_DISABLE | GPIO_INT_ENABLE_DISABLE_ONLY,
794 GPIO_INT_MODE_ENABLE_ONLY = GPIO_INT_ENABLE | GPIO_INT_ENABLE_DISABLE_ONLY,
795#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
796};
797
805 GPIO_INT_TRIG_LOW = GPIO_INT_LOW_0,
808 GPIO_INT_TRIG_HIGH = GPIO_INT_HIGH_1,
810 GPIO_INT_TRIG_BOTH = GPIO_INT_LOW_0 | GPIO_INT_HIGH_1,
822 GPIO_INT_TRIG_WAKE_BOTH = GPIO_INT_LOW_0 | GPIO_INT_HIGH_1 | GPIO_INT_WAKEUP,
823};
824
829typedef int (*gpio_api_pin_configure_t)(const struct device *port, gpio_pin_t pin,
831
836typedef int (*gpio_api_pin_get_config_t)(const struct device *port, gpio_pin_t pin,
838
843typedef int (*gpio_api_port_get_raw_t)(const struct device *port,
844 gpio_port_value_t *value);
845
850typedef int (*gpio_api_port_set_masked_raw_t)(const struct device *port,
851 gpio_port_pins_t mask,
852 gpio_port_value_t value);
853
858typedef int (*gpio_api_port_set_bits_raw_t)(const struct device *port,
859 gpio_port_pins_t pins);
860
865typedef int (*gpio_api_port_clear_bits_raw_t)(const struct device *port,
866 gpio_port_pins_t pins);
867
872typedef int (*gpio_api_port_toggle_bits_t)(const struct device *port,
873 gpio_port_pins_t pins);
874
881typedef int (*gpio_api_pin_interrupt_configure_t)(const struct device *port,
882 gpio_pin_t pin,
883 enum gpio_int_mode mode,
884 enum gpio_int_trig trig);
885
890typedef int (*gpio_api_manage_callback_t)(const struct device *port,
891 struct gpio_callback *cb,
892 bool set);
893
898typedef uint32_t (*gpio_api_get_pending_int_t)(const struct device *dev);
899
904typedef int (*gpio_api_port_get_direction_t)(const struct device *port, gpio_port_pins_t map,
905 gpio_port_pins_t *inputs, gpio_port_pins_t *outputs);
906
947
949
958static inline bool gpio_is_ready_dt(const struct gpio_dt_spec *spec)
959{
960 /* Validate port is ready */
961 return device_is_ready(spec->port);
962}
963
987__syscall int gpio_pin_interrupt_configure(const struct device *port,
988 gpio_pin_t pin,
990
991static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port,
992 gpio_pin_t pin,
994{
995 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
996 __unused const struct gpio_driver_config *const cfg =
997 (const struct gpio_driver_config *)port->config;
998 const struct gpio_driver_data *const data =
999 (const struct gpio_driver_data *)port->data;
1000 enum gpio_int_trig trig;
1001 enum gpio_int_mode mode;
1002 int ret;
1003
1004 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, interrupt_configure, port, pin, flags);
1005
1006 if (api->pin_interrupt_configure == NULL) {
1007 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, -ENOSYS);
1008 return -ENOSYS;
1009 }
1010
1011 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE))
1012 != (GPIO_INT_DISABLE | GPIO_INT_ENABLE),
1013 "Cannot both enable and disable interrupts");
1014
1015 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE)) != 0U,
1016 "Must either enable or disable interrupts");
1017
1018 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
1019 ((flags & GPIO_INT_EDGE) != 0) ||
1020 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) !=
1021 (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)),
1022 "Only one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 can be "
1023 "enabled for a level interrupt.");
1024
1026#ifdef CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT
1027#define GPIO_INT_ENABLE_DISABLE_ONLY_VALUE GPIO_INT_ENABLE_DISABLE_ONLY
1028#else
1029#define GPIO_INT_ENABLE_DISABLE_ONLY_VALUE 0
1030#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
1032
1033 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
1034 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) != 0) ||
1035 (flags & GPIO_INT_ENABLE_DISABLE_ONLY_VALUE) != 0,
1036 "At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be enabled.");
1037#undef GPIO_INT_ENABLE_DISABLE_ONLY_VALUE
1038 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1039 "Unsupported pin");
1040
1041 if (((flags & GPIO_INT_LEVELS_LOGICAL) != 0) &&
1042 ((data->invert & (gpio_port_pins_t)BIT(pin)) != 0)) {
1043 /* Invert signal bits */
1044 flags ^= (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1);
1045 }
1046
1047 trig = (enum gpio_int_trig)(flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1 | GPIO_INT_WAKEUP));
1048#ifdef CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT
1049 mode = (enum gpio_int_mode)(flags & (GPIO_INT_EDGE | GPIO_INT_DISABLE | GPIO_INT_ENABLE |
1050 GPIO_INT_ENABLE_DISABLE_ONLY));
1051#else
1052 mode = (enum gpio_int_mode)(flags & (GPIO_INT_EDGE | GPIO_INT_DISABLE | GPIO_INT_ENABLE));
1053#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
1054
1055 ret = api->pin_interrupt_configure(port, pin, mode, trig);
1056 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, ret);
1057 return ret;
1058}
1059
1077static inline int gpio_pin_interrupt_configure_dt(const struct gpio_dt_spec *spec,
1079{
1080 return gpio_pin_interrupt_configure(spec->port, spec->pin,
1081 flags | (spec->dt_flags & GPIO_INT_WAKEUP));
1082}
1083
1099__syscall int gpio_pin_configure(const struct device *port,
1100 gpio_pin_t pin,
1102
1103static inline int z_impl_gpio_pin_configure(const struct device *port,
1104 gpio_pin_t pin,
1106{
1107 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1108 __unused const struct gpio_driver_config *const cfg =
1109 (const struct gpio_driver_config *)port->config;
1110 struct gpio_driver_data *data =
1111 (struct gpio_driver_data *)port->data;
1112 int ret;
1113
1114 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, configure, port, pin, flags);
1115
1116 __ASSERT((flags & GPIO_INT_MASK) == 0,
1117 "Interrupt flags are not supported");
1118
1119 __ASSERT((flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) !=
1121 "Pull Up and Pull Down should not be enabled simultaneously");
1122
1123 __ASSERT(!((flags & GPIO_INPUT) && !(flags & GPIO_OUTPUT) && (flags & GPIO_SINGLE_ENDED)),
1124 "Input cannot be enabled for 'Open Drain', 'Open Source' modes without Output");
1125
1126 __ASSERT_NO_MSG((flags & GPIO_SINGLE_ENDED) != 0 ||
1127 (flags & GPIO_LINE_OPEN_DRAIN) == 0);
1128
1129 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) == 0
1130 || (flags & GPIO_OUTPUT) != 0,
1131 "Output needs to be enabled to be initialized low or high");
1132
1133 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH))
1134 != (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH),
1135 "Output cannot be initialized low and high");
1136
1137 if (((flags & GPIO_OUTPUT_INIT_LOGICAL) != 0)
1138 && ((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) != 0)
1139 && ((flags & GPIO_ACTIVE_LOW) != 0)) {
1140 flags ^= GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH;
1141 }
1142
1143 flags &= ~GPIO_OUTPUT_INIT_LOGICAL;
1144
1145 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1146 "Unsupported pin");
1147
1148 if ((flags & GPIO_ACTIVE_LOW) != 0) {
1149 data->invert |= (gpio_port_pins_t)BIT(pin);
1150 } else {
1151 data->invert &= ~(gpio_port_pins_t)BIT(pin);
1152 }
1153
1154 ret = api->pin_configure(port, pin, flags);
1155 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, configure, port, pin, ret);
1156 return ret;
1157}
1158
1170static inline int gpio_pin_configure_dt(const struct gpio_dt_spec *spec,
1171 gpio_flags_t extra_flags)
1172{
1173 return gpio_pin_configure(spec->port,
1174 spec->pin,
1175 spec->dt_flags | extra_flags);
1176}
1177
1196__syscall int gpio_port_get_direction(const struct device *port, gpio_port_pins_t map,
1197 gpio_port_pins_t *inputs, gpio_port_pins_t *outputs);
1198
1199#ifdef CONFIG_GPIO_GET_DIRECTION
1200static inline int z_impl_gpio_port_get_direction(const struct device *port, gpio_port_pins_t map,
1201 gpio_port_pins_t *inputs,
1202 gpio_port_pins_t *outputs)
1203{
1204 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1205 int ret;
1206
1207 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, get_direction, port, map, inputs, outputs);
1208
1209 if (api->port_get_direction == NULL) {
1210 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_direction, port, -ENOSYS);
1211 return -ENOSYS;
1212 }
1213
1214 ret = api->port_get_direction(port, map, inputs, outputs);
1215 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_direction, port, ret);
1216 return ret;
1217}
1218#endif /* CONFIG_GPIO_GET_DIRECTION */
1219
1232static inline int gpio_pin_is_input(const struct device *port, gpio_pin_t pin)
1233{
1234 int rv;
1235 gpio_port_pins_t pins;
1236 __unused const struct gpio_driver_config *cfg =
1237 (const struct gpio_driver_config *)port->config;
1238
1239 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, "Unsupported pin");
1240
1241 rv = gpio_port_get_direction(port, BIT(pin), &pins, NULL);
1242 if (rv < 0) {
1243 return rv;
1244 }
1245
1246 return (int)!!((gpio_port_pins_t)BIT(pin) & pins);
1247}
1248
1260static inline int gpio_pin_is_input_dt(const struct gpio_dt_spec *spec)
1261{
1262 return gpio_pin_is_input(spec->port, spec->pin);
1263}
1264
1277static inline int gpio_pin_is_output(const struct device *port, gpio_pin_t pin)
1278{
1279 int rv;
1280 gpio_port_pins_t pins;
1281 __unused const struct gpio_driver_config *cfg =
1282 (const struct gpio_driver_config *)port->config;
1283
1284 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, "Unsupported pin");
1285
1286 rv = gpio_port_get_direction(port, BIT(pin), NULL, &pins);
1287 if (rv < 0) {
1288 return rv;
1289 }
1290
1291 return (int)!!((gpio_port_pins_t)BIT(pin) & pins);
1292}
1293
1305static inline int gpio_pin_is_output_dt(const struct gpio_dt_spec *spec)
1306{
1307 return gpio_pin_is_output(spec->port, spec->pin);
1308}
1309
1325__syscall int gpio_pin_get_config(const struct device *port, gpio_pin_t pin,
1327
1328#ifdef CONFIG_GPIO_GET_CONFIG
1329static inline int z_impl_gpio_pin_get_config(const struct device *port,
1330 gpio_pin_t pin,
1332{
1333 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1334 int ret;
1335
1336 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, get_config, port, pin, *flags);
1337
1338 if (api->pin_get_config == NULL) {
1339 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, -ENOSYS);
1340 return -ENOSYS;
1341 }
1342
1343 ret = api->pin_get_config(port, pin, flags);
1344 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, ret);
1345 return ret;
1346}
1347#endif
1348
1361static inline int gpio_pin_get_config_dt(const struct gpio_dt_spec *spec,
1363{
1364 return gpio_pin_get_config(spec->port, spec->pin, flags);
1365}
1366
1384__syscall int gpio_port_get_raw(const struct device *port,
1385 gpio_port_value_t *value);
1386
1387static inline int z_impl_gpio_port_get_raw(const struct device *port, gpio_port_value_t *value)
1388{
1389 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1390 int ret;
1391
1392 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, get_raw, port, value);
1393
1394 ret = api->port_get_raw(port, value);
1395 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_raw, port, ret);
1396 return ret;
1397}
1398
1417__syscall int gpio_port_get(const struct device *port,
1418 gpio_port_value_t *value);
1419
1420static inline int z_impl_gpio_port_get(const struct device *port,
1421 gpio_port_value_t *value)
1422{
1423 const struct gpio_driver_data *const data =
1424 (const struct gpio_driver_data *)port->data;
1425 int ret;
1426
1427 ret = z_impl_gpio_port_get_raw(port, value);
1428 if (ret == 0) {
1429 *value ^= data->invert;
1430 }
1431
1432 return ret;
1433}
1434
1452__syscall int gpio_port_set_masked_raw(const struct device *port,
1453 gpio_port_pins_t mask,
1454 gpio_port_value_t value);
1455
1456static inline int z_impl_gpio_port_set_masked_raw(const struct device *port,
1457 gpio_port_pins_t mask,
1458 gpio_port_value_t value)
1459{
1460 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1461 int ret;
1462
1463 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, set_masked_raw, port, mask, value);
1464
1465 ret = api->port_set_masked_raw(port, mask, value);
1466 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, set_masked_raw, port, ret);
1467 return ret;
1468}
1469
1490__syscall int gpio_port_set_masked(const struct device *port,
1491 gpio_port_pins_t mask,
1492 gpio_port_value_t value);
1493
1494static inline int z_impl_gpio_port_set_masked(const struct device *port,
1495 gpio_port_pins_t mask,
1496 gpio_port_value_t value)
1497{
1498 const struct gpio_driver_data *const data =
1499 (const struct gpio_driver_data *)port->data;
1500
1501 value ^= data->invert;
1502
1503 return z_impl_gpio_port_set_masked_raw(port, mask, value);
1504}
1505
1516__syscall int gpio_port_set_bits_raw(const struct device *port,
1517 gpio_port_pins_t pins);
1518
1519static inline int z_impl_gpio_port_set_bits_raw(const struct device *port,
1520 gpio_port_pins_t pins)
1521{
1522 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1523 int ret;
1524
1525 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, set_bits_raw, port, pins);
1526
1527 ret = api->port_set_bits_raw(port, pins);
1528 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, set_bits_raw, port, ret);
1529 return ret;
1530}
1531
1542__syscall int gpio_port_set_bits(const struct device *port,
1543 gpio_port_pins_t pins);
1544
1545static inline int z_impl_gpio_port_set_bits(const struct device *port,
1546 gpio_port_pins_t pins)
1547{
1548 return z_impl_gpio_port_set_masked(port, pins, pins);
1549}
1550
1561__syscall int gpio_port_clear_bits_raw(const struct device *port,
1562 gpio_port_pins_t pins);
1563
1564static inline int z_impl_gpio_port_clear_bits_raw(const struct device *port,
1565 gpio_port_pins_t pins)
1566{
1567 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1568 int ret;
1569
1570 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, clear_bits_raw, port, pins);
1571
1572 ret = api->port_clear_bits_raw(port, pins);
1573 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, clear_bits_raw, port, ret);
1574 return ret;
1575}
1576
1587__syscall int gpio_port_clear_bits(const struct device *port,
1588 gpio_port_pins_t pins);
1589
1590static inline int z_impl_gpio_port_clear_bits(const struct device *port,
1591 gpio_port_pins_t pins)
1592{
1593 return z_impl_gpio_port_set_masked(port, pins, 0);
1594}
1595
1606__syscall int gpio_port_toggle_bits(const struct device *port,
1607 gpio_port_pins_t pins);
1608
1609static inline int z_impl_gpio_port_toggle_bits(const struct device *port,
1610 gpio_port_pins_t pins)
1611{
1612 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1613 int ret;
1614
1615 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, toggle_bits, port, pins);
1616
1617 ret = api->port_toggle_bits(port, pins);
1618 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, toggle_bits, port, ret);
1619 return ret;
1620}
1621
1633__syscall int gpio_port_set_clr_bits_raw(const struct device *port,
1634 gpio_port_pins_t set_pins,
1635 gpio_port_pins_t clear_pins);
1636
1637static inline int z_impl_gpio_port_set_clr_bits_raw(const struct device *port,
1638 gpio_port_pins_t set_pins,
1639 gpio_port_pins_t clear_pins)
1640{
1641 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1642
1643 return z_impl_gpio_port_set_masked_raw(port, set_pins | clear_pins, set_pins);
1644}
1645
1657__syscall int gpio_port_set_clr_bits(const struct device *port,
1658 gpio_port_pins_t set_pins,
1659 gpio_port_pins_t clear_pins);
1660
1661static inline int z_impl_gpio_port_set_clr_bits(const struct device *port,
1662 gpio_port_pins_t set_pins,
1663 gpio_port_pins_t clear_pins)
1664{
1665 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1666
1667 return z_impl_gpio_port_set_masked(port, set_pins | clear_pins, set_pins);
1668}
1669
1685__syscall int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin);
1686
1687static inline int z_impl_gpio_pin_get_raw(const struct device *port, gpio_pin_t pin)
1688{
1689 __unused const struct gpio_driver_config *const cfg =
1690 (const struct gpio_driver_config *)port->config;
1691 gpio_port_value_t value;
1692 int ret;
1693
1694 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1695 "Unsupported pin");
1696
1697 ret = z_impl_gpio_port_get_raw(port, &value);
1698 if (ret == 0) {
1699 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1700 }
1701
1702 return ret;
1703}
1704
1724__syscall int gpio_pin_get(const struct device *port, gpio_pin_t pin);
1725
1726static inline int z_impl_gpio_pin_get(const struct device *port, gpio_pin_t pin)
1727{
1728 __unused const struct gpio_driver_config *const cfg =
1729 (const struct gpio_driver_config *)port->config;
1730 gpio_port_value_t value;
1731 int ret;
1732
1733 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1734 "Unsupported pin");
1735
1736 ret = z_impl_gpio_port_get(port, &value);
1737 if (ret == 0) {
1738 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1739 }
1740
1741 return ret;
1742}
1743
1754static inline int gpio_pin_get_dt(const struct gpio_dt_spec *spec)
1755{
1756 return gpio_pin_get(spec->port, spec->pin);
1757}
1758
1774__syscall int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin, int value);
1775
1776static inline int z_impl_gpio_pin_set_raw(const struct device *port, gpio_pin_t pin,
1777 int value)
1778{
1779 __unused const struct gpio_driver_config *const cfg =
1780 (const struct gpio_driver_config *)port->config;
1781 int ret;
1782
1783 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1784 "Unsupported pin");
1785
1786 if (value != 0) {
1787 ret = z_impl_gpio_port_set_bits_raw(port, (gpio_port_pins_t)BIT(pin));
1788 } else {
1789 ret = z_impl_gpio_port_clear_bits_raw(port, (gpio_port_pins_t)BIT(pin));
1790 }
1791
1792 return ret;
1793}
1794
1816__syscall int gpio_pin_set(const struct device *port, gpio_pin_t pin, int value);
1817
1818static inline int z_impl_gpio_pin_set(const struct device *port, gpio_pin_t pin,
1819 int value)
1820{
1821 __unused const struct gpio_driver_config *const cfg =
1822 (const struct gpio_driver_config *)port->config;
1823 const struct gpio_driver_data *const data =
1824 (const struct gpio_driver_data *)port->data;
1825
1826 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1827 "Unsupported pin");
1828
1829 if (data->invert & (gpio_port_pins_t)BIT(pin)) {
1830 value = (value != 0) ? 0 : 1;
1831 }
1832
1833 return z_impl_gpio_pin_set_raw(port, pin, value);
1834}
1835
1847static inline int gpio_pin_set_dt(const struct gpio_dt_spec *spec, int value)
1848{
1849 return gpio_pin_set(spec->port, spec->pin, value);
1850}
1851
1862__syscall int gpio_pin_toggle(const struct device *port, gpio_pin_t pin);
1863
1864static inline int z_impl_gpio_pin_toggle(const struct device *port, gpio_pin_t pin)
1865{
1866 __unused const struct gpio_driver_config *const cfg =
1867 (const struct gpio_driver_config *)port->config;
1868
1869 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1870 "Unsupported pin");
1871
1872 return z_impl_gpio_port_toggle_bits(port, (gpio_port_pins_t)BIT(pin));
1873}
1874
1885static inline int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec)
1886{
1887 return gpio_pin_toggle(spec->port, spec->pin);
1888}
1889
1896static inline void gpio_init_callback(struct gpio_callback *callback,
1898 gpio_port_pins_t pin_mask)
1899{
1900 SYS_PORT_TRACING_FUNC_ENTER(gpio, init_callback, callback, handler, pin_mask);
1901
1902 __ASSERT(callback, "Callback pointer should not be NULL");
1903 __ASSERT(handler, "Callback handler pointer should not be NULL");
1904
1905 callback->handler = handler;
1906 callback->pin_mask = pin_mask;
1907
1908 SYS_PORT_TRACING_FUNC_EXIT(gpio, init_callback, callback);
1909}
1910
1924static inline int gpio_add_callback(const struct device *port,
1925 struct gpio_callback *callback)
1926{
1927 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1928 int ret;
1929
1930 SYS_PORT_TRACING_FUNC_ENTER(gpio, add_callback, port, callback);
1931
1932 if (api->manage_callback == NULL) {
1933 SYS_PORT_TRACING_FUNC_EXIT(gpio, add_callback, port, -ENOSYS);
1934 return -ENOSYS;
1935 }
1936
1937 ret = api->manage_callback(port, callback, true);
1938 SYS_PORT_TRACING_FUNC_EXIT(gpio, add_callback, port, ret);
1939 return ret;
1940}
1941
1953static inline int gpio_add_callback_dt(const struct gpio_dt_spec *spec,
1954 struct gpio_callback *callback)
1955{
1956 return gpio_add_callback(spec->port, callback);
1957}
1958
1976static inline int gpio_remove_callback(const struct device *port,
1977 struct gpio_callback *callback)
1978{
1979 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1980 int ret;
1981
1982 SYS_PORT_TRACING_FUNC_ENTER(gpio, remove_callback, port, callback);
1983
1984 if (api->manage_callback == NULL) {
1985 SYS_PORT_TRACING_FUNC_EXIT(gpio, remove_callback, port, -ENOSYS);
1986 return -ENOSYS;
1987 }
1988
1989 ret = api->manage_callback(port, callback, false);
1990 SYS_PORT_TRACING_FUNC_EXIT(gpio, remove_callback, port, ret);
1991 return ret;
1992}
1993
2005static inline int gpio_remove_callback_dt(const struct gpio_dt_spec *spec,
2006 struct gpio_callback *callback)
2007{
2008 return gpio_remove_callback(spec->port, callback);
2009}
2010
2025__syscall int gpio_get_pending_int(const struct device *dev);
2026
2027static inline int z_impl_gpio_get_pending_int(const struct device *dev)
2028{
2029 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, dev);
2030 int ret;
2031
2033
2034 if (api->get_pending_int == NULL) {
2036 return -ENOSYS;
2037 }
2038
2039 ret = api->get_pending_int(dev);
2041 return ret;
2042}
2043
2047
2048#ifdef __cplusplus
2049}
2050#endif
2051
2052#include <zephyr/syscalls/gpio.h>
2053
2054#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
System error numbers.
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
static int gpio_add_callback(const struct device *port, struct gpio_callback *callback)
Add an application callback.
Definition gpio.h:1924
int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin, int value)
Set physical level of an output pin.
int(* gpio_api_pin_get_config_t)(const struct device *port, gpio_pin_t pin, gpio_flags_t *flags)
Callback API to get the configuration of a single pin.
Definition gpio.h:836
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.
#define GPIO_OUTPUT
Enables pin as output, no change to the output state.
Definition gpio.h:58
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_is_input(const struct device *port, gpio_pin_t pin)
Check if pin is configured for input.
Definition gpio.h:1232
int gpio_port_set_bits_raw(const struct device *port, gpio_port_pins_t pins)
Set physical level of selected output pins to high.
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_pin_is_output_dt(const struct gpio_dt_spec *spec)
Check if a single pin from gpio_dt_spec is configured for output.
Definition gpio.h:1305
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.
Definition gpio.h:1077
uint32_t(* gpio_api_get_pending_int_t)(const struct device *dev)
Callback API to get pending interrupts.
Definition gpio.h:898
int(* gpio_api_manage_callback_t)(const struct device *port, struct gpio_callback *cb, bool set)
Callback API to add or remove an application callback.
Definition gpio.h:890
static int gpio_remove_callback_dt(const struct gpio_dt_spec *spec, struct gpio_callback *callback)
Remove an application callback.
Definition gpio.h:2005
static int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec)
Toggle pin level from a gpio_dt_spec.
Definition gpio.h:1885
uint8_t gpio_pin_t
Provides a type to hold a GPIO pin index.
Definition gpio.h:262
static int gpio_pin_is_output(const struct device *port, gpio_pin_t pin)
Check if pin is configured for output.
Definition gpio.h:1277
int gpio_get_pending_int(const struct device *dev)
Function to get pending interrupts.
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.
Definition gpio.h:1170
int(* gpio_api_port_clear_bits_raw_t)(const struct device *port, gpio_port_pins_t pins)
Callback API to set the physical level of selected output pins to low.
Definition gpio.h:865
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.
int gpio_pin_get(const struct device *port, gpio_pin_t pin)
Get logical level of an input pin.
gpio_int_trig
Interrupt triggers for the pin_interrupt_configure driver operation.
Definition gpio.h:801
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.
Definition gpio.h:1847
static int gpio_add_callback_dt(const struct gpio_dt_spec *spec, struct gpio_callback *callback)
Add an application callback.
Definition gpio.h:1953
int(* gpio_api_port_get_direction_t)(const struct device *port, gpio_port_pins_t map, gpio_port_pins_t *inputs, gpio_port_pins_t *outputs)
Callback API to get the direction of selected pins in a port.
Definition gpio.h:904
uint32_t gpio_flags_t
Provides a type to hold GPIO configuration flags.
Definition gpio.h:282
#define GPIO_ACTIVE_LOW
GPIO pin is active (has logical value '1') in low state.
Definition gpio.h:24
int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin)
Get physical level of an input pin.
#define GPIO_INT_WAKEUP
Configures GPIO interrupt to wakeup the system from low power mode.
Definition gpio.h:83
int(* gpio_api_pin_configure_t)(const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
Callback API to configure a single pin.
Definition gpio.h:829
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.
Definition gpio.h:1896
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.
Definition gpio.h:1260
#define GPIO_INPUT
Enables pin as input.
Definition gpio.h:55
int gpio_port_get(const struct device *port, gpio_port_value_t *value)
Get logical level of all input pins in a port.
uint32_t gpio_port_pins_t
Identifies a set of pins associated with a port.
Definition gpio.h:241
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.
Definition gpio.h:1361
int gpio_port_toggle_bits(const struct device *port, gpio_port_pins_t pins)
Toggle level of selected output pins.
gpio_int_mode
@def_driverbackendgroup{GPIO,gpio_interface}
Definition gpio.h:777
int(* gpio_api_port_toggle_bits_t)(const struct device *port, gpio_port_pins_t pins)
Callback API to toggle the level of selected output pins.
Definition gpio.h:872
#define GPIO_INT_DISABLE
Disables GPIO pin interrupt.
Definition gpio.h:108
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_pin_interrupt_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
Configure pin interrupt.
int gpio_port_clear_bits_raw(const struct device *port, gpio_port_pins_t pins)
Set physical level of selected output pins to low.
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.
int gpio_pin_toggle(const struct device *port, gpio_pin_t pin)
Toggle pin level.
#define GPIO_PULL_UP
Enables GPIO pin pull-up.
Definition gpio.h:73
static int gpio_pin_get_dt(const struct gpio_dt_spec *spec)
Get logical level of an input pin from a gpio_dt_spec.
Definition gpio.h:1754
static bool gpio_is_ready_dt(const struct gpio_dt_spec *spec)
Validate that GPIO port is ready.
Definition gpio.h:958
int(* gpio_api_port_set_masked_raw_t)(const struct device *port, gpio_port_pins_t mask, gpio_port_value_t value)
Callback API to set the physical level of selected output pins in a port.
Definition gpio.h:850
int(* gpio_api_port_set_bits_raw_t)(const struct device *port, gpio_port_pins_t pins)
Callback API to set the physical level of selected output pins to high.
Definition gpio.h:858
uint32_t gpio_port_value_t
Provides values for a set of pins associated with a port.
Definition gpio.h:254
static int gpio_remove_callback(const struct device *port, struct gpio_callback *callback)
Remove an application callback.
Definition gpio.h:1976
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.
int(* gpio_api_port_get_raw_t)(const struct device *port, gpio_port_value_t *value)
Callback API to get the physical level of all input pins in a port.
Definition gpio.h:843
uint16_t gpio_dt_flags_t
Provides a type to hold GPIO devicetree flags.
Definition gpio.h:274
int gpio_pin_set(const struct device *port, gpio_pin_t pin, int value)
Set logical level of an output pin.
#define GPIO_PULL_DOWN
Enable GPIO pin pull-down.
Definition gpio.h:76
int gpio_port_get_raw(const struct device *port, gpio_port_value_t *value)
Get physical level of all input pins in a port.
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_pin_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
Configure a single pin.
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.
Definition gpio.h:733
int(* gpio_api_pin_interrupt_configure_t)(const struct device *port, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig)
Callback API to configure a pin interrupt.
Definition gpio.h:881
@ GPIO_INT_TRIG_WAKE_HIGH
Trigger a system wakeup when input state is (or transitions to) physical high.
Definition gpio.h:820
@ GPIO_INT_TRIG_WAKE
Trigger a system wakeup.
Definition gpio.h:812
@ GPIO_INT_TRIG_HIGH
Trigger detection when input state is (or transitions to) physical high.
Definition gpio.h:808
@ GPIO_INT_TRIG_BOTH
Trigger detection on pin rising or falling edge.
Definition gpio.h:810
@ GPIO_INT_TRIG_WAKE_BOTH
Trigger a system wakeup on pin rising or falling edge.
Definition gpio.h:822
@ GPIO_INT_TRIG_LOW
Trigger detection when input state is (or transitions to) physical low.
Definition gpio.h:805
@ GPIO_INT_TRIG_WAKE_LOW
Trigger a system wakeup when input state is (or transitions to) physical low.
Definition gpio.h:816
@ GPIO_INT_MODE_DISABLE_ONLY
Disable a previously configured pin interrupt without deconfiguring it.
Definition gpio.h:789
@ GPIO_INT_MODE_EDGE
Enable edge-triggered pin interrupt.
Definition gpio.h:783
@ GPIO_INT_MODE_DISABLED
Disable pin interrupt.
Definition gpio.h:779
@ GPIO_INT_MODE_ENABLE_ONLY
Re-enable a previously configured pin interrupt.
Definition gpio.h:794
@ GPIO_INT_MODE_LEVEL
Enable level-triggered pin interrupt.
Definition gpio.h:781
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
#define SYS_PORT_TRACING_FUNC_ENTER(type, func,...)
Tracing macro for the entry into a function that might or might not return a value.
Definition tracing_macros.h:257
#define SYS_PORT_TRACING_FUNC_EXIT(type, func,...)
Tracing macro for when a function ends its execution.
Definition tracing_macros.h:283
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define NULL
Definition iar_missing_defs.h:20
flags
Definition parser.h:97
Header file for the single-linked list API.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
const void * config
Address of device instance config information.
Definition device.h:517
GPIO callback structure.
Definition gpio.h:747
sys_snode_t node
This is meant to be used in the driver and the user should not mess with it (see drivers/gpio/gpio_ut...
Definition gpio.h:751
gpio_port_pins_t pin_mask
A mask of pins the callback is interested in, if 0 the callback will never be called.
Definition gpio.h:762
gpio_callback_handler_t handler
Actual callback function being called when relevant.
Definition gpio.h:754
@driver_ops{GPIO}
Definition gpio.h:910
gpio_api_port_set_bits_raw_t port_set_bits_raw
@driver_ops_mandatory Set physical level of selected output pins to high.
Definition gpio.h:925
gpio_api_get_pending_int_t get_pending_int
@driver_ops_optional Function to get pending interrupts.
Definition gpio.h:938
gpio_api_port_get_raw_t port_get_raw
@driver_ops_mandatory Get physical level of all input pins in a port.
Definition gpio.h:921
gpio_api_port_toggle_bits_t port_toggle_bits
@driver_ops_mandatory Toggle level of selected output pins.
Definition gpio.h:929
gpio_api_pin_configure_t pin_configure
@driver_ops_mandatory Configure a single pin.
Definition gpio.h:912
gpio_api_pin_interrupt_configure_t pin_interrupt_configure
@driver_ops_optional Configure pin interrupt.
Definition gpio.h:931
gpio_api_port_get_direction_t port_get_direction
@driver_ops_optional Get direction of select pins in a port.
Definition gpio.h:944
gpio_api_manage_callback_t manage_callback
@driver_ops_optional Add or remove an application callback.
Definition gpio.h:936
gpio_api_pin_get_config_t pin_get_config
@driver_ops_optional Get a configuration of a single pin.
Definition gpio.h:918
gpio_api_port_clear_bits_raw_t port_clear_bits_raw
@driver_ops_mandatory Set physical level of selected output pins to low.
Definition gpio.h:927
gpio_api_port_set_masked_raw_t port_set_masked_raw
@driver_ops_mandatory Set physical level of output pins in a port.
Definition gpio.h:923
This structure is common to all GPIO drivers and is expected to be the first element in the object po...
Definition gpio.h:698
gpio_port_pins_t port_pin_mask
Mask identifying pins supported by the controller.
Definition gpio.h:704
This structure is common to all GPIO drivers and is expected to be the first element in the driver's ...
Definition gpio.h:711
gpio_port_pins_t invert
Mask identifying pins that are configured as active low.
Definition gpio.h:717
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
gpio_dt_flags_t dt_flags
The pin's configuration flags as specified in devicetree.
Definition gpio.h:302
Main header file for tracing subsystem API.