@web-font-path: "roboto-debian.css";
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _HARDWARE_GPIO_H
8#define _HARDWARE_GPIO_H
9
10#include "pico.h"
11#include "hardware/structs/sio.h"
12#include "hardware/structs/pads_bank0.h"
13#include "hardware/structs/io_bank0.h"
14#include "hardware/irq.h"
15
16// PICO_CONFIG: PICO_USE_GPIO_COPROCESSOR, Enable/disable use of the GPIO coprocessor for GPIO access, type=bool, default=1, group=hardware_gpio
17#if !defined(PICO_USE_GPIO_COPROCESSOR) && HAS_GPIO_COPROCESSOR
18#define PICO_USE_GPIO_COPROCESSOR 1
19#endif
20
21#if PICO_USE_GPIO_COPROCESSOR
22#include "hardware/gpio_coproc.h"
23#endif
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_GPIO, Enable/disable assertions in the hardware_gpio module, type=bool, default=0, group=hardware_gpio
30#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_GPIO
31#ifdef PARAM_ASSERTIONS_ENABLED_GPIO // backwards compatibility with SDK < 2.0.0
32#define PARAM_ASSERTIONS_ENABLED_HARDWARE_GPIO PARAM_ASSERTIONS_ENABLED_GPIO
33#else
34#define PARAM_ASSERTIONS_ENABLED_HARDWARE_GPIO 0
35#endif
36#endif
37
169
171 GPIO_OUT = 1u,
172 GPIO_IN = 0u,
173};
174
196
205typedef void (*gpio_irq_callback_t)(uint gpio, uint32_t event_mask);
206
218
230
243
244static inline void check_gpio_param(__unused uint gpio) {
245 invalid_params_if(HARDWARE_GPIO, gpio >= NUM_BANK0_GPIOS);
246}
247
248// ----------------------------------------------------------------------------
249// Pad Controls + IO Muxing
250// ----------------------------------------------------------------------------
251// Declarations for gpio.c
252
259void gpio_set_function(uint gpio, gpio_function_t fn);
260
268void gpio_set_function_masked(uint32_t gpio_mask, gpio_function_t fn);
269
277void gpio_set_function_masked64(uint64_t gpio_mask, gpio_function_t fn);
278
286
297void gpio_set_pulls(uint gpio, bool up, bool down);
298
304static inline void gpio_pull_up(uint gpio) {
305 gpio_set_pulls(gpio, true, false);
306}
307
314static inline bool gpio_is_pulled_up(uint gpio) {
315 return (pads_bank0_hw->io[gpio] & PADS_BANK0_GPIO0_PUE_BITS) != 0;
316}
317
323static inline void gpio_pull_down(uint gpio) {
324 gpio_set_pulls(gpio, false, true);
325}
326
333static inline bool gpio_is_pulled_down(uint gpio) {
334 return (pads_bank0_hw->io[gpio] & PADS_BANK0_GPIO0_PDE_BITS) != 0;
335}
336
342static inline void gpio_disable_pulls(uint gpio) {
343 gpio_set_pulls(gpio, false, false);
344}
345
354void gpio_set_irqover(uint gpio, uint value);
355
362void gpio_set_outover(uint gpio, uint value);
363
370void gpio_set_inover(uint gpio, uint value);
371
378void gpio_set_oeover(uint gpio, uint value);
379
386void gpio_set_input_enabled(uint gpio, bool enabled);
387
400void gpio_set_input_hysteresis_enabled(uint gpio, bool enabled);
401
409
417void gpio_set_slew_rate(uint gpio, enum gpio_slew_rate slew);
418
426enum gpio_slew_rate gpio_get_slew_rate(uint gpio);
427
435void gpio_set_drive_strength(uint gpio, enum gpio_drive_strength drive);
436
445
471void gpio_set_irq_enabled(uint gpio, uint32_t event_mask, bool enabled);
472
473// PICO_CONFIG: GPIO_IRQ_CALLBACK_ORDER_PRIORITY, IRQ priority order of the default IRQ callback, min=0, max=255, default=PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY, group=hardware_gpio
474#ifndef GPIO_IRQ_CALLBACK_ORDER_PRIORITY
475#define GPIO_IRQ_CALLBACK_ORDER_PRIORITY PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY
476#endif
477
478// PICO_CONFIG: GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY, IRQ priority order of raw IRQ handlers if the priority is not specified, min=0, max=255, default=PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY, group=hardware_gpio
479#ifndef GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY
480#define GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY
481#endif
482
498
530void gpio_set_irq_enabled_with_callback(uint gpio, uint32_t event_mask, bool enabled, gpio_irq_callback_t callback);
531
542void gpio_set_dormant_irq_enabled(uint gpio, uint32_t event_mask, bool enabled);
543
551static inline uint32_t gpio_get_irq_event_mask(uint gpio) {
552 check_gpio_param(gpio);
553 io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_num() ?
554 &io_bank0_hw->proc1_irq_ctrl : &io_bank0_hw->proc0_irq_ctrl;
555 io_ro_32 *status_reg = &irq_ctrl_base->ints[gpio >> 3u];
556 return (*status_reg >> (4 * (gpio & 7u))) & 0xfu;
557}
558
573static inline void gpio_acknowledge_irq(uint gpio, uint32_t event_mask) {
574 check_gpio_param(gpio);
575 io_bank0_hw->intr[gpio / 8] = event_mask << (4 * (gpio % 8));
576}
577
611void gpio_add_raw_irq_handler_with_order_priority_masked(uint32_t gpio_mask, irq_handler_t handler, uint8_t order_priority);
612
646void gpio_add_raw_irq_handler_with_order_priority_masked64(uint64_t gpio_mask, irq_handler_t handler, uint8_t order_priority);
647
677static inline void gpio_add_raw_irq_handler_with_order_priority(uint gpio, irq_handler_t handler, uint8_t order_priority) {
678 check_gpio_param(gpio);
679#if NUM_BANK0_GPIOS > 32
680 gpio_add_raw_irq_handler_with_order_priority_masked64(1ull << gpio, handler, order_priority);
681#else
682 gpio_add_raw_irq_handler_with_order_priority_masked(1u << gpio, handler, order_priority);
683#endif
684}
685
716void gpio_add_raw_irq_handler_masked(uint32_t gpio_mask, irq_handler_t handler);
717
748void gpio_add_raw_irq_handler_masked64(uint64_t gpio_mask, irq_handler_t handler);
749
776static inline void gpio_add_raw_irq_handler(uint gpio, irq_handler_t handler) {
777 check_gpio_param(gpio);
778#if NUM_BANK0_GPIOS > 32
779 gpio_add_raw_irq_handler_masked64(1ull << gpio, handler);
780#else
781 gpio_add_raw_irq_handler_masked(1u << gpio, handler);
782#endif
783}
784
798void gpio_remove_raw_irq_handler_masked(uint32_t gpio_mask, irq_handler_t handler);
799
811void gpio_remove_raw_irq_handler_masked64(uint64_t gpio_mask, irq_handler_t handler);
812
824static inline void gpio_remove_raw_irq_handler(uint gpio, irq_handler_t handler) {
825 check_gpio_param(gpio);
826#if NUM_BANK0_GPIOS > 32
827 gpio_remove_raw_irq_handler_masked64(1ull << gpio, handler);
828#else
829 gpio_remove_raw_irq_handler_masked(1u << gpio, handler);
830#endif
831}
832
841void gpio_init(uint gpio);
842
848void gpio_deinit(uint gpio);
849
858void gpio_init_mask(uint gpio_mask);
859// ----------------------------------------------------------------------------
860// Input
861// ----------------------------------------------------------------------------
862
869static inline bool gpio_get(uint gpio) {
870#if NUM_BANK0_GPIOS <= 32
871 return sio_hw->gpio_in & (1u << gpio);
872#else
873 if (gpio < 32) {
874 return sio_hw->gpio_in & (1u << gpio);
875 } else {
876 return sio_hw->gpio_hi_in & (1u << (gpio - 32));
877 }
878#endif
879}
880
886static inline uint32_t gpio_get_all(void) {
887#if PICO_USE_GPIO_COPROCESSOR
888 return gpioc_lo_in_get();
889#else
890 return sio_hw->gpio_in;
891#endif
892}
893
899static inline uint64_t gpio_get_all64(void) {
900#if PICO_USE_GPIO_COPROCESSOR
901 return gpioc_hilo_in_get();
902#elif NUM_BANK0_GPIOS <= 32
903 return sio_hw->gpio_in;
904#else
905 return sio_hw->gpio_in | (((uint64_t)sio_hw->gpio_hi_in) << 32u);
906#endif
907}
908
909// ----------------------------------------------------------------------------
910// Output
911// ----------------------------------------------------------------------------
912
918static inline void gpio_set_mask(uint32_t mask) {
919#if PICO_USE_GPIO_COPROCESSOR
920 gpioc_lo_out_set(mask);
921#else
922 sio_hw->gpio_set = mask;
923#endif
924}
925
931static inline void gpio_set_mask64(uint64_t mask) {
932#if PICO_USE_GPIO_COPROCESSOR
933 gpioc_hilo_out_set(mask);
934#elif NUM_BANK0_GPIOS <= 32
935 sio_hw->gpio_set = (uint32_t)mask;
936#else
937 sio_hw->gpio_set = (uint32_t)mask;
938 sio_hw->gpio_hi_set = (uint32_t)(mask >> 32u);
939#endif
940}
941
948static inline void gpio_set_mask_n(uint n, uint32_t mask) {
949 if (!n) {
950 gpio_set_mask(mask);
951 } else if (n == 1) {
952#if PICO_USE_GPIO_COPROCESSOR
953 gpioc_hi_out_set(mask);
954#elif NUM_BANK0_GPIOS >= 32
955 sio_hw->gpio_hi_set = mask;
956#endif
957 }
958}
959
965static inline void gpio_clr_mask(uint32_t mask) {
966#if PICO_USE_GPIO_COPROCESSOR
967 gpioc_lo_out_clr(mask);
968#else
969 sio_hw->gpio_clr = mask;
970#endif
971}
972
978static inline void gpio_clr_mask64(uint64_t mask) {
979#if PICO_USE_GPIO_COPROCESSOR
980 gpioc_hilo_out_clr(mask);
981#elif NUM_BANK0_GPIOS <= 32
982 sio_hw->gpio_clr = (uint32_t)mask;
983#else
984 sio_hw->gpio_clr = (uint32_t)mask;
985 sio_hw->gpio_hi_clr = (uint32_t)(mask >> 32u);
986#endif
987}
988
989
996static inline void gpio_clr_mask_n(uint n, uint32_t mask) {
997 if (!n) {
998 gpio_clr_mask(mask);
999 } else if (n == 1) {
1000#if PICO_USE_GPIO_COPROCESSOR
1001 gpioc_hi_out_clr(mask);
1002#elif NUM_BANK0_GPIOS >= 32
1003 sio_hw->gpio_hi_clr = mask;
1004#endif
1005 }
1006}
1007
1013static inline void gpio_xor_mask(uint32_t mask) {
1014#if PICO_USE_GPIO_COPROCESSOR
1015 gpioc_lo_out_xor(mask);
1016#else
1017 sio_hw->gpio_togl = mask;
1018#endif
1019}
1020
1026static inline void gpio_xor_mask64(uint64_t mask) {
1027#if PICO_USE_GPIO_COPROCESSOR
1028 gpioc_hilo_out_xor(mask);
1029#elif NUM_BANK0_GPIOS <= 32
1030 sio_hw->gpio_togl = (uint32_t)mask;
1031#else
1032 sio_hw->gpio_togl = (uint32_t)mask;
1033 sio_hw->gpio_hi_togl = (uint32_t)(mask >> 32u);
1034#endif
1035}
1036
1043static inline void gpio_xor_mask_n(uint n, uint32_t mask) {
1044 if (!n) {
1045 gpio_xor_mask(mask);
1046 } else if (n == 1) {
1047#if PICO_USE_GPIO_COPROCESSOR
1048 gpioc_hi_out_xor(mask);
1049#elif NUM_BANK0_GPIOS >= 32
1050 sio_hw->gpio_hi_togl = mask;
1051#endif
1052 }
1053}
1054
1066static inline void gpio_put_masked(uint32_t mask, uint32_t value) {
1067#if PICO_USE_GPIO_COPROCESSOR
1068 gpioc_lo_out_xor((gpioc_lo_out_get() ^ value) & mask);
1069#else
1070 sio_hw->gpio_togl = (sio_hw->gpio_out ^ value) & mask;
1071#endif
1072}
1073
1085static inline void gpio_put_masked64(uint64_t mask, uint64_t value) {
1086#if PICO_USE_GPIO_COPROCESSOR
1087 gpioc_hilo_out_xor((gpioc_hilo_out_get() ^ value) & mask);
1088#elif NUM_BANK0_GPIOS <= 32
1089 sio_hw->gpio_togl = (sio_hw->gpio_out ^ (uint32_t)value) & (uint32_t)mask;
1090#else
1091 sio_hw->gpio_togl = (sio_hw->gpio_out ^ (uint32_t)value) & (uint32_t)mask;
1092 sio_hw->gpio_hi_togl = (sio_hw->gpio_hi_out ^ (uint32_t)(value>>32u)) & (uint32_t)(mask>>32u);
1093#endif
1094}
1095
1108static inline void gpio_put_masked_n(uint n, uint32_t mask, uint32_t value) {
1109 if (!n) {
1110 gpio_put_masked(mask, value);
1111 } else if (n == 1) {
1112#if PICO_USE_GPIO_COPROCESSOR
1113 gpioc_hi_out_xor((gpioc_hi_out_get() ^ value) & mask);
1114#else
1115 sio_hw->gpio_hi_togl = (sio_hw->gpio_hi_out ^ value) & mask;
1116#endif
1117 }
1118}
1119
1125static inline void gpio_put_all(uint32_t value) {
1126#if PICO_USE_GPIO_COPROCESSOR
1127 gpioc_lo_out_put(value);
1128#else
1129 sio_hw->gpio_out = value;
1130#endif
1131}
1132
1138static inline void gpio_put_all64(uint64_t value) {
1139#if PICO_USE_GPIO_COPROCESSOR
1140 gpioc_hilo_out_put(value);
1141#elif NUM_BANK0_GPIOS <= 32
1142 sio_hw->gpio_out = (uint32_t)value;
1143#else
1144 sio_hw->gpio_out = (uint32_t)value;
1145 sio_hw->gpio_hi_out = (uint32_t)(value >> 32u);
1146#endif
1147}
1148
1155static inline void gpio_put(uint gpio, bool value) {
1156#if PICO_USE_GPIO_COPROCESSOR
1157 gpioc_bit_out_put(gpio, value);
1158#elif NUM_BANK0_GPIOS <= 32
1159 uint32_t mask = 1ul << gpio;
1160 if (value)
1161 gpio_set_mask(mask);
1162 else
1163 gpio_clr_mask(mask);
1164#else
1165 uint32_t mask = 1ul << (gpio & 0x1fu);
1166 if (gpio < 32) {
1167 if (value) {
1168 sio_hw->gpio_set = mask;
1169 } else {
1170 sio_hw->gpio_clr = mask;
1171 }
1172 } else {
1173 if (value) {
1174 sio_hw->gpio_hi_set = mask;
1175 } else {
1176 sio_hw->gpio_hi_clr = mask;
1177 }
1178 }
1179#endif
1180}
1181
1198static inline bool gpio_get_out_level(uint gpio) {
1199#if NUM_BANK0_GPIOS <= 32
1200 return sio_hw->gpio_out & (1u << gpio);
1201#else
1202 uint32_t bits = gpio < 32 ? sio_hw->gpio_out : sio_hw->gpio_hi_out;
1203 return bits & (1u << (gpio & 0x1fu));
1204#endif
1205}
1206
1207// ----------------------------------------------------------------------------
1208// Direction
1209// ----------------------------------------------------------------------------
1210
1218static inline void gpio_set_dir_out_masked(uint32_t mask) {
1219#if PICO_USE_GPIO_COPROCESSOR
1220 gpioc_lo_oe_set(mask);
1221#else
1222 sio_hw->gpio_oe_set = mask;
1223#endif
1224}
1225
1233static inline void gpio_set_dir_out_masked64(uint64_t mask) {
1234#if PICO_USE_GPIO_COPROCESSOR
1235 gpioc_hilo_oe_set(mask);
1236#elif NUM_BANK0_GPIOS <= 32
1237 sio_hw->gpio_oe_set = mask;
1238#else
1239 sio_hw->gpio_oe_set = (uint32_t)mask;
1240 sio_hw->gpio_hi_oe_set = (uint32_t)(mask >> 32u);
1241#endif
1242}
1243
1249static inline void gpio_set_dir_in_masked(uint32_t mask) {
1250#if PICO_USE_GPIO_COPROCESSOR
1251 gpioc_lo_oe_clr(mask);
1252#else
1253 sio_hw->gpio_oe_clr = mask;
1254#endif
1255}
1256
1262static inline void gpio_set_dir_in_masked64(uint64_t mask) {
1263#if PICO_USE_GPIO_COPROCESSOR
1264 gpioc_hilo_oe_clr(mask);
1265#elif NUM_BANK0_GPIOS <= 32
1266 sio_hw->gpio_oe_clr = mask;
1267#else
1268 sio_hw->gpio_oe_clr = (uint32_t)mask;
1269 sio_hw->gpio_hi_oe_clr = (uint32_t)(mask >> 32u);
1270#endif
1271}
1272
1284static inline void gpio_set_dir_masked(uint32_t mask, uint32_t value) {
1285#if PICO_USE_GPIO_COPROCESSOR
1286 gpioc_lo_oe_xor((gpioc_lo_oe_get() ^ value) & mask);
1287#else
1288 sio_hw->gpio_oe_togl = (sio_hw->gpio_oe ^ value) & mask;
1289#endif
1290}
1291
1303static inline void gpio_set_dir_masked64(uint64_t mask, uint64_t value) {
1304#if PICO_USE_GPIO_COPROCESSOR
1305 gpioc_hilo_oe_xor((gpioc_hilo_oe_get() ^ value) & mask);
1306#elif NUM_BANK0_GPIOS <= 32
1307 sio_hw->gpio_oe_togl = (sio_hw->gpio_oe ^ (uint32_t)value) & (uint32_t)mask;
1308#else
1309 sio_hw->gpio_oe_togl = (sio_hw->gpio_oe ^ (uint32_t)value) & (uint32_t)mask;
1310 sio_hw->gpio_hi_oe_togl = (sio_hw->gpio_hi_oe ^ (uint32_t)(value >> 32u)) & (uint32_t)(mask >> 32u);
1311#endif
1312}
1313
1314
1320static inline void gpio_set_dir_all_bits(uint32_t values) {
1321#if PICO_USE_GPIO_COPROCESSOR
1322 gpioc_lo_oe_put(values);
1323#else
1324 sio_hw->gpio_oe = values;
1325#endif
1326}
1327
1333static inline void gpio_set_dir_all_bits64(uint64_t values) {
1334#if PICO_USE_GPIO_COPROCESSOR
1335 gpioc_hilo_oe_put(values);
1336#elif NUM_BANK0_GPIOS <= 32
1337 sio_hw->gpio_oe = (uint32_t)values;
1338#else
1339 sio_hw->gpio_oe = (uint32_t)values;
1340 sio_hw->gpio_hi_oe = (uint32_t)(values >> 32u);
1341#endif
1342}
1343
1350static inline void gpio_set_dir(uint gpio, bool out) {
1351#if PICO_USE_GPIO_COPROCESSOR
1352 gpioc_bit_oe_put(gpio, out);
1353#elif PICO_RP2040 || NUM_BANK0_GPIOS <= 32
1354 uint32_t mask = 1ul << gpio;
1355 if (out)
1357 else
1359#else
1360 uint32_t mask = 1u << (gpio & 0x1fu);
1361 if (gpio < 32) {
1362 if (out) {
1363 sio_hw->gpio_oe_set = mask;
1364 } else {
1365 sio_hw->gpio_oe_clr = mask;
1366 }
1367 } else {
1368 if (out) {
1369 sio_hw->gpio_hi_oe_set = mask;
1370 } else {
1371 sio_hw->gpio_hi_oe_clr = mask;
1372 }
1373 }
1374#endif
1375}
1376
1383static inline bool gpio_is_dir_out(uint gpio) {
1384#if NUM_BANK0_GPIOS <= 32
1385 return sio_hw->gpio_oe & (1u << (gpio));
1386#else
1387 uint32_t bits = gpio < 32 ? sio_hw->gpio_oe : sio_hw->gpio_hi_oe;
1388 return bits & (1u << (gpio & 0x1fu));
1389#endif
1390}
1391
1398static inline uint gpio_get_dir(uint gpio) {
1399 return gpio_is_dir_out(gpio); // note GPIO_OUT is 1/true and GPIO_IN is 0/false anyway
1400}
1401
1402#if PICO_SECURE
1403static inline void gpio_assign_to_ns(uint gpio, bool ns) {
1404 check_gpio_param(gpio);
1405 if (ns) hw_set_bits(&accessctrl_hw->gpio_nsmask[gpio/32], 1u << (gpio & 0x1fu));
1406 else hw_clear_bits(&accessctrl_hw->gpio_nsmask[gpio/32], 1u << (gpio & 0x1fu));
1407}
1408#endif
1409extern void gpio_debug_pins_init(void);
1410
1411#ifdef __cplusplus
1412}
1413#endif
1414
1415
1416// PICO_CONFIG: PICO_DEBUG_PIN_BASE, First pin to use for debug output (if enabled), min=0, max=31 on RP2350B, 29 otherwise, default=19, group=hardware_gpio
1417#ifndef PICO_DEBUG_PIN_BASE
1418#define PICO_DEBUG_PIN_BASE 19u
1419#endif
1420
1421// PICO_CONFIG: PICO_DEBUG_PIN_COUNT, Number of pins to use for debug output (if enabled), min=1, max=32 on RP2350B, 30 otherwise, default=3, group=hardware_gpio
1422#ifndef PICO_DEBUG_PIN_COUNT
1423#define PICO_DEBUG_PIN_COUNT 3u
1424#endif
1425
1426#ifndef __cplusplus
1427// note these two macros may only be used once per and only apply per compilation unit (hence the CU_)
1428#define CU_REGISTER_DEBUG_PINS(...) enum __unused DEBUG_PIN_TYPE { _none = 0, __VA_ARGS__ }; static enum DEBUG_PIN_TYPE __selected_debug_pins;
1429#define CU_SELECT_DEBUG_PINS(x) static enum DEBUG_PIN_TYPE __selected_debug_pins = (x);
1430#define DEBUG_PINS_ENABLED(p) (__selected_debug_pins == (p))
1431#else
1432#define CU_REGISTER_DEBUG_PINS(p...) \
1433 enum DEBUG_PIN_TYPE { _none = 0, p }; \
1434 template <enum DEBUG_PIN_TYPE> class __debug_pin_settings { \
1435 public: \
1436 static inline bool enabled() { return false; } \
1437 };
1438#define CU_SELECT_DEBUG_PINS(x) template<> inline bool __debug_pin_settings<x>::enabled() { return true; };
1439#define DEBUG_PINS_ENABLED(p) (__debug_pin_settings<p>::enabled())
1440#endif
1441#define DEBUG_PINS_SET(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_set_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
1442#define DEBUG_PINS_CLR(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_clr_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
1443#define DEBUG_PINS_XOR(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_xor_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
1444
1445#endif // _GPIO_H_
gpio_dir
Definition gpio.h:170
@ GPIO_OUT
set GPIO to output
Definition gpio.h:171
@ GPIO_IN
set GPIO to input
Definition gpio.h:172
static __force_inline void hw_set_bits(io_rw_32 *addr, uint32_t mask)
Atomically set the specified bits to 1 in a HW register.
Definition address_mapped.h:135
static __force_inline void hw_clear_bits(io_rw_32 *addr, uint32_t mask)
Atomically clear the specified bits to 0 in a HW register.
Definition address_mapped.h:145
static void gpio_add_raw_irq_handler_with_order_priority(uint gpio, irq_handler_t handler, uint8_t order_priority)
Adds a raw GPIO IRQ handler for a specific GPIO on the current core.
Definition gpio.h:677
void gpio_set_irq_enabled(uint gpio, uint32_t event_mask, bool enabled)
Enable or disable specific interrupt events for specified GPIO.
Definition gpio.c:186
static bool gpio_get_out_level(uint gpio)
Determine whether a GPIO is currently driven high or low.
Definition gpio.h:1198
static void gpio_put_all64(uint64_t value)
Drive all pins simultaneously.
Definition gpio.h:1138
void gpio_set_dormant_irq_enabled(uint gpio, uint32_t event_mask, bool enabled)
Enable dormant wake up interrupt for specified GPIO and events.
Definition gpio.c:250
void gpio_set_drive_strength(uint gpio, enum gpio_drive_strength drive)
Set drive strength for a specified GPIO.
Definition gpio.c:138
enum gpio_function_rp2040 gpio_function_t
GPIO pin function selectors on RP2040 (used as typedef gpio_function_t).
enum gpio_drive_strength gpio_get_drive_strength(uint gpio)
Determine current drive strength for a specified GPIO.
Definition gpio.c:146
gpio_drive_strength
Drive strength levels for GPIO outputs.
Definition gpio.h:237
void gpio_set_input_hysteresis_enabled(uint gpio, bool enabled)
Enable/disable GPIO input hysteresis (Schmitt trigger).
Definition gpio.c:106
void gpio_set_function(uint gpio, gpio_function_t fn)
Select GPIO function.
Definition gpio.c:38
gpio_function_t gpio_get_function(uint gpio)
Determine current GPIO function.
Definition gpio.c:56
void gpio_add_raw_irq_handler_masked64(uint64_t gpio_mask, irq_handler_t handler)
Adds a raw GPIO IRQ handler for the specified GPIOs on the current core.
Definition gpio.c:234
void gpio_set_oeover(uint gpio, uint value)
Select GPIO output enable override.
Definition gpio.c:98
void gpio_remove_raw_irq_handler_masked(uint32_t gpio_mask, irq_handler_t handler)
Removes a raw GPIO IRQ handler for the specified GPIOs on the current core.
Definition gpio.c:238
static uint gpio_get_dir(uint gpio)
Get a specific GPIO direction.
Definition gpio.h:1398
static void gpio_set_dir_masked64(uint64_t mask, uint64_t value)
Set multiple GPIO directions.
Definition gpio.h:1303
static void gpio_add_raw_irq_handler(uint gpio, irq_handler_t handler)
Adds a raw GPIO IRQ handler for a specific GPIO on the current core.
Definition gpio.h:776
void gpio_init_mask(uint gpio_mask)
Initialise multiple GPIOs (enabled I/O and set func to GPIO_FUNC_SIO).
Definition gpio.c:283
static void gpio_pull_up(uint gpio)
Set specified GPIO to be pulled up.
Definition gpio.h:304
void gpio_set_function_masked(uint32_t gpio_mask, gpio_function_t fn)
Select the function for multiple GPIOs.
Definition gpio.c:292
void gpio_set_irq_callback(gpio_irq_callback_t callback)
Set the generic callback used for GPIO IRQ events for the current core.
Definition gpio.c:205
enum gpio_slew_rate gpio_get_slew_rate(uint gpio)
Determine current slew rate for a specified GPIO.
Definition gpio.c:128
static void gpio_remove_raw_irq_handler(uint gpio, irq_handler_t handler)
Removes a raw GPIO IRQ handler for the specified GPIO on the current core.
Definition gpio.h:824
void gpio_deinit(uint gpio)
Resets a GPIO back to the NULL function, i.e. disables it.
Definition gpio.c:279
static void gpio_set_dir_all_bits(uint32_t values)
Set direction of all pins simultaneously.
Definition gpio.h:1320
static bool gpio_is_pulled_down(uint gpio)
Determine if the specified GPIO is pulled down.
Definition gpio.h:333
void gpio_set_inover(uint gpio, uint value)
Select GPIO input override.
Definition gpio.c:82
void gpio_set_irq_enabled_with_callback(uint gpio, uint32_t event_mask, bool enabled, gpio_irq_callback_t callback)
Convenience function which performs multiple GPIO IRQ related initializations.
Definition gpio.c:198
gpio_irq_level
GPIO Interrupt level definitions (GPIO events).
Definition gpio.h:190
static void gpio_xor_mask(uint32_t mask)
Toggle every GPIO appearing in mask.
Definition gpio.h:1013
static void gpio_set_dir(uint gpio, bool out)
Set a single GPIO direction.
Definition gpio.h:1350
static void gpio_clr_mask(uint32_t mask)
Drive low every GPIO appearing in mask.
Definition gpio.h:965
static void gpio_put_masked_n(uint n, uint32_t mask, uint32_t value)
Drive GPIOs high/low depending on parameters.
Definition gpio.h:1108
static void gpio_set_dir_out_masked64(uint64_t mask)
Set a number of GPIOs to output.
Definition gpio.h:1233
static void gpio_put(uint gpio, bool value)
Drive a single GPIO high/low.
Definition gpio.h:1155
static void gpio_xor_mask_n(uint n, uint32_t mask)
Toggle every GPIO appearing in mask.
Definition gpio.h:1043
gpio_slew_rate
Slew rate limiting levels for GPIO outputs.
Definition gpio.h:226
void gpio_set_input_enabled(uint gpio, bool enabled)
Enable GPIO input.
Definition gpio.c:265
gpio_override
GPIO override modes.
Definition gpio.h:212
void gpio_add_raw_irq_handler_with_order_priority_masked64(uint64_t gpio_mask, irq_handler_t handler, uint8_t order_priority)
Adds a raw GPIO IRQ handler for the specified GPIOs on the current core.
Definition gpio.c:224
static void gpio_set_dir_in_masked(uint32_t mask)
Set a number of GPIOs to input.
Definition gpio.h:1249
static void gpio_put_all(uint32_t value)
Drive all pins simultaneously.
Definition gpio.h:1125
static void gpio_set_dir_out_masked(uint32_t mask)
Set a number of GPIOs to output.
Definition gpio.h:1218
void gpio_set_outover(uint gpio, uint value)
Set GPIO output override.
Definition gpio.c:90
void gpio_set_function_masked64(uint64_t gpio_mask, gpio_function_t fn)
Select the function for multiple GPIOs.
Definition gpio.c:301
void gpio_init(uint gpio)
Initialise a GPIO for (enabled I/O and set func to GPIO_FUNC_SIO).
Definition gpio.c:273
void(* gpio_irq_callback_t)(uint gpio, uint32_t event_mask)
Definition gpio.h:205
void gpio_remove_raw_irq_handler_masked64(uint64_t gpio_mask, irq_handler_t handler)
Removes a raw GPIO IRQ handler for the specified GPIOs on the current core.
Definition gpio.c:244
static void gpio_set_mask_n(uint n, uint32_t mask)
Drive high every GPIO appearing in mask.
Definition gpio.h:948
static void gpio_clr_mask_n(uint n, uint32_t mask)
Drive low every GPIO appearing in mask.
Definition gpio.h:996
void gpio_set_irqover(uint gpio, uint value)
Set GPIO IRQ override.
Definition gpio.c:73
static void gpio_set_mask64(uint64_t mask)
Drive high every GPIO appearing in mask.
Definition gpio.h:931
static bool gpio_is_dir_out(uint gpio)
Check if a specific GPIO direction is OUT.
Definition gpio.h:1383
static uint64_t gpio_get_all64(void)
Get raw value of all GPIOs.
Definition gpio.h:899
static void gpio_put_masked64(uint64_t mask, uint64_t value)
Drive GPIOs high/low depending on parameters.
Definition gpio.h:1085
static void gpio_set_dir_masked(uint32_t mask, uint32_t value)
Set multiple GPIO directions.
Definition gpio.h:1284
static void gpio_clr_mask64(uint64_t mask)
Drive low every GPIO appearing in mask.
Definition gpio.h:978
static void gpio_set_dir_all_bits64(uint64_t values)
Set direction of all pins simultaneously.
Definition gpio.h:1333
void gpio_set_pulls(uint gpio, bool up, bool down)
Select up and down pulls on specific GPIO.
Definition gpio.c:63
static void gpio_xor_mask64(uint64_t mask)
Toggle every GPIO appearing in mask.
Definition gpio.h:1026
bool gpio_is_input_hysteresis_enabled(uint gpio)
Determine whether input hysteresis is enabled on a specified GPIO.
Definition gpio.c:115
static void gpio_set_dir_in_masked64(uint64_t mask)
Set a number of GPIOs to input.
Definition gpio.h:1262
static bool gpio_is_pulled_up(uint gpio)
Determine if the specified GPIO is pulled up.
Definition gpio.h:314
static void gpio_put_masked(uint32_t mask, uint32_t value)
Drive GPIOs high/low depending on parameters.
Definition gpio.h:1066
static void gpio_acknowledge_irq(uint gpio, uint32_t event_mask)
Acknowledge a GPIO interrupt for the specified events on the calling core.
Definition gpio.h:573
static void gpio_disable_pulls(uint gpio)
Disable pulls on specified GPIO.
Definition gpio.h:342
static uint32_t gpio_get_all(void)
Get raw value of all GPIOs.
Definition gpio.h:886
static void gpio_pull_down(uint gpio)
Set specified GPIO to be pulled down.
Definition gpio.h:323
void gpio_set_slew_rate(uint gpio, enum gpio_slew_rate slew)
Set slew rate for a specified GPIO.
Definition gpio.c:120
static uint32_t gpio_get_irq_event_mask(uint gpio)
Return the current interrupt status (pending events) for the given GPIO.
Definition gpio.h:551
static bool gpio_get(uint gpio)
Get state of a single specified GPIO.
Definition gpio.h:869
static void gpio_set_mask(uint32_t mask)
Drive high every GPIO appearing in mask.
Definition gpio.h:918
void gpio_add_raw_irq_handler_with_order_priority_masked(uint32_t gpio_mask, irq_handler_t handler, uint8_t order_priority)
Adds a raw GPIO IRQ handler for the specified GPIOs on the current core.
Definition gpio.c:218
void gpio_add_raw_irq_handler_masked(uint32_t gpio_mask, irq_handler_t handler)
Adds a raw GPIO IRQ handler for the specified GPIOs on the current core.
Definition gpio.c:230
@ GPIO_DRIVE_STRENGTH_2MA
2 mA nominal drive strength
Definition gpio.h:238
@ GPIO_DRIVE_STRENGTH_8MA
8 mA nominal drive strength
Definition gpio.h:240
@ GPIO_DRIVE_STRENGTH_12MA
12 mA nominal drive strength
Definition gpio.h:241
@ GPIO_DRIVE_STRENGTH_4MA
4 mA nominal drive strength
Definition gpio.h:239
@ GPIO_IRQ_EDGE_RISE
IRQ when the GPIO has transitioned from a logical 0 to a logical 1.
Definition gpio.h:194
@ GPIO_IRQ_EDGE_FALL
IRQ when the GPIO has transitioned from a logical 1 to a logical 0.
Definition gpio.h:193
@ GPIO_IRQ_LEVEL_LOW
IRQ when the GPIO pin is a logical 0.
Definition gpio.h:191
@ GPIO_IRQ_LEVEL_HIGH
IRQ when the GPIO pin is a logical 1.
Definition gpio.h:192
@ GPIO_SLEW_RATE_FAST
Slew rate limiting disabled.
Definition gpio.h:228
@ GPIO_SLEW_RATE_SLOW
Slew rate limiting enabled.
Definition gpio.h:227
@ GPIO_OVERRIDE_INVERT
invert peripheral signal selected via gpio_set_function
Definition gpio.h:214
@ GPIO_OVERRIDE_HIGH
drive high/enable output
Definition gpio.h:216
@ GPIO_OVERRIDE_LOW
drive low/disable output
Definition gpio.h:215
@ GPIO_OVERRIDE_NORMAL
peripheral signal selected via gpio_set_function
Definition gpio.h:213
void(* irq_handler_t)(void)
Interrupt handler function type.
Definition irq.h:195
static __force_inline uint get_core_num(void)
Get the current core number.
Definition platform.h:114
Definition io_bank0.h:67