gpio.h File Reference
#include "pico.h"
#include "hardware/structs/sio.h"
#include "hardware/structs/padsbank0.h"
#include "hardware/structs/iobank0.h"
#include "hardware/irq.h"
Include dependency graph for gpio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PARAM_ASSERTIONS_ENABLED_GPIO   0
 
#define GPIO_OUT   1
 
#define GPIO_IN   0
 
#define GPIO_IRQ_CALLBACK_ORDER_PRIORITY   PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY
 
#define GPIO_RAW_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY   PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY
 
#define PICO_DEBUG_PIN_BASE   19u
 
#define PICO_DEBUG_PIN_COUNT   3u
 
#define CU_REGISTER_DEBUG_PINS(...)   enum __unused DEBUG_PIN_TYPE { _none = 0, __VA_ARGS__ }; static enum DEBUG_PIN_TYPE __selected_debug_pins;
 
#define CU_SELECT_DEBUG_PINS(x)   static enum DEBUG_PIN_TYPE __selected_debug_pins = (x);
 
#define DEBUG_PINS_ENABLED(p)   (__selected_debug_pins == (p))
 
#define DEBUG_PINS_SET(p, v)   if (DEBUG_PINS_ENABLED(p)) gpio_set_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
 
#define DEBUG_PINS_CLR(p, v)   if (DEBUG_PINS_ENABLED(p)) gpio_clr_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
 
#define DEBUG_PINS_XOR(p, v)   if (DEBUG_PINS_ENABLED(p)) gpio_xor_mask((unsigned)(v)<<PICO_DEBUG_PIN_BASE)
 

Typedefs

typedef void(* gpio_irq_callback_t) (uint gpio, uint32_t event_mask)
 

Enumerations

enum  gpio_function {
  GPIO_FUNC_XIP = 0, GPIO_FUNC_SPI = 1, GPIO_FUNC_UART = 2, GPIO_FUNC_I2C = 3,
  GPIO_FUNC_PWM = 4, GPIO_FUNC_SIO = 5, GPIO_FUNC_PIO0 = 6, GPIO_FUNC_PIO1 = 7,
  GPIO_FUNC_GPCK = 8, GPIO_FUNC_USB = 9, GPIO_FUNC_NULL = 0x1f
}
 GPIO function definitions for use with function select. More...
 
enum  gpio_irq_level { GPIO_IRQ_LEVEL_LOW = 0x1u, GPIO_IRQ_LEVEL_HIGH = 0x2u, GPIO_IRQ_EDGE_FALL = 0x4u, GPIO_IRQ_EDGE_RISE = 0x8u }
 GPIO Interrupt level definitions (GPIO events) More...
 
enum  gpio_override { GPIO_OVERRIDE_NORMAL = 0, GPIO_OVERRIDE_INVERT = 1, GPIO_OVERRIDE_LOW = 2, GPIO_OVERRIDE_HIGH = 3 }
 
enum  gpio_slew_rate { GPIO_SLEW_RATE_SLOW = 0, GPIO_SLEW_RATE_FAST = 1 }
 Slew rate limiting levels for GPIO outputsSlew rate limiting increases the minimum rise/fall time when a GPIO output is lightly loaded, which can help to reduce electromagnetic emissions. More...
 
enum  gpio_drive_strength { GPIO_DRIVE_STRENGTH_2MA = 0, GPIO_DRIVE_STRENGTH_4MA = 1, GPIO_DRIVE_STRENGTH_8MA = 2, GPIO_DRIVE_STRENGTH_12MA = 3 }
 Drive strength levels for GPIO outputsDrive strength levels for GPIO outputs. More...
 

Functions

static void check_gpio_param (__unused uint gpio)
 
void gpio_set_function (uint gpio, enum gpio_function fn)
 Select GPIO function. More...
 
enum gpio_function gpio_get_function (uint gpio)
 Determine current GPIO function. More...
 
void gpio_set_pulls (uint gpio, bool up, bool down)
 Select up and down pulls on specific GPIO. More...
 
static void gpio_pull_up (uint gpio)
 Set specified GPIO to be pulled up. More...
 
static bool gpio_is_pulled_up (uint gpio)
 Determine if the specified GPIO is pulled up. More...
 
static void gpio_pull_down (uint gpio)
 Set specified GPIO to be pulled down. More...
 
static bool gpio_is_pulled_down (uint gpio)
 Determine if the specified GPIO is pulled down. More...
 
static void gpio_disable_pulls (uint gpio)
 Disable pulls on specified GPIO. More...
 
void gpio_set_irqover (uint gpio, uint value)
 Set GPIO IRQ overrideOptionally invert a GPIO IRQ signal, or drive it high or low. More...
 
void gpio_set_outover (uint gpio, uint value)
 Set GPIO output override. More...
 
void gpio_set_inover (uint gpio, uint value)
 Select GPIO input override. More...
 
void gpio_set_oeover (uint gpio, uint value)
 Select GPIO output enable override. More...
 
void gpio_set_input_enabled (uint gpio, bool enabled)
 Enable GPIO input. More...
 
void gpio_set_input_hysteresis_enabled (uint gpio, bool enabled)
 Enable/disable GPIO input hysteresis (Schmitt trigger)Enable or disable the Schmitt trigger hysteresis on a given GPIO. This is enabled on all GPIOs by default. Disabling input hysteresis can lead to inconsistent readings when the input signal has very long rise or fall times, but slightly reduces the GPIO's input delay. More...
 
bool gpio_is_input_hysteresis_enabled (uint gpio)
 Determine whether input hysteresis is enabled on a specified GPIO. More...
 
