Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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)
262
265#define GPIO_DS_DFLT (GPIO_DS_DFLT_LOW | GPIO_DS_DFLT_HIGH)
266
269#define GPIO_DS_ALT (GPIO_DS_ALT_LOW | GPIO_DS_ALT_HIGH)
270
272#define GPIO_DS_MASK (GPIO_DS_LOW_MASK | GPIO_DS_HIGH_MASK)
278#define GPIO_DIR_MASK (GPIO_INPUT | GPIO_OUTPUT)
288
301
309
318
326
341 const struct device *port;
346};
347
382#define GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx) \
383 { \
384 .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
385 .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
386 .dt_flags = DT_GPIO_FLAGS_BY_IDX(node_id, prop, idx), \
387 }
388
406#define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
407 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
408 (GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), \
409 (default_value))
410
419#define GPIO_DT_SPEC_GET(node_id, prop) \
420 GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
421
432#define GPIO_DT_SPEC_GET_OR(node_id, prop, default_value) \
433 GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
434
445#define GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
446 GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
447
459#define GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value) \
460 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)
461
470#define GPIO_DT_SPEC_INST_GET(inst, prop) \
471 GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
472
483#define GPIO_DT_SPEC_INST_GET_OR(inst, prop, default_value) \
484 GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
485
489#define GPIO_MAX_PINS_PER_PORT (sizeof(gpio_port_pins_t) * __CHAR_BIT__)
490
497 /* Mask identifying pins supported by the controller.
498 *
499 * Initialization of this mask is the responsibility of device
500 * instance generation in the driver.
501 */
503};
504
510 /* Mask identifying pins that are configured as active low.
511 *
512 * Management of this mask is the responsibility of the
513 * wrapper functions in this header.
514 */
516};
517
518struct gpio_callback;
519
532typedef void (*gpio_callback_handler_t)(const struct device *port,
533 struct gpio_callback *cb,
534 gpio_port_pins_t pins);
535
551
554
562};
563
570/* Used by driver api function pin_interrupt_configure, these are defined
571 * in terms of the public flags so we can just mask and pass them
572 * through to the driver api
573 */
574enum gpio_int_mode {
575 GPIO_INT_MODE_DISABLED = GPIO_INT_DISABLE,
576 GPIO_INT_MODE_LEVEL = GPIO_INT_ENABLE,
577 GPIO_INT_MODE_EDGE = GPIO_INT_ENABLE | GPIO_INT_EDGE,
578};
579
580enum gpio_int_trig {
581 /* Trigger detection when input state is (or transitions to)
582 * physical low. (Edge Failing or Active Low) */
583 GPIO_INT_TRIG_LOW = GPIO_INT_LOW_0,
584 /* Trigger detection when input state is (or transitions to)
585 * physical high. (Edge Rising or Active High) */
586 GPIO_INT_TRIG_HIGH = GPIO_INT_HIGH_1,
587 /* Trigger detection on pin rising or falling edge. */
588 GPIO_INT_TRIG_BOTH = GPIO_INT_LOW_0 | GPIO_INT_HIGH_1,
589};
590
591__subsystem struct gpio_driver_api {
592 int (*pin_configure)(const struct device *port, gpio_pin_t pin,
594 int (*port_get_raw)(const struct device *port,
595 gpio_port_value_t *value);
596 int (*port_set_masked_raw)(const struct device *port,
597 gpio_port_pins_t mask,
598 gpio_port_value_t value);
599 int (*port_set_bits_raw)(const struct device *port,
600 gpio_port_pins_t pins);
601 int (*port_clear_bits_raw)(const struct device *port,
602 gpio_port_pins_t pins);
603 int (*port_toggle_bits)(const struct device *port,
604 gpio_port_pins_t pins);
605 int (*pin_interrupt_configure)(const struct device *port,
606 gpio_pin_t pin,
607 enum gpio_int_mode, enum gpio_int_trig);
608 int (*manage_callback)(const struct device *port,
609 struct gpio_callback *cb,
610 bool set);
611 uint32_t (*get_pending_int)(const struct device *dev);
612};
613
638__syscall int gpio_pin_interrupt_configure(const struct device *port,
639 gpio_pin_t pin,
641
642static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port,
643 gpio_pin_t pin,
645{
646 const struct gpio_driver_api *api =
647 (const struct gpio_driver_api *)port->api;
648 const struct gpio_driver_config *const cfg =
649 (const struct gpio_driver_config *)port->config;
650 const struct gpio_driver_data *const data =
651 (const struct gpio_driver_data *)port->data;
652 enum gpio_int_trig trig;
653 enum gpio_int_mode mode;
654
655 __ASSERT_NO_MSG((flags & GPIO_INT_DEBOUNCE) == 0);
656
657 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE))
658 != (GPIO_INT_DISABLE | GPIO_INT_ENABLE),
659 "Cannot both enable and disable interrupts");
660
661 __ASSERT((flags & (GPIO_INT_DISABLE | GPIO_INT_ENABLE)) != 0U,
662 "Must either enable or disable interrupts");
663
664 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
665 ((flags & GPIO_INT_EDGE) != 0) ||
666 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) !=
667 (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)),
668 "Only one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 can be "
669 "enabled for a level interrupt.");
670
671 __ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
672 ((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) != 0),
673 "At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be "
674 "enabled.");
675
676 (void)cfg;
677 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
678 "Unsupported pin");
679
680 if (((flags & GPIO_INT_LEVELS_LOGICAL) != 0) &&
681 ((data->invert & (gpio_port_pins_t)BIT(pin)) != 0)) {
682 /* Invert signal bits */
683 flags ^= (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1);
684 }
685
686 trig = (enum gpio_int_trig)(flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1));
687 mode = (enum gpio_int_mode)(flags & (GPIO_INT_EDGE | GPIO_INT_DISABLE | GPIO_INT_ENABLE));
688
689 return api->pin_interrupt_configure(port, pin, mode, trig);
690}
691
705static inline int gpio_pin_interrupt_configure_dt(const struct gpio_dt_spec *spec,
707{
708 return gpio_pin_interrupt_configure(spec->port, spec->pin, flags);
709}
710
727__syscall int gpio_pin_configure(const struct device *port,
728 gpio_pin_t pin,
730
731static inline int z_impl_gpio_pin_configure(const struct device *port,
732 gpio_pin_t pin,
734{
735 const struct gpio_driver_api *api =
736 (const struct gpio_driver_api *)port->api;
737 const struct gpio_driver_config *const cfg =
738 (const struct gpio_driver_config *)port->config;
739 struct gpio_driver_data *data =
740 (struct gpio_driver_data *)port->data;
741
742 __ASSERT((flags & GPIO_INT_MASK) == 0,
743 "Interrupt flags are not supported");
744
745 __ASSERT((flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) !=
747 "Pull Up and Pull Down should not be enabled simultaneously");
748
749 __ASSERT((flags & GPIO_OUTPUT) != 0 || (flags & GPIO_SINGLE_ENDED) == 0,
750 "Output needs to be enabled for 'Open Drain', 'Open Source' "
751 "mode to be supported");
752
753 __ASSERT_NO_MSG((flags & GPIO_SINGLE_ENDED) != 0 ||
754 (flags & GPIO_LINE_OPEN_DRAIN) == 0);
755
756 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) == 0
757 || (flags & GPIO_OUTPUT) != 0,
758 "Output needs to be enabled to be initialized low or high");
759
760 __ASSERT((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH))
761 != (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH),
762 "Output cannot be initialized low and high");
763
764 if (((flags & GPIO_OUTPUT_INIT_LOGICAL) != 0)
765 && ((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) != 0)
766 && ((flags & GPIO_ACTIVE_LOW) != 0)) {
767 flags ^= GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH;
768 }
769
770 flags &= ~GPIO_OUTPUT_INIT_LOGICAL;
771
772 (void)cfg;
773 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
774 "Unsupported pin");
775
776 if ((flags & GPIO_ACTIVE_LOW) != 0) {
777 data->invert |= (gpio_port_pins_t)BIT(pin);
778 } else {
779 data->invert &= ~(gpio_port_pins_t)BIT(pin);
780 }
781
782 return api->pin_configure(port, pin, flags);
783}
784
796static inline int gpio_pin_configure_dt(const struct gpio_dt_spec *spec,
797 gpio_flags_t extra_flags)
798{
799 return gpio_pin_configure(spec->port,
800 spec->pin,
801 spec->dt_flags | extra_flags);
802}
803
821__syscall int gpio_port_get_raw(const struct device *port,
822 gpio_port_value_t *value);
823
824static inline int z_impl_gpio_port_get_raw(const struct device *port,
825 gpio_port_value_t *value)
826{
827 const struct gpio_driver_api *api =
828 (const struct gpio_driver_api *)port->api;
829
830 return api->port_get_raw(port, value);
831}
832
851static inline int gpio_port_get(const struct device *port,
852 gpio_port_value_t *value)
853{
854 const struct gpio_driver_data *const data =
855 (const struct gpio_driver_data *)port->data;
856 int ret;
857
858 ret = gpio_port_get_raw(port, value);
859 if (ret == 0) {
860 *value ^= data->invert;
861 }
862
863 return ret;
864}
865
883__syscall int gpio_port_set_masked_raw(const struct device *port,
884 gpio_port_pins_t mask,
885 gpio_port_value_t value);
886
887static inline int z_impl_gpio_port_set_masked_raw(const struct device *port,
888 gpio_port_pins_t mask,
889 gpio_port_value_t value)
890{
891 const struct gpio_driver_api *api =
892 (const struct gpio_driver_api *)port->api;
893
894 return api->port_set_masked_raw(port, mask, value);
895}
896
917static inline int gpio_port_set_masked(const struct device *port,
918 gpio_port_pins_t mask,
919 gpio_port_value_t value)
920{
921 const struct gpio_driver_data *const data =
922 (const struct gpio_driver_data *)port->data;
923
924 value ^= data->invert;
925
926 return gpio_port_set_masked_raw(port, mask, value);
927}
928
939__syscall int gpio_port_set_bits_raw(const struct device *port,
940 gpio_port_pins_t pins);
941
942static inline int z_impl_gpio_port_set_bits_raw(const struct device *port,
943 gpio_port_pins_t pins)
944{
945 const struct gpio_driver_api *api =
946 (const struct gpio_driver_api *)port->api;
947
948 return api->port_set_bits_raw(port, pins);
949}
950
961static inline int gpio_port_set_bits(const struct device *port,
962 gpio_port_pins_t pins)
963{
964 return gpio_port_set_masked(port, pins, pins);
965}
966
977__syscall int gpio_port_clear_bits_raw(const struct device *port,
978 gpio_port_pins_t pins);
979
980static inline int z_impl_gpio_port_clear_bits_raw(const struct device *port,
981 gpio_port_pins_t pins)
982{
983 const struct gpio_driver_api *api =
984 (const struct gpio_driver_api *)port->api;
985
986 return api->port_clear_bits_raw(port, pins);
987}
988
999static inline int gpio_port_clear_bits(const struct device *port,
1000 gpio_port_pins_t pins)
1001{
1002 return gpio_port_set_masked(port, pins, 0);
1003}
1004
1015__syscall int gpio_port_toggle_bits(const struct device *port,
1016 gpio_port_pins_t pins);
1017
1018static inline int z_impl_gpio_port_toggle_bits(const struct device *port,
1019 gpio_port_pins_t pins)
1020{
1021 const struct gpio_driver_api *api =
1022 (const struct gpio_driver_api *)port->api;
1023
1024 return api->port_toggle_bits(port, pins);
1025}
1026
1038static inline int gpio_port_set_clr_bits_raw(const struct device *port,
1039 gpio_port_pins_t set_pins,
1040 gpio_port_pins_t clear_pins)
1041{
1042 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1043
1044 return gpio_port_set_masked_raw(port, set_pins | clear_pins, set_pins);
1045}
1046
1058static inline int gpio_port_set_clr_bits(const struct device *port,
1059 gpio_port_pins_t set_pins,
1060 gpio_port_pins_t clear_pins)
1061{
1062 __ASSERT((set_pins & clear_pins) == 0, "Set and Clear pins overlap");
1063
1064 return gpio_port_set_masked(port, set_pins | clear_pins, set_pins);
1065}
1066
1082static inline int gpio_pin_get_raw(const struct device *port, gpio_pin_t pin)
1083{
1084 const struct gpio_driver_config *const cfg =
1085 (const struct gpio_driver_config *)port->config;
1086 gpio_port_value_t value;
1087 int ret;
1088
1089 (void)cfg;
1090 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1091 "Unsupported pin");
1092
1093 ret = gpio_port_get_raw(port, &value);
1094 if (ret == 0) {
1095 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1096 }
1097
1098 return ret;
1099}
1100
1120static inline int gpio_pin_get(const struct device *port, gpio_pin_t pin)
1121{
1122 const struct gpio_driver_config *const cfg =
1123 (const struct gpio_driver_config *)port->config;
1124 gpio_port_value_t value;
1125 int ret;
1126
1127 (void)cfg;
1128 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1129 "Unsupported pin");
1130
1131 ret = gpio_port_get(port, &value);
1132 if (ret == 0) {
1133 ret = (value & (gpio_port_pins_t)BIT(pin)) != 0 ? 1 : 0;
1134 }
1135
1136 return ret;
1137}
1138
1149static inline int gpio_pin_get_dt(const struct gpio_dt_spec *spec)
1150{
1151 return gpio_pin_get(spec->port, spec->pin);
1152}
1153
1169static inline int gpio_pin_set_raw(const struct device *port, gpio_pin_t pin,
1170 int value)
1171{
1172 const struct gpio_driver_config *const cfg =
1173 (const struct gpio_driver_config *)port->config;
1174 int ret;
1175
1176 (void)cfg;
1177 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1178 "Unsupported pin");
1179
1180 if (value != 0) {
1182 } else {
1184 }
1185
1186 return ret;
1187}
1188
1210static inline int gpio_pin_set(const struct device *port, gpio_pin_t pin,
1211 int value)
1212{
1213 const struct gpio_driver_config *const cfg =
1214 (const struct gpio_driver_config *)port->config;
1215 const struct gpio_driver_data *const data =
1216 (const struct gpio_driver_data *)port->data;
1217
1218 (void)cfg;
1219 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1220 "Unsupported pin");
1221
1222 if (data->invert & (gpio_port_pins_t)BIT(pin)) {
1223 value = (value != 0) ? 0 : 1;
1224 }
1225
1226 return gpio_pin_set_raw(port, pin, value);
1227}
1228
1240static inline int gpio_pin_set_dt(const struct gpio_dt_spec *spec, int value)
1241{
1242 return gpio_pin_set(spec->port, spec->pin, value);
1243}
1244
1255static inline int gpio_pin_toggle(const struct device *port, gpio_pin_t pin)
1256{
1257 const struct gpio_driver_config *const cfg =
1258 (const struct gpio_driver_config *)port->config;
1259
1260 (void)cfg;
1261 __ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
1262 "Unsupported pin");
1263
1264 return gpio_port_toggle_bits(port, (gpio_port_pins_t)BIT(pin));
1265}
1266
1277static inline int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec)
1278{
1279 return gpio_pin_toggle(spec->port, spec->pin);
1280}
1281
1288static inline void gpio_init_callback(struct gpio_callback *callback,
1290 gpio_port_pins_t pin_mask)
1291{
1292 __ASSERT(callback, "Callback pointer should not be NULL");
1293 __ASSERT(handler, "Callback handler pointer should not be NULL");
1294
1295 callback->handler = handler;
1296 callback->pin_mask = pin_mask;
1297}
1298
1311static inline int gpio_add_callback(const struct device *port,
1312 struct gpio_callback *callback)
1313{
1314 const struct gpio_driver_api *api =
1315 (const struct gpio_driver_api *)port->api;
1316
1317 if (api->manage_callback == NULL) {
1318 return -ENOTSUP;
1319 }
1320
1321 return api->manage_callback(port, callback, true);
1322}
1323
1340static inline int gpio_remove_callback(const struct device *port,
1341 struct gpio_callback *callback)
1342{
1343 const struct gpio_driver_api *api =
1344 (const struct gpio_driver_api *)port->api;
1345
1346 if (api->manage_callback == NULL) {
1347 return -ENOTSUP;
1348 }
1349
1350 return api->manage_callback(port, callback, false);
1351}
1352
1366__syscall int gpio_get_pending_int(const struct device *dev);
1367
1368static inline int z_impl_gpio_get_pending_int(const struct device *dev)
1369{
1370 const struct gpio_driver_api *api =
1371 (const struct gpio_driver_api *)dev->api;
1372
1373 if (api->get_pending_int == NULL) {
1374 return -ENOTSUP;
1375 }
1376
1377 return api->get_pending_int(dev);
1378}
1379
1384#ifdef __cplusplus
1385}
1386#endif
1387
1388#include <syscalls/gpio.h>
1389
1390#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_H_ */
static int gpio_add_callback(const struct device *port, struct gpio_callback *callback)
Add an application callback.
Definition: gpio.h:1311
#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:1082
static int gpio_pin_get(const struct device *port, gpio_pin_t pin)
Get logical level of an input pin.
Definition: gpio.h:1120
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:705
uint8_t gpio_dt_flags_t
Provides a type to hold GPIO devicetree flags.
Definition: gpio.h:317
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:532
#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:1277
uint8_t gpio_pin_t
Provides a type to hold a GPIO pin index.
Definition: gpio.h:308
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:796
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:1240
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:961
uint32_t gpio_flags_t
Provides a type to hold GPIO configuration flags.
Definition: gpio.h:325
#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:1038
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:1058
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:1288
uint32_t gpio_port_pins_t
Identifies a set of pins associated with a port.
Definition: gpio.h:287
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:1149
static int gpio_pin_toggle(const struct device *port, gpio_pin_t pin)
Toggle pin level.
Definition: gpio.h:1255
uint32_t gpio_port_value_t
Provides values for a set of pins associated with a port.
Definition: gpio.h:300
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:1210
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:999
static int gpio_remove_callback(const struct device *port, struct gpio_callback *callback)
Remove an application callback.
Definition: gpio.h:1340
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:917
#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:1169
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:851
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:450
const void * api
Definition: device.h:456
void *const data
Definition: device.h:460
const void * config
Definition: device.h:454
GPIO callback structure.
Definition: gpio.h:546
sys_snode_t node
Definition: gpio.h:550
gpio_port_pins_t pin_mask
Definition: gpio.h:561
gpio_callback_handler_t handler
Definition: gpio.h:553
Definition: gpio.h:496
gpio_port_pins_t port_pin_mask
Definition: gpio.h:502
Definition: gpio.h:509
gpio_port_pins_t invert
Definition: gpio.h:515
Container for GPIO pin information specified in devicetree.
Definition: gpio.h:339
const struct device * port
Definition: gpio.h:341
gpio_pin_t pin
Definition: gpio.h:343
gpio_dt_flags_t dt_flags
Definition: gpio.h:345
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static void handler(struct k_timer *timer)
Definition: main.c:19