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
277#if NUM_BANK0_GPIOS <= 32
278static inline void gpio_set_function_masked64(uint64_t gpio_mask, gpio_function_t fn) {
279 gpio_set_function_masked((uint32_t)gpio_mask, fn);
280}
281#else
282void gpio_set_function_masked64(uint64_t gpio_mask, gpio_function_t fn);
283#endif
284
292
303void gpio_set_pulls(uint gpio, bool up, bool down);
304
310static inline void gpio_pull_up(uint gpio) {
311 gpio_set_pulls(gpio, true, false);
312}
313
320static inline bool gpio_is_pulled_up(uint gpio) {
321 return (pads_bank0_hw->io[gpio] & PADS_BANK0_GPIO0_PUE_BITS) != 0;
322}
323
329static inline void gpio_pull_down(uint gpio) {
330 gpio_set_pulls(gpio, false, true);
331}
332
339static inline bool gpio_is_pulled_down(uint gpio) {
340 return (pads_bank0_hw->io[gpio] & PADS_BANK0_GPIO0_PDE_BITS) != 0;
341}
342
348static inline void gpio_disable_pulls(uint gpio) {
349 gpio_set_pulls(gpio, false, false);
350}
351
360void gpio_set_irqover(uint gpio, uint value);
361
368void gpio_set_outover(uint gpio, uint value);
369
376void gpio_set_inover(uint gpio, uint value);
377
384void gpio_set_oeover(uint gpio, uint value);
385
392void gpio_set_input_enabled(uint gpio, bool enabled);
393
406void gpio_set_input_hysteresis_enabled(uint gpio, bool enabled);
407
415
423void gpio_set_slew_rate(uint gpio, enum gpio_slew_rate slew);
424
432enum gpio_slew_rate gpio_get_slew_rate(uint gpio);
433
441void gpio_set_drive_strength(uint gpio, enum gpio_drive_strength drive);
442
451
477void gpio_set_irq_enabled(uint gpio, uint32_t event_mask, bool enabled);
478
479// 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
480#ifndef GPIO_IRQ_CALLBACK_ORDER_PRIORITY
481#define GPIO_IRQ_CALLBACK_ORDER_PRIORITY PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY
482#endif
483
484// 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
485#ifndef GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY
486#define GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY
487#endif
488
504
536void gpio_set_irq_enabled_with_callback(uint gpio, uint32_t event_mask, bool enabled, gpio_irq_callback_t callback);
537
548void gpio_set_dormant_irq_enabled(uint gpio, uint32_t event_mask, bool enabled);
549
550static __force_inline io_bank0_irq_ctrl_hw_t *get_core_irq_ctrl(uint core_num) {
551 return &io_bank0_hw->irq_ctrl[core_num];
552}
553
561static inline uint32_t gpio_get_irq_event_mask(uint gpio) {
562 check_gpio_param(gpio);
563 io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_irq_ctrl(get_core_num());
564 io_ro_32 *status_reg = &irq_ctrl_base->ints[gpio >> 3u];
565 return (*status_reg >> (4 * (gpio & 7u))) & 0xfu;
566}
567
582static inline void gpio_acknowledge_irq(uint gpio, uint32_t event_mask) {
583 check_gpio_param(gpio);
584 io_bank0_hw->intr[gpio / 8] = event_mask << (4 * (gpio % 8));
585}
586
620void gpio_add_raw_irq_handler_with_order_priority_masked(uint32_t gpio_mask, irq_handler_t handler, uint8_t order_priority);
621
655void gpio_add_raw_irq_handler_with_order_priority_masked64(uint64_t gpio_mask, irq_handler_t handler, uint8_t order_priority);
656
686static inline void gpio_add_raw_irq_handler_with_order_priority(uint gpio, irq_handler_t handler, uint8_t order_priority) {
687 check_gpio_param(gpio);
688#if NUM_BANK0_GPIOS > 32
689 gpio_add_raw_irq_handler_with_order_priority_masked64(1ull << gpio, handler, order_priority);
690#else
691 gpio_add_raw_irq_handler_with_order_priority_masked(1u << gpio, handler, order_priority);
692#endif
693}
694
725void gpio_add_raw_irq_handler_masked(uint32_t gpio_mask, irq_handler_t handler);
726
757void gpio_add_raw_irq_handler_masked64(uint64_t gpio_mask, irq_handler_t handler);
758
785static inline void gpio_add_raw_irq_handler(uint gpio, irq_handler_t handler) {
786 check_gpio_param(gpio);
787#if NUM_BANK0_GPIOS > 32
788 gpio_add_raw_irq_handler_masked64(1ull << gpio, handler);
789#else
790 gpio_add_raw_irq_handler_masked(1u << gpio, handler);
791#endif
792}
793
807void gpio_remove_raw_irq_handler_masked(uint32_t gpio_mask, irq_handler_t handler);
808
820void gpio_remove_raw_irq_handler_masked64(uint64_t gpio_mask, irq_handler_t handler);
821
833static inline void gpio_remove_raw_irq_handler(uint gpio, irq_handler_t handler) {
834 check_gpio_param(gpio);
835#if NUM_BANK0_GPIOS > 32
836 gpio_remove_raw_irq_handler_masked64(1ull << gpio, handler);
837#else
838 gpio_remove_raw_irq_handler_masked(1u << gpio, handler);
839#endif
840}
841
850void gpio_init(uint gpio);
851
857void gpio_deinit(uint gpio);
858
867void gpio_init_mask(uint32_t gpio_mask);
868
877#if NUM_BANK0_GPIOS <= 32
878static inline void gpio_init_mask64(uint64_t gpio_mask) {
879 gpio_init_mask((uint32_t)gpio_mask);
880}
881#else
882void gpio_init_mask64(uint64_t gpio_mask);
883#endif
884// ----------------------------------------------------------------------------
885// Input
886// ----------------------------------------------------------------------------
887
894static inline bool gpio_get(uint gpio) {
895#if NUM_BANK0_GPIOS <= 32
896 return sio_hw->gpio_in & (1u << gpio);
897#else
898 if (gpio < 32) {
899 return sio_hw->gpio_in & (1u << gpio);
900 } else {
901 return sio_hw->gpio_hi_in & (1u << (gpio - 32));
902 }
903#endif
904}
905
911static inline uint32_t gpio_get_all(void) {
912#if PICO_USE_GPIO_COPROCESSOR
913 return gpioc_lo_in_get();
914#else
915 return sio_hw->gpio_in;
916#endif
917}
918
924static inline uint64_t gpio_get_all64(void) {
925#if PICO_USE_GPIO_COPROCESSOR
926 return gpioc_hilo_in_get();
927#elif NUM_BANK0_GPIOS <= 32
928 return sio_hw->gpio_in;
929#else
930 return sio_hw->gpio_in | (((uint64_t)sio_hw->gpio_hi_in) << 32u);
931#endif
932}
933
934// ----------------------------------------------------------------------------
935// Output
936// ----------------------------------------------------------------------------
937
943static inline void gpio_set_mask(uint32_t mask) {
944#if PICO_USE_GPIO_COPROCESSOR
945 gpioc_lo_out_set(mask);
946#else
947 sio_hw->gpio_set = mask;
948#endif
949}
950
956static inline void gpio_set_mask64(uint64_t mask) {
957#if PICO_USE_GPIO_COPROCESSOR
958 gpioc_hilo_out_set(mask);
959#elif NUM_BANK0_GPIOS <= 32
960 sio_hw->gpio_set = (uint32_t)mask;
961#else
962 sio_hw->gpio_set = (uint32_t)mask;
963 sio_hw->gpio_hi_set = (uint32_t)(mask >> 32u);
964#endif
965}
966
973static inline void gpio_set_mask_n(uint n, uint32_t mask) {
974 if (!n) {
975 gpio_set_mask(mask);
976 } else if (n == 1) {
977#if PICO_USE_GPIO_COPROCESSOR
978 gpioc_hi_out_set(mask);
979#elif NUM_BANK0_GPIOS >= 32
980 sio_hw->gpio_hi_set = mask;
981#endif
982 }
983}
984
990static inline void gpio_clr_mask(uint32_t mask) {
991#if PICO_USE_GPIO_COPROCESSOR
992 gpioc_lo_out_clr(mask);
993#else
994 sio_hw->gpio_clr = mask;
995#endif
996}
997
1003static inline void gpio_clr_mask64(uint64_t mask) {
1004#if PICO_USE_GPIO_COPROCESSOR
1005 gpioc_hilo_out_clr(mask);
1006#elif NUM_BANK0_GPIOS <= 32
1007 sio_hw->gpio_clr = (uint32_t)mask;
1008#else
1009 sio_hw->gpio_clr = (uint32_t)mask;
1010 sio_hw->gpio_hi_clr = (uint32_t)(mask >> 32u);
1011#endif
1012}
1013
1014
1021static inline void gpio_clr_mask_n(uint n, uint32_t mask) {
1022 if (!n) {
1023 gpio_clr_mask(mask);
1024 } else if (n == 1) {
1025#if PICO_USE_GPIO_COPROCESSOR
1026 gpioc_hi_out_clr(mask);
1027#elif NUM_BANK0_GPIOS >= 32
1028 sio_hw->gpio_hi_clr = mask;
1029#endif
1030 }
1031}
1032
1038static inline void gpio_xor_mask(uint32_t mask) {
1039#if PICO_USE_GPIO_COPROCESSOR
1040 gpioc_lo_out_xor(mask);
1041#else
1042 sio_hw->gpio_togl = mask;
1043#endif
1044}
1045
1051static inline void gpio_xor_mask64(uint64_t mask) {
1052#if PICO_USE_GPIO_COPROCESSOR
1053 gpioc_hilo_out_xor(mask);
1054#elif NUM_BANK0_GPIOS <= 32
1055 sio_hw->gpio_togl = (uint32_t)mask;
1056#else
1057 sio_hw->gpio_togl = (uint32_t)mask;
1058 sio_hw->gpio_hi_togl = (uint32_t)(mask >> 32u);
1059#endif
1060}
1061
1068static inline void gpio_xor_mask_n(uint n, uint32_t mask) {
1069 if (!n) {
1070 gpio_xor_mask(mask);
1071 } else if (n == 1) {
1072#if PICO_USE_GPIO_COPROCESSOR
1073 gpioc_hi_out_xor(mask);
1074#elif NUM_BANK0_GPIOS >= 32
1075 sio_hw->gpio_hi_togl = mask;
1076#endif
1077 }
1078}
1079
1091static inline void gpio_put_masked(uint32_t mask, uint32_t value) {
1092#if PICO_USE_GPIO_COPROCESSOR
1093 gpioc_lo_out_xor((gpioc_lo_out_get() ^ value) & mask);
1094#else
1095 sio_hw->gpio_togl = (sio_hw->gpio_out ^ value) & mask;
1096#endif
1097}
1098
1110static inline void gpio_put_masked64(uint64_t mask, uint64_t value) {
1111#if PICO_USE_GPIO_COPROCESSOR
1112 gpioc_hilo_out_xor((gpioc_hilo_out_get() ^ value) & mask);
1113#elif NUM_BANK0_GPIOS <= 32
1114 sio_hw->gpio_togl = (sio_hw->gpio_out ^ (uint32_t)value) & (uint32_t)mask;
1115#else
1116 sio_hw->gpio_togl = (sio_hw->gpio_out ^ (uint32_t)value) & (uint32_t)mask;
1117 sio_hw->gpio_hi_togl = (sio_hw->gpio_hi_out ^ (uint32_t)(value>>32u)) & (uint32_t)(mask>>32u);
1118#endif
1119}
1120
1133static inline void gpio_put_masked_n(uint n, uint32_t mask, uint32_t value) {
1134 if (!n) {
1135 gpio_put_masked(mask, value);
1136 } else if (n == 1) {
1137#if PICO_USE_GPIO_COPROCESSOR
1138 gpioc_hi_out_xor((gpioc_hi_out_get() ^ value) & mask);
1139#else
1140 sio_hw->gpio_hi_togl = (sio_hw->gpio_hi_out ^ value) & mask;
1141#endif
1142 }
1143}
1144
1150static inline void gpio_put_all(uint32_t value) {
1151#if PICO_USE_GPIO_COPROCESSOR
1152 gpioc_lo_out_put(value);
1153#else
1154 sio_hw->gpio_out = value;
1155#endif
1156}
1157
1163static inline void gpio_put_all64(uint64_t value) {
1164#if PICO_USE_GPIO_COPROCESSOR
1165 gpioc_hilo_out_put(value);
1166#elif NUM_BANK0_GPIOS <= 32
1167 sio_hw->gpio_out = (uint32_t)value;
1168#else
1169 sio_hw->gpio_out = (uint32_t)value;
1170 sio_hw->gpio_hi_out = (uint32_t)(value >> 32u);
1171#endif
1172}
1173
1180static inline void gpio_put(uint gpio, bool value) {
1181#if PICO_USE_GPIO_COPROCESSOR
1182 gpioc_bit_out_put(gpio, value);
1183#elif NUM_BANK0_GPIOS <= 32
1184 uint32_t mask = 1ul << gpio;
1185 if (value)
1186 gpio_set_mask(mask);
1187 else
1188 gpio_clr_mask(mask);
1189#else
1190 uint32_t mask = 1ul << (gpio & 0x1fu);
1191 if (gpio < 32) {
1192 if (value) {
1193 sio_hw->gpio_set = mask;
1194 } else {
1195 sio_hw->gpio_clr = mask;
1196 }
1197 } else {
1198 if (value) {
1199 sio_hw->gpio_hi_set = mask;
1200 } else {
1201 sio_hw->gpio_hi_clr = mask;
1202 }
1203 }
1204#endif
1205}
1206
1223static inline bool gpio_get_out_level(uint gpio) {
1224#if NUM_BANK0_GPIOS <= 32
1225 return sio_hw->gpio_out & (1u << gpio);
1226#else
1227 uint32_t bits = gpio < 32 ? sio_hw->gpio_out : sio_hw->gpio_hi_out;
1228 return bits & (1u << (gpio & 0x1fu));
1229#endif
1230}
1231
1232// ----------------------------------------------------------------------------
1233// Direction
1234// ----------------------------------------------------------------------------
1235
1243static inline void gpio_set_dir_out_masked(uint32_t mask) {
1244#if PICO_USE_GPIO_COPROCESSOR
1245 gpioc_lo_oe_set(mask);
1246#else
1247 sio_hw->gpio_oe_set = mask;
1248#endif
1249}
1250
1258static inline void gpio_set_dir_out_masked64(uint64_t mask) {
1259#if PICO_USE_GPIO_COPROCESSOR
1260 gpioc_hilo_oe_set(mask);
1261#elif NUM_BANK0_GPIOS <= 32
1262 sio_hw->gpio_oe_set = mask;
1263#else
1264 sio_hw->gpio_oe_set = (uint32_t)mask;
1265 sio_hw->gpio_hi_oe_set = (uint32_t)(mask >> 32u);
1266#endif
1267}
1268
1274static inline void gpio_set_dir_in_masked(uint32_t mask) {
1275#if PICO_USE_GPIO_COPROCESSOR
1276 gpioc_lo_oe_clr(mask);
1277#else
1278 sio_hw->gpio_oe_clr = mask;
1279#endif
1280}
1281
1287static inline void gpio_set_dir_in_masked64(uint64_t mask) {
1288#if PICO_USE_GPIO_COPROCESSOR
1289 gpioc_hilo_oe_clr(mask);
1290#elif NUM_BANK0_GPIOS <= 32
1291 sio_hw->gpio_oe_clr = mask;
1292#else
1293 sio_hw->gpio_oe_clr = (uint32_t)mask;
1294 sio_hw->gpio_hi_oe_clr = (uint32_t)(mask >> 32u);
1295#endif
1296}
1297
1309static inline void gpio_set_dir_masked(uint32_t mask, uint32_t value) {
1310#if PICO_USE_GPIO_COPROCESSOR
1311 gpioc_lo_oe_xor((gpioc_lo_oe_get() ^ value) & mask);
1312#else
1313 sio_hw->gpio_oe_togl = (sio_hw->gpio_oe ^ value) & mask;
1314#endif
1315}
1316
1328static inline void gpio_set_dir_masked64(uint64_t mask, uint64_t value) {
1329#if PICO_USE_GPIO_COPROCESSOR
1330 gpioc_hilo_oe_xor((gpioc_hilo_oe_get() ^ value) & mask);
1331#elif NUM_BANK0_GPIOS <= 32
1332 sio_hw->gpio_oe_togl = (sio_hw->gpio_oe ^ (uint32_t)value) & (uint32_t)mask;
1333#else
1334 sio_hw->gpio_oe_togl = (sio_hw->gpio_oe ^ (uint32_t)value) & (uint32_t)mask;
1335 sio_hw->gpio_hi_oe_togl = (sio_hw->gpio_hi_oe ^ (uint32_t)(value >> 32u)) & (uint32_t)(mask >> 32u);
1336#endif
1337}
1338
1339
1345static inline void gpio_set_dir_all_bits(uint32_t values) {
1346#if PICO_USE_GPIO_COPROCESSOR
1347 gpioc_lo_oe_put(values);
1348#else
1349 sio_hw->gpio_oe = values;
1350#endif
1351}
1352
1358static inline void gpio_set_dir_all_bits64(uint64_t values) {
1359#if PICO_USE_GPIO_COPROCESSOR
1360 gpioc_hilo_oe_put(values);
1361#elif NUM_BANK0_GPIOS <= 32
1362 sio_hw->gpio_oe = (uint32_t)values;
1363#else
1364 sio_hw->gpio_oe = (uint32_t)values;
1365 sio_hw->gpio_hi_oe = (uint32_t)(values >> 32u);
1366#endif
1367}
1368
1375static inline void gpio_set_dir(uint gpio, bool out) {
1376#if PICO_USE_GPIO_COPROCESSOR
1377 gpioc_bit_oe_put(gpio, out);
1378#elif PICO_RP2040 || NUM_BANK0_GPIOS <= 32
1379 uint32_t mask = 1ul << gpio;
1380 if (out)
1382 else
1384#else
1385 uint32_t mask = 1u << (gpio & 0x1fu);
1386 if (gpio < 32) {
1387 if (out) {
1388 sio_hw->gpio_oe_set = mask;
1389 } else {
1390 sio_hw->gpio_oe_clr = mask;
1391 }
1392 } else {
1393 if (out) {
1394 sio_hw->gpio_hi_oe_set = mask;
1395 } else {
1396 sio_hw->gpio_hi_oe_clr = mask;
1397 }
1398 }
1399#endif
1400}
1401
1408static inline bool gpio_is_dir_out(uint gpio) {
1409#if NUM_BANK0_GPIOS <= 32
1410 return sio_hw->gpio_oe & (1u << (gpio));
1411#else
1412 uint32_t bits = gpio < 32 ? sio_hw->gpio_oe : sio_hw->gpio_hi_oe;
1413 return bits & (1u << (gpio & 0x1fu));
1414#endif
1415}
1416
1423static inline uint gpio_get_dir(uint gpio) {
1424 return gpio_is_dir_out(gpio); // note GPIO_OUT is 1/true and GPIO_IN is 0/false anyway
1425}
1426
1427#if PICO_SECURE
1428static inline void gpio_assign_to_ns(uint gpio, bool ns) {
1429 check_gpio_param(gpio);
1430 if (ns) hw_set_bits(&accessctrl_hw->gpio_nsmask[gpio/32], 1u << (gpio & 0x1fu));
1431 else hw_clear_bits(&accessctrl_hw->gpio_nsmask[gpio/32], 1u << (gpio & 0x1fu));
1432}
1433#endif
1434extern void gpio_debug_pins_init(void);
1435
1436#ifdef __cplusplus
1437}
1438#endif
1439
1440
1441// 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
1442#ifndef PICO_DEBUG_PIN_BASE
1443#define PICO_DEBUG_PIN_BASE 19u
1444#endif
1445
1446// 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
1447#ifndef PICO_DEBUG_PIN_COUNT
1448#define PICO_DEBUG_PIN_COUNT 3u
1449#endif
1450
1451#ifndef __cplusplus
1452// note these two macros may only be used once per and only apply per compilation unit (hence the CU_)
1453#define CU_REGISTER_DEBUG_PINS(...) enum __unused DEBUG_PIN_TYPE { _none = 0, __VA_ARGS__ }; static enum DEBUG_PIN_TYPE __selected_debug_pins;
1454#define CU_SELECT_DEBUG_PINS(x) static enum DEBUG_PIN_TYPE __selected_debug_pins = (x);
1455#define DEBUG_PINS_ENABLED(p) (__selected_debug_pins == (p))
1456#else
1457#define CU_REGISTER_DEBUG_PINS(p...) \
1458 enum DEBUG_PIN_TYPE { _none = 0, p }; \
1459 template <enum DEBUG_PIN_TYPE> class __debug_pin_settings { \
1460 public: \
1461 static inline bool enabled() { return false; } \
1462 };
1463#define CU_SELECT_DEBUG_PINS(x) template<> inline bool __debug_pin_settings<x>::enabled() { return true; };
1464#define DEBUG_PINS_ENABLED(p) (__debug_pin_settings<p>::enabled())
1465#endif
1466#define DEBUG_PINS_SET(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_set_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
1467#define DEBUG_PINS_CLR(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_clr_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
1468#define DEBUG_PINS_XOR(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_xor_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
1469
1470#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:686
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:1223
static void gpio_put_all64(uint64_t value)
Drive all pins simultaneously.
Definition gpio.h:1163
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:251
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_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:235
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:239
static uint gpio_get_dir(uint gpio)
Get a specific GPIO direction.
Definition gpio.h:1423
static void gpio_set_dir_masked64(uint64_t mask, uint64_t value)
Set multiple GPIO directions.
Definition gpio.h:1328
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:785
static void gpio_pull_up(uint gpio)
Set specified GPIO to be pulled up.
Definition gpio.h:310
void gpio_set_function_masked(uint32_t gpio_mask, gpio_function_t fn)
Select the function for multiple GPIOs.
Definition gpio.c:284
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:206
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:833
void gpio_deinit(uint gpio)
Resets a GPIO back to the NULL function, i.e. disables it.
Definition gpio.c:280
static void gpio_set_dir_all_bits(uint32_t values)
Set direction of all pins simultaneously.
Definition gpio.h:1345
static void gpio_set_function_masked64(uint64_t gpio_mask, gpio_function_t fn)
Select the function for multiple GPIOs.
Definition gpio.h:278
static bool gpio_is_pulled_down(uint gpio)
Determine if the specified GPIO is pulled down.
Definition gpio.h:339
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:197
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:1038
static void gpio_init_mask64(uint64_t gpio_mask)
Initialise multiple GPIOs (enabled I/O and set func to GPIO_FUNC_SIO).
Definition gpio.h:878
static void gpio_set_dir(uint gpio, bool out)
Set a single GPIO direction.
Definition gpio.h:1375
static void gpio_clr_mask(uint32_t mask)
Drive low every GPIO appearing in mask.
Definition gpio.h:990
static void gpio_put_masked_n(uint n, uint32_t mask, uint32_t value)
Drive GPIOs high/low depending on parameters.
Definition gpio.h:1133
static void gpio_set_dir_out_masked64(uint64_t mask)
Set a number of GPIOs to output.
Definition gpio.h:1258
static void gpio_put(uint gpio, bool value)
Drive a single GPIO high/low.
Definition gpio.h:1180
static void gpio_xor_mask_n(uint n, uint32_t mask)
Toggle every GPIO appearing in mask.
Definition gpio.h:1068
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:266
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:225
static void gpio_set_dir_in_masked(uint32_t mask)
Set a number of GPIOs to input.
Definition gpio.h:1274
static void gpio_put_all(uint32_t value)
Drive all pins simultaneously.
Definition gpio.h:1150
static void gpio_set_dir_out_masked(uint32_t mask)
Set a number of GPIOs to output.
Definition gpio.h:1243
void gpio_set_outover(uint gpio, uint value)
Set GPIO output override.
Definition gpio.c:90
void gpio_init_mask(uint32_t gpio_mask)
Initialise multiple GPIOs (enabled I/O and set func to GPIO_FUNC_SIO).
Definition gpio.c:294
enum gpio_function_rp2350 gpio_function_t
GPIO pin function selectors on RP2350 (used as typedef gpio_function_t).
void gpio_init(uint gpio)
Initialise a GPIO for (enabled I/O and set func to GPIO_FUNC_SIO).
Definition gpio.c:274
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:245
static void gpio_set_mask_n(uint n, uint32_t mask)
Drive high every GPIO appearing in mask.
Definition gpio.h:973
static void gpio_clr_mask_n(uint n, uint32_t mask)
Drive low every GPIO appearing in mask.
Definition gpio.h:1021
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:956
static bool gpio_is_dir_out(uint gpio)
Check if a specific GPIO direction is OUT.
Definition gpio.h:1408
static uint64_t gpio_get_all64(void)
Get raw value of all GPIOs.
Definition gpio.h:924
static void gpio_put_masked64(uint64_t mask, uint64_t value)
Drive GPIOs high/low depending on parameters.
Definition gpio.h:1110
static void gpio_set_dir_masked(uint32_t mask, uint32_t value)
Set multiple GPIO directions.
Definition gpio.h:1309
static void gpio_clr_mask64(uint64_t mask)
Drive low every GPIO appearing in mask.
Definition gpio.h:1003
static void gpio_set_dir_all_bits64(uint64_t values)
Set direction of all pins simultaneously.
Definition gpio.h:1358
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:1051
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:1287
static bool gpio_is_pulled_up(uint gpio)
Determine if the specified GPIO is pulled up.
Definition gpio.h:320
static void gpio_put_masked(uint32_t mask, uint32_t value)
Drive GPIOs high/low depending on parameters.
Definition gpio.h:1091
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:582
static void gpio_disable_pulls(uint gpio)
Disable pulls on specified GPIO.
Definition gpio.h:348
static uint32_t gpio_get_all(void)
Get raw value of all GPIOs.
Definition gpio.h:911
static void gpio_pull_down(uint gpio)
Set specified GPIO to be pulled down.
Definition gpio.h:329
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:561
static bool gpio_get(uint gpio)
Get state of a single specified GPIO.
Definition gpio.h:894
static void gpio_set_mask(uint32_t mask)
Drive high every GPIO appearing in mask.
Definition gpio.h:943
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:219
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:231
@ 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:206
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition compiler.h:128
static __force_inline uint get_core_num(void)
Get the current core number.
Definition platform.h:128
Definition io_bank0.h:65