@web-font-path: "roboto-debian.css";
v2.2.0 (RP2040)
Loading...
Searching...
No Matches
hardware_pio

Programmable I/O (PIO) API. More...

## Topics

| sm_config
| PIO state machine configuration.
| pio_instructions
| PIO instruction encoding.

## Macros

#define | pio0 pio0_hw
#define | pio1 pio1_hw
#define | PIO_NUM(pio)
| Returns the PIO number for a PIO instance.
#define | PIO_INSTANCE(instance)
| Returns the PIO instance with the given PIO number.
#define | PIO_FUNCSEL_NUM(pio, gpio)
| Returns gpio_function_t needed to select the PIO function for the given PIO instance on the given GPIO.
#define | PIO_DREQ_NUM(pio, sm, is_tx)
| Returns the dreq_num_t used for pacing DMA transfers to or from a given state machine's FIFOs on this PIO instance. If is_tx is true, then it is for transfers to the PIO state machine TX FIFO else for transfers from the PIO state machine RX FIFO.
#define | PIO_IRQ_NUM(pio, irqn)
| Returns the irq_num_t for processor interrupts from the given PIO instance.

## Typedefs

typedef enum pio_interrupt_source | pio_interrupt_source_t
| PIO interrupt source numbers for pio related IRQs.

## Enumerations

enum | pio_fifo_join { PIO_FIFO_JOIN_NONE = 0 , PIO_FIFO_JOIN_TX = 1 , PIO_FIFO_JOIN_RX = 2 }
| FIFO join states. More...
enum | pio_mov_status_type { STATUS_TX_LESSTHAN = 0 , STATUS_RX_LESSTHAN = 1 }
| MOV status types.

enum

pio_interrupt_source {
pis_interrupt0 = PIO_INTR_SM0_LSB , pis_interrupt1 = PIO_INTR_SM1_LSB , pis_interrupt2 = PIO_INTR_SM2_LSB , pis_interrupt3 = PIO_INTR_SM3_LSB ,
pis_sm0_tx_fifo_not_full = PIO_INTR_SM0_TXNFULL_LSB , pis_sm1_tx_fifo_not_full = PIO_INTR_SM1_TXNFULL_LSB , pis_sm2_tx_fifo_not_full = PIO_INTR_SM2_TXNFULL_LSB , pis_sm3_tx_fifo_not_full = PIO_INTR_SM3_TXNFULL_LSB ,
pis_sm0_rx_fifo_not_empty = PIO_INTR_SM0_RXNEMPTY_LSB , pis_sm1_rx_fifo_not_empty = PIO_INTR_SM1_RXNEMPTY_LSB , pis_sm2_rx_fifo_not_empty = PIO_INTR_SM2_RXNEMPTY_LSB , pis_sm3_rx_fifo_not_empty = PIO_INTR_SM3_RXNEMPTY_LSB
}

| PIO interrupt source numbers for pio related IRQs. More...

## Functions

