7 #ifndef _HARDWARE_GPIO_H     8 #define _HARDWARE_GPIO_H    11 #include "hardware/structs/sio.h"    12 #include "hardware/structs/padsbank0.h"    13 #include "hardware/structs/iobank0.h"    21 #ifndef PARAM_ASSERTIONS_ENABLED_GPIO    22 #define PARAM_ASSERTIONS_ENABLED_GPIO 0   101     GPIO_FUNC_NULL = 0x1f,
   123     GPIO_IRQ_LEVEL_LOW = 0x1u,
   124     GPIO_IRQ_LEVEL_HIGH = 0x2u,
   125     GPIO_IRQ_EDGE_FALL = 0x4u,
   126     GPIO_IRQ_EDGE_RISE = 0x8u,
   171 static inline void check_gpio_param(__unused uint gpio) {
   172     invalid_params_if(GPIO, gpio >= NUM_BANK0_GPIOS);
   224     return (padsbank0_hw->io[gpio] & PADS_BANK0_GPIO0_PUE_BITS) != 0;
   243     return (padsbank0_hw->io[gpio] & PADS_BANK0_GPIO0_PDE_BITS) != 0;
   384 #ifndef GPIO_IRQ_CALLBACK_ORDER_PRIORITY   385 #define GPIO_IRQ_CALLBACK_ORDER_PRIORITY PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY   389 #ifndef GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY   390 #define GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY   462     check_gpio_param(gpio);
   464                                       &iobank0_hw->proc1_irq_ctrl : &iobank0_hw->proc0_irq_ctrl;
   465     io_ro_32 *status_reg = &irq_ctrl_base->ints[gpio >> 3u];
   466     return (*status_reg >> (4 * (gpio & 7u))) & 0xfu;
   546     check_gpio_param(gpio);
   605     check_gpio_param(gpio);
   634     check_gpio_param(gpio);
   675     return !!((1ul << gpio) & sio_hw->gpio_in);
   684     return sio_hw->gpio_in;
   697     sio_hw->gpio_set = mask;
   706     sio_hw->gpio_clr = mask;
   715     sio_hw->gpio_togl = mask;
   730     sio_hw->gpio_togl = (sio_hw->gpio_out ^ value) & mask;
   739     sio_hw->gpio_out = value;
   748 static inline void gpio_put(uint gpio, 
bool value) {
   749     uint32_t mask = 1ul << gpio;
   773     return !!(sio_hw->gpio_out & (1u << gpio));
   788     sio_hw->gpio_oe_set = mask;
   797     sio_hw->gpio_oe_clr = mask;
   812     sio_hw->gpio_oe_togl = (sio_hw->gpio_oe ^ value) & mask;
   821     sio_hw->gpio_oe = values;
   831     uint32_t mask = 1ul << gpio;
   845     return !!(sio_hw->gpio_oe & (1u << (gpio)));
   858 extern void gpio_debug_pins_init(
void);
   866 #ifndef PICO_DEBUG_PIN_BASE   867 #define PICO_DEBUG_PIN_BASE 19u   871 #ifndef PICO_DEBUG_PIN_COUNT   872 #define PICO_DEBUG_PIN_COUNT 3u   877 #define CU_REGISTER_DEBUG_PINS(...) enum __unused DEBUG_PIN_TYPE { _none = 0, __VA_ARGS__ }; static enum DEBUG_PIN_TYPE __selected_debug_pins;   878 #define CU_SELECT_DEBUG_PINS(x) static enum DEBUG_PIN_TYPE __selected_debug_pins = (x);   879 #define DEBUG_PINS_ENABLED(p) (__selected_debug_pins == (p))   881 #define CU_REGISTER_DEBUG_PINS(p...) \   882     enum DEBUG_PIN_TYPE { _none = 0, p }; \   883     template <enum DEBUG_PIN_TYPE> class __debug_pin_settings { \   885             static inline bool enabled() { return false; } \   887 #define CU_SELECT_DEBUG_PINS(x) template<> inline bool __debug_pin_settings<x>::enabled() { return true; };   888 #define DEBUG_PINS_ENABLED(p) (__debug_pin_settings<p>::enabled())   890 #define DEBUG_PINS_SET(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_set_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)   891 #define DEBUG_PINS_CLR(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_clr_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)   892 #define DEBUG_PINS_XOR(p, v) if (DEBUG_PINS_ENABLED(p)) gpio_xor_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE) void gpio_set_slew_rate(uint gpio, enum gpio_slew_rate slew)
Set slew rate for a specified GPIO. 
Definition: gpio.c:110
 
Slew rate limiting disabled. 
Definition: gpio.h:155
 
drive high/enable output 
Definition: gpio.h:143
 
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 initializationsThis method is a slightl...
Definition: gpio.c:184
 
static void gpio_set_dir_in_masked(uint32_t mask)
Set a number of GPIOs to input. 
Definition: gpio.h:796
 
void gpio_remove_raw_irq_handler_masked(uint gpio_mask, irq_handler_t handler)
Removes a raw GPIO IRQ handler for the specified GPIOs on the current coreIn addition to the default ...
Definition: gpio.c:213
 
gpio_function
GPIO function definitions for use with function select. 
Definition: gpio.h:90
 
void gpio_set_irq_enabled(uint gpio, uint32_t event_mask, bool enabled)
Enable or disable specific interrupt events for specified GPIOThis function sets which GPIO events ca...
Definition: gpio.c:176
 
void gpio_set_input_hysteresis_enabled(uint gpio, bool enabled)
Enable/disable GPIO input hysteresis (Schmitt trigger)Enable or disable the Schmitt trigger hysteresi...
Definition: gpio.c:96
 
gpio_irq_level
GPIO Interrupt level definitions (GPIO events) 
Definition: gpio.h:122
 
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 coreIn addition to the default m...
Definition: gpio.h:633
 
enum gpio_slew_rate gpio_get_slew_rate(uint gpio)
Determine current slew rate for a specified GPIO. 
Definition: gpio.c:118
 
static void gpio_clr_mask(uint32_t mask)
Drive low every GPIO appearing in mask. 
Definition: gpio.h:705
 
gpio_slew_rate
Slew rate limiting levels for GPIO outputsSlew rate limiting increases the minimum rise/fall time whe...
Definition: gpio.h:153
 
void gpio_deinit(uint gpio)
Resets a GPIO back to the NULL function, i.e. disables it. 
Definition: gpio.c:252
 
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 coreIn addition to the default mechani...
Definition: gpio.h:545
 
enum gpio_drive_strength gpio_get_drive_strength(uint gpio)
Determine current slew rate for a specified GPIO. 
Definition: gpio.c:136
 
static void gpio_set_dir_out_masked(uint32_t mask)
Set a number of GPIOs to outputSwitch all GPIOs in "mask" to output. 
Definition: gpio.h:787
 
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 coreIn addition to the default mechani...
Definition: gpio.h:604
 
static void gpio_set_mask(uint32_t mask)
Drive high every GPIO appearing in mask. 
Definition: gpio.h:696
 
static void gpio_pull_down(uint gpio)
Set specified GPIO to be pulled down. 
Definition: gpio.h:232
 
static bool gpio_get(uint gpio)
Get state of a single specified GPIO. 
Definition: gpio.h:674
 
4 mA nominal drive strength 
Definition: gpio.h:166
 
void gpio_set_dormant_irq_enabled(uint gpio, uint32_t event_mask, bool enabled)
Enable dormant wake up interrupt for specified GPIO and eventsThis configures IRQs to restart the XOS...
Definition: gpio.c:219
 
void gpio_set_oeover(uint gpio, uint value)
Select GPIO output enable override. 
Definition: gpio.c:88
 
void gpio_add_raw_irq_handler_with_order_priority_masked(uint gpio_mask, irq_handler_t handler, uint8_t order_priority)
Adds a raw GPIO IRQ handler for the specified GPIOs on the current coreIn addition to the default mec...
Definition: gpio.c:203
 
void gpio_set_outover(uint gpio, uint value)
Set GPIO output override. 
Definition: gpio.c:80
 
static bool gpio_get_out_level(uint gpio)
Determine whether a GPIO is currently driven high or lowThis function returns the high/low output lev...
Definition: gpio.h:772
 
peripheral signal selected via gpio_set_function 
Definition: gpio.h:140
 
invert peripheral signal selected via gpio_set_function 
Definition: gpio.h:141
 
void gpio_init_mask(uint gpio_mask)
Initialise multiple GPIOs (enabled I/O and set func to GPIO_FUNC_SIO)Clear the output enable (i...
Definition: gpio.c:256
 
void gpio_set_irq_callback(gpio_irq_callback_t callback)
Set the generic callback used for GPIO IRQ events for the current coreThis function sets the callback...
Definition: gpio.c:190
 
enum gpio_function gpio_get_function(uint gpio)
Determine current GPIO function. 
Definition: gpio.c:46
 
void gpio_set_pulls(uint gpio, bool up, bool down)
Select up and down pulls on specific GPIO. 
Definition: gpio.c:53
 
void gpio_set_irqover(uint gpio, uint value)
Set GPIO IRQ overrideOptionally invert a GPIO IRQ signal, or drive it high or low. 
Definition: gpio.c:63
 
static bool gpio_is_pulled_up(uint gpio)
Determine if the specified GPIO is pulled up. 
Definition: gpio.h:223
 
void gpio_set_inover(uint gpio, uint value)
Select GPIO input override. 
Definition: gpio.c:72
 
void gpio_set_input_enabled(uint gpio, bool enabled)
Enable GPIO input. 
Definition: gpio.c:239
 
void gpio_set_function(uint gpio, enum gpio_function fn)
Select GPIO function. 
Definition: gpio.c:32
 
8 mA nominal drive strength 
Definition: gpio.h:167
 
static void gpio_xor_mask(uint32_t mask)
Toggle every GPIO appearing in mask. 
Definition: gpio.h:714
 
static void gpio_put_all(uint32_t value)
Drive all pins simultaneously. 
Definition: gpio.h:738
 
12 mA nominal drive strength 
Definition: gpio.h:168
 
static uint32_t gpio_get_irq_event_mask(uint gpio)
Return the current interrupt status (pending events) for the given GPIO. 
Definition: gpio.h:461
 
void gpio_set_drive_strength(uint gpio, enum gpio_drive_strength drive)
Set drive strength for a specified GPIO. 
Definition: gpio.c:128
 
static void gpio_set_dir_masked(uint32_t mask, uint32_t value)
Set multiple GPIO directions. 
Definition: gpio.h:811
 
static void gpio_set_dir_all_bits(uint32_t values)
Set direction of all pins simultaneously. 
Definition: gpio.h:820
 
gpio_drive_strength
Drive strength levels for GPIO outputsDrive strength levels for GPIO outputs. 
Definition: gpio.h:164
 
void(* irq_handler_t)(void)
Interrupt handler function typeAll interrupts handlers should be of this type, and follow normal ARM ...
Definition: irq.h:128
 
static bool gpio_is_pulled_down(uint gpio)
Determine if the specified GPIO is pulled down. 
Definition: gpio.h:242
 
void(* gpio_irq_callback_t)(uint gpio, uint32_t event_mask)
Definition: gpio.h:137
 
static uint32_t gpio_get_all(void)
Get raw value of all GPIOs. 
Definition: gpio.h:683
 
void gpio_init(uint gpio)
Initialise a GPIO for (enabled I/O and set func to GPIO_FUNC_SIO)Clear the output enable (i...
Definition: gpio.c:246
 
static void gpio_put_masked(uint32_t mask, uint32_t value)
Drive GPIO high/low depending on parameters. 
Definition: gpio.h:729
 
static uint gpio_get_dir(uint gpio)
Get a specific GPIO direction. 
Definition: gpio.h:854
 
void gpio_acknowledge_irq(uint gpio, uint32_t event_mask)
Acknowledge a GPIO interrupt for the specified events on the calling core. 
Definition: gpio.c:225
 
static bool gpio_is_dir_out(uint gpio)
Check if a specific GPIO direction is OUT. 
Definition: gpio.h:844
 
static void gpio_put(uint gpio, bool value)
Drive a single GPIO high/low. 
Definition: gpio.h:748
 
2 mA nominal drive strength 
Definition: gpio.h:165
 
bool gpio_is_input_hysteresis_enabled(uint gpio)
Determine whether input hysteresis is enabled on a specified GPIO. 
Definition: gpio.c:105
 
gpio_override
Definition: gpio.h:139
 
void gpio_add_raw_irq_handler_masked(uint gpio_mask, irq_handler_t handler)
Adds a raw GPIO IRQ handler for the specified GPIOs on the current coreIn addition to the default mec...
Definition: gpio.c:209
 
static void gpio_pull_up(uint gpio)
Set specified GPIO to be pulled up. 
Definition: gpio.h:213
 
static void gpio_set_dir(uint gpio, bool out)
Set a single GPIO direction. 
Definition: gpio.h:830
 
drive low/disable output 
Definition: gpio.h:142
 
Slew rate limiting enabled. 
Definition: gpio.h:154
 
static void gpio_disable_pulls(uint gpio)
Disable pulls on specified GPIO. 
Definition: gpio.h:251