Loading...
Searching...
No Matches
pio.h File Reference

Internal PIO interface. More...

Detailed Description

Internal PIO interface.

Author
Fabian Hüßler fabia.nosp@m.n.hu.nosp@m.essle.nosp@m.r@ov.nosp@m.gu.de

Definition in file pio.h.

#include "periph_conf.h"
#include "periph/gpio.h"
#include "periph/pio.h"
+ Include dependency graph for pio.h:

Go to the source code of this file.

Data Structures

struct  pio_gpio_init_t
 Type used to configure PIO gpios pins. More...
 
struct  pio_sm_ctrl_regs
 Internal state machine registers. More...
 
struct  pio_isr_vec
 PIO interrupt callbacks for FIFO interrupts. More...
 
struct  pio_isr_sm_vec
 PIO state machine interrupt callbacks for state machine interrupts. More...
 
struct  pio_program_conf
 PIO program configuration. More...
 
struct  pio_sm_clkdiv
 PIO clock configuration. More...
 

Macros

#define PIO_SM_CTRL_BASE(dev)   ((pio_sm_ctrl_regs_t *)(&((dev)->SM0_CLKDIV)))
 State machine configuration registers.
 
#define PIO_SM_CLKDIV_MAX   65536
 Maximum clock divider.
 
#define PIO_SM_MASK(sm)   (1u << (sm))
 Convert state machine index to bitmask.
 
#define PIO_IRQ_MASK(irq)   (1u << (irq))
 Convert IRQ index to bitmask.
 
#define PIO_IRQ_REL_MASK(irq, sm)   PIO_IRQ_MASK(pio_irq_rel_index(irq, sm))
 Convert relative IRQ index to bitmask.
 

Typedefs

typedef struct pio_sm_ctrl_regs pio_sm_ctrl_regs_t
 Internal state machine registers.
 
typedef struct pio_isr_vec pio_isr_vec_t
 PIO interrupt callbacks for FIFO interrupts.
 
typedef struct pio_isr_sm_vec pio_isr_sm_vec_t
 PIO state machine interrupt callbacks for state machine interrupts.
 
typedef struct pio_program_conf pio_program_conf_t
 PIO program configuration.
 
typedef struct pio_sm_clkdiv pio_sm_clkdiv_t
 PIO clock configuration.
 

Enumerations

enum  pio_irq_source_t {
  PIO_IRQ_SM_3 = PIO0_INTR_SM3_Msk , PIO_IRQ_SM_2 = PIO0_INTR_SM2_Msk , PIO_IRQ_SM_1 = PIO0_INTR_SM1_Msk , PIO_IRQ_SM_0 = PIO0_INTR_SM0_Msk ,
  PIO_IRQ_TXNFULL_SM3 = PIO0_INTR_SM3_TXNFULL_Msk , PIO_IRQ_TXNFULL_SM2 = PIO0_INTR_SM2_TXNFULL_Msk , PIO_IRQ_TXNFULL_SM1 = PIO0_INTR_SM1_TXNFULL_Msk , PIO_IRQ_TXNFULL_SM0 = PIO0_INTR_SM0_TXNFULL_Msk ,
  PIO_IRQ_RXNEMPTY_SM3 = PIO0_INTR_SM3_RXNEMPTY_Msk , PIO_IRQ_RXNEMPTY_SM2 = PIO0_INTR_SM2_RXNEMPTY_Msk , PIO_IRQ_RXNEMPTY_SM1 = PIO0_INTR_SM1_RXNEMPTY_Msk , PIO_IRQ_RXNEMPTY_SM0 = PIO0_INTR_SM0_RXNEMPTY_Msk ,
  PIO_IRQ_ALL_SM , PIO_IRQ_ALL
}
 PIO IRQ flags. More...
 
enum  pio_irq_line_t { PIO_IRQ_LINE_0 = 0 , PIO_IRQ_LINE_1 , PIO_IRQ_LINE_NUMOF }
 PIO interrupt lines. More...
 
enum  pio_sm_mask_t {
  PIO_SM0 = PIO_SM_MASK(0) , PIO_SM1 = PIO_SM_MASK(1) , PIO_SM2 = PIO_SM_MASK(2) , PIO_SM3 = PIO_SM_MASK(3) ,
  PIO_SM_ALL
}
 PIO state machine flags. More...
 

Functions

static unsigned pio_irq_rel_index (unsigned irq_abs, unsigned sm)
 Convert absolute IRQ index to relative IRQ index.
 
static unsigned pio_irq_rel_sm (unsigned irq_abs, unsigned irq_rel)
 Get state machine index from relative IRQ index.
 
int pio_sm_exec (pio_t pio, pio_sm_t sm, pio_instr_t inst)
 Execute a single instruction.
 
void pio_sm_exec_block (pio_t pio, pio_sm_t sm, pio_instr_t inst)
 Execute a single instruction.
 
int pio_write_program (pio_t pio, pio_program_t *prog, const pio_instr_t *instr)
 Write program instructions to their allocated location.
 
void pio_sm_reset (pio_t pio, pio_sm_t sm)
 Apply the default state machine configuration.
 
void pio_sm_restart (pio_t pio, pio_sm_t sm)
 Restart a state machine.
 
void pio_set_isr_vec (pio_t pio, pio_sm_t sm, const pio_isr_vec_t *vec)
 Set ISR callbacks for FIFO interrupts per state machine.
 
void pio_set_isr_sm_vec (pio_t pio, unsigned irq, const pio_isr_sm_vec_t *vec)
 Set ISR callbacks for state machine interrupts.
 
void pio_sm_set_out_pins (pio_t pio, pio_sm_t sm, gpio_t pin_base, unsigned pin_count)
 Configure which pins are writeable by an 'out pins' instruction.
 
void pio_sm_set_in_pins (pio_t pio, pio_sm_t sm, gpio_t pin_base)
 Configure the state machine input pin mapping.
 
void pio_sm_set_set_pins (pio_t pio, pio_sm_t sm, gpio_t pin_base, unsigned pin_count)
 Configure which pins are effected by a 'set pins' instructions.
 
void pio_sm_set_sideset_pins (pio_t pio, pio_sm_t sm, gpio_t pin_base)
 Set the first pin of a sequence of sideset count pins which are effected by sideset instructions.
 
void pio_sm_set_sideset_count (pio_t pio, pio_sm_t sm, unsigned pin_count, bool enable)
 Configure how many pins are sideset pins and whether a sideset is optional or required for every instruction.
 
void pio_sm_set_sideset_target (pio_t pio, pio_sm_t sm, bool pindir)
 Configure whether a sideset effects pins or pin directions.
 
pio_sm_clkdiv_t pio_sm_clkdiv (uint32_t f_hz)
 Create a clock divider struct.
 
void pio_sm_set_clkdiv (pio_t pio, pio_sm_t sm, pio_sm_clkdiv_t clk)
 Apply the clock configuration to a PIO.
 
void pio_sm_clkdiv_restart (pio_t pio, unsigned sm_mask)
 Restart the clock divider of several state machines.
 
void pio_sm_set_wrap (pio_t pio, pio_sm_t sm, unsigned prog_loc, uint8_t top, uint8_t bottom)
 Set program instruction wrap boundaries.
 
void pio_sm_set_jmp_pin (pio_t pio, pio_sm_t sm, gpio_t pin)
 Configure the pin on which to branch on a 'jmp pins' instruction.
 
void pio_sm_set_in_shift (pio_t pio, pio_sm_t sm, bool right, bool autopush, unsigned threshold)
 Configure the shift in behaviour of a state machine.
 
void pio_sm_set_out_shift (pio_t pio, pio_sm_t sm, bool right, bool autopull, unsigned threshold)
 Configure the shift out behaviour of a state machine.
 
void pio_sm_set_fifo_join_rx (pio_t pio, pio_sm_t sm)
 Join the TX FIFO to the RX FIFO.
 
void pio_sm_set_fifo_join_tx (pio_t pio, pio_sm_t sm)
 Join the RX FIFO to the TX FIFO.
 
void pio_sm_reset_fifos (pio_t pio, pio_sm_t sm)
 No joined FIFO.
 
void pio_sm_clear_fifos (pio_t pio, pio_sm_t sm)
 Drop all pending words in the tx and rx FIFO.
 
void pio_irq_enable (pio_t pio, pio_irq_line_t irq, pio_irq_source_t irq_mask)
 Enable PIO<pio>_IRQ<irq> interrupts.
 