static uint | pio_get_gpio_base (PIO pio)
| Return the base GPIO base for the PIO instance.
static int | pio_sm_set_config (PIO pio, uint sm, const pio_sm_config *config)
| Apply a state machine configuration to a state machine.
static uint | pio_get_index (PIO pio)
| Return the instance number of a PIO instance.
static uint | pio_get_funcsel (PIO pio)
| Return the funcsel number of a PIO instance.
static PIO | pio_get_instance (uint instance)
| Convert PIO instance to hardware instance.
static void | pio_gpio_init (PIO pio, uint pin)
| Setup the function select for a GPIO to use output from the given PIO instance.
static uint | pio_get_dreq (PIO pio, uint sm, bool is_tx)
| Return the DREQ to use for pacing transfers to/from a particular state machine FIFO.
int | pio_set_gpio_base (PIO pio, uint gpio_base)
| Set the base GPIO base for the PIO instance.
bool | pio_can_add_program (PIO pio, const pio_program_t *program)
| Determine whether the given program can (at the time of the call) be loaded onto the PIO instance.
bool | pio_can_add_program_at_offset (PIO pio, const pio_program_t *program, uint offset)
| Determine whether the given program can (at the time of the call) be loaded onto the PIO instance starting at a particular location.
int | pio_add_program (PIO pio, const pio_program_t *program)
| Attempt to load the program.
int | pio_add_program_at_offset (PIO pio, const pio_program_t *program, uint offset)
| Attempt to load the program at the specified instruction memory offset.
void | pio_remove_program (PIO pio, const pio_program_t *program, uint loaded_offset)
| Remove a program from a PIO instance's instruction memory.
void | pio_clear_instruction_memory (PIO pio)
| Clears all of a PIO instance's instruction memory.
int | pio_sm_init (PIO pio, uint sm, uint initial_pc, const pio_sm_config *config)
| Resets the state machine to a consistent state, and configures it.
static void | pio_sm_set_enabled (PIO pio, uint sm, bool enabled)
| Enable or disable a PIO state machine.
static void | pio_set_sm_mask_enabled (PIO pio, uint32_t mask, bool enabled)
| Enable or disable multiple PIO state machines.
static void | pio_sm_restart (PIO pio, uint sm)
| Restart a state machine with a known state.
static void | pio_restart_sm_mask (PIO pio, uint32_t mask)
| Restart multiple state machine with a known state.
static void | pio_sm_clkdiv_restart (PIO pio, uint sm)
| Restart a state machine's clock divider from a phase of 0.
static void | pio_clkdiv_restart_sm_mask (PIO pio, uint32_t mask)
| Restart multiple state machines' clock dividers from a phase of 0.
static void | pio_enable_sm_mask_in_sync (PIO pio, uint32_t mask)
| Enable multiple PIO state machines synchronizing their clock dividers.
static void | pio_set_irq0_source_enabled (PIO pio, pio_interrupt_source_t source, bool enabled)
| Enable/Disable a single source on a PIO's IRQ 0.
static void | pio_set_irq1_source_enabled (PIO pio, pio_interrupt_source_t source, bool enabled)
| Enable/Disable a single source on a PIO's IRQ 1.
static void | pio_set_irq0_source_mask_enabled (PIO pio, uint32_t source_mask, bool enabled)
| Enable/Disable multiple sources on a PIO's IRQ 0.
static void | pio_set_irq1_source_mask_enabled (PIO pio, uint32_t source_mask, bool enabled)
| Enable/Disable multiple sources on a PIO's IRQ 1.
static void | pio_set_irqn_source_enabled (PIO pio, uint irq_index, pio_interrupt_source_t source, bool enabled)
| Enable/Disable a single source on a PIO's specified (0/1) IRQ index.
static void | pio_set_irqn_source_mask_enabled (PIO pio, uint irq_index, uint32_t source_mask, bool enabled)
| Enable/Disable multiple sources on a PIO's specified (0/1) IRQ index.
static bool | pio_interrupt_get (PIO pio, uint pio_interrupt_num)
| Determine if a particular PIO interrupt is set.
static void | pio_interrupt_clear (PIO pio, uint pio_interrupt_num)
| Clear a particular PIO interrupt.
static uint8_t | pio_sm_get_pc (PIO pio, uint sm)
| Return the current program counter for a state machine.
static void | pio_sm_exec (PIO pio, uint sm, uint instr)
| Immediately execute an instruction on a state machine.
static bool | pio_sm_is_exec_stalled (PIO pio, uint sm)
| Determine if an instruction set by pio_sm_exec() is stalled executing.
static void | pio_sm_exec_wait_blocking (PIO pio, uint sm, uint instr)
| Immediately execute an instruction on a state machine and wait for it to complete.
static void | pio_sm_set_wrap (PIO pio, uint sm, uint wrap_target, uint wrap)
| Set the current wrap configuration for a state machine.
static void | pio_sm_set_out_pins (PIO pio, uint sm, uint out_base, uint out_count)
| Set the current 'out' pins for a state machine.
static void | pio_sm_set_set_pins (PIO pio, uint sm, uint set_base, uint set_count)
| Set the current 'set' pins for a state machine.
static void | pio_sm_set_in_pins (PIO pio, uint sm, uint in_base)
| Set the current 'in' pins for a state machine.
static void | pio_sm_set_sideset_pins (PIO pio, uint sm, uint sideset_base)
| Set the current 'sideset' pins for a state machine.
static void | pio_sm_set_jmp_pin (PIO pio, uint sm, uint pin)
| Set the 'jmp' pin for a state machine.
static void | pio_sm_put (PIO pio, uint sm, uint32_t data)
| Write a word of data to a state machine's TX FIFO.
static uint32_t | pio_sm_get (PIO pio, uint sm)
| Read a word of data from a state machine's RX FIFO.
static bool | pio_sm_is_rx_fifo_full (PIO pio, uint sm)
| Determine if a state machine's RX FIFO is full.
static bool | pio_sm_is_rx_fifo_empty (PIO pio, uint sm)
| Determine if a state machine's RX FIFO is empty.
static uint | pio_sm_get_rx_fifo_level (PIO pio, uint sm)
| Return the number of elements currently in a state machine's RX FIFO.
static bool | pio_sm_is_tx_fifo_full (PIO pio, uint sm)
| Determine if a state machine's TX FIFO is full.
static bool | pio_sm_is_tx_fifo_empty (PIO pio, uint sm)
| Determine if a state machine's TX FIFO is empty.
static uint | pio_sm_get_tx_fifo_level (PIO pio, uint sm)
| Return the number of elements currently in a state machine's TX FIFO.
static void | pio_sm_put_blocking (PIO pio, uint sm, uint32_t data)
| Write a word of data to a state machine's TX FIFO, blocking if the FIFO is full.
static uint32_t | pio_sm_get_blocking (PIO pio, uint sm)
| Read a word of data from a state machine's RX FIFO, blocking if the FIFO is empty.
void | pio_sm_drain_tx_fifo (PIO pio, uint sm)
| Empty out a state machine's TX FIFO.
static void | pio_sm_set_clkdiv_int_frac8 (PIO pio, uint sm, uint32_t div_int, uint8_t div_frac8)
| set the current clock divider for a state machine using a 16:8 fraction
static void | pio_sm_set_clkdiv (PIO pio, uint sm, float div)
| set the current clock divider for a state machine
static void | pio_sm_clear_fifos (PIO pio, uint sm)
| Clear a state machine's TX and RX FIFOs.
void | pio_sm_set_pins (PIO pio, uint sm, uint32_t pin_values)
| Use a state machine to set a value on all pins for the PIO instance.
void | pio_sm_set_pins64 (PIO pio, uint sm, uint64_t pin_values)
| Use a state machine to set a value on all pins for the PIO instance.
void | pio_sm_set_pins_with_mask (PIO pio, uint sm, uint32_t pin_values, uint32_t pin_mask)
| Use a state machine to set a value on multiple pins for the PIO instance.
void | pio_sm_set_pins_with_mask64 (PIO pio, uint sm, uint64_t pin_values, uint64_t pin_mask)
| Use a state machine to set a value on multiple pins for the PIO instance.
void | pio_sm_set_pindirs_with_mask (PIO pio, uint sm, uint32_t pin_dirs, uint32_t pin_mask)
| Use a state machine to set the pin directions for multiple pins for the PIO instance.
void | pio_sm_set_pindirs_with_mask64 (PIO pio, uint sm, uint64_t pin_dirs, uint64_t pin_mask)
| Use a state machine to set the pin directions for multiple pins for the PIO instance.
int | pio_sm_set_consecutive_pindirs (PIO pio, uint sm, uint pins_base, uint pin_count, bool is_out)
| Use a state machine to set the same pin direction for multiple consecutive pins for the PIO instance.
void | pio_sm_claim (PIO pio, uint sm)
| Mark a state machine as used.
void | pio_claim_sm_mask (PIO pio, uint sm_mask)
| Mark multiple state machines as used.
void | pio_sm_unclaim (PIO pio, uint sm)
| Mark a state machine as no longer used.
int | pio_claim_unused_sm (PIO pio, bool required)
| Claim a free state machine on a PIO instance.
bool | pio_sm_is_claimed (PIO pio, uint sm)
| Determine if a PIO state machine is claimed.
bool | pio_claim_free_sm_and_add_program (const pio_program_t *program, PIO *pio, uint *sm, uint *offset)
| Finds a PIO and statemachine and adds a program into PIO memory.
bool | pio_claim_free_sm_and_add_program_for_gpio_range (const pio_program_t *program, PIO *pio, uint *sm, uint *offset, uint gpio_base, uint gpio_count, bool set_gpio_base)
| Finds a PIO and statemachine and adds a program into PIO memory.
void | pio_remove_program_and_unclaim_sm (const pio_program_t *program, PIO pio, uint sm, uint offset)
| Removes a program from PIO memory and unclaims the state machine.
static int | pio_get_irq_num (PIO pio, uint irqn)
| Return an IRQ for a PIO hardware instance.
static pio_interrupt_source_t | pio_get_tx_fifo_not_full_interrupt_source (uint sm)
| Return the interrupt source for a state machines TX FIFO not full interrupt.
static pio_interrupt_source_t | pio_get_rx_fifo_not_empty_interrupt_source (uint sm)
| Return the interrupt source for a state machines RX FIFO not empty interrupt.

