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
708static inline bool gpio_port_pin_is_supported(gpio_port_pins_t port_pin_mask, gpio_pin_t pin)
709{
710 if (pin >= GPIO_MAX_PINS_PER_PORT) {
711 return false;
712 }
713
714 return (port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U;
715}
716
730
743
744struct gpio_callback;
745
757typedef void (*gpio_callback_handler_t)(const struct device *port,
758 struct gpio_callback *cb,
759 gpio_port_pins_t pins);
760
788
793
805 GPIO_INT_MODE_LEVEL = GPIO_INT_ENABLE,
807 GPIO_INT_MODE_EDGE = GPIO_INT_ENABLE | GPIO_INT_EDGE,
808#if defined(CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT) || defined(__DOXYGEN__)
813 GPIO_INT_MODE_DISABLE_ONLY = GPIO_INT_DISABLE | GPIO_INT_ENABLE_DISABLE_ONLY,
818 GPIO_INT_MODE_ENABLE_ONLY = GPIO_INT_ENABLE | GPIO_INT_ENABLE_DISABLE_ONLY,
819#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
820};
821
829 GPIO_INT_TRIG_LOW = GPIO_INT_LOW_0,
832 GPIO_INT_TRIG_HIGH = GPIO_INT_HIGH_1,
834 GPIO_INT_TRIG_BOTH = GPIO_INT_LOW_0 | GPIO_INT_HIGH_1,
846 GPIO_INT_TRIG_WAKE_BOTH = GPIO_INT_LOW_0 | GPIO_INT_HIGH_1 | GPIO_INT_WAKEUP,
847};
848
853typedef int (*gpio_api_pin_configure_t)(const struct device *port, gpio_pin_t pin,
855
860typedef int (*gpio_api_pin_get_config_t)(const struct device *port, gpio_pin_t pin,
862
867typedef int (*gpio_api_port_get_raw_t)(const struct device *port,
868 gpio_port_value_t *value);
869
874typedef int (*gpio_api_port_set_masked_raw_t)(const struct device *port,
875 gpio_port_pins_t mask,
876 gpio_port_value_t value);
877
882typedef int (*gpio_api_port_set_bits_raw_t)(const struct device *port,
883 gpio_port_pins_t pins);
884
889typedef int (*gpio_api_port_clear_bits_raw_t)(const struct device *port,
890 gpio_port_pins_t pins);
891
896typedef int (*gpio_api_port_toggle_bits_t)(const struct device *port,
897 gpio_port_pins_t pins);
898
905typedef int (*gpio_api_pin_interrupt_configure_t)(const struct device *port,
906 gpio_pin_t pin,
907 enum gpio_int_mode mode,
908 enum gpio_int_trig trig);
909
914typedef int (*gpio_api_manage_callback_t)(const struct device *port,
915 struct gpio_callback *cb,
916 bool set);
917
922typedef uint32_t (*gpio_api_get_pending_int_t)(const struct device *dev);
923
928typedef int (*gpio_api_port_get_direction_t)(const struct device *port, gpio_port_pins_t map,
929 gpio_port_pins_t *inputs, gpio_port_pins_t *outputs);
930
971
973
982static inline bool gpio_is_ready_dt(const struct gpio_dt_spec *spec)
983{
984 /* Validate port is ready */
985 return device_is_ready(spec->port);
986}
987
1011__syscall int gpio_pin_interrupt_configure(const struct device *port,
1012 gpio_pin_t pin,
1014
1015static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port,
1016 gpio_pin_t pin,
1018{
1019 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1020 __unused const struct gpio_driver_config *const cfg =
1021 (const struct gpio_driver_config *)port->config;
1022 const struct gpio_driver_data *const data =
1023 (const struct gpio_driver_data *)port->data;
1024 enum gpio_int_trig trig;
1025 enum gpio_int_mode mode;
1026 int ret;
1027
1028 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, interrupt_configure, port, pin, flags);
1029
1030 if (api->pin_interrupt_configure == NULL) {
1031 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, -ENOSYS);
1032 return -ENOSYS;
1033 }
1034
1035 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE))
1036 != (GPIO_INT_DISABLE | GPIO_INT_ENABLE),
1037 "Cannot both enable and disable interrupts");
1038
1039 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE)) != 0U,
1040 "Must either enable or disable interrupts");
1041
1042 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
1043 ((flags & GPIO_INT_EDGE) != 0) ||
1044 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) !=
1045 (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)),
1046 "Only one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 can be "
1047 "enabled for a level interrupt.");
1048
1050#ifdef CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT
1051#define GPIO_INT_ENABLE_DISABLE_ONLY_VALUE GPIO_INT_ENABLE_DISABLE_ONLY
1052#else
1053#define GPIO_INT_ENABLE_DISABLE_ONLY_VALUE 0
1054#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
1056
1057 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
1058 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) != 0) ||
1059 (flags & GPIO_INT_ENABLE_DISABLE_ONLY_VALUE) != 0,
1060 "At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be enabled.");
1061#undef GPIO_INT_ENABLE_DISABLE_ONLY_VALUE
1062 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1063
1064 /* See the note in z_impl_gpio_pin_configure(). */
1065 if (pin >= GPIO_MAX_PINS_PER_PORT) {
1066 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, -EINVAL);
1067 return -EINVAL;
1068 }
1069
1070 if (((flags & GPIO_INT_LEVELS_LOGICAL) != 0) &&
1071 ((data->invert & (gpio_port_pins_t)BIT(pin)) != 0)) {
1072 /* Invert signal bits */
1073 flags ^= (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1);
1074 }
1075
1076 trig = (enum gpio_int_trig)(flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1 | GPIO_INT_WAKEUP));
1077#ifdef CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT
1078 mode = (enum gpio_int_mode)(flags & (GPIO_INT_EDGE | GPIO_INT_DISABLE | GPIO_INT_ENABLE |
1079 GPIO_INT_ENABLE_DISABLE_ONLY));
1080#else
1081 mode = (enum gpio_int_mode)(flags & (GPIO_INT_EDGE | GPIO_INT_DISABLE | GPIO_INT_ENABLE));
1082#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
1083
1084 ret = api->pin_interrupt_configure(port, pin, mode, trig);
1085 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, interrupt_configure, port, pin, ret);
1086 return ret;
1087}
1088
1106static inline int gpio_pin_interrupt_configure_dt(const struct gpio_dt_spec *spec,
1108{
1109 return gpio_pin_interrupt_configure(spec->port, spec->pin,
1110 flags | (spec->dt_flags & GPIO_INT_WAKEUP));
1111}
1112
1128__syscall int gpio_pin_configure(const struct device *port,
1129 gpio_pin_t pin,
1131
1132static inline int z_impl_gpio_pin_configure(const struct device *port,
1133 gpio_pin_t pin,
1135{
1136 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1137 __unused const struct gpio_driver_config *const cfg =
1138 (const struct gpio_driver_config *)port->config;
1139 struct gpio_driver_data *data =
1140 (struct gpio_driver_data *)port->data;
1141 int ret;
1142
1143 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, configure, port, pin, flags);
1144
1145 __ASSERT((flags & GPIO_INT_MASK) == 0,
1146 "Interrupt flags are not supported");
1147
1148 __ASSERT((flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) !=
1150 "Pull Up and Pull Down should not be enabled simultaneously");
1151
1152 __ASSERT(!((flags & GPIO_INPUT) && !(flags & GPIO_OUTPUT) && (flags & GPIO_SINGLE_ENDED)),
1153 "Input cannot be enabled for 'Open Drain', 'Open Source' modes without Output");
1154
1155 __ASSERT_NO_MSG((flags & GPIO_SINGLE_ENDED) != 0 ||
1156 (flags & GPIO_LINE_OPEN_DRAIN) == 0);
1157
1158 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) == 0
1159 || (flags & GPIO_OUTPUT) != 0,
1160 "Output needs to be enabled to be initialized low or high");
1161
1162 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH))
1163 != (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH),
1164 "Output cannot be initialized low and high");
1165
1166 if (((flags & GPIO_OUTPUT_INIT_LOGICAL) != 0)
1167 && ((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) != 0)
1168 && ((flags & GPIO_ACTIVE_LOW) != 0)) {
1169 flags ^= GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH;
1170 }
1171
1172 flags &= ~GPIO_OUTPUT_INIT_LOGICAL;
1173
1174 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1175
1176 /*
1177 * pin is passed on to the driver as-is, where it is commonly used as an
1178 * array index, so it must be range checked even when assertions are
1179 * compiled out.
1180 */
1181 if (pin >= GPIO_MAX_PINS_PER_PORT) {
1182 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, configure, port, pin, -EINVAL);
1183 return -EINVAL;
1184 }
1185
1186 if ((flags & GPIO_ACTIVE_LOW) != 0) {
1187 data->invert |= (gpio_port_pins_t)BIT(pin);
1188 } else {
1189 data->invert &= ~(gpio_port_pins_t)BIT(pin);
1190 }
1191
1192 ret = api->pin_configure(port, pin, flags);
1193 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, configure, port, pin, ret);
1194 return ret;
1195}
1196
1208static inline int gpio_pin_configure_dt(const struct gpio_dt_spec *spec,
1209 gpio_flags_t extra_flags)
1210{
1211 return gpio_pin_configure(spec->port,
1212 spec->pin,
1213 spec->dt_flags | extra_flags);
1214}
1215
1234__syscall int gpio_port_get_direction(const struct device *port, gpio_port_pins_t map,
1235 gpio_port_pins_t *inputs, gpio_port_pins_t *outputs);
1236
1237#ifdef CONFIG_GPIO_GET_DIRECTION
1238static inline int z_impl_gpio_port_get_direction(const struct device *port, gpio_port_pins_t map,
1239 gpio_port_pins_t *inputs,
1240 gpio_port_pins_t *outputs)
1241{
1242 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1243 int ret;
1244
1245 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, get_direction, port, map, inputs, outputs);
1246
1247 if (api->port_get_direction == NULL) {
1248 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_direction, port, -ENOSYS);
1249 return -ENOSYS;
1250 }
1251
1252 ret = api->port_get_direction(port, map, inputs, outputs);
1253 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_direction, port, ret);
1254 return ret;
1255}
1256#endif /* CONFIG_GPIO_GET_DIRECTION */
1257
1270static inline int gpio_pin_is_input(const struct device *port, gpio_pin_t pin)
1271{
1272 int rv;
1273 gpio_port_pins_t pins;
1274 __unused const struct gpio_driver_config *cfg =
1275 (const struct gpio_driver_config *)port->config;
1276
1277 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1278
1279 rv = gpio_port_get_direction(port, BIT(pin), &pins, NULL);
1280 if (rv < 0) {
1281 return rv;
1282 }
1283
1284 return (int)!!((gpio_port_pins_t)BIT(pin) & pins);
1285}
1286
1298static inline int gpio_pin_is_input_dt(const struct gpio_dt_spec *spec)
1299{
1300 return gpio_pin_is_input(spec->port, spec->pin);
1301}
1302
1315static inline int gpio_pin_is_output(const struct device *port, gpio_pin_t pin)
1316{
1317 int rv;
1318 gpio_port_pins_t pins;
1319 __unused const struct gpio_driver_config *cfg =
1320 (const struct gpio_driver_config *)port->config;
1321
1322 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1323
1324 rv = gpio_port_get_direction(port, BIT(pin), NULL, &pins);
1325 if (rv < 0) {
1326 return rv;
1327 }
1328
1329 return (int)!!((gpio_port_pins_t)BIT(pin) & pins);
1330}
1331
1343static inline int gpio_pin_is_output_dt(const struct gpio_dt_spec *spec)
1344{
1345 return gpio_pin_is_output(spec->port, spec->pin);
1346}
1347
1363__syscall int gpio_pin_get_config(const struct device *port, gpio_pin_t pin,
1365
1366#ifdef CONFIG_GPIO_GET_CONFIG
1367static inline int z_impl_gpio_pin_get_config(const struct device *port,
1368 gpio_pin_t pin,
1370{
1371 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1372 int ret;
1373
1374 SYS_PORT_TRACING_FUNC_ENTER(gpio_pin, get_config, port, pin, *flags);
1375
1376 if (api->pin_get_config == NULL) {
1377 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, -ENOSYS);
1378 return -ENOSYS;
1379 }
1380
1381 /* See the note in z_impl_gpio_pin_configure(). */
1382 if (pin >= GPIO_MAX_PINS_PER_PORT) {
1383 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, -EINVAL);
1384 return -EINVAL;
1385 }
1386
1387 ret = api->pin_get_config(port, pin, flags);
1388 SYS_PORT_TRACING_FUNC_EXIT(gpio_pin, get_config, port, pin, ret);
1389 return ret;
1390}
1391#endif
1392
1405static inline int gpio_pin_get_config_dt(const struct gpio_dt_spec *spec,
1407{
1408 return gpio_pin_get_config(spec->port, spec->pin, flags);
1409}
1410
1428__syscall int gpio_port_get_raw(const struct device *port,
1429 gpio_port_value_t *value);
1430
1431static inline int z_impl_gpio_port_get_raw(const struct device *port, gpio_port_value_t *value)
1432{
1433 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1434 int ret;
1435
1436 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, get_raw, port, value);
1437
1438 ret = api->port_get_raw(port, value);
1439 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, get_raw, port, ret);
1440 return ret;
1441}
1442
1461__syscall int gpio_port_get(const struct device *port,
1462 gpio_port_value_t *value);
1463
1464static inline int z_impl_gpio_port_get(const struct device *port,
1465 gpio_port_value_t *value)
1466{
1467 const struct gpio_driver_data *const data =
1468 (const struct gpio_driver_data *)port->data;
1469 int ret;
1470
1471 ret = z_impl_gpio_port_get_raw(port, value);
1472 if (ret == 0) {
1473 *value ^= data->invert;
1474 }
1475
1476 return ret;
1477}
1478
1496__syscall int gpio_port_set_masked_raw(const struct device *port,
1497 gpio_port_pins_t mask,
1498 gpio_port_value_t value);
1499
1500static inline int z_impl_gpio_port_set_masked_raw(const struct device *port,
1501 gpio_port_pins_t mask,
1502 gpio_port_value_t value)
1503{
1504 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1505 int ret;
1506
1507 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, set_masked_raw, port, mask, value);
1508
1509 ret = api->port_set_masked_raw(port, mask, value);
1510 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, set_masked_raw, port, ret);
1511 return ret;
1512}
1513
1534__syscall int gpio_port_set_masked(const struct device *port,
1535 gpio_port_pins_t mask,
1536 gpio_port_value_t value);
1537
1538static inline int z_impl_gpio_port_set_masked(const struct device *port,
1539 gpio_port_pins_t mask,
1540 gpio_port_value_t value)
1541{
1542 const struct gpio_driver_data *const data =
1543 (const struct gpio_driver_data *)port->data;
1544
1545 value ^= data->invert;
1546
1547 return z_impl_gpio_port_set_masked_raw(port, mask, value);
1548}
1549
1560__syscall int gpio_port_set_bits_raw(const struct device *port,
1561 gpio_port_pins_t pins);
1562
1563static inline int z_impl_gpio_port_set_bits_raw(const struct device *port,
1564 gpio_port_pins_t pins)
1565{
1566 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1567 int ret;
1568
1569 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, set_bits_raw, port, pins);
1570
1571 ret = api->port_set_bits_raw(port, pins);
1572 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, set_bits_raw, port, ret);
1573 return ret;
1574}
1575
1586__syscall int gpio_port_set_bits(const struct device *port,
1587 gpio_port_pins_t pins);
1588
1589static inline int z_impl_gpio_port_set_bits(const struct device *port,
1590 gpio_port_pins_t pins)
1591{
1592 return z_impl_gpio_port_set_masked(port, pins, pins);
1593}
1594
1605__syscall int gpio_port_clear_bits_raw(const struct device *port,
1606 gpio_port_pins_t pins);
1607
1608static inline int z_impl_gpio_port_clear_bits_raw(const struct device *port,
1609 gpio_port_pins_t pins)
1610{
1611 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1612 int ret;
1613
1614 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, clear_bits_raw, port, pins);
1615
1616 ret = api->port_clear_bits_raw(port, pins);
1617 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, clear_bits_raw, port, ret);
1618 return ret;
1619}
1620
1631__syscall int gpio_port_clear_bits(const struct device *port,
1632 gpio_port_pins_t pins);
1633
1634static inline int z_impl_gpio_port_clear_bits(const struct device *port,
1635 gpio_port_pins_t pins)
1636{
1637 return z_impl_gpio_port_set_masked(port, pins, 0);
1638}
1639
1650__syscall int gpio_port_toggle_bits(const struct device *port,
1651 gpio_port_pins_t pins);
1652
1653static inline int z_impl_gpio_port_toggle_bits(const struct device *port,
1654 gpio_port_pins_t pins)
1655{
1656 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1657 int ret;
1658
1659 SYS_PORT_TRACING_FUNC_ENTER(gpio_port, toggle_bits, port, pins);
1660
1661 ret = api->port_toggle_bits(port, pins);
1662 SYS_PORT_TRACING_FUNC_EXIT(gpio_port, toggle_bits, port, ret);
1663 return ret;
1664}
1665
1677__syscall int gpio_port_set_clr_bits_raw(const struct device *port,
1678 gpio_port_pins_t set_pins,
1679 gpio_port_pins_t clear_pins);
1680
1681static inline int z_impl_gpio_port_set_clr_bits_raw(const struct device *port,
1682 gpio_port_pins_t set_pins,
1683 gpio_port_pins_t clear_pins)
1684{
1685 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1686
1687 return z_impl_gpio_port_set_masked_raw(port, set_pins | clear_pins, set_pins);
1688}
1689
1701__syscall int gpio_port_set_clr_bits(const struct device *port,
1702 gpio_port_pins_t set_pins,
1703 gpio_port_pins_t clear_pins);
1704
1705static inline int z_impl_gpio_port_set_clr_bits(const struct device *port,
1706 gpio_port_pins_t set_pins,
1707 gpio_port_pins_t clear_pins)
1708{
1709 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1710
1711 return z_impl_gpio_port_set_masked(port, set_pins | clear_pins, set_pins);
1712}
1713
1729__syscall int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin);
1730
1731static inline int z_impl_gpio_pin_get_raw(const struct device *port, gpio_pin_t pin)
1732{
1733 __unused const struct gpio_driver_config *const cfg =
1734 (const struct gpio_driver_config *)port->config;
1735 gpio_port_value_t value;
1736 int ret;
1737
1738 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1739
1740 ret = z_impl_gpio_port_get_raw(port, &value);
1741 if (ret == 0) {
1742 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1743 }
1744
1745 return ret;
1746}
1747
1767__syscall int gpio_pin_get(const struct device *port, gpio_pin_t pin);
1768
1769static inline int z_impl_gpio_pin_get(const struct device *port, gpio_pin_t pin)
1770{
1771 __unused const struct gpio_driver_config *const cfg =
1772 (const struct gpio_driver_config *)port->config;
1773 gpio_port_value_t value;
1774 int ret;
1775
1776 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1777
1778 ret = z_impl_gpio_port_get(port, &value);
1779 if (ret == 0) {
1780 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1781 }
1782
1783 return ret;
1784}
1785
1796static inline int gpio_pin_get_dt(const struct gpio_dt_spec *spec)
1797{
1798 return gpio_pin_get(spec->port, spec->pin);
1799}
1800
1816__syscall int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin, int value);
1817
1818static inline int z_impl_gpio_pin_set_raw(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 int ret;
1824
1825 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1826
1827 if (value != 0) {
1828 ret = z_impl_gpio_port_set_bits_raw(port, (gpio_port_pins_t)BIT(pin));
1829 } else {
1830 ret = z_impl_gpio_port_clear_bits_raw(port, (gpio_port_pins_t)BIT(pin));
1831 }
1832
1833 return ret;
1834}
1835
1857__syscall int gpio_pin_set(const struct device *port, gpio_pin_t pin, int value);
1858
1859static inline int z_impl_gpio_pin_set(const struct device *port, gpio_pin_t pin,
1860 int value)
1861{
1862 __unused const struct gpio_driver_config *const cfg =
1863 (const struct gpio_driver_config *)port->config;
1864 const struct gpio_driver_data *const data =
1865 (const struct gpio_driver_data *)port->data;
1866
1867 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1868
1869 if (data->invert & (gpio_port_pins_t)BIT(pin)) {
1870 value = (value != 0) ? 0 : 1;
1871 }
1872
1873 return z_impl_gpio_pin_set_raw(port, pin, value);
1874}
1875
1887static inline int gpio_pin_set_dt(const struct gpio_dt_spec *spec, int value)
1888{
1889 return gpio_pin_set(spec->port, spec->pin, value);
1890}
1891
1902__syscall int gpio_pin_toggle(const struct device *port, gpio_pin_t pin);
1903
1904static inline int z_impl_gpio_pin_toggle(const struct device *port, gpio_pin_t pin)
1905{
1906 __unused const struct gpio_driver_config *const cfg =
1907 (const struct gpio_driver_config *)port->config;
1908
1909 __ASSERT(gpio_port_pin_is_supported(cfg->port_pin_mask, pin), "Unsupported pin");
1910
1911 return z_impl_gpio_port_toggle_bits(port, (gpio_port_pins_t)BIT(pin));
1912}
1913
1924static inline int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec)
1925{
1926 return gpio_pin_toggle(spec->port, spec->pin);
1927}
1928
1935static inline void gpio_init_callback(struct gpio_callback *callback,
1937 gpio_port_pins_t pin_mask)
1938{
1939 SYS_PORT_TRACING_FUNC_ENTER(gpio, init_callback, callback, handler, pin_mask);
1940
1941 __ASSERT(callback, "Callback pointer should not be NULL");
1942 __ASSERT(handler, "Callback handler pointer should not be NULL");
1943
1944 callback->handler = handler;
1945 callback->pin_mask = pin_mask;
1946
1947 SYS_PORT_TRACING_FUNC_EXIT(gpio, init_callback, callback);
1948}
1949
1963static inline int gpio_add_callback(const struct device *port,
1964 struct gpio_callback *callback)
1965{
1966 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
1967 int ret;
1968
1969 SYS_PORT_TRACING_FUNC_ENTER(gpio, add_callback, port, callback);
1970
1971 if (api->manage_callback == NULL) {
1972 SYS_PORT_TRACING_FUNC_EXIT(gpio, add_callback, port, -ENOSYS);
1973 return -ENOSYS;
1974 }
1975
1976 ret = api->manage_callback(port, callback, true);
1977 SYS_PORT_TRACING_FUNC_EXIT(gpio, add_callback, port, ret);
1978 return ret;
1979}
1980
1992static inline int gpio_add_callback_dt(const struct gpio_dt_spec *spec,
1993 struct gpio_callback *callback)
1994{
1995 return gpio_add_callback(spec->port, callback);
1996}
1997
2015static inline int gpio_remove_callback(const struct device *port,
2016 struct gpio_callback *callback)
2017{
2018 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, port);
2019 int ret;
2020
2021 SYS_PORT_TRACING_FUNC_ENTER(gpio, remove_callback, port, callback);
2022
2023 if (api->manage_callback == NULL) {
2024 SYS_PORT_TRACING_FUNC_EXIT(gpio, remove_callback, port, -ENOSYS);
2025 return -ENOSYS;
2026 }
2027
2028 ret = api->manage_callback(port, callback, false);
2029 SYS_PORT_TRACING_FUNC_EXIT(gpio, remove_callback, port, ret);
2030 return ret;
2031}
2032
2044static inline int gpio_remove_callback_dt(const struct gpio_dt_spec *spec,
2045 struct gpio_callback *callback)
2046{
2047 return gpio_remove_callback(spec->port, callback);
2048}
2049
2064__syscall int gpio_get_pending_int(const struct device *dev);
2065
2066static inline int z_impl_gpio_get_pending_int(const struct device *dev)
2067{
2068 const struct gpio_driver_api *api = DEVICE_API_GET(gpio, dev);
2069 int ret;
2070
2072
2073 if (api->get_pending_int == NULL) {
2075 return -ENOSYS;
2076 }
2077
2078 ret = api->get_pending_int(dev);
2080 return ret;
2081}
2082
2086
2087#ifdef __cplusplus
2088}
2089#endif
2090
2091#include <zephyr/syscalls/gpio.h>
2092
2093#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:1461
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:1963
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:860
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.
#define GPIO_MAX_PINS_PER_PORT
Maximum number of pins that are supported by gpio_port_pins_t.
Definition gpio.h:691
static int gpio_pin_is_input(const struct device *port, gpio_pin_t pin)
Check if pin is configured for input.
Definition gpio.h:1270
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:1343
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:1106
uint32_t(* gpio_api_get_pending_int_t)(const struct device *dev)
Callback API to get pending interrupts.
Definition gpio.h:922
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:914
static int gpio_remove_callback_dt(const struct gpio_dt_spec *spec, struct gpio_callback *callback)
Remove an application callback.
Definition gpio.h:2044
static int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec)
Toggle pin level from a gpio_dt_spec.
Definition gpio.h:1924
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:1315
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:1208
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:889
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:825
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:1887
static int gpio_add_callback_dt(const struct gpio_dt_spec *spec, struct gpio_callback *callback)
Add an application callback.
Definition gpio.h:1992
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:928
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:853
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:1935
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:1298
#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:1405
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:801
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:896
#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:1796
static bool gpio_is_ready_dt(const struct gpio_dt_spec *spec)
Validate that GPIO port is ready.
Definition gpio.h:982
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:874
static bool gpio_port_pin_is_supported(gpio_port_pins_t port_pin_mask, gpio_pin_t pin)
Check whether a pin is in range and supported by a GPIO controller.
Definition gpio.h:708
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:882
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:2015
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:867
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:757
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:905
@ GPIO_INT_TRIG_WAKE_HIGH
Trigger a system wakeup when input state is (or transitions to) physical high.
Definition gpio.h:844
@ GPIO_INT_TRIG_WAKE
Trigger a system wakeup.
Definition gpio.h:836
@ GPIO_INT_TRIG_HIGH
Trigger detection when input state is (or transitions to) physical high.
Definition gpio.h:832
@ GPIO_INT_TRIG_BOTH
Trigger detection on pin rising or falling edge.
Definition gpio.h:834
@ GPIO_INT_TRIG_WAKE_BOTH
Trigger a system wakeup on pin rising or falling edge.
Definition gpio.h:846
@ GPIO_INT_TRIG_LOW
Trigger detection when input state is (or transitions to) physical low.
Definition gpio.h:829
@ GPIO_INT_TRIG_WAKE_LOW
Trigger a system wakeup when input state is (or transitions to) physical low.
Definition gpio.h:840
@ GPIO_INT_MODE_DISABLE_ONLY
Disable a previously configured pin interrupt without deconfiguring it.
Definition gpio.h:813
@ GPIO_INT_MODE_EDGE
Enable edge-triggered pin interrupt.
Definition gpio.h:807
@ GPIO_INT_MODE_DISABLED
Disable pin interrupt.
Definition gpio.h:803
@ GPIO_INT_MODE_ENABLE_ONLY
Re-enable a previously configured pin interrupt.
Definition gpio.h:818
@ GPIO_INT_MODE_LEVEL
Enable level-triggered pin interrupt.
Definition gpio.h:805
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 EINVAL
Invalid argument.
Definition errno.h:61
#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:525
void * data
Address of the device instance private data.
Definition device.h:535
const void * config
Address of device instance config information.
Definition device.h:529
GPIO callback structure.
Definition gpio.h:771
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:775
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:786
gpio_callback_handler_t handler
Actual callback function being called when relevant.
Definition gpio.h:778
@driver_ops{GPIO}
Definition gpio.h:934
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:949
gpio_api_get_pending_int_t get_pending_int
@driver_ops_optional Function to get pending interrupts.
Definition gpio.h:962
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:945
gpio_api_port_toggle_bits_t port_toggle_bits
@driver_ops_mandatory Toggle level of selected output pins.
Definition gpio.h:953
gpio_api_pin_configure_t pin_configure
@driver_ops_mandatory Configure a single pin.
Definition gpio.h:936
gpio_api_pin_interrupt_configure_t pin_interrupt_configure
@driver_ops_optional Configure pin interrupt.
Definition gpio.h:955
gpio_api_port_get_direction_t port_get_direction
@driver_ops_optional Get direction of select pins in a port.
Definition gpio.h:968
gpio_api_manage_callback_t manage_callback
@driver_ops_optional Add or remove an application callback.
Definition gpio.h:960
gpio_api_pin_get_config_t pin_get_config
@driver_ops_optional Get a configuration of a single pin.
Definition gpio.h:942
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:951
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:947
This structure is common to all GPIO drivers and is expected to be the first element in the object po...
Definition gpio.h:722
gpio_port_pins_t port_pin_mask
Mask identifying pins supported by the controller.
Definition gpio.h:728
This structure is common to all GPIO drivers and is expected to be the first element in the driver's ...
Definition gpio.h:735
gpio_port_pins_t invert
Mask identifying pins that are configured as active low.
Definition gpio.h:741
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.