void gpio_set_slew_rate (uint gpio, enum gpio_slew_rate slew)
 Set slew rate for a specified GPIO. More...
 
enum gpio_slew_rate gpio_get_slew_rate (uint gpio)
 Determine current slew rate for a specified GPIO. More...
 
void gpio_set_drive_strength (uint gpio, enum gpio_drive_strength drive)
 Set drive strength for a specified GPIO. More...
 
enum gpio_drive_strength gpio_get_drive_strength (uint gpio)
 Determine current slew rate for a specified GPIO. More...
 
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 cause a GPIO interrupt on the calling core. See gpio_set_irq_callback, gpio_set_irq_enabled_with_callback and gpio_add_raw_irq_handler to set up a GPIO interrupt handler to handle the events. More...
 
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 used for all GPIO IRQs on the current core that are not explicitly hooked via gpio_add_raw_irq_handler or other gpio_add_raw_irq_handler_ functions. More...
 
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 slightly eclectic mix of initialization, that: More...
 
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 XOSC or ROSC when they are disabled in dormant mode. More...
 
static uint32_t gpio_get_irq_event_mask (uint gpio)
 Return the current interrupt status (pending events) for the given GPIO. More...
 
void gpio_acknowledge_irq (uint gpio, uint32_t event_mask)
 Acknowledge a GPIO interrupt for the specified events on the calling core. More...
 
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 mechanism of a single GPIO IRQ event callback per core (see gpio_set_irq_callback), it is possible to add explicit GPIO IRQ handlers which are called independent of the default callback. The order relative to the default callback can be controlled via the order_priority parameter (the default callback has the priority GPIO_IRQ_CALLBACK_ORDER_PRIORITY which defaults to the lowest priority with the intention of it running last). More...
 
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 mechanism of a single GPIO IRQ event callback per core (see gpio_set_irq_callback), it is possible to add explicit GPIO IRQ handlers which are called independent of the default callback. The order relative to the default callback can be controlled via the order_priority parameter(the default callback has the priority GPIO_IRQ_CALLBACK_ORDER_PRIORITY which defaults to the lowest priority with the intention of it running last). More...
 
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 mechanism of a single GPIO IRQ event callback per core (see gpio_set_irq_callback), it is possible to add explicit GPIO IRQ handlers which are called independent of the default event callback. More...
 
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 mechanism of a single GPIO IRQ event callback per core (see gpio_set_irq_callback), it is possible to add explicit GPIO IRQ handlers which are called independent of the default event callback. More...
 
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 mechanism of a single GPIO IRQ event callback per core (see gpio_set_irq_callback), it is possible to add explicit GPIO IRQ handlers which are called independent of the default event callback. More...
 
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 mechanism of a single GPIO IRQ event callback per core (see gpio_set_irq_callback), it is possible to add explicit GPIO IRQ handlers which are called independent of the default event callback. More...
 
void gpio_init (uint gpio)
 Initialise a GPIO for (enabled I/O and set func to GPIO_FUNC_SIO)Clear the output enable (i.e. set to input). Clear any output value. More...
 
void gpio_deinit (uint gpio)
 Resets a GPIO back to the NULL function, i.e. disables it. More...
 
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.e. set to input). Clear any output value. More...
 
static bool gpio_get (uint gpio)
 Get state of a single specified GPIO. More...
 
static uint32_t gpio_get_all (void)
 Get raw value of all GPIOs. More...
 
static void gpio_set_mask (uint32_t mask)
 Drive high every GPIO appearing in mask. More...
 
static void gpio_clr_mask (uint32_t mask)
 Drive low every GPIO appearing in mask. More...
 
static void gpio_xor_mask (uint32_t mask)
 Toggle every GPIO appearing in mask. More...
 
static void gpio_put_masked (uint32_t mask, uint32_t value)
 Drive GPIO high/low depending on parameters. More...
 
static void gpio_put_all (uint32_t value)
 Drive all pins simultaneously. More...
 
static void gpio_put (uint gpio, bool value)
 Drive a single GPIO high/low. More...
 
static bool gpio_get_out_level (uint gpio)
 Determine whether a GPIO is currently driven high or lowThis function returns the high/low output level most recently assigned to a GPIO via gpio_put() or similar. This is the value that is presented outward to the IO muxing, not the input level back from the pad (which can be read using gpio_get()). More...
 
static void gpio_set_dir_out_masked (uint32_t mask)
 Set a number of GPIOs to outputSwitch all GPIOs in "mask" to output. More...
 
static void gpio_set_dir_in_masked (uint32_t mask)
 Set a number of GPIOs to input. More...
 
static void gpio_set_dir_masked (uint32_t mask, uint32_t value)
 Set multiple GPIO directions. More...
 
static void gpio_set_dir_all_bits (uint32_t values)
 Set direction of all pins simultaneously. More...
 
static void gpio_set_dir (uint gpio, bool out)
 Set a single GPIO direction. More...
 
static bool gpio_is_dir_out (uint gpio)
 Check if a specific GPIO direction is OUT. More...
 
static uint gpio_get_dir (uint gpio)
 Get a specific GPIO direction. More...
 
void gpio_debug_pins_init (void)
 

Enumeration Type Documentation

◆ gpio_override

Enumerator
GPIO_OVERRIDE_NORMAL 

peripheral signal selected via gpio_set_function

GPIO_OVERRIDE_INVERT 

invert peripheral signal selected via gpio_set_function

GPIO_OVERRIDE_LOW 

drive low/disable output

GPIO_OVERRIDE_HIGH 

drive high/enable output