## Detailed Description

Programmable I/O (PIO) API.

A programmable input/output block (PIO) is a versatile hardware interface which can support a number of different IO standards.

There are two PIO blocks in the RP2040.

Each PIO is programmable in the same sense as a processor: the four state machines independently execute short, sequential programs, to manipulate GPIOs and transfer data. Unlike a general purpose processor, PIO state machines are highly specialised for IO, with a focus on determinism, precise timing, and close integration with fixed-function hardware. Each state machine is equipped with:

- Two 32-bit shift registers – either direction, any shift count
- Two 32-bit scratch registers
- 4×32 bit bus FIFO in each direction (TX/RX), reconfigurable as 8×32 in a single direction
- Fractional clock divider (16 integer, 8 fractional bits)
- Flexible GPIO mapping
- DMA interface, sustained throughput up to 1 word per clock from system DMA
- IRQ flag set/clear/status

Full details of the PIO can be found in the appropriate RP-series datasheet. Note that there are additional features in the RP2350 PIO implementation that mean care should be taken when writing PIO code that needs to run on both the RP2040 and the RP2350.

On RP2040, pin numbers may always be specified from 0-31

## Macro Definition Documentation

## pio0

#define pio0 pio0_hw

Identifier for the first (PIO 0) hardware PIO instance (for use in PIO functions).

e.g. pio_gpio_init(pio0, 5)

## pio1

#define pio1 pio1_hw

Identifier for the second (PIO 1) hardware PIO instance (for use in PIO functions).

e.g. pio_gpio_init(pio1, 5)

## PIO_DREQ_NUM

#define PIO_DREQ_NUM | ( |  | pio,
|  |  | sm,
|  |  | is_tx )

Returns the dreq_num_t used for pacing DMA transfers to or from a given state machine's FIFOs on this PIO instance. If is_tx is true, then it is for transfers to the PIO state machine TX FIFO else for transfers from the PIO state machine RX FIFO.

Note this macro is intended to resolve at compile time, and does no parameter checking

## PIO_FUNCSEL_NUM

#define PIO_FUNCSEL_NUM | ( |  | pio,
|  |  | gpio )

Returns gpio_function_t needed to select the PIO function for the given PIO instance on the given GPIO.

Note this macro is intended to resolve at compile time, and does no parameter checking

## PIO_INSTANCE

#define PIO_INSTANCE | ( |  | instance | ) |

Returns the PIO instance with the given PIO number.

Note this macro is intended to resolve at compile time, and does no parameter checking

## PIO_IRQ_NUM

#define PIO_IRQ_NUM | ( |  | pio,
|  |  | irqn )

Returns the irq_num_t for processor interrupts from the given PIO instance.

Note this macro is intended to resolve at compile time, and does no parameter checking

## PIO_NUM

#define PIO_NUM | ( |  | pio | ) |

Returns the PIO number for a PIO instance.

Note this macro is intended to resolve at compile time, and does no parameter checking

## Enumeration Type Documentation

## pio_fifo_join

enum pio_fifo_join

FIFO join states.

Enumerator
PIO_FIFO_JOIN_NONE | TX FIFO length=4 is used for transmit, RX FIFO length=4 is used for receive.
PIO_FIFO_JOIN_TX | TX FIFO length=8 is used for transmit, RX FIFO is disabled.
PIO_FIFO_JOIN_RX | RX FIFO length=8 is used for receive, TX FIFO is disabled.

## pio_interrupt_source

enum pio_interrupt_source

PIO interrupt source numbers for pio related IRQs.

Enumerator
pis_interrupt0 | PIO interrupt 0 is raised.
pis_interrupt1 | PIO interrupt 1 is raised.
pis_interrupt2 | PIO interrupt 2 is raised.
pis_interrupt3 | PIO interrupt 3 is raised.
pis_sm0_tx_fifo_not_full | State machine 0 TX FIFO is not full.
pis_sm1_tx_fifo_not_full | State machine 1 TX FIFO is not full.
pis_sm2_tx_fifo_not_full | State machine 2 TX FIFO is not full.
pis_sm3_tx_fifo_not_full | State machine 3 TX FIFO is not full.
pis_sm0_rx_fifo_not_empty | State machine 0 RX FIFO is not empty.
pis_sm1_rx_fifo_not_empty | State machine 1 RX FIFO is not empty.
pis_sm2_rx_fifo_not_empty | State machine 2 RX FIFO is not empty.
pis_sm3_rx_fifo_not_empty | State machine 3 RX FIFO is not empty.

## Function Documentation

## pio_add_program()

int pio_add_program | ( | PIO | pio,
|  | const pio_program_t * | program )

Attempt to load the program.

See pio_can_add_program() if you need to check whether the program can be loaded

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  program | the program definition

Returns
  the instruction memory offset the program is loaded at, or negative for error (for backwards compatibility with prior SDK the error value is -1 i.e. PICO_ERROR_GENERIC)

## pio_add_program_at_offset()

int pio_add_program_at_offset | ( | PIO | pio,
|  | const pio_program_t * | program,
|  | uint | offset )

Attempt to load the program at the specified instruction memory offset.

See pio_can_add_program_at_offset() if you need to check whether the program can be loaded

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  program | the program definition
  offset | the instruction memory offset wanted for the start of the program

Returns
  the instruction memory offset the program is loaded at, or negative for error (for backwards compatibility with prior SDK the error value is -1 i.e. PICO_ERROR_GENERIC)

