gpio.h File Reference
#include "pico.h"
#include "hardware/structs/sio.h"
#include "hardware/structs/padsbank0.h"

Go to the source code of this file.

Macros

#define PARAM_ASSERTIONS_ENABLED_GPIO   0
 
#define GPIO_OUT   1
 
#define GPIO_IN   0
 
#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 events)
 

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 = 0xf
}
 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. More...
 
enum  gpio_override { GPIO_OVERRIDE_NORMAL = 0, GPIO_OVERRIDE_INVERT = 1, GPIO_OVERRIDE_LOW = 2, GPIO_OVERRIDE_HIGH = 3 }
 

Functions

void gpio_set_function (uint gpio, enum gpio_function fn)
 Select GPIO function. More...
 
enum gpio_function gpio_get_function (uint gpio)
 
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_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_irq_enabled (uint gpio, uint32_t events, bool enabled)
 Enable or disable interrupts for specified GPIO. More...
 
void gpio_set_irq_enabled_with_callback (uint gpio, uint32_t events, bool enabled, gpio_irq_callback_t callback)
 Enable interrupts for specified GPIO. More...
 
void gpio_set_dormant_irq_enabled (uint gpio, uint32_t events, bool enabled)
 Enable dormant wake up interrupt for specified GPIO. More...
 
void gpio_acknowledge_irq (uint gpio, uint32_t events)
 Acknowledge a GPIO interrupt. More...
 
void gpio_init (uint gpio)
 Initialise a GPIO for (enabled I/O and set func to GPIO_FUNC_SIO) More...
 
void gpio_init_mask (uint gpio_mask)
 Initialise multiple GPIOs (enabled I/O and set func to GPIO_FUNC_SIO) 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 void gpio_set_dir_out_masked (uint32_t mask)
 Set a number of GPIOs 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