void pio_irq_disable (pio_t pio, pio_irq_line_t irq, pio_irq_source_t irq_mask)
 Disable PIO<pio>_IRQ<irq> interrupts.
 
int pio_sm_transmit_word (pio_t pio, pio_sm_t sm, uint32_t word)
 Send one word to a state machine.
 
void pio_sm_transmit_word_block (pio_t pio, pio_sm_t sm, uint32_t word)
 Send one word to a state machine.
 
void pio_sm_transmit_words_block (pio_t pio, pio_sm_t sm, const uint32_t *words, unsigned count)
 Send count words to a state machine.
 
int pio_sm_receive_word (pio_t pio, pio_sm_t sm, uint32_t *word)
 Receive a word from a state machine.
 
void pio_sm_receive_word_block (pio_t pio, pio_sm_t sm, uint32_t *word)
 Receive one word from a state machine.
 
void pio_sm_receive_words_block (pio_t pio, pio_sm_t sm, uint32_t *words, unsigned count)
 Receive words from a state machine.
 
uint32_t pio_irq_get (pio_t pio)
 Read interrupt flags.
 
void pio_irq_clear (pio_t pio, unsigned irq_flags)
 Clear interrupt flags.
 
int pio_sm_init_common (pio_t pio, pio_sm_t sm, const pio_program_t *prog, const pio_program_conf_t *conf)
 Apply common program configuration.
 
void pio_sm_set_pindirs_with_mask (pio_t pio, pio_sm_t sm, gpio_t values, gpio_t mask)
 Apply pin directions in values for which the corresponding bit in mask is set.
 
void pio_sm_set_pins_with_mask (pio_t pio, pio_sm_t sm, gpio_t values, gpio_t mask)
 Apply pin values in values for which the corresponding bit in mask is set.
 
void pio_sm_set_set_pins_init (pio_t pio, pio_sm_t sm, const pio_gpio_init_t *pin_init)
 Set pins affected by 'set pins' and 'set pindirs' instructions and initialize the pins as PIO pins and a state according to pin_init.
 
void pio_sm_set_out_pins_init (pio_t pio, pio_sm_t sm, const pio_gpio_init_t *pin_init)
 Set output pins affected by 'out pins', 'out pindirs' and 'mov pins' instructions and initialize the pins as PIO pins and a state according to pin_init.
 
void pio_sm_set_sideset_pins_init (pio_t pio, pio_sm_t sm, const pio_gpio_init_t *pin_init)
 Set pins affected by sideset instructions and initialize the pins as PIO pins and a state according to pin_init.
 
void pio_print_status (pio_t pio)
 Print status information about the FIFOs and programs.
 
void pio_print_debug (pio_t pio)
 Print debug information about the current state of this PIO.
 
static void pio_sm_clear_debug_txstall (pio_t pio, unsigned sm_mask)
 Clear TX stall debug flag.
 
static void pio_sm_clear_debug_txover (pio_t pio, unsigned sm_mask)
 Clear TX overflow debug flag.
 
static void pio_sm_clear_debug_rxunder (pio_t pio, unsigned sm_mask)
 Clear RX underflow debug flag.
 
static void pio_sm_clear_debug_rxstall (pio_t pio, unsigned sm_mask)
 Clear RX stall debug flag.
 
static bool pio_sm_tx_fifo_empty (pio_t pio, pio_sm_t sm)
 Check if TX FIFO is empty.
 
static bool pio_sm_tx_fifo_full (pio_t pio, pio_sm_t sm)
 Check if TX FIFO is full.
 
static bool pio_sm_rx_fifo_empty (pio_t pio, pio_sm_t sm)
 Check if RX FIFO is empty.
 
static bool pio_sm_rx_fifo_full (pio_t pio, pio_sm_t sm)
 Check if RX FIFO is full.
 
#define PIO_SM_NUMOF   4
 Number of state machines per PIO.
 
#define PIO_INSTR_NUMOF   32
 Maximum number of instructions per PIO.
 
#define PIO_IRQ_NUMOF   8
 Number of interrupt flags per PIO.
 
#define PIO_GPIO_INIT_HIGH(pin)   (((gpio_t)(1)) << (pin))
 To be used to set the state of a PIO pin in pio_gpio_init_t::gpio_state to high.
 
#define PIO_GPIO_INIT_LOW(pin)   ((gpio_t)0)
 To be used to set the state of a PIO pin in pio_gpio_init_t::gpio_state to low.
 
#define PIO_GPIO_INIT_OUT(pin)   (((gpio_t)(1)) << (pin))
 To be used to set the direction of a PIO pin in pio_gpio_init_t::gpio_state as output.
 
#define PIO_GPIO_INIT_IN(pin)   ((gpio_t)0)
 To be used to set the direction of a PIO pin in pio_gpio_init_t::gpio_state as input.
 
typedef uint16_t pio_instr_t
 Type to represent the width of an instruction.
 

PIO instruction set

#define PIO_INST_JMP   (0u << 13)
 JMP opcode.
 
#define PIO_INST_JMP_MASK   (7u << 13)
 JMP opcode mask.
 
#define PIO_INST_JMP_CONDITION_SHIFT   5
 JMP condition shift position.
 
#define PIO_INST_JMP_CONDITION_MASK   (7u << PIO_INST_JMP_CONDITION_SHIFT)
 JMP condition mask.
 
#define PIO_INST_JMP_ADDRESS_MASK   (31u)
 JMP address mask.
 
#define PIO_INST_WAIT   (1u << 13)
 WAIT opcode.
 
#define PIO_INST_WAIT_MASK   (7u << 13)
 WAIT opcode mask.
 
#define PIO_INST_WAIT_POL_SHIFT   7
 WAIT polarity shift position.
 
#define PIO_INST_WAIT_POL_MASK   (1u << PIO_INST_WAIT_POL_SHIFT)
 WAIT polarity mask.
 
#define PIO_INST_WAIT_SOURCE_SHIFT   5
 WAIT source shift positions.
 
#define PIO_INST_WAIT_SOURCE_MASK   (3u << PIO_INST_WAIT_SOURCE_SHIFT)
 WAIT source mask.
 
#define PIO_INST_WAIT_INDEX_MASK   (31u)
 WAIT index mask.
 
#define PIO_INST_IN   (2u << 13)
 IN opcode.
 
#define PIO_INST_IN_MASK   (7u << 13)
 IN opcode mask.
 
#define PIO_INST_IN_SOURCE_SHIFT   5
 IN source shift position.
 
#define PIO_INST_IN_SOURCE_MASK   (7u << PIO_INST_IN_SOURCE_SHIFT)
 IN source mask.
 
#define PIO_INST_IN_BIT_COUNT_MASK   (31u)
 Number of bits to be shifted into the input shift register.
 
#define PIO_INST_OUT   (3u << 13)
 OUT opcode.
 
#define PIO_INST_OUT_MASK   (7u << 13)
 OUT opcode mask.
 
#define PIO_INST_OUT_DESTINATION_SHIFT   5
 OUT destination shift position.
 
#define PIO_INST_OUT_DESTINATION_MASK   (7u << PIO_INST_OUT_DESTINATION_SHIFT)
 OUT destination mask.
 
#define PIO_INST_OUT_BIT_COUNT_MASK   (31u)
 Number of bits to be shifted out of the output shift register.
 
#define PIO_INST_PUSH   (4u << 13)
 PUSH opcode.
 
#define PIO_INST_PUSH_MASK   ((7u << 13) | (1u << 7) | 31u)
 PUSH opcode mask.
 
#define PIO_INST_PUSH_IF_FULL_SHIFT   6
 PUSH if input shift register is full shift position.
 
#define PIO_INST_PUSH_IF_FULL_MASK   (1u << PIO_INST_PUSH_IF_FULL_SHIFT)
 PUSH if input shift register is full mask.
 
#define PIO_INST_PUSH_BLOCK_SHIFT   5
 PUSH if RX FIFO is not full shift position.
 
#define PIO_INST_PUSH_BLOCK_MASK   (1u << PIO_INST_PUSH_BLOCK_SHIFT)
 PUSH if RX FIFO is not full mask.
 
#define PIO_INST_PULL   ((4u << 13) | (1u << 7))
 PULL opcode.
 
#define PIO_INST_PULL_MASK   ((7u << 13) | (1u << 7) | 31u)
 PULL opcode mask.
 
#define PIO_INST_PULL_IF_EMPTY_SHIFT   6
 PULL if output shift register is empty flag shift position.
 