## pio_can_add_program()

bool pio_can_add_program | ( | PIO | pio,
|  | const pio_program_t * | program )

Determine whether the given program can (at the time of the call) be loaded onto the PIO instance.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  program | the program definition

Returns
  true if the program can be loaded; false if not, e.g. if there is not suitable space in the instruction memory

## pio_can_add_program_at_offset()

bool pio_can_add_program_at_offset | ( | PIO | pio,
|  | const pio_program_t * | program,
|  | uint | offset )

Determine whether the given program can (at the time of the call) be loaded onto the PIO instance starting at a particular location.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  program | the program definition
  offset | the instruction memory offset wanted for the start of the program

Returns
  true if the program can be loaded at that location; false if not, e.g. if there is not space in the instruction memory

## pio_claim_free_sm_and_add_program()

bool pio_claim_free_sm_and_add_program | ( | const pio_program_t * | program,
|  | PIO * | pio,
|  | uint * | sm,
|  | uint * | offset )

Finds a PIO and statemachine and adds a program into PIO memory.

Parameters

  program | PIO program to add
  pio | Returns the PIO hardware instance or NULL if no PIO is available
  sm | Returns the index of the PIO state machine that was claimed
  offset | Returns the instruction memory offset of the start of the program

Returns
  true on success, false otherwise

See also
  pio_remove_program_and_unclaim_sm

## pio_claim_free_sm_and_add_program_for_gpio_range()

bool pio_claim_free_sm_and_add_program_for_gpio_range | ( | const pio_program_t * | program,
|  | PIO * | pio,
|  | uint * | sm,
|  | uint * | offset,
|  | uint | gpio_base,
|  | uint | gpio_count,
|  | bool | set_gpio_base )

Finds a PIO and statemachine and adds a program into PIO memory.

This variation of pio_claim_free_sm_and_add_program is useful on RP2350 QFN80 where the "GPIO Base" must be set per PIO instance to either address the 32 GPIOs (0->31) or the 32 GPIOS (16-47). No single PIO instance can interact with both pins 0->15 or 32->47 at the same time.

This method takes additional information about the GPIO pins needed (via gpio_base and gpio_count), and optionally will set the GPIO base (see pio_set_gpio_base) of an unused PIO instance if necessary

Parameters

  program | PIO program to add
  pio | Returns the PIO hardware instance or NULL if no PIO is available
  sm | Returns the index of the PIO state machine that was claimed
  offset | Returns the instruction memory offset of the start of the program
  gpio_base | the lowest GPIO number required (0-47 on RP2350B, 0-31 otherwise)
  gpio_count | the count of GPIOs required
  set_gpio_base | if there is no free SM on a PIO instance with the right GPIO base, and there IS an unused PIO instance, then that PIO will be reconfigured so that this method can succeed

Returns
  true on success, false otherwise

See also
  pio_remove_program_and_unclaim_sm

## pio_claim_sm_mask()

void pio_claim_sm_mask | ( | PIO | pio,
|  | uint | sm_mask )

Mark multiple state machines as used.

Method for cooperative claiming of hardware. Will cause a panic if any of the state machines are already claimed. Use of this method by libraries detects accidental configurations that would fail in unpredictable ways.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm_mask | Mask of state machine indexes

## pio_claim_unused_sm()

int pio_claim_unused_sm | ( | PIO | pio,
|  | bool | required )

Claim a free state machine on a PIO instance.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  required | if true the function will panic if none are available

Returns
  the state machine index or negative if required was false, and none were free (for backwards compatibility with prior SDK the error value is -1 i.e. PICO_ERROR_GENERIC)

## pio_clear_instruction_memory()

void pio_clear_instruction_memory | ( | PIO | pio | ) |

Clears all of a PIO instance's instruction memory.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1

## pio_clkdiv_restart_sm_mask()

void pio_clkdiv_restart_sm_mask | ( | PIO | pio,
|  | uint32_t | mask )

inline static

Restart multiple state machines' clock dividers from a phase of 0.

Each state machine's clock divider is a free-running piece of hardware, that generates a pattern of clock enable pulses for the state machine, based only on the configured integer/fractional divisor. The pattern of running/halted cycles slows the state machine's execution to some controlled rate.

This function simultaneously clears the integer and fractional phase accumulators of multiple state machines' clock dividers. If these state machines all have the same integer and fractional divisors configured, their clock dividers will run in precise deterministic lockstep from this point.

With their execution clocks synchronised in this way, it is then safe to e.g. have multiple state machines performing a 'wait irq' on the same flag, and all clear it on the same cycle.

Also note that this function can be called whilst state machines are running (e.g. if you have just changed the clock divisors of some state machines and wish to resynchronise them), and that disabling a state machine does not halt its clock divider: that is, if multiple state machines have their clocks synchronised, you can safely disable and re-enable one of the state machines without losing synchronisation.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  mask | bit mask of state machine indexes to modify the enabled state of

## pio_enable_sm_mask_in_sync()

void pio_enable_sm_mask_in_sync | ( | PIO | pio,
|  | uint32_t | mask )

inline static

Enable multiple PIO state machines synchronizing their clock dividers.

This is equivalent to calling both pio_set_sm_mask_enabled() and pio_clkdiv_restart_sm_mask() on the same clock cycle. All state machines specified by 'mask' are started simultaneously and, assuming they have the same clock divisors, their divided clocks will stay precisely synchronised.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  mask | bit mask of state machine indexes to modify the enabled state of

## pio_get_dreq()

uint pio_get_dreq | ( | PIO | pio,
|  | uint | sm,
|  | bool | is_tx )

inline static

Return the DREQ to use for pacing transfers to/from a particular state machine FIFO.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  is_tx | true for sending data to the state machine, false for receiving data from the state machine

## pio_get_funcsel()

uint pio_get_funcsel | ( | PIO | pio | ) |

inline static

Return the funcsel number of a PIO instance.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1

Returns
  the PIO instance number (0, 1, ...)

See also
  gpio_function_t

## pio_get_gpio_base()

uint pio_get_gpio_base | ( | PIO | pio | ) |

inline static

Return the base GPIO base for the PIO instance.

This method always return 0 in RP2040

