Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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#ifndef ZEPHYR_INCLUDE_DRIVERS_GPIO_H_
16#define ZEPHYR_INCLUDE_DRIVERS_GPIO_H_
17
18#include <sys/__assert.h>
19#include <sys/slist.h>
20
21#include <zephyr/types.h>
22#include <stddef.h>
23#include <device.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
43#define GPIO_INPUT (1U << 8)
44
46#define GPIO_OUTPUT (1U << 9)
47
49#define GPIO_DISCONNECTED 0
50
53/* Initializes output to a low state. */
54#define GPIO_OUTPUT_INIT_LOW (1U << 10)
55
56/* Initializes output to a high state. */
57#define GPIO_OUTPUT_INIT_HIGH (1U << 11)
58
59/* Initializes output based on logic level */
60#define GPIO_OUTPUT_INIT_LOGICAL (1U << 12)
61
65#define GPIO_OUTPUT_LOW (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW)
67#define GPIO_OUTPUT_HIGH (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH)
69#define GPIO_OUTPUT_INACTIVE (GPIO_OUTPUT | \
70 GPIO_OUTPUT_INIT_LOW | \
71 GPIO_OUTPUT_INIT_LOGICAL)
73#define GPIO_OUTPUT_ACTIVE (GPIO_OUTPUT | \
74 GPIO_OUTPUT_INIT_HIGH | \
75 GPIO_OUTPUT_INIT_LOGICAL)
76
91#define GPIO_INT_DISABLE (1U << 13)
92
95/* Enables GPIO pin interrupt. */
96#define GPIO_INT_ENABLE (1U << 14)
97
98/* GPIO interrupt is sensitive to logical levels.
99 *
100 * This is a component flag that should be combined with other
101 * `GPIO_INT_*` flags to produce a meaningful configuration.
102 */
103#define GPIO_INT_LEVELS_LOGICAL (1U << 15)
104
105/* GPIO interrupt is edge sensitive.
106 *
107 * Note: by default interrupts are level sensitive.
108 *
109 * This is a component flag that should be combined with other
110 * `GPIO_INT_*` flags to produce a meaningful configuration.
111 */
112#define GPIO_INT_EDGE (1U << 16)
113
114/* Trigger detection when input state is (or transitions to) physical low or
115 * logical 0 level.
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_LOW_0 (1U << 17)
121
122/* Trigger detection on input state is (or transitions to) physical high or
123 * logical 1 level.
124 *
125 * This is a component flag that should be combined with other
126 * `GPIO_INT_*` flags to produce a meaningful configuration.
127 */
128#define GPIO_INT_HIGH_1 (1U << 18)
129
130#define GPIO_INT_MASK (GPIO_INT_DISABLE | \
131 GPIO_INT_ENABLE | \
132 GPIO_INT_LEVELS_LOGICAL | \
133 GPIO_INT_EDGE | \
134 GPIO_INT_LOW_0 | \
135 GPIO_INT_HIGH_1)
136
141#define GPIO_INT_EDGE_RISING (GPIO_INT_ENABLE | \
142 GPIO_INT_EDGE | \
143 GPIO_INT_HIGH_1)
144
148#define GPIO_INT_EDGE_FALLING (GPIO_INT_ENABLE | \
149 GPIO_INT_EDGE | \
150 GPIO_INT_LOW_0)
151
155#define GPIO_INT_EDGE_BOTH (GPIO_INT_ENABLE | \
156 GPIO_INT_EDGE | \
157 GPIO_INT_LOW_0 | \
158 GPIO_INT_HIGH_1)
159
163#define GPIO_INT_LEVEL_LOW (GPIO_INT_ENABLE | \
164 GPIO_INT_LOW_0)
165
169#define GPIO_INT_LEVEL_HIGH (GPIO_INT_ENABLE | \
170 GPIO_INT_HIGH_1)
171
175#define GPIO_INT_EDGE_TO_INACTIVE (GPIO_INT_ENABLE | \
176 GPIO_INT_LEVELS_LOGICAL | \
177 GPIO_INT_EDGE | \
178 GPIO_INT_LOW_0)
179
183#define GPIO_INT_EDGE_TO_ACTIVE (GPIO_INT_ENABLE | \
184 GPIO_INT_LEVELS_LOGICAL | \
185 GPIO_INT_EDGE | \
186 GPIO_INT_HIGH_1)
187
191#define GPIO_INT_LEVEL_INACTIVE (GPIO_INT_ENABLE | \
192 GPIO_INT_LEVELS_LOGICAL | \
193 GPIO_INT_LOW_0)
194
198#define GPIO_INT_LEVEL_ACTIVE (GPIO_INT_ENABLE | \
199 GPIO_INT_LEVELS_LOGICAL | \
200 GPIO_INT_HIGH_1)
201
209#define GPIO_INT_DEBOUNCE (1U << 19)
210
234#define GPIO_DS_LOW_POS 20
235#define GPIO_DS_LOW_MASK (0x3U << GPIO_DS_LOW_POS)
240#define GPIO_DS_DFLT_LOW (0x0U << GPIO_DS_LOW_POS)
241
246#define GPIO_DS_ALT_LOW (0x1U << GPIO_DS_LOW_POS)
247
249#define GPIO_DS_HIGH_POS 22
250#define GPIO_DS_HIGH_MASK (0x3U << GPIO_DS_HIGH_POS)
255#define GPIO_DS_DFLT_HIGH (0x0U << GPIO_DS_HIGH_POS)
256
261#define GPIO_DS_ALT_HIGH (0x1U << GPIO_DS_HIGH_POS)
265#define GPIO_DIR_MASK (GPIO_INPUT | GPIO_OUTPUT)
275
288
296
305
313
322 const struct device *port;
325};
326
361#define GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx) \
362 { \
363 .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
364 .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
365 .dt_flags = DT_GPIO_FLAGS_BY_IDX(node_id, prop, idx), \
366 }
367
385#define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
386 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
387 (GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
388 (default_value))
389
398#define GPIO_DT_SPEC_GET(node_id, prop) \
399 GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
400
411#define GPIO_DT_SPEC_GET_OR(node_id, prop, default_value) \
412 GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
413
424#define GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
425 GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
426
438#define GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value) \
439 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)
440
449#define GPIO_DT_SPEC_INST_GET(inst, prop) \
450 GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
451
462#define GPIO_DT_SPEC_INST_GET_OR(inst, prop, default_value) \
463 GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
464
468#define GPIO_MAX_PINS_PER_PORT (sizeof(gpio_port_pins_t) * __CHAR_BIT__)
469
476 /* Mask identifying pins supported by the controller.
477 *
478 * Initialization of this mask is the responsibility of device
479 * instance generation in the driver.
480 */
482};
483
489 /* Mask identifying pins that are configured as active low.
490 *
491 * Management of this mask is the responsibility of the
492 * wrapper functions in this header.
493 */
495};
496
497struct gpio_callback;
498
511typedef void (*gpio_callback_handler_t)(const struct device *port,
512 struct gpio_callback *cb,
513 gpio_port_pins_t pins);
514
530
533
541};
542
549/* Used by driver api function pin_interrupt_configure, these are defined
550 * in terms of the public flags so we can just mask and pass them
551 * through to the driver api
552 */
553enum gpio_int_mode {
554 GPIO_INT_MODE_DISABLED = GPIO_INT_DISABLE,
555 GPIO_INT_MODE_LEVEL = GPIO_INT_ENABLE,
556 GPIO_INT_MODE_EDGE = GPIO_INT_ENABLE | GPIO_INT_EDGE,
557};
558
559enum gpio_int_trig {
560 /* Trigger detection when input state is (or transitions to)
561 * physical low. (Edge Failing or Active Low) */
562 GPIO_INT_TRIG_LOW = GPIO_INT_LOW_0,
563 /* Trigger detection when input state is (or transitions to)
564 * physical high. (Edge Rising or Active High) */
565 GPIO_INT_TRIG_HIGH = GPIO_INT_HIGH_1,
566 /* Trigger detection on pin rising or falling edge. */
567 GPIO_INT_TRIG_BOTH = GPIO_INT_LOW_0 | GPIO_INT_HIGH_1,
568};
569
570__subsystem struct gpio_driver_api {
571 int (*pin_configure)(const struct device *port, gpio_pin_t pin,
573 int (*port_get_raw)(const struct device *port,
574 gpio_port_value_t *value);
575 int (*port_set_masked_raw)(const struct device *port,
576 gpio_port_pins_t mask,
577 gpio_port_value_t value);
578 int (*port_set_bits_raw)(const struct device *port,
579 gpio_port_pins_t pins);
580 int (*port_clear_bits_raw)(const struct device *port,
581 gpio_port_pins_t pins);
582 int (*port_toggle_bits)(const struct device *port,
583 gpio_port_pins_t pins);
584 int (*pin_interrupt_configure)(const struct device *port,
585 gpio_pin_t pin,
586 enum gpio_int_mode, enum gpio_int_trig);
587 int (*manage_callback)(const struct device *port,
588 struct gpio_callback *cb,
589 bool set);
590 uint32_t (*get_pending_int)(const struct device *dev);
591};
592
617__syscall int gpio_pin_interrupt_configure(const struct device *port,
618 gpio_pin_t pin,
620
621static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port,
622 gpio_pin_t pin,
624{
625 const struct gpio_driver_api *api =
626 (const struct gpio_driver_api *)port->api;
627 const struct gpio_driver_config *const cfg =
628 (const struct gpio_driver_config *)port->config;
629 const struct gpio_driver_data *const data =
630 (const struct gpio_driver_data *)port->data;
631 enum gpio_int_trig trig;
632 enum gpio_int_mode mode;
633
634 __ASSERT_NO_MSG((flags & GPIO_INT_DEBOUNCE) == 0);
635
636 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE))
637 != (GPIO_INT_DISABLE | GPIO_INT_ENABLE),
638 "Cannot both enable and disable interrupts");
639
640 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE)) != 0U,
641 "Must either enable or disable interrupts");
642
643 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
644 ((flags & GPIO_INT_EDGE) != 0) ||
645 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) !=
646 (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)),
647 "Only one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 can be "
648 "enabled for a level interrupt.");
649
650 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
651 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) != 0),
652 "At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be "
653 "enabled.");
654
655 (void)cfg;
656 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
657 "Unsupported pin");
658
659 if (((flags & GPIO_INT_LEVELS_LOGICAL) != 0) &&
660 ((data->invert & (gpio_port_pins_t)BIT(pin)) != 0)) {
661 /* Invert signal bits */
662 flags ^= (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1);
663 }
664
665 trig = (enum gpio_int_trig)(flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1));
666 mode = (enum gpio_int_mode)(flags & (GPIO_INT_EDGE | GPIO_INT_DISABLE | GPIO_INT_ENABLE));
667
668 return api->pin_interrupt_configure(port, pin, mode, trig);
669}
670
684static inline int gpio_pin_interrupt_configure_dt(const struct gpio_dt_spec *spec,
686{
687 return gpio_pin_interrupt_configure(spec->port, spec->pin, flags);
688}
689
706__syscall int gpio_pin_configure(const struct device *port,
707 gpio_pin_t pin,
709
710static inline int z_impl_gpio_pin_configure(const struct device *port,
711 gpio_pin_t pin,
713{
714 const struct gpio_driver_api *api =
715 (const struct gpio_driver_api *)port->api;
716 const struct gpio_driver_config *const cfg =
717 (const struct gpio_driver_config *)port->config;
718 struct gpio_driver_data *data =
719 (struct gpio_driver_data *)port->data;
720
721 __ASSERT((flags & GPIO_INT_MASK) == 0,
722 "Interrupt flags are not supported");
723
724 __ASSERT((flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) !=
726 "Pull Up and Pull Down should not be enabled simultaneously");
727
728 __ASSERT((flags & GPIO_OUTPUT) != 0 || (flags & GPIO_SINGLE_ENDED) == 0,
729 "Output needs to be enabled for 'Open Drain', 'Open Source' "
730 "mode to be supported");
731
732 __ASSERT_NO_MSG((flags & GPIO_SINGLE_ENDED) != 0 ||
733 (flags & GPIO_LINE_OPEN_DRAIN) == 0);
734
735 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) == 0
736 || (flags & GPIO_OUTPUT) != 0,
737 "Output needs to be enabled to be initialized low or high");
738
739 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH))
740 != (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH),
741 "Output cannot be initialized low and high");
742
743 if (((flags & GPIO_OUTPUT_INIT_LOGICAL) != 0)
744 && ((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) != 0)
745 && ((flags & GPIO_ACTIVE_LOW) != 0)) {
746 flags ^= GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH;
747 }
748
749 flags &= ~GPIO_OUTPUT_INIT_LOGICAL;
750
751 (void)cfg;
752 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
753 "Unsupported pin");
754
755 if ((flags & GPIO_ACTIVE_LOW) != 0) {
756 data->invert |= (gpio_port_pins_t)BIT(pin);
757 } else {
758 data->invert &= ~(gpio_port_pins_t)BIT(pin);
759 }
760
761 return api->pin_configure(port, pin, flags);
762}
763
775static inline int gpio_pin_configure_dt(const struct gpio_dt_spec *spec,
776 gpio_flags_t extra_flags)
777{
778 return gpio_pin_configure(spec->port,
779 spec->pin,
780 spec->dt_flags | extra_flags);
781}
782
800__syscall int gpio_port_get_raw(const struct device *port,
801 gpio_port_value_t *value);
802
803static inline int z_impl_gpio_port_get_raw(const struct device *port,
804 gpio_port_value_t *value)
805{
806 const struct gpio_driver_api *api =
807 (const struct gpio_driver_api *)port->api;
808
809 return api->port_get_raw(port, value);
810}
811
830static inline int gpio_port_get(const struct device *port,
831 gpio_port_value_t *value)
832{
833 const struct gpio_driver_data *const data =
834 (const struct gpio_driver_data *)port->data;
835 int ret;
836
837 ret = gpio_port_get_raw(port, value);
838 if (ret == 0) {
839 *value ^= data->invert;
840 }
841
842 return ret;
843}
844
862__syscall int gpio_port_set_masked_raw(const struct device *port,
863 gpio_port_pins_t mask,
864 gpio_port_value_t value);
865
866static inline int z_impl_gpio_port_set_masked_raw(const struct device *port,
867 gpio_port_pins_t mask,
868 gpio_port_value_t value)
869{
870 const struct gpio_driver_api *api =
871 (const struct gpio_driver_api *)port->api;
872
873 return api->port_set_masked_raw(port, mask, value);
874}
875
896static inline int gpio_port_set_masked(const struct device *port,
897 gpio_port_pins_t mask,
898 gpio_port_value_t value)
899{
900 const struct gpio_driver_data *const data =
901 (const struct gpio_driver_data *)port->data;
902
903 value ^= data->invert;
904
905 return gpio_port_set_masked_raw(port, mask, value);
906}
907
918__syscall int gpio_port_set_bits_raw(const struct device *port,
919 gpio_port_pins_t pins);
920
921static inline int z_impl_gpio_port_set_bits_raw(const struct device *port,
922 gpio_port_pins_t pins)
923{
924 const struct gpio_driver_api *api =
925 (const struct gpio_driver_api *)port->api;
926
927 return api->port_set_bits_raw(port, pins);
928}
929
940static inline int gpio_port_set_bits(const struct device *port,
941 gpio_port_pins_t pins)
942{
943 return gpio_port_set_masked(port, pins, pins);
944}
945
956__syscall int gpio_port_clear_bits_raw(const struct device *port,
957 gpio_port_pins_t pins);
958
959static inline int z_impl_gpio_port_clear_bits_raw(const struct device *port,
960 gpio_port_pins_t pins)
961{
962 const struct gpio_driver_api *api =
963 (const struct gpio_driver_api *)port->api;
964
965 return api->port_clear_bits_raw(port, pins);
966}
967
978static inline int gpio_port_clear_bits(const struct device *port,
979 gpio_port_pins_t pins)
980{
981 return gpio_port_set_masked(port, pins, 0);
982}
983
994__syscall int gpio_port_toggle_bits(const struct device *port,
995 gpio_port_pins_t pins);
996
997static inline int z_impl_gpio_port_toggle_bits(const struct device *port,
998 gpio_port_pins_t pins)
999{
1000 const struct gpio_driver_api *api =
1001 (const struct gpio_driver_api *)port->api;
1002
1003 return api->port_toggle_bits(port, pins);
1004}
1005
1017static inline int gpio_port_set_clr_bits_raw(const struct device *port,
1018 gpio_port_pins_t set_pins,
1019 gpio_port_pins_t clear_pins)
1020{
1021 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1022
1023 return gpio_port_set_masked_raw(port, set_pins | clear_pins, set_pins);
1024}
1025
1037static inline int gpio_port_set_clr_bits(const struct device *port,
1038 gpio_port_pins_t set_pins,
1039 gpio_port_pins_t clear_pins)
1040{
1041 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1042
1043 return gpio_port_set_masked(port, set_pins | clear_pins, set_pins);
1044}
1045
1061static inline int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin)
1062{
1063 const struct gpio_driver_config *const cfg =
1064 (const struct gpio_driver_config *)port->config;
1065 gpio_port_value_t value;
1066 int ret;
1067
1068 (void)cfg;
1069 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1070 "Unsupported pin");
1071
1072 ret = gpio_port_get_raw(port, &value);
1073 if (ret == 0) {
1074 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1075 }
1076
1077 return ret;
1078}
1079
1099static inline int gpio_pin_get(const struct device *port, gpio_pin_t pin)
1100{
1101 const struct gpio_driver_config *const cfg =
1102 (const struct gpio_driver_config *)port->config;
1103 gpio_port_value_t value;
1104 int ret;
1105
1106 (void)cfg;
1107 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1108 "Unsupported pin");
1109
1110 ret = gpio_port_get(port, &value);
1111 if (ret == 0) {
1112 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1113 }
1114
1115 return ret;
1116}
1117
1128static inline int gpio_pin_get_dt(const struct gpio_dt_spec *spec)
1129{
1130 return gpio_pin_get(spec->port, spec->pin);
1131}
1132
1148static inline int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin,
1149 int value)
1150{
1151 const struct gpio_driver_config *const cfg =
1152 (const struct gpio_driver_config *)port->config;
1153 int ret;
1154
1155 (void)cfg;
1156 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1157 "Unsupported pin");
1158
1159 if (value != 0) {
1161 } else {
1163 }
1164
1165 return ret;
1166}
1167
1189static inline int gpio_pin_set(const struct device *port, gpio_pin_t pin,
1190 int value)
1191{
1192 const struct gpio_driver_config *const cfg =
1193 (const struct gpio_driver_config *)port->config;
1194 const struct gpio_driver_data *const data =
1195 (const struct gpio_driver_data *)port->data;
1196
1197 (void)cfg;
1198 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1199 "Unsupported pin");
1200
1201 if (data->invert & (gpio_port_pins_t)BIT(pin)) {
1202 value = (value != 0) ? 0 : 1;
1203 }
1204
1205 return gpio_pin_set_raw(port, pin, value);
1206}
1207
1219static inline int gpio_pin_set_dt(const struct gpio_dt_spec *spec, int value)
1220{
1221 return gpio_pin_set(spec->port, spec->pin, value);
1222}
1223
1234static inline int gpio_pin_toggle(const struct device *port, gpio_pin_t pin)
1235{
1236 const struct gpio_driver_config *const cfg =
1237 (const struct gpio_driver_config *)port->config;
1238
1239 (void)cfg;
1240 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1241 "Unsupported pin");
1242
1243 return gpio_port_toggle_bits(port, (gpio_port_pins_t)BIT(pin));
1244}
1245
1256static inline int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec)
1257{
1258 return gpio_pin_toggle(spec->port, spec->pin);
1259}
1260
1267static inline void gpio_init_callback(struct gpio_callback *callback,
1269 gpio_port_pins_t pin_mask)
1270{
1271 __ASSERT(callback, "Callback pointer should not be NULL");
1272 __ASSERT(handler, "Callback handler pointer should not be NULL");
1273
1274 callback->handler = handler;
1275 callback->pin_mask = pin_mask;
1276}
1277
1290static inline int gpio_add_callback(const struct device *port,
1291 struct gpio_callback *callback)
1292{
1293 const struct gpio_driver_api *api =
1294 (const struct gpio_driver_api *)port->api;
1295
1296 if (api->manage_callback == NULL) {
1297 return -ENOTSUP;
1298 }
1299
1300 return api->manage_callback(port, callback, true);
1301}
1302
1319static inline int gpio_remove_callback(const struct device *port,
1320 struct gpio_callback *callback)
1321{
1322 const struct gpio_driver_api *api =
1323 (const struct gpio_driver_api *)port->api;
1324
1325 if (api->manage_callback == NULL) {
1326 return -ENOTSUP;
1327 }
1328
1329 return api->manage_callback(port, callback, false);
1330}
1331
1345__syscall int gpio_get_pending_int(const struct device *dev);
1346
1347static inline int z_impl_gpio_get_pending_int(const struct device *dev)
1348{
1349 const struct gpio_driver_api *api =
1350 (const struct gpio_driver_api *)dev->api;
1351
1352 if (api->get_pending_int == NULL) {
1353 return -ENOTSUP;
1354 }
1355
1356 return api->get_pending_int(dev);
1357}
1358
1363#ifdef __cplusplus
1364}
1365#endif
1366
1367#include <syscalls/gpio.h>
1368
1369#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_H_ */
void
Definition: eswifi_shell.c:15
static int gpio_add_callback(const struct device *port, struct gpio_callback *callback)
Add an application callback.
Definition: gpio.h:1290
#define GPIO_OUTPUT
Definition: gpio.h:46
static int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin)
Get physical level of an input pin.
Definition: gpio.h:1061
static int gpio_pin_get(const struct device *port, gpio_pin_t pin)
Get logical level of an input pin.
Definition: gpio.h:1099
int gpio_port_set_bits_raw(const struct device *port, gpio_port_pins_t pins)
Set physical level of selected output pins to high.
static int gpio_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:684
uint8_t gpio_dt_flags_t
Provides a type to hold GPIO devicetree flags.
Definition: gpio.h:304
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:511
#define GPIO_INT_DEBOUNCE
Definition: gpio.h:209
static int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec)
Toggle pin level from a gpio_dt_spec.
Definition: gpio.h:1256
uint8_t gpio_pin_t
Provides a type to hold a GPIO pin index.
Definition: gpio.h:295
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:775
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:1219
static int gpio_port_set_bits(const struct device *port, gpio_port_pins_t pins)
Set logical level of selected output pins to active.
Definition: gpio.h:940
uint32_t gpio_flags_t
Provides a type to hold GPIO configuration flags.
Definition: gpio.h:312
#define GPIO_ACTIVE_LOW
Definition: gpio.h:23
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.
Definition: gpio.h:1017
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.
Definition: gpio.h:1037
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:1267
uint32_t gpio_port_pins_t
Identifies a set of pins associated with a port.
Definition: gpio.h:274
int gpio_port_toggle_bits(const struct device *port, gpio_port_pins_t pins)
Toggle level of selected output pins.
#define GPIO_INT_DISABLE
Definition: gpio.h:91
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.
#define GPIO_PULL_UP
Definition: gpio.h:72
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:1128
static int gpio_pin_toggle(const struct device *port, gpio_pin_t pin)
Toggle pin level.
Definition: gpio.h:1234
uint32_t gpio_port_value_t
Provides values for a set of pins associated with a port.
Definition: gpio.h:287
static int gpio_pin_set(const struct device *port, gpio_pin_t pin, int value)
Set logical level of an output pin.
Definition: gpio.h:1189
static int gpio_port_clear_bits(const struct device *port, gpio_port_pins_t pins)
Set logical level of selected output pins to inactive.
Definition: gpio.h:978
static int gpio_remove_callback(const struct device *port, struct gpio_callback *callback)
Remove an application callback.
Definition: gpio.h:1319
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.
Definition: gpio.h:896
#define GPIO_PULL_DOWN
Definition: gpio.h:75
static int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin, int value)
Set physical level of an output pin.
Definition: gpio.h:1148
int gpio_port_get_raw(const struct device *port, gpio_port_value_t *value)
Get physical level of all input pins in a port.
static int gpio_port_get(const struct device *port, gpio_port_value_t *value)
Get logical level of all input pins in a port.
Definition: gpio.h:830
int gpio_pin_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
Configure a single pin.
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
#define ENOTSUP
Definition: errno.h:115
flags
Definition: http_parser.h:131
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28
Single-linked list implementation.
struct _snode sys_snode_t
Definition: slist.h:33
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
void *const data
Definition: device.h:377
const void * config
Definition: device.h:371
GPIO callback structure.
Definition: gpio.h:525
sys_snode_t node
Definition: gpio.h:529
gpio_port_pins_t pin_mask
Definition: gpio.h:540
gpio_callback_handler_t handler
Definition: gpio.h:532
Definition: gpio.h:475
gpio_port_pins_t port_pin_mask
Definition: gpio.h:481
Definition: gpio.h:488
gpio_port_pins_t invert
Definition: gpio.h:494
Provides a type to hold GPIO information specified in devicetree.
Definition: gpio.h:321
const struct device * port
Definition: gpio.h:322
gpio_pin_t pin
Definition: gpio.h:323
gpio_dt_flags_t dt_flags
Definition: gpio.h:324
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static void handler(struct k_timer *timer)
Definition: main.c:19