#define PIO_INST_PULL_IF_EMPTY_MASK   (1u << PIO_INST_PULL_IF_EMPTY_SHIFT)
 PULL if output shift register is empty mask.
 
#define PIO_INST_PULL_BLOCK_SHIFT   5
 PULL if TX FIFO is not empty flag shift position.
 
#define PIO_INST_PULL_BLOCK_MASK   (1u << PIO_INST_PULL_BLOCK_SHIFT)
 PULL if TX FIFO is not empty mask.
 
#define PIO_INST_MOV   (5u << 13)
 MOV opcode.
 
#define PIO_INST_MOV_MASK   (7u << 13)
 MOV opcode mask.
 
#define PIO_INST_MOV_DESTINATION_SHIFT   5
 MOV destination shift position.
 
#define PIO_INST_MOV_DESTINATION_MASK   (7u << PIO_INST_MOV_DESTINATION_SHIFT)
 MOV destination mask.
 
#define PIO_INST_MOV_OP_SHIFT   3
 MOV operation shift position.
 
#define PIO_INST_MOV_OP_MASK   (3u << PIO_INST_MOV_OP_SHIFT)
 MOV operation mask.
 
#define PIO_INST_MOV_SOURCE_SHIFT   0
 MOV source shift position.
 
#define PIO_INST_MOV_SOURCE_MASK   (7u)
 MOV source mask.
 
#define PIO_INST_IRQ   (6u << 13)
 IRQ opcode.
 
#define PIO_INST_IRQ_MASK   ((7u << 13) | (1u << 7))
 IRQ opcode mask.
 
#define PIO_INST_IRQ_CLR_SHIFT   6
 IRQ clear flag shift position.
 
#define PIO_INST_IRQ_CLR_MASK   (1u << PIO_INST_IRQ_CLR_SHIFT)
 IRQ clear flag mask.
 
#define PIO_INST_IRQ_WAIT_SHIFT   5
 IRQ wait until cleared flag shift position.
 
#define PIO_INST_IRQ_WAIT_MASK   (1u << PIO_INST_IRQ_WAIT_SHIFT)
 IRQ wait until cleared flag mask.
 
#define PIO_INST_IRQ_INDEX_MASK   (31u)
 IRQ index mask.
 
#define PIO_INST_SET   (7u << 13)
 SET opcode.
 
#define PIO_INST_SET_MASK   (7u << 13)
 SET opcode mask.
 
#define PIO_INST_SET_DESTINATION_SHIFT   5
 SET destination shift position.
 
#define PIO_INST_SET_DESTINATION_MASK   (7u << PIO_INST_SET_DESTINATION_SHIFT)
 SET destination mask.
 
#define PIO_INST_SET_DATA_MASK   (31u)
 SET data mask.
 
enum  pio_inst_jmp_cond_t {
  PIO_INST_JMP_COND_NONE = 0 , PIO_INST_JMP_COND_X_ZERO = 1 , PIO_INST_JMP_COND_X_DEC = 2 , PIO_INST_JMP_COND_Y_ZERO = 3 ,
  PIO_INST_JMP_COND_Y_DEC = 4 , PIO_INST_JMP_COND_NOT_X_EQ_Y = 5 , PIO_INST_JMP_COND_PIN = 6 , PIO_INST_JMP_COND_NOT_OSR_EMPTY = 7
}
 JMP conditions. More...
 
enum  pio_inst_wait_pol_t { PIO_INST_WAIT_POL_LOW = 0 , PIO_INST_WAIT_POL_HIGH = 1 }
 WAIT polarities. More...
 
enum  pio_inst_wait_src_t { PIO_INST_WAIT_SRC_GPIO = 0 , PIO_INST_WAIT_SRC_PIN = 1 , PIO_INST_WAIT_SRC_IRQ = 2 }
 WAIT sources. More...
 
enum  pio_inst_in_src_t {
  PIO_INST_IN_SRC_PINS = 0 , PIO_INST_IN_SRC_X = 1 , PIO_INST_IN_SRC_Y = 2 , PIO_INST_IN_SRC_NULL = 3 ,
  PIO_INST_IN_SRC_ISR = 6 , PIO_INST_IN_SRC_OSR = 7
}
 IN sources. More...
 
enum  pio_inst_out_dst_t {
  PIO_INST_OUT_DST_PINS = 0 , PIO_INST_OUT_DST_X = 1 , PIO_INST_OUT_DST_Y = 2 , PIO_INST_OUT_DST_NULL = 3 ,
  PIO_INST_OUT_DST_PINDIRS = 4 , PIO_INST_OUT_DST_PC = 5 , PIO_INST_OUT_DST_ISR = 6 , PIO_INST_OUT_DST_EXEC = 7
}
 OUT destinations. More...
 
enum  pio_inst_mov_dst_t {
  PIO_INST_MOV_DST_PINS = 0 , PIO_INST_MOV_DST_X = 1 , PIO_INST_MOV_DST_Y = 2 , PIO_INST_MOV_DST_EXEC = 4 ,
  PIO_INST_MOV_DST_PC = 5 , PIO_INST_MOV_DST_ISR = 6 , PIO_INST_MOV_DST_OSR = 7
}
 MOV destinations. More...
 
enum  pio_inst_mov_op_t { PIO_INST_MOV_OP_NONE = 0 , PIO_INST_MOV_OP_INVERT = 1 , PIO_INST_MOV_OP_REVERSE = 2 }
 MOV operation. More...
 
enum  pio_inst_mov_src_t {
  PIO_INST_MOV_SRC_PINS = 0 , PIO_INST_MOV_SRC_X = 1 , PIO_INST_MOV_SRC_Y = 2 , PIO_INST_MOV_SRC_NULL = 3 ,
  PIO_INST_MOV_SRC_STATUS = 5 , PIO_INST_MOV_SRC_ISR = 6 , PIO_INST_MOV_SRC_OSR = 7
}
 MOV source. More...
 
enum  pio_inst_set_dst_t { PIO_INST_SET_DST_PINS = 0 , PIO_INST_SET_DST_X = 1 , PIO_INST_SET_DST_Y = 2 , PIO_INST_SET_DST_PINDIRS = 4 }
 SET destinations. More...
 
static pio_instr_t pio_inst_jmp (pio_inst_jmp_cond_t condition, unsigned address)
 Construct a JMP instruction.
 
static pio_instr_t pio_inst_wait (pio_inst_wait_pol_t polarity, pio_inst_wait_src_t source, bool relative, unsigned index)
 Construct a WAIT instruction.
 
static pio_instr_t pio_inst_in (pio_inst_in_src_t source, unsigned bit_count)
 Construct an IN instruction.
 
static pio_instr_t pio_inst_out (pio_inst_out_dst_t destination, unsigned bit_count)
 Construct an OUT instruction.
 
static pio_instr_t pio_inst_push (bool if_full, bool block)
 Construct a PUSH instruction.
 
static pio_instr_t pio_inst_pull (bool if_empty, bool block)
 Construct a PULL instruction.
 
static pio_instr_t pio_inst_mov (pio_inst_mov_dst_t destination, pio_inst_mov_op_t operation, pio_inst_mov_src_t source)
 Construct a MOV instruction.
 
static pio_instr_t pio_inst_irq (bool clear, bool wait, bool relative, unsigned index)
 Construct an IRQ instruction.
 
static pio_instr_t pio_inst_set (pio_inst_set_dst_t destination, unsigned data)
 Construct a SET instruction.
 
static pio_instr_t pio_inst_delay_sideset (unsigned sideset, unsigned sideset_count, bool sideset_opt, unsigned delay)
 Encode the delay/sideset instruction field.
 

Macro Definition Documentation

◆ PIO_GPIO_INIT_HIGH

#define PIO_GPIO_INIT_HIGH (   pin)    (((gpio_t)(1)) << (pin))

To be used to set the state of a PIO pin in pio_gpio_init_t::gpio_state to high.

Parameters
[in]pinGPIO pin relative to pio_gpio_init_t::gpio_base starting with 0

Definition at line 57 of file pio.h.

◆ PIO_GPIO_INIT_IN

#define PIO_GPIO_INIT_IN (   pin)    ((gpio_t)0)

To be used to set the direction of a PIO pin in pio_gpio_init_t::gpio_state as input.

Parameters
[in]pinGPIO pin relative to pio_gpio_init_t::gpio_base starting with 0

Definition at line 78 of file pio.h.

◆ PIO_GPIO_INIT_LOW

#define PIO_GPIO_INIT_LOW (   pin)    ((gpio_t)0)