Parameters

  pio | The PIO instance; e.g. pio0 or pio1

Returns
  the current GPIO base for the PIO instance

## pio_get_index()

uint pio_get_index | ( | PIO | pio | ) |

inline static

Return the instance number of a PIO instance.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1

Returns
  the PIO instance number (0, 1, ...)

## pio_get_instance()

PIO pio_get_instance | ( | uint | instance | ) |

inline static

Convert PIO instance to hardware instance.

Parameters

  instance | Instance of PIO, 0 or 1

Returns
  the PIO hardware instance

## pio_get_irq_num()

int pio_get_irq_num | ( | PIO | pio,
|  | uint | irqn )

inline static

Return an IRQ for a PIO hardware instance.

Parameters

  pio | PIO hardware instance
  irqn | 0 for PIOx_IRQ_0 or 1 for PIOx_IRQ_1 etc where x is the PIO number

Returns
  The IRQ number to use for the PIO

## pio_get_rx_fifo_not_empty_interrupt_source()

pio_interrupt_source_t pio_get_rx_fifo_not_empty_interrupt_source | ( | uint | sm | ) |

inline static

Return the interrupt source for a state machines RX FIFO not empty interrupt.

Parameters

  sm | State machine index (0..3)

Returns
  The interrupt source number for use in pio_set_irqn_source_enabled or similar functions

## pio_get_tx_fifo_not_full_interrupt_source()

pio_interrupt_source_t pio_get_tx_fifo_not_full_interrupt_source | ( | uint | sm | ) |

inline static

Return the interrupt source for a state machines TX FIFO not full interrupt.

Parameters

  sm | State machine index (0..3)

Returns
  The interrupt source number for use in pio_set_irqn_source_enabled or similar functions

## pio_gpio_init()

void pio_gpio_init | ( | PIO | pio,
|  | uint | pin )

inline static

Setup the function select for a GPIO to use output from the given PIO instance.

PIO appears as an alternate function in the GPIO muxing, just like an SPI or UART. This function configures that multiplexing to connect a given PIO instance to a GPIO. It also configures the GPIO pad to pass signals in and out, by:

- Clearing the pad output disable (OD) bit
- Setting the pad input enable (IE) bit
- (Non-RP2040) removing pad isolation

This function achieves this low-level pad setup by calling gpio_set_function() internally.

Note that, if your PIO program only needs the input from a given GPIO, it's not necessary to select the PIO GPIO function, because PIO input paths ignore the GPIO muxing. However, you must still configure the GPIO pad itself for input.

Conversely, if using PIO for both input and output on a given pin, you must select the PIO GPIO function for the given PIO instance, as well as configuring the pad for input and output. Calling this function is sufficient for both the input-only and input/output case.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  pin | the GPIO pin whose function select to set

## pio_interrupt_clear()

void pio_interrupt_clear | ( | PIO | pio,
|  | uint | pio_interrupt_num )

inline static

Clear a particular PIO interrupt.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  pio_interrupt_num | the PIO interrupt number 0-7

## pio_interrupt_get()

bool pio_interrupt_get | ( | PIO | pio,
|  | uint | pio_interrupt_num )

inline static

Determine if a particular PIO interrupt is set.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  pio_interrupt_num | the PIO interrupt number 0-7

Returns
  true if corresponding PIO interrupt is currently set

## pio_remove_program()

void pio_remove_program | ( | PIO | pio,
|  | const pio_program_t * | program,
|  | uint | loaded_offset )

Remove a program from a PIO instance's instruction memory.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  program | the program definition
  loaded_offset | the loaded offset returned when the program was added

## pio_remove_program_and_unclaim_sm()

void pio_remove_program_and_unclaim_sm | ( | const pio_program_t * | program,
|  | PIO | pio,
|  | uint | sm,
|  | uint | offset )

Removes a program from PIO memory and unclaims the state machine.

Parameters

  program | PIO program to remove from memory
  pio | PIO hardware instance being used
  sm | PIO state machine that was claimed
  offset | offset of the program in PIO memory

See also
  pio_claim_free_sm_and_add_program

## pio_restart_sm_mask()

void pio_restart_sm_mask | ( | PIO | pio,
|  | uint32_t | mask )

inline static

Restart multiple state machine with a known state.

This method clears the ISR, shift counters, clock divider counter pin write flags, delay counter, latched EXEC instruction, and IRQ wait condition.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  mask | bit mask of state machine indexes to modify the enabled state of

## pio_set_gpio_base()

int pio_set_gpio_base | ( | PIO | pio,
|  | uint | gpio_base )

Set the base GPIO base for the PIO instance.

Since an individual PIO accesses only 32 pins, to be able to access more pins, the PIO instance must specify a base GPIO where the instance's "pin 0" maps. For RP2350 the valid values are 0 and 16, indicating the PIO instance has access to pins 0-31, or 16-47 respectively.

NOTE: This method simply changes the underlying PIO register, it does not detect or attempt to prevent any side effects this change will have on in use state machines on this PIO.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  gpio_base | the GPIO base (either 0 or 16)

Returns
  PICO_OK (0) on success, error code otherwise

## pio_set_irq0_source_enabled()

void pio_set_irq0_source_enabled | ( | PIO | pio,
|  | pio_interrupt_source_t | source,
|  | bool | enabled )

inline static

Enable/Disable a single source on a PIO's IRQ 0.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  source | the source number (see pio_interrupt_source)
  enabled | true to enable IRQ 0 for the source, false to disable.

## pio_set_irq0_source_mask_enabled()

void pio_set_irq0_source_mask_enabled | ( | PIO | pio,
|  | uint32_t | source_mask,
|  | bool | enabled )

inline static

Enable/Disable multiple sources on a PIO's IRQ 0.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  source_mask | Mask of bits, one for each source number (see pio_interrupt_source) to affect
  enabled | true to enable all the sources specified in the mask on IRQ 0, false to disable all the sources specified in the mask on IRQ 0

## pio_set_irq1_source_enabled()

void pio_set_irq1_source_enabled | ( | PIO | pio,
|  | pio_interrupt_source_t | source,
|  | bool | enabled )

inline static

Enable/Disable a single source on a PIO's IRQ 1.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  source | the source number (see pio_interrupt_source)
  enabled | true to enable IRQ 0 for the source, false to disable.

## pio_set_irq1_source_mask_enabled()

void pio_set_irq1_source_mask_enabled | ( | PIO | pio,
|  | uint32_t | source_mask,
|  | bool | enabled )

inline static

Enable/Disable multiple sources on a PIO's IRQ 1.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  source_mask | Mask of bits, one for each source number (see pio_interrupt_source) to affect
  enabled | true to enable all the sources specified in the mask on IRQ 1, false to disable all the source specified in the mask on IRQ 1

## pio_set_irqn_source_enabled()

void pio_set_irqn_source_enabled | ( | PIO | pio,
|  | uint | irq_index,
|  | pio_interrupt_source_t | source,
|  | bool | enabled )

inline static

Enable/Disable a single source on a PIO's specified (0/1) IRQ index.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  irq_index | the IRQ index; either 0 or 1
  source | the source number (see pio_interrupt_source)
  enabled | true to enable the source on the specified IRQ, false to disable.

## pio_set_irqn_source_mask_enabled()

void pio_set_irqn_source_mask_enabled | ( | PIO | pio,
|  | uint | irq_index,
|  | uint32_t | source_mask,
|  | bool | enabled )

inline static

Enable/Disable multiple sources on a PIO's specified (0/1) IRQ index.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  irq_index | the IRQ index; either 0 or 1
  source_mask | Mask of bits, one for each source number (see pio_interrupt_source) to affect
  enabled | true to enable all the sources specified in the mask on the specified IRQ, false to disable all the sources specified in the mask on the specified IRQ

## pio_set_sm_mask_enabled()

void pio_set_sm_mask_enabled | ( | PIO | pio,
|  | uint32_t | mask,
|  | bool | enabled )

inline static

Enable or disable multiple PIO state machines.

Note that this method just sets the enabled state of the state machine; if now enabled they continue exactly from where they left off.

See pio_enable_sm_mask_in_sync() if you wish to enable multiple state machines and ensure their clock dividers are in sync.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  mask | bit mask of state machine indexes to modify the enabled state of
  enabled | true to enable the state machines; false to disable

## pio_sm_claim()

void pio_sm_claim | ( | PIO | pio,
|  | uint | sm )

Mark a state machine as used.

Method for cooperative claiming of hardware. Will cause a panic if the state machine is already claimed. Use of this method by libraries detects accidental configurations that would fail in unpredictable ways.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

## pio_sm_clear_fifos()

void pio_sm_clear_fifos | ( | PIO | pio,
|  | uint | sm )

inline static

Clear a state machine's TX and RX FIFOs.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

## pio_sm_clkdiv_restart()

void pio_sm_clkdiv_restart | ( | PIO | pio,
|  | uint | sm )

inline static

Restart a state machine's clock divider from a phase of 0.

Each state machine's clock divider is a free-running piece of hardware, that generates a pattern of clock enable pulses for the state machine, based only on the configured integer/fractional divisor. The pattern of running/halted cycles slows the state machine's execution to some controlled rate.

This function clears the divider's integer and fractional phase accumulators so that it restarts this pattern from the beginning. It is called automatically by pio_sm_init() but can also be called at a later time, when you enable the state machine, to ensure precisely consistent timing each time you load and run a given PIO program.

More commonly this hardware mechanism is used to synchronise the execution clocks of multiple state machines – see pio_clkdiv_restart_sm_mask().

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

## pio_sm_drain_tx_fifo()

void pio_sm_drain_tx_fifo | ( | PIO | pio,
|  | uint | sm )

Empty out a state machine's TX FIFO.

This method executes pull instructions on the state machine until the TX FIFO is empty. This disturbs the contents of the OSR, so see also pio_sm_clear_fifos() which clears both FIFOs but leaves the state machine's internal state undisturbed.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

See also
  pio_sm_clear_fifos()

## pio_sm_exec()

void pio_sm_exec | ( | PIO | pio,
|  | uint | sm,
|  | uint | instr )

inline static

Immediately execute an instruction on a state machine.

This instruction is executed instead of the next instruction in the normal control flow on the state machine. Subsequent calls to this method replace the previous executed instruction if it is still running. See pio_sm_is_exec_stalled() to see if an executed instruction is still running (i.e. it is stalled on some condition)

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  instr | the encoded PIO instruction

## pio_sm_exec_wait_blocking()

void pio_sm_exec_wait_blocking | ( | PIO | pio,
|  | uint | sm,
|  | uint | instr )

inline static

Immediately execute an instruction on a state machine and wait for it to complete.

This instruction is executed instead of the next instruction in the normal control flow on the state machine. Subsequent calls to this method replace the previous executed instruction if it is still running. See pio_sm_is_exec_stalled() to see if an executed instruction is still running (i.e. it is stalled on some condition)

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  instr | the encoded PIO instruction

## pio_sm_get()

uint32_t pio_sm_get | ( | PIO | pio,
|  | uint | sm )

inline static

Read a word of data from a state machine's RX FIFO.

This is a raw FIFO access that does not check for emptiness. If the FIFO is empty, the hardware ignores the attempt to read from the FIFO (the FIFO remains in an empty state following the read) and the sticky RXUNDER flag for this FIFO is set in FDEBUG to indicate that the system tried to read from this FIFO when empty. The data returned by this function is undefined when the FIFO is empty.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

See also
  pio_sm_get_blocking()

## pio_sm_get_blocking()

uint32_t pio_sm_get_blocking | ( | PIO | pio,
|  | uint | sm )

inline static

Read a word of data from a state machine's RX FIFO, blocking if the FIFO is empty.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

## pio_sm_get_pc()

uint8_t pio_sm_get_pc | ( | PIO | pio,
|  | uint | sm )

inline static

Return the current program counter for a state machine.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  the program counter

## pio_sm_get_rx_fifo_level()

uint pio_sm_get_rx_fifo_level | ( | PIO | pio,
|  | uint | sm )

inline static

Return the number of elements currently in a state machine's RX FIFO.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  the number of elements in the RX FIFO

## pio_sm_get_tx_fifo_level()

uint pio_sm_get_tx_fifo_level | ( | PIO | pio,
|  | uint | sm )

inline static

Return the number of elements currently in a state machine's TX FIFO.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  the number of elements in the TX FIFO

## pio_sm_init()

int pio_sm_init | ( | PIO | pio,
|  | uint | sm,
|  | uint | initial_pc,
|  | const pio_sm_config * | config )

Resets the state machine to a consistent state, and configures it.

This method:

- Disables the state machine (if running)
- Clears the FIFOs
- Applies the configuration specified by 'config'
- Resets any internal state e.g. shift counters
- Jumps to the initial program location given by 'initial_pc'

The state machine is left disabled on return from this call.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  initial_pc | the initial program memory offset to run from
  config | the configuration to apply (or NULL to apply defaults)

Returns
  PICO_OK, or < 0 for an error (see pico_error_codes)

## pio_sm_is_claimed()

bool pio_sm_is_claimed | ( | PIO | pio,
|  | uint | sm )

Determine if a PIO state machine is claimed.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  true if claimed, false otherwise

See also
  pio_sm_claim
  pio_claim_sm_mask

## pio_sm_is_exec_stalled()

bool pio_sm_is_exec_stalled | ( | PIO | pio,
|  | uint | sm )

inline static

Determine if an instruction set by pio_sm_exec() is stalled executing.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  true if the executed instruction is still running (stalled)

## pio_sm_is_rx_fifo_empty()

bool pio_sm_is_rx_fifo_empty | ( | PIO | pio,
|  | uint | sm )

inline static

Determine if a state machine's RX FIFO is empty.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  true if the RX FIFO is empty

## pio_sm_is_rx_fifo_full()

bool pio_sm_is_rx_fifo_full | ( | PIO | pio,
|  | uint | sm )

inline static

Determine if a state machine's RX FIFO is full.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  true if the RX FIFO is full

## pio_sm_is_tx_fifo_empty()

bool pio_sm_is_tx_fifo_empty | ( | PIO | pio,
|  | uint | sm )

inline static

Determine if a state machine's TX FIFO is empty.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  true if the TX FIFO is empty

## pio_sm_is_tx_fifo_full()

bool pio_sm_is_tx_fifo_full | ( | PIO | pio,
|  | uint | sm )

inline static

Determine if a state machine's TX FIFO is full.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

Returns
  true if the TX FIFO is full

## pio_sm_put()

void pio_sm_put | ( | PIO | pio,
|  | uint | sm,
|  | uint32_t | data )

inline static

Write a word of data to a state machine's TX FIFO.

This is a raw FIFO access that does not check for fullness. If the FIFO is full, the FIFO contents and state are not affected by the write attempt. Hardware sets the TXOVER sticky flag for this FIFO in FDEBUG, to indicate that the system attempted to write to a full FIFO.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  data | the 32 bit data value

See also
  pio_sm_put_blocking()

## pio_sm_put_blocking()

void pio_sm_put_blocking | ( | PIO | pio,
|  | uint | sm,
|  | uint32_t | data )

inline static

Write a word of data to a state machine's TX FIFO, blocking if the FIFO is full.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  data | the 32 bit data value

## pio_sm_restart()

void pio_sm_restart | ( | PIO | pio,
|  | uint | sm )

inline static

Restart a state machine with a known state.

This method clears the ISR, shift counters, clock divider counter pin write flags, delay counter, latched EXEC instruction, and IRQ wait condition.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)

## pio_sm_set_clkdiv()

void pio_sm_set_clkdiv | ( | PIO | pio,
|  | uint | sm,
|  | float | div )

inline static

set the current clock divider for a state machine

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  div | the floating point clock divider

## pio_sm_set_clkdiv_int_frac8()

void pio_sm_set_clkdiv_int_frac8 | ( | PIO | pio,
|  | uint | sm,
|  | uint32_t | div_int,
|  | uint8_t | div_frac8 )

inline static

set the current clock divider for a state machine using a 16:8 fraction

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  div_int | the integer part of the clock divider
  div_frac8 | the fractional part of the clock divider in 1/256s

## pio_sm_set_config()

int pio_sm_set_config | ( | PIO | pio,
|  | uint | sm,
|  | const pio_sm_config * | config )

inline static

Apply a state machine configuration to a state machine.

Parameters

  pio | Handle to PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  config | the configuration to apply

Returns
  PICO_OK (0) on success, negative error code otherwise

## pio_sm_set_consecutive_pindirs()

int pio_sm_set_consecutive_pindirs | ( | PIO | pio,
|  | uint | sm,
|  | uint | pins_base,
|  | uint | pin_count,
|  | bool | is_out )

Use a state machine to set the same pin direction for multiple consecutive pins for the PIO instance.

This method repeatedly reconfigures the target state machine's pin configuration and executes 'set' instructions to set the pin direction on consecutive pins, before restoring the state machine's pin configuration to what it was.

This method is provided as a convenience to set initial pin directions, and should not be used against a state machine that is enabled.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3) to use
  pins_base | the first pin to set a direction for. See pio_sm_ pins for more detail on pin arguments
  pin_count | the count of consecutive pins to set the direction for
  is_out | the direction to set; true = out, false = in

Returns
  PICO_OK (0) on success, error code otherwise

## pio_sm_set_enabled()

void pio_sm_set_enabled | ( | PIO | pio,
|  | uint | sm,
|  | bool | enabled )

inline static

Enable or disable a PIO state machine.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  enabled | true to enable the state machine; false to disable

## pio_sm_set_in_pins()

void pio_sm_set_in_pins | ( | PIO | pio,
|  | uint | sm,
|  | uint | in_base )

inline static

Set the current 'in' pins for a state machine.

'in' pins can overlap with the 'out', 'set' and 'sideset' pins

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  in_base | First pin to use as input. See pio_sm_ pins for more detail on pin arguments

## pio_sm_set_jmp_pin()

void pio_sm_set_jmp_pin | ( | PIO | pio,
|  | uint | sm,
|  | uint | pin )

inline static

Set the 'jmp' pin for a state machine.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  pin | The pin number to use as the source for a jmp pin instruction. See pio_sm_ pins for more detail on pin arguments

## pio_sm_set_out_pins()

void pio_sm_set_out_pins | ( | PIO | pio,
|  | uint | sm,
|  | uint | out_base,
|  | uint | out_count )

inline static

Set the current 'out' pins for a state machine.