To be used to set the state of a PIO pin in pio_gpio_init_t::gpio_state to low.

Parameters
[in]pinGPIO pin relative to pio_gpio_init_t::gpio_base starting with 0

Definition at line 64 of file pio.h.

◆ PIO_GPIO_INIT_OUT

#define PIO_GPIO_INIT_OUT (   pin)    (((gpio_t)(1)) << (pin))

To be used to set the direction of a PIO pin in pio_gpio_init_t::gpio_state as output.

Parameters
[in]pinGPIO pin relative to pio_gpio_init_t::gpio_base starting with 0

Definition at line 71 of file pio.h.

◆ PIO_INST_IN

#define PIO_INST_IN   (2u << 13)

IN opcode.

Definition at line 175 of file pio.h.

◆ PIO_INST_IN_BIT_COUNT_MASK

#define PIO_INST_IN_BIT_COUNT_MASK   (31u)

Number of bits to be shifted into the input shift register.

Definition at line 191 of file pio.h.

◆ PIO_INST_IN_MASK

#define PIO_INST_IN_MASK   (7u << 13)

IN opcode mask.

Definition at line 179 of file pio.h.

◆ PIO_INST_IN_SOURCE_MASK

#define PIO_INST_IN_SOURCE_MASK   (7u << PIO_INST_IN_SOURCE_SHIFT)

IN source mask.

Definition at line 187 of file pio.h.

◆ PIO_INST_IN_SOURCE_SHIFT

#define PIO_INST_IN_SOURCE_SHIFT   5

IN source shift position.

Definition at line 183 of file pio.h.

◆ PIO_INST_IRQ

#define PIO_INST_IRQ   (6u << 13)

IRQ opcode.

Definition at line 351 of file pio.h.

◆ PIO_INST_IRQ_CLR_MASK

#define PIO_INST_IRQ_CLR_MASK   (1u << PIO_INST_IRQ_CLR_SHIFT)

IRQ clear flag mask.

Definition at line 363 of file pio.h.

◆ PIO_INST_IRQ_CLR_SHIFT

#define PIO_INST_IRQ_CLR_SHIFT   6

IRQ clear flag shift position.

Definition at line 359 of file pio.h.

◆ PIO_INST_IRQ_INDEX_MASK

#define PIO_INST_IRQ_INDEX_MASK   (31u)

IRQ index mask.

Definition at line 375 of file pio.h.

◆ PIO_INST_IRQ_MASK

#define PIO_INST_IRQ_MASK   ((7u << 13) | (1u << 7))

IRQ opcode mask.

Definition at line 355 of file pio.h.

◆ PIO_INST_IRQ_WAIT_MASK

#define PIO_INST_IRQ_WAIT_MASK   (1u << PIO_INST_IRQ_WAIT_SHIFT)

IRQ wait until cleared flag mask.

Definition at line 371 of file pio.h.

◆ PIO_INST_IRQ_WAIT_SHIFT

#define PIO_INST_IRQ_WAIT_SHIFT   5

IRQ wait until cleared flag shift position.

Definition at line 367 of file pio.h.

◆ PIO_INST_JMP

#define PIO_INST_JMP   (0u << 13)

JMP opcode.

Definition at line 99 of file pio.h.

◆ PIO_INST_JMP_ADDRESS_MASK

#define PIO_INST_JMP_ADDRESS_MASK   (31u)

JMP address mask.

Definition at line 115 of file pio.h.

◆ PIO_INST_JMP_CONDITION_MASK

#define PIO_INST_JMP_CONDITION_MASK   (7u << PIO_INST_JMP_CONDITION_SHIFT)

JMP condition mask.

Definition at line 111 of file pio.h.

◆ PIO_INST_JMP_CONDITION_SHIFT

#define PIO_INST_JMP_CONDITION_SHIFT   5

JMP condition shift position.

Definition at line 107 of file pio.h.

◆ PIO_INST_JMP_MASK

#define PIO_INST_JMP_MASK   (7u << 13)

JMP opcode mask.

Definition at line 103 of file pio.h.

◆ PIO_INST_MOV

#define PIO_INST_MOV   (5u << 13)

MOV opcode.

Definition at line 287 of file pio.h.

◆ PIO_INST_MOV_DESTINATION_MASK

#define PIO_INST_MOV_DESTINATION_MASK   (7u << PIO_INST_MOV_DESTINATION_SHIFT)

MOV destination mask.

Definition at line 299 of file pio.h.

◆ PIO_INST_MOV_DESTINATION_SHIFT

#define PIO_INST_MOV_DESTINATION_SHIFT   5

MOV destination shift position.

Definition at line 295 of file pio.h.

◆ PIO_INST_MOV_MASK

#define PIO_INST_MOV_MASK   (7u << 13)

MOV opcode mask.

Definition at line 291 of file pio.h.

◆ PIO_INST_MOV_OP_MASK

#define PIO_INST_MOV_OP_MASK   (3u << PIO_INST_MOV_OP_SHIFT)

MOV operation mask.

Definition at line 307 of file pio.h.

◆ PIO_INST_MOV_OP_SHIFT

#define PIO_INST_MOV_OP_SHIFT   3

MOV operation shift position.

Definition at line 303 of file pio.h.

◆ PIO_INST_MOV_SOURCE_MASK

#define PIO_INST_MOV_SOURCE_MASK   (7u)

MOV source mask.

Definition at line 315 of file pio.h.

◆ PIO_INST_MOV_SOURCE_SHIFT

#define PIO_INST_MOV_SOURCE_SHIFT   0

MOV source shift position.

Definition at line 311 of file pio.h.

◆ PIO_INST_OUT

#define PIO_INST_OUT   (3u << 13)

OUT opcode.

Definition at line 206 of file pio.h.

◆ PIO_INST_OUT_BIT_COUNT_MASK

#define PIO_INST_OUT_BIT_COUNT_MASK   (31u)

Number of bits to be shifted out of the output shift register.

Definition at line 222 of file pio.h.

◆ PIO_INST_OUT_DESTINATION_MASK

#define PIO_INST_OUT_DESTINATION_MASK   (7u << PIO_INST_OUT_DESTINATION_SHIFT)

OUT destination mask.

Definition at line 218 of file pio.h.

◆ PIO_INST_OUT_DESTINATION_SHIFT

#define PIO_INST_OUT_DESTINATION_SHIFT   5

OUT destination shift position.

Definition at line 214 of file pio.h.

◆ PIO_INST_OUT_MASK

#define PIO_INST_OUT_MASK   (7u << 13)

OUT opcode mask.

Definition at line 210 of file pio.h.

◆ PIO_INST_PULL

#define PIO_INST_PULL   ((4u << 13) | (1u << 7))

PULL opcode.

Definition at line 263 of file pio.h.

◆ PIO_INST_PULL_BLOCK_MASK

#define PIO_INST_PULL_BLOCK_MASK   (1u << PIO_INST_PULL_BLOCK_SHIFT)

PULL if TX FIFO is not empty mask.

Definition at line 283 of file pio.h.

◆ PIO_INST_PULL_BLOCK_SHIFT

#define PIO_INST_PULL_BLOCK_SHIFT   5

PULL if TX FIFO is not empty flag shift position.

Definition at line 279 of file pio.h.

◆ PIO_INST_PULL_IF_EMPTY_MASK

#define PIO_INST_PULL_IF_EMPTY_MASK   (1u << PIO_INST_PULL_IF_EMPTY_SHIFT)

PULL if output shift register is empty mask.

Definition at line 275 of file pio.h.

◆ PIO_INST_PULL_IF_EMPTY_SHIFT

#define PIO_INST_PULL_IF_EMPTY_SHIFT   6

PULL if output shift register is empty flag shift position.

Definition at line 271 of file pio.h.

◆ PIO_INST_PULL_MASK

#define PIO_INST_PULL_MASK   ((7u << 13) | (1u << 7) | 31u)

PULL opcode mask.

Definition at line 267 of file pio.h.

◆ PIO_INST_PUSH

#define PIO_INST_PUSH   (4u << 13)

PUSH opcode.

Definition at line 239 of file pio.h.

◆ PIO_INST_PUSH_BLOCK_MASK

#define PIO_INST_PUSH_BLOCK_MASK   (1u << PIO_INST_PUSH_BLOCK_SHIFT)

PUSH if RX FIFO is not full mask.

Definition at line 259 of file pio.h.

◆ PIO_INST_PUSH_BLOCK_SHIFT

#define PIO_INST_PUSH_BLOCK_SHIFT   5

PUSH if RX FIFO is not full shift position.

Definition at line 255 of file pio.h.

◆ PIO_INST_PUSH_IF_FULL_MASK

#define PIO_INST_PUSH_IF_FULL_MASK   (1u << PIO_INST_PUSH_IF_FULL_SHIFT)

PUSH if input shift register is full mask.

Definition at line 251 of file pio.h.

◆ PIO_INST_PUSH_IF_FULL_SHIFT

#define PIO_INST_PUSH_IF_FULL_SHIFT   6

PUSH if input shift register is full shift position.

Definition at line 247 of file pio.h.

◆ PIO_INST_PUSH_MASK

#define PIO_INST_PUSH_MASK   ((7u << 13) | (1u << 7) | 31u)

PUSH opcode mask.

Definition at line 243 of file pio.h.

◆ PIO_INST_SET

#define PIO_INST_SET   (7u << 13)

SET opcode.

Definition at line 379 of file pio.h.

◆ PIO_INST_SET_DATA_MASK

#define PIO_INST_SET_DATA_MASK   (31u)

SET data mask.

Definition at line 395 of file pio.h.

◆ PIO_INST_SET_DESTINATION_MASK

#define PIO_INST_SET_DESTINATION_MASK   (7u << PIO_INST_SET_DESTINATION_SHIFT)

SET destination mask.

Definition at line 391 of file pio.h.

◆ PIO_INST_SET_DESTINATION_SHIFT

#define PIO_INST_SET_DESTINATION_SHIFT   5

SET destination shift position.

Definition at line 387 of file pio.h.

◆ PIO_INST_SET_MASK

#define PIO_INST_SET_MASK   (7u << 13)

SET opcode mask.

Definition at line 383 of file pio.h.

◆ PIO_INST_WAIT

#define PIO_INST_WAIT   (1u << 13)

WAIT opcode.

Definition at line 132 of file pio.h.

◆ PIO_INST_WAIT_INDEX_MASK

#define PIO_INST_WAIT_INDEX_MASK   (31u)

WAIT index mask.

Definition at line 156 of file pio.h.

◆ PIO_INST_WAIT_MASK

#define PIO_INST_WAIT_MASK   (7u << 13)

WAIT opcode mask.

Definition at line 136 of file pio.h.

◆ PIO_INST_WAIT_POL_MASK

#define PIO_INST_WAIT_POL_MASK   (1u << PIO_INST_WAIT_POL_SHIFT)

WAIT polarity mask.

Definition at line 144 of file pio.h.

◆ PIO_INST_WAIT_POL_SHIFT

#define PIO_INST_WAIT_POL_SHIFT   7

WAIT polarity shift position.

Definition at line 140 of file pio.h.

◆ PIO_INST_WAIT_SOURCE_MASK

#define PIO_INST_WAIT_SOURCE_MASK   (3u << PIO_INST_WAIT_SOURCE_SHIFT)

WAIT source mask.

Definition at line 152 of file pio.h.

◆ PIO_INST_WAIT_SOURCE_SHIFT

#define PIO_INST_WAIT_SOURCE_SHIFT   5

WAIT source shift positions.

Definition at line 148 of file pio.h.

◆ PIO_INSTR_NUMOF

#define PIO_INSTR_NUMOF   32

Maximum number of instructions per PIO.

Definition at line 39 of file pio.h.

◆ PIO_IRQ_MASK

#define PIO_IRQ_MASK (   irq)    (1u << (irq))

Convert IRQ index to bitmask.

Definition at line 606 of file pio.h.

◆ PIO_IRQ_NUMOF

#define PIO_IRQ_NUMOF   8

Number of interrupt flags per PIO.

Definition at line 44 of file pio.h.

◆ PIO_IRQ_REL_MASK

#define PIO_IRQ_REL_MASK (   irq,
  sm 
)    PIO_IRQ_MASK(pio_irq_rel_index(irq, sm))

Convert relative IRQ index to bitmask.

Definition at line 665 of file pio.h.

◆ PIO_SM_CLKDIV_MAX

#define PIO_SM_CLKDIV_MAX   65536

Maximum clock divider.

Definition at line 596 of file pio.h.

◆ PIO_SM_CTRL_BASE

#define PIO_SM_CTRL_BASE (   dev)    ((pio_sm_ctrl_regs_t *)(&((dev)->SM0_CLKDIV)))

State machine configuration registers.

Definition at line 591 of file pio.h.

◆ PIO_SM_MASK

#define PIO_SM_MASK (   sm)    (1u << (sm))

Convert state machine index to bitmask.

Definition at line 601 of file pio.h.

◆ PIO_SM_NUMOF

#define PIO_SM_NUMOF   4

Number of state machines per PIO.

Definition at line 34 of file pio.h.

Typedef Documentation

◆ pio_instr_t

typedef uint16_t pio_instr_t

Type to represent the width of an instruction.

Definition at line 50 of file pio.h.

Enumeration Type Documentation

◆ pio_inst_in_src_t

IN sources.

Enumerator
PIO_INST_IN_SRC_PINS 

From input pins.

PIO_INST_IN_SRC_X 

From scratch X.

PIO_INST_IN_SRC_Y 

From scratch Y.

PIO_INST_IN_SRC_NULL 

Fill with zeros.

PIO_INST_IN_SRC_ISR 

From input shift register.

PIO_INST_IN_SRC_OSR 

From output shift register.

Definition at line 195 of file pio.h.

◆ pio_inst_jmp_cond_t

JMP conditions.

Enumerator
PIO_INST_JMP_COND_NONE 

Unconditionally.

PIO_INST_JMP_COND_X_ZERO 

If scratch X is 0.

PIO_INST_JMP_COND_X_DEC 

If scratch X– is not 0.

PIO_INST_JMP_COND_Y_ZERO 

If scratch Y is 0.

PIO_INST_JMP_COND_Y_DEC 

If scratch Y– is not 0.

PIO_INST_JMP_COND_NOT_X_EQ_Y 

If scratch X != scratch Y.

PIO_INST_JMP_COND_PIN 

If jump pin is high.

PIO_INST_JMP_COND_NOT_OSR_EMPTY 

If OSR is not empty.

Definition at line 119 of file pio.h.

◆ pio_inst_mov_dst_t

MOV destinations.

Enumerator
PIO_INST_MOV_DST_PINS 

To output pins.

PIO_INST_MOV_DST_X 

To scratch X.

PIO_INST_MOV_DST_Y 

To scratch Y.

PIO_INST_MOV_DST_EXEC 

Execute data as instruction.

PIO_INST_MOV_DST_PC 

To program counter.

PIO_INST_MOV_DST_ISR 

To input shift register.

PIO_INST_MOV_DST_OSR 

To output shift register.

Definition at line 319 of file pio.h.

◆ pio_inst_mov_op_t

MOV operation.

Enumerator
PIO_INST_MOV_OP_NONE 

No operation.

PIO_INST_MOV_OP_INVERT 

Bitwise complement.

PIO_INST_MOV_OP_REVERSE 

Bitwise reverse.

Definition at line 331 of file pio.h.

◆ pio_inst_mov_src_t

MOV source.

Enumerator
PIO_INST_MOV_SRC_PINS 

From input pins.

PIO_INST_MOV_SRC_X 

From scratch X.

PIO_INST_MOV_SRC_Y 

From scratch Y.

PIO_INST_MOV_SRC_NULL 

Fill with zeros.

PIO_INST_MOV_SRC_STATUS 

From status.

PIO_INST_MOV_SRC_ISR 

From input shift register.

PIO_INST_MOV_SRC_OSR 

From output shift register.

Definition at line 339 of file pio.h.

◆ pio_inst_out_dst_t

OUT destinations.

Enumerator
PIO_INST_OUT_DST_PINS 

To output pins.

PIO_INST_OUT_DST_X 

To scratch X.

PIO_INST_OUT_DST_Y 

To scratch Y.

PIO_INST_OUT_DST_NULL 

Discard data.

PIO_INST_OUT_DST_PINDIRS 

To output pin directions.

PIO_INST_OUT_DST_PC 

To program counter.

PIO_INST_OUT_DST_ISR 

To input shift register.

PIO_INST_OUT_DST_EXEC 

Execute as instruction.

Definition at line 226 of file pio.h.

◆ pio_inst_set_dst_t

SET destinations.

Enumerator
PIO_INST_SET_DST_PINS 

To set pins.

PIO_INST_SET_DST_X 

To scratch X.

PIO_INST_SET_DST_Y 

To scratch Y.

PIO_INST_SET_DST_PINDIRS 

To set pin directions.

Definition at line 399 of file pio.h.

◆ pio_inst_wait_pol_t

WAIT polarities.

Enumerator
PIO_INST_WAIT_POL_LOW 

Wait for 0.

PIO_INST_WAIT_POL_HIGH 

Wait for 1.

Definition at line 160 of file pio.h.

◆ pio_inst_wait_src_t

WAIT sources.

Enumerator
PIO_INST_WAIT_SRC_GPIO 

Wait on GPIO.

PIO_INST_WAIT_SRC_PIN 

Wait on input pin.

PIO_INST_WAIT_SRC_IRQ 

Wait on interrupt.

Definition at line 167 of file pio.h.

◆ pio_irq_line_t

PIO interrupt lines.

Enumerator
PIO_IRQ_LINE_0 

IRQ line 0.

PIO_IRQ_LINE_1 

IRQ line 1.

PIO_IRQ_LINE_NUMOF 

Number of IRQ lines.

Definition at line 706 of file pio.h.

◆ pio_irq_source_t

PIO IRQ flags.

Enumerator
PIO_IRQ_SM_3 

Any state machine issued irq 3.

PIO_IRQ_SM_2 

Any state machine issued irq 2.

PIO_IRQ_SM_1 

Any state machine issued irq 1.

PIO_IRQ_SM_0 

any state machine issued irq 0

PIO_IRQ_TXNFULL_SM3 

SM3 TX FIFO is not full.

PIO_IRQ_TXNFULL_SM2 

SM2 TX FIFO is not full.

PIO_IRQ_TXNFULL_SM1 

SM1 TX FIFO is not full.

PIO_IRQ_TXNFULL_SM0 

SM0 TX FIFO is not full.

PIO_IRQ_RXNEMPTY_SM3 

SM3 RX FIFO is not empty.

PIO_IRQ_RXNEMPTY_SM2 

SM2 RX FIFO is not empty.

PIO_IRQ_RXNEMPTY_SM1 

SM1 RX FIFO is not empty.

PIO_IRQ_RXNEMPTY_SM0 

SM0 RX FIFO is not empty.

PIO_IRQ_ALL_SM 

All SM interrupts.

PIO_IRQ_ALL 

All flags above.

Definition at line 670 of file pio.h.

◆ pio_sm_mask_t

PIO state machine flags.

Enumerator
PIO_SM0 

Mask bit of SM 0.

PIO_SM1 

Mask bit of SM 1.

PIO_SM2 

Mask bit of SM 2.

PIO_SM3 

Mask bit of SM 3.

PIO_SM_ALL 

All flags above.

Definition at line 715 of file pio.h.

Function Documentation

◆ pio_inst_delay_sideset()

static pio_instr_t pio_inst_delay_sideset ( unsigned  sideset,
unsigned  sideset_count,
bool  sideset_opt,
unsigned  delay 
)
inlinestatic

Encode the delay/sideset instruction field.

Parameters
[in]sidesetSideset value to write to sideset pins
[in]sideset_countNumber of sideset pins
[in]sideset_optIf sideset is optional
[in]delayDelay cycles
Returns
Delay/sideset encoding that can be added to an instruction

Definition at line 565 of file pio.h.

◆ pio_inst_in()

static pio_instr_t pio_inst_in ( pio_inst_in_src_t  source,
unsigned  bit_count 
)
inlinestatic

Construct an IN instruction.

Parameters
[in]sourceFrom where to shift
[in]bit_countNumber of bits to shift
Returns
IN instruction

Definition at line 449 of file pio.h.

◆ pio_inst_irq()

static pio_instr_t pio_inst_irq ( bool  clear,
bool  wait,
bool  relative,
unsigned  index 
)
inlinestatic

Construct an IRQ instruction.

Parameters
[in]clearClear IRQ instead to raise it
[in]waitWait until IRQ is cleared if raised
[in]relativeIRQ index is relative to SM number
[in]indexIRQ index
Returns
IRQ instruction

Definition at line 529 of file pio.h.

◆ pio_inst_jmp()

static pio_instr_t pio_inst_jmp ( pio_inst_jmp_cond_t  condition,
unsigned  address 
)
inlinestatic

Construct a JMP instruction.

Parameters
[in]conditionJump if this condition is true
[in]addressAddress in instruction memory to jump to
Returns
JMP instruction

Definition at line 414 of file pio.h.

◆ pio_inst_mov()

static pio_instr_t pio_inst_mov ( pio_inst_mov_dst_t  destination,
pio_inst_mov_op_t  operation,
pio_inst_mov_src_t  source 
)
inlinestatic

Construct a MOV instruction.

Parameters
[in]destinationWhere to move to
[in]operationOperation to perform on move
[in]sourceWhere to move from
Returns
MOV instruction

Definition at line 510 of file pio.h.

◆ pio_inst_out()

static pio_instr_t pio_inst_out ( pio_inst_out_dst_t  destination,
unsigned  bit_count 
)
inlinestatic

Construct an OUT instruction.

Parameters
[in]destinationTo where to shift
[in]bit_countNumber of bits to shift
Returns
OUT instruction

Definition at line 464 of file pio.h.

◆ pio_inst_pull()

static pio_instr_t pio_inst_pull ( bool  if_empty,
bool  block 
)
inlinestatic

Construct a PULL instruction.

Parameters
[in]if_emptyOnly pull if shift threshold is reached
[in]blockBlock if TX FIFO is empty
Returns
PULL instruction

Definition at line 494 of file pio.h.

◆ pio_inst_push()

static pio_instr_t pio_inst_push ( bool  if_full,
bool  block 
)
inlinestatic

Construct a PUSH instruction.

Parameters
[in]if_fullOnly push if shift threshold is reached
[in]blockStall if RX FIFO is full
Returns
PUSH instruction

Definition at line 479 of file pio.h.

◆ pio_inst_set()

static pio_instr_t pio_inst_set ( pio_inst_set_dst_t  destination,
unsigned  data 
)
inlinestatic

Construct a SET instruction.

Parameters
[in]destinationSet destination
[in]dataData to set
Returns
SET instruction

Definition at line 547 of file pio.h.

◆ pio_inst_wait()

static pio_instr_t pio_inst_wait ( pio_inst_wait_pol_t  polarity,
pio_inst_wait_src_t  source,
bool  relative,
unsigned  index 
)
inlinestatic

Construct a WAIT instruction.

Parameters
[in]polarityPolarity
[in]sourceWhich source to wait on
[in]relativeIRQ index is relative to SM index
[in]indexWhich GPIO/PIN/IRQ to wait on
Returns
WAIT instruction

Definition at line 431 of file pio.h.

◆ pio_irq_clear()

void pio_irq_clear ( pio_t  pio,
unsigned  irq_flags 
)

Clear interrupt flags.

Parameters
[in]pioPIO index
[in]irq_flagsInterrupt flags to clear

◆ pio_irq_disable()

void pio_irq_disable ( pio_t  pio,
pio_irq_line_t  irq,
pio_irq_source_t  irq_mask 
)

Disable PIO<pio>_IRQ<irq> interrupts.

Parameters
[in]pioPIO index
[in]irqPIO IRQ line to use
[in]irq_maskIRQ flags to disable

◆ pio_irq_enable()

void pio_irq_enable ( pio_t  pio,
pio_irq_line_t  irq,
pio_irq_source_t  irq_mask 
)

Enable PIO<pio>_IRQ<irq> interrupts.

Parameters
[in]pioPIO index
[in]irqPIO IRQ line to use
[in]irq_maskIRQ flags to enable

◆ pio_irq_get()

uint32_t pio_irq_get ( pio_t  pio)

Read interrupt flags.

Parameters
[in]pioPIO index
Returns
IRQ flags

◆ pio_irq_rel_index()

static unsigned pio_irq_rel_index ( unsigned  irq_abs,
unsigned  sm 
)
inlinestatic

Convert absolute IRQ index to relative IRQ index.

A relative state machine interrupt instruction (see datasheet 3.4.9 IRQ) raises a certain flag in the IRQ register. The following table shows the values of the IRQ register for all combinations of interrupts and state machines. This allows that a program running on different state machines to raise a different IRQ flag. There are 8 PIO IRQ flags but only the lower 4 IRQ flags are cached by NVIC.

* +--------+---------------------------+---------------------------+---------------------------+---------------------------+
* |        | SM 0                      | SM 1                      | SM 2                      | SM 3                      |
* |        | IRQ indice | irq register | IRQ indice | irq register | IRQ indice | IRQ register | IRQ indice | IRQ register |
* +--------+---------------------------+---------------------------+---------------------------+---------------------------+
* | IRQ 0  | 0          | 0b00000001   | 1          | 0b00000010   | 2          | 0b00000100   | 3          | 0b00001000   |
* | IRQ 1  | 1          | 0b00000010   | 2          | 0b00000100   | 3          | 0b00001000   | 0          | 0b00000001   |
* | IRQ 2  | 2          | 0b00000100   | 3          | 0b00001000   | 0          | 0b00000001   | 1          | 0b00000010   |
* | IRQ 3  | 3          | 0b00001000   | 0          | 0b00000001   | 1          | 0b00000010   | 2          | 0b00000100   |
* +--------+------------+--------------+------------+--------------+------------+--------------+------------+--------------|
* | IRQ 4  | 4          | 0b00010000   | 5          | 0b00100000   | 6          | 0b01000000   | 7          | 0b10000000   |
* | IRQ 5  | 5          | 0b00100000   | 6          | 0b01000000   | 7          | 0b10000000   | 4          | 0b00010000   |
* | IRQ 6  | 6          | 0b01000000   | 7          | 0b10000000   | 4          | 0b00010000   | 5          | 0b00100000   |
* | IRQ 7  | 7          | 0b10000000   | 4          | 0b00010000   | 5          | 0b00100000   | 6          | 0b01000000   |
* +--------+------------+--------------+------------+--------------+------------+--------------+------------+--------------+
* 
Parameters
[in]irq_absAbsolute PIO IRQ index [0-7]
[in]smPIO state machine index
Returns
Relative PIO IRQ index

Definition at line 640 of file pio.h.

◆ pio_irq_rel_sm()

static unsigned pio_irq_rel_sm ( unsigned  irq_abs,
unsigned  irq_rel 
)
inlinestatic

Get state machine index from relative IRQ index.

rel = pio_irq_rel_index(abs, sm) <=> pio_irq_rel_sm(abs, rel) = sm

Parameters
[in]irq_absAbsolute PIO IRQ index [0-7]
[in]irq_relRelative PIO IRQ index [0-7]
Returns
PIO state machine index

Definition at line 656 of file pio.h.

◆ pio_print_debug()

void pio_print_debug ( pio_t  pio)

Print debug information about the current state of this PIO.

Parameters
[in]pioPIO index

◆ pio_print_status()

void pio_print_status ( pio_t  pio)

Print status information about the FIFOs and programs.

Parameters
[in]pioPIO index

◆ pio_set_isr_sm_vec()

void pio_set_isr_sm_vec ( pio_t  pio,
unsigned  irq,
const pio_isr_sm_vec_t vec 
)

Set ISR callbacks for state machine interrupts.

Parameters
[in]pioPIO index
[in]irqPIO IRQ index [0-3] or use pio_irq_rel_index
[in]vecState machine ISR callback vector

◆ pio_set_isr_vec()

void pio_set_isr_vec ( pio_t  pio,
pio_sm_t  sm,
const pio_isr_vec_t vec 
)

Set ISR callbacks for FIFO interrupts per state machine.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]vecFIFO ISR callback vector

◆ pio_sm_clear_debug_rxstall()

static void pio_sm_clear_debug_rxstall ( pio_t  pio,
unsigned  sm_mask 
)
inlinestatic

Clear RX stall debug flag.

Parameters
[in]pioPIO index
[in]sm_maskSM mask

Definition at line 1273 of file pio.h.

◆ pio_sm_clear_debug_rxunder()

static void pio_sm_clear_debug_rxunder ( pio_t  pio,
unsigned  sm_mask 
)
inlinestatic

Clear RX underflow debug flag.

Parameters
[in]pioPIO index
[in]sm_maskSM mask

Definition at line 1261 of file pio.h.

◆ pio_sm_clear_debug_txover()

static void pio_sm_clear_debug_txover ( pio_t  pio,
unsigned  sm_mask 
)
inlinestatic

Clear TX overflow debug flag.

Parameters
[in]pioPIO index
[in]sm_maskSM mask

Definition at line 1249 of file pio.h.

◆ pio_sm_clear_debug_txstall()

static void pio_sm_clear_debug_txstall ( pio_t  pio,
unsigned  sm_mask 
)
inlinestatic

Clear TX stall debug flag.

Parameters
[in]pioPIO index
[in]sm_maskSM mask

Definition at line 1237 of file pio.h.

◆ pio_sm_clear_fifos()

void pio_sm_clear_fifos ( pio_t  pio,
pio_sm_t  sm 
)

Drop all pending words in the tx and rx FIFO.

Parameters
[in]pioPIO index
[in]smPIO state machine index

◆ pio_sm_clkdiv()

pio_sm_clkdiv_t pio_sm_clkdiv ( uint32_t  f_hz)

Create a clock divider struct.

Warning
If the resulting clock divisor CLOCK_CORECLOCK / f_hz would be greater than PIO_SM_CLKDIV_MAX, an assert is fired.
Parameters
[in]f_hzDesired PIO frequency
Returns
Clock divider struct

◆ pio_sm_clkdiv_restart()

void pio_sm_clkdiv_restart ( pio_t  pio,
unsigned  sm_mask 
)

Restart the clock divider of several state machines.

This is useful if several state machines must be synchronized and to resync after the clock divider has been changed on-the-fly.

Parameters
[in]pioPIO index
[in]sm_maskPIO state machine mask pio_sm_mask_t

◆ pio_sm_exec()

int pio_sm_exec ( pio_t  pio,
pio_sm_t  sm,
pio_instr_t  inst 
)

Execute a single instruction.

This function does not wait until the instruction has completed. The instruction is written to SMx INSTR register and is immediately executed, interrupting other execution.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]instInstruction to be executed
Returns
Success: 0 Failure: < 0 (state machine stalls on a previous instruction)

◆ pio_sm_exec_block()

void pio_sm_exec_block ( pio_t  pio,
pio_sm_t  sm,
pio_instr_t  inst 
)

Execute a single instruction.

This function blocks until the instruction has completed. The instruction is written to SMx INSTR register and is immediately executed, interrupting other execution.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]instInstruction to be executed

◆ pio_sm_init_common()

int pio_sm_init_common ( pio_t  pio,
pio_sm_t  sm,
const pio_program_t prog,
const pio_program_conf_t conf 
)

Apply common program configuration.

This function should be called before any specific program parameters are set because the state machine is reset first.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]progProgram
[in]confProgram configuration
Returns
Success: 0 Failure: != 0

◆ pio_sm_receive_word()

int pio_sm_receive_word ( pio_t  pio,
pio_sm_t  sm,
uint32_t *  word 
)

Receive a word from a state machine.

This function does not block but returns a negative integer if there is no data.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[out]wordDestination to store the received word
Returns
Success: 0 Failure: != 0

◆ pio_sm_receive_word_block()

void pio_sm_receive_word_block ( pio_t  pio,
pio_sm_t  sm,
uint32_t *  word 
)

Receive one word from a state machine.

This function blocks until one word has been received.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[out]wordDestination to store the received word

◆ pio_sm_receive_words_block()

void pio_sm_receive_words_block ( pio_t  pio,
pio_sm_t  sm,
uint32_t *  words,
unsigned  count 
)

Receive words from a state machine.

This function blocks until count words have been received.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[out]wordsBuffer to store received words
[in]countNumber of words

◆ pio_sm_reset()

void pio_sm_reset ( pio_t  pio,
pio_sm_t  sm 
)

Apply the default state machine configuration.

Parameters
[in]pioPIO index
[in]smPIO state machine index

◆ pio_sm_reset_fifos()

void pio_sm_reset_fifos ( pio_t  pio,
pio_sm_t  sm 
)

No joined FIFO.

Parameters
[in]pioPIO index
[in]smPIO state machine index

◆ pio_sm_restart()

void pio_sm_restart ( pio_t  pio,
pio_sm_t  sm 
)

Restart a state machine.

Parameters
[in]pioPIO index
[in]smPIO state machine index

◆ pio_sm_rx_fifo_empty()

static bool pio_sm_rx_fifo_empty ( pio_t  pio,
pio_sm_t  sm 
)
inlinestatic

Check if RX FIFO is empty.

Parameters
[in]pioPIO index
[in]smPIO state machine index
Returns
If RX FIFO is empty

Definition at line 1313 of file pio.h.

◆ pio_sm_rx_fifo_full()

static bool pio_sm_rx_fifo_full ( pio_t  pio,
pio_sm_t  sm 
)
inlinestatic

Check if RX FIFO is full.

Parameters
[in]pioPIO index
[in]smPIO state machine index
Returns
If RX FIFO is full

Definition at line 1326 of file pio.h.

◆ pio_sm_set_clkdiv()

void pio_sm_set_clkdiv ( pio_t  pio,
pio_sm_t  sm,
pio_sm_clkdiv_t  clk 
)

Apply the clock configuration to a PIO.

There is an integer and a fractional portion of the clock divider. The fractional parameter is in 1/100. That means 90 means .90 and 9 means .09. The PIOs are running from the system clock.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]clkClock configuration

◆ pio_sm_set_fifo_join_rx()

void pio_sm_set_fifo_join_rx ( pio_t  pio,
pio_sm_t  sm 
)

Join the TX FIFO to the RX FIFO.

Parameters
[in]pioPIO index
[in]smPIO state machine index

◆ pio_sm_set_fifo_join_tx()

void pio_sm_set_fifo_join_tx ( pio_t  pio,
pio_sm_t  sm 
)

Join the RX FIFO to the TX FIFO.

Parameters
[in]pioPIO index
[in]smPIO state machine index

◆ pio_sm_set_in_pins()

void pio_sm_set_in_pins ( pio_t  pio,
pio_sm_t  sm,
gpio_t  pin_base 
)

Configure the state machine input pin mapping.

The pin sequence wraps around after the maximum pin.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_baseFirst pin of a pin sequence effected by an in instruction

◆ pio_sm_set_in_shift()

void pio_sm_set_in_shift ( pio_t  pio,
pio_sm_t  sm,
bool  right,
bool  autopush,
unsigned  threshold 
)

Configure the shift in behaviour of a state machine.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]rightWhether to shift right instead of left
[in]autopushWhether to automatically push on reached threshold
[in]thresholdIn shift threshold

◆ pio_sm_set_jmp_pin()

void pio_sm_set_jmp_pin ( pio_t  pio,
pio_sm_t  sm,
gpio_t  pin 
)

Configure the pin on which to branch on a 'jmp pins' instruction.

The jump is executed if the pin is high.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pinBranch pin

◆ pio_sm_set_out_pins()

void pio_sm_set_out_pins ( pio_t  pio,
pio_sm_t  sm,
gpio_t  pin_base,
unsigned  pin_count 
)

Configure which pins are writeable by an 'out pins' instruction.

The pins start at pin_base and are pin_count many. The pin sequence wraps around after the maximum pin.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_baseFirst pin of a pin sequence effected by an out instruction
[in]pin_countNumber of out pins

◆ pio_sm_set_out_pins_init()

void pio_sm_set_out_pins_init ( pio_t  pio,
pio_sm_t  sm,
const pio_gpio_init_t pin_init 
)

Set output pins affected by 'out pins', 'out pindirs' and 'mov pins' instructions and initialize the pins as PIO pins and a state according to pin_init.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_initGPIO pin initialization values

◆ pio_sm_set_out_shift()

void pio_sm_set_out_shift ( pio_t  pio,
pio_sm_t  sm,
bool  right,
bool  autopull,
unsigned  threshold 
)

Configure the shift out behaviour of a state machine.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]rightWhether to shift right instead of left
[in]autopullWhether to automatically pull on reached threshold
[in]thresholdOut shift threshold

◆ pio_sm_set_pindirs_with_mask()

void pio_sm_set_pindirs_with_mask ( pio_t  pio,
pio_sm_t  sm,
gpio_t  values,
gpio_t  mask 
)

Apply pin directions in values for which the corresponding bit in mask is set.

1 means output, 0 means input.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]valuesPin directions out/in to be set
[in]maskMask of which pins should be modified

◆ pio_sm_set_pins_with_mask()

void pio_sm_set_pins_with_mask ( pio_t  pio,
pio_sm_t  sm,
gpio_t  values,
gpio_t  mask 
)

Apply pin values in values for which the corresponding bit in mask is set.

1 means high, 0 means low.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]valuesPin values on/off to be set
[in]maskMask of which pins should be modified

◆ pio_sm_set_set_pins()

void pio_sm_set_set_pins ( pio_t  pio,
pio_sm_t  sm,
gpio_t  pin_base,
unsigned  pin_count 
)

Configure which pins are effected by a 'set pins' instructions.

The pins start at pin_base and are pin_count many. The pin sequence wraps around after the maximum pin.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_baseFirst pin of a pin sequence effected by a set instruction
[in]pin_countNumber of set pins

◆ pio_sm_set_set_pins_init()

void pio_sm_set_set_pins_init ( pio_t  pio,
pio_sm_t  sm,
const pio_gpio_init_t pin_init 
)

Set pins affected by 'set pins' and 'set pindirs' instructions and initialize the pins as PIO pins and a state according to pin_init.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_initGPIO pin initialization values

◆ pio_sm_set_sideset_count()

void pio_sm_set_sideset_count ( pio_t  pio,
pio_sm_t  sm,
unsigned  pin_count,
bool  enable 
)

Configure how many pins are sideset pins and whether a sideset is optional or required for every instruction.

Each sideset pin occupies one bit of the delay field of an instruction. If sidesets are optional, one more bit is used.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_countNumber of pins effected by a sideset instruction
[in]enableWhether the sideset is optional

◆ pio_sm_set_sideset_pins()

void pio_sm_set_sideset_pins ( pio_t  pio,
pio_sm_t  sm,
gpio_t  pin_base 
)

Set the first pin of a sequence of sideset count pins which are effected by sideset instructions.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_baseFirst pin of a pin sequence effected by a sideset instruction

◆ pio_sm_set_sideset_pins_init()

void pio_sm_set_sideset_pins_init ( pio_t  pio,
pio_sm_t  sm,
const pio_gpio_init_t pin_init 
)

Set pins affected by sideset instructions and initialize the pins as PIO pins and a state according to pin_init.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pin_initGPIO pin initialization values

◆ pio_sm_set_sideset_target()

void pio_sm_set_sideset_target ( pio_t  pio,
pio_sm_t  sm,
bool  pindir 
)

Configure whether a sideset effects pins or pin directions.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]pindirWhether the sideset effects pin directions

◆ pio_sm_set_wrap()

void pio_sm_set_wrap ( pio_t  pio,
pio_sm_t  sm,
unsigned  prog_loc,
uint8_t  top,
uint8_t  bottom 
)

Set program instruction wrap boundaries.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]prog_locProgram location
[in]topwrap from
[in]bottomwrap to

◆ pio_sm_transmit_word()

int pio_sm_transmit_word ( pio_t  pio,
pio_sm_t  sm,
uint32_t  word 
)

Send one word to a state machine.

This function does not block but returns a negative integer if the FIFO is fill.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]wordWord to transmit
Returns
Success: 0 Failure: != 0

◆ pio_sm_transmit_word_block()

void pio_sm_transmit_word_block ( pio_t  pio,
pio_sm_t  sm,
uint32_t  word 
)

Send one word to a state machine.

This function blocks until one word has been sent.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]wordWord to transmit

◆ pio_sm_transmit_words_block()

void pio_sm_transmit_words_block ( pio_t  pio,
pio_sm_t  sm,
const uint32_t *  words,
unsigned  count 
)

Send count words to a state machine.

This function blocks until count words have been sent.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]wordsWords to transmit
[in]countNumber of words

◆ pio_sm_tx_fifo_empty()

static bool pio_sm_tx_fifo_empty ( pio_t  pio,
pio_sm_t  sm 
)
inlinestatic

Check if TX FIFO is empty.

Parameters
[in]pioPIO index
[in]smPIO state machine index
Returns
If TX FIFO is empty

Definition at line 1287 of file pio.h.

◆ pio_sm_tx_fifo_full()

static bool pio_sm_tx_fifo_full ( pio_t  pio,
pio_sm_t  sm 
)
inlinestatic

Check if TX FIFO is full.

Parameters
[in]pioPIO index
[in]smPIO state machine index
Returns
If TX FIFO is full

Definition at line 1300 of file pio.h.

◆ pio_write_program()

int pio_write_program ( pio_t  pio,
pio_program_t prog,
const pio_instr_t instr 
)

Write program instructions to their allocated location.

Parameters
[in]pioPIO index
[in,out]progPIO program to write
[in]instrProgram instructions
Returns
Success: 0 Failure: != 0