'out' pins can overlap with the 'in', 'set' and 'sideset' pins

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  out_base | First pin to set as output. See pio_sm_ pins for more detail on pin arguments
  out_count | 0-32 Number of pins to set.

## pio_sm_set_pindirs_with_mask()

void pio_sm_set_pindirs_with_mask | ( | PIO | pio,
|  | uint | sm,
|  | uint32_t | pin_dirs,
|  | uint32_t | pin_mask )

Use a state machine to set the pin directions for multiple pins for the PIO instance.

This method repeatedly reconfigures the target state machine's pin configuration and executes 'set' instructions to set pin directions on up to 32 pins, before restoring the state machine's pin configuration to what it was.

This method is provided as a convenience to set initial pin directions, and should not be used against a state machine that is enabled. Note: This method only works for pins < 32. To use with pins >= 32 call pio_sm_set_pindirs_with_mask64

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3) to use
  pin_dirs | the pin directions to set - 1 = out, 0 = in (if the corresponding bit in pin_mask is set)
  pin_mask | a bit for each pin to indicate whether the corresponding pin_value for that pin should be applied.

## pio_sm_set_pindirs_with_mask64()

void pio_sm_set_pindirs_with_mask64 | ( | PIO | pio,
|  | uint | sm,
|  | uint64_t | pin_dirs,
|  | uint64_t | pin_mask )

Use a state machine to set the pin directions for multiple pins for the PIO instance.

This method repeatedly reconfigures the target state machine's pin configuration and executes 'set' instructions to set pin directions on up to 32 pins, before restoring the state machine's pin configuration to what it was.

This method is provided as a convenience to set initial pin directions, and should not be used against a state machine that is enabled.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3) to use
  pin_dirs | the pin directions to set - 1 = out, 0 = in (if the corresponding bit in pin_mask is set)
  pin_mask | a bit for each pin to indicate whether the corresponding pin_value for that pin should be applied.

## pio_sm_set_pins()

void pio_sm_set_pins | ( | PIO | pio,
|  | uint | sm,
|  | uint32_t | pin_values )

Use a state machine to set a value on all pins for the PIO instance.

This method repeatedly reconfigures the target state machine's pin configuration and executes 'set' instructions to set values on all 32 pins, before restoring the state machine's pin configuration to what it was.

This method is provided as a convenience to set initial pin states, and should not be used against a state machine that is enabled. Note: This method only works for pins < 32. To use with pins >= 32 call pio_sm_set_pins64

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3) to use
  pin_values | the pin values to set. See pio_sm_ pins for more detail on pin arguments

## pio_sm_set_pins64()

void pio_sm_set_pins64 | ( | PIO | pio,
|  | uint | sm,
|  | uint64_t | pin_values )

Use a state machine to set a value on all pins for the PIO instance.

This method repeatedly reconfigures the target state machine's pin configuration and executes 'set' instructions to set values on all 32 pins, before restoring the state machine's pin configuration to what it was.

This method is provided as a convenience to set initial pin states, and should not be used against a state machine that is enabled.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3) to use
  pin_values | the pin values to set. See pio_sm_ pins for more detail on pin arguments

## pio_sm_set_pins_with_mask()

void pio_sm_set_pins_with_mask | ( | PIO | pio,
|  | uint | sm,
|  | uint32_t | pin_values,
|  | uint32_t | pin_mask )

Use a state machine to set a value on multiple pins for the PIO instance.

This method repeatedly reconfigures the target state machine's pin configuration and executes 'set' instructions to set values on up to 32 pins, before restoring the state machine's pin configuration to what it was.

This method is provided as a convenience to set initial pin states, and should not be used against a state machine that is enabled. Note: This method only works for pins < 32. To use with pins >= 32 call pio_sm_set_pins_with_mask64

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3) to use
  pin_values | the pin values to set (if the corresponding bit in pin_mask is set)
  pin_mask | a bit for each pin to indicate whether the corresponding pin_value for that pin should be applied. See pio_sm_ pins for more detail on pin arguments

## pio_sm_set_pins_with_mask64()

void pio_sm_set_pins_with_mask64 | ( | PIO | pio,
|  | uint | sm,
|  | uint64_t | pin_values,
|  | uint64_t | pin_mask )

Use a state machine to set a value on multiple pins for the PIO instance.

This method repeatedly reconfigures the target state machine's pin configuration and executes 'set' instructions to set values on up to 32 pins, before restoring the state machine's pin configuration to what it was.

This method is provided as a convenience to set initial pin states, and should not be used against a state machine that is enabled.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3) to use
  pin_values | the pin values to set (if the corresponding bit in pin_mask is set)
  pin_mask | a bit for each pin to indicate whether the corresponding pin_value for that pin should be applied. See pio_sm_ pins for more detail on pin arguments

## pio_sm_set_set_pins()

void pio_sm_set_set_pins | ( | PIO | pio,
|  | uint | sm,
|  | uint | set_base,
|  | uint | set_count )

inline static

Set the current 'set' pins for a state machine.

'set' pins can overlap with the 'in', 'out' and 'sideset' pins

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  set_base | First pin to set as 'set'. See pio_sm_ pins for more detail on pin arguments
  set_count | 0-5 Number of pins to set.

## pio_sm_set_sideset_pins()

void pio_sm_set_sideset_pins | ( | PIO | pio,
|  | uint | sm,
|  | uint | sideset_base )

inline static

Set the current 'sideset' pins for a state machine.

'sideset' pins can overlap with the 'in', 'out' and 'set' pins

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  sideset_base | Base pin for 'side set'. See pio_sm_ pins for more detail on pin arguments

## pio_sm_set_wrap()

void pio_sm_set_wrap | ( | PIO | pio,
|  | uint | sm,
|  | uint | wrap_target,
|  | uint | wrap )

inline static

Set the current wrap configuration for a state machine.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)
  wrap_target | the instruction memory address to wrap to
  wrap | the instruction memory address after which to set the program counter to wrap_target if the instruction does not itself update the program_counter

## pio_sm_unclaim()

void pio_sm_unclaim | ( | PIO | pio,
|  | uint | sm )

Mark a state machine as no longer used.

Method for cooperative claiming of hardware.

Parameters

  pio | The PIO instance; e.g. pio0 or pio1
  sm | State machine index (0..3)