Loading...
Searching...
No Matches
pio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _HARDWARE_PIO_H
8#define _HARDWARE_PIO_H
9
10#include "pico.h"
12#include "hardware/structs/pio.h"
13#include "hardware/gpio.h"
14#include "hardware/regs/dreq.h"
15#include "hardware/pio_instructions.h"
16
17// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_PIO, Enable/disable assertions in the hardware_pio module, type=bool, default=0, group=hardware_pio
18#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_PIO
19#ifdef PARAM_ASSERTIONS_ENABLED_PIO // backwards compatibility with SDK < 2.0.0
20#define PARAM_ASSERTIONS_ENABLED_HARDWARE_PIO PARAM_ASSERTIONS_ENABLED_PIO
21#else
22#define PARAM_ASSERTIONS_ENABLED_HARDWARE_PIO 0
23#endif
24#endif
25
26// PICO_CONFIG: PICO_PIO_CLKDIV_ROUND_NEAREST, True if floating point PIO clock divisors should be rounded to the nearest possible clock divisor rather than rounding down, type=bool, default=PICO_CLKDIV_ROUND_NEAREST, group=hardware_pio
27#ifndef PICO_PIO_CLKDIV_ROUND_NEAREST
28#define PICO_PIO_CLKDIV_ROUND_NEAREST PICO_CLKDIV_ROUND_NEAREST
29#endif
30
89
90#ifdef __cplusplus
91extern "C" {
92#endif
93
94static_assert(PIO_SM0_SHIFTCTRL_FJOIN_RX_LSB == PIO_SM0_SHIFTCTRL_FJOIN_TX_LSB + 1, "");
95
103#if PICO_PIO_VERSION > 0
104 PIO_FIFO_JOIN_TXGET = 4,
105 PIO_FIFO_JOIN_TXPUT = 8,
106 PIO_FIFO_JOIN_PUTGET = 12,
107#endif
108};
109
114 STATUS_TX_LESSTHAN = 0,
115 STATUS_RX_LESSTHAN = 1,
116#if PICO_PIO_VERSION > 0
117 STATUS_IRQ_SET = 2
118#endif
119};
120
121typedef pio_hw_t *PIO;
122
129#define pio0 pio0_hw
130
137#define pio1 pio1_hw
138
139#if NUM_PIOS > 2
146#define pio2 pio2_hw
147#endif
148
149#if PICO_PIO_VERSION > 0
150#ifndef PICO_PIO_USE_GPIO_BASE
151// PICO_CONFIG: PICO_PIO_USE_GPIO_BASE, Enable code for handling more than 32 PIO pins, type=bool, default=true when supported and when the device has more than 32 pins, group=hardware_pio
152#define PICO_PIO_USE_GPIO_BASE ((NUM_BANK0_GPIOS) > 32)
153#endif
154#else
155#define PICO_PIO_USE_GPIO_BASE 0
156#endif
157
166#ifndef PIO_NUM
167static_assert(PIO1_BASE - PIO0_BASE == (1u << 20), "hardware layout mismatch");
168#if NUM_PIOS > 2
169static_assert(PIO2_BASE - PIO0_BASE == (2u << 20), "hardware layout mismatch");
170#endif
171#define PIO_NUM(pio) (((uintptr_t)(pio) - PIO0_BASE) >> 20)
172#endif
173
182#ifndef PIO_INSTANCE
183static_assert(PIO1_BASE - PIO0_BASE == (1u << 20), "hardware layout mismatch");
184#if NUM_PIOS > 2
185static_assert(PIO2_BASE - PIO0_BASE == (2u << 20), "hardware layout mismatch");
186#endif
187#define PIO_INSTANCE(instance) ((pio_hw_t *)(PIO0_BASE + (instance) * (1u << 20)))
188#endif
189
198#ifndef PIO_IS_INSTANCE
199#if NUM_PIOS > 2
200 static_assert(NUM_PIOS == 3, "");
201 #define PIO_IS_INSTANCE(pio) ((pio) == pio0 || (pio) == pio1 || (pio) == pio2)
202#else
203 static_assert(NUM_PIOS == 2, "");
204 #define PIO_IS_INSTANCE(pio) ((pio) == pio0 || (pio) == pio1)
205#endif
206#endif
207
216#ifndef PIO_FUNCSEL_NUM
217#define PIO_FUNCSEL_NUM(pio, gpio) ((gpio_function_t) (GPIO_FUNC_PIO0 + PIO_NUM(pio)))
218#endif
219
229#ifndef PIO_DREQ_NUM
230static_assert(DREQ_PIO0_TX1 == DREQ_PIO0_TX0 + 1, "");
231static_assert(DREQ_PIO0_TX2 == DREQ_PIO0_TX0 + 2, "");
232static_assert(DREQ_PIO0_TX3 == DREQ_PIO0_TX0 + 3, "");
233static_assert(DREQ_PIO0_RX0 == DREQ_PIO0_TX0 + NUM_PIO_STATE_MACHINES, "");
234static_assert(DREQ_PIO1_TX0 == DREQ_PIO0_RX0 + NUM_PIO_STATE_MACHINES, "");
235static_assert(DREQ_PIO1_RX0 == DREQ_PIO1_TX0 + NUM_PIO_STATE_MACHINES, "");
236#if NUM_PIOS > 2
237static_assert(DREQ_PIO2_TX0 == DREQ_PIO1_RX0 + NUM_PIO_STATE_MACHINES, "");
238static_assert(DREQ_PIO2_RX0 == DREQ_PIO2_TX0 + NUM_PIO_STATE_MACHINES, "");
239#endif
240#define PIO_DREQ_NUM(pio, sm, is_tx) (DREQ_PIO0_TX0 + (sm) + (((is_tx) ? 0 : NUM_PIO_STATE_MACHINES) + PIO_NUM(pio) * (DREQ_PIO1_TX0 - DREQ_PIO0_TX0)))
241#endif
242
251#ifndef PIO_IRQ_NUM
252#define PIO_IRQ_NUM(pio, irqn) (PIO0_IRQ_0 + NUM_PIO_IRQS * PIO_NUM(pio) + (irqn))
253#endif
254
300
307typedef struct {
308 uint32_t clkdiv;
309 uint32_t execctrl;
310 uint32_t shiftctrl;
311 uint32_t pinctrl;
312#if PICO_PIO_USE_GPIO_BASE
313#define PINHI_ALL_PINCTRL_LSBS ((1u << PIO_SM0_PINCTRL_IN_BASE_LSB) | (1u << PIO_SM0_PINCTRL_OUT_BASE_LSB) | \
314 (1u << PIO_SM0_PINCTRL_SET_BASE_LSB) | (1u << PIO_SM0_PINCTRL_SIDESET_BASE_LSB))
315// note we put the out_special pin starting at bit 20
316#define PINHI_EXECCTRL_LSB 20
317static_assert( (1u << PINHI_EXECCTRL_LSB) > (PINHI_ALL_PINCTRL_LSBS * 0x1f), "");
318#define PINHI_ALL_PIN_LSBS ((1u << PINHI_EXECCTRL_LSB) | PINHI_ALL_PINCTRL_LSBS)
319 // each 5-bit field which would usually be used for the pin_base in pin_ctrl, is used for:
320 // 0b11111 - corresponding field not specified
321 // 0b00000 - pin is in range 0-15
322 // 0b00001 - pin is in range 16-31
323 // 0b00010 - pin is in range 32-47
324 uint32_t pinhi;
325#endif
327
328static inline void check_sm_param(__unused uint sm) {
329 valid_params_if(HARDWARE_PIO, sm < NUM_PIO_STATE_MACHINES);
330}
331
332static inline void check_sm_mask(__unused uint mask) {
333 valid_params_if(HARDWARE_PIO, mask < (1u << NUM_PIO_STATE_MACHINES));
334}
335
336static inline void check_pio_param(__unused PIO pio) {
337 valid_params_if(HARDWARE_PIO, PIO_IS_INSTANCE(pio));
338}
339
340static inline void check_pio_pin_param(__unused uint pin) {
341#if !PICO_PIO_USE_GPIO_BASE
342 invalid_params_if(HARDWARE_PIO, pin >= 32);
343#else
344 // pin base allows us to move up 16 pins at a time
345 invalid_params_if(HARDWARE_PIO, pin >= ((NUM_BANK0_GPIOS + 15u)&~15u));
346#endif
347}
348
357static inline void sm_config_set_out_pin_base(pio_sm_config *c, uint out_base) {
358 check_pio_pin_param(out_base);
359 c->pinctrl = (c->pinctrl & ~PIO_SM0_PINCTRL_OUT_BASE_BITS) |
360 ((out_base & 31) << PIO_SM0_PINCTRL_OUT_BASE_LSB);
361#if PICO_PIO_USE_GPIO_BASE
362 c->pinhi = (c->pinhi & ~(31u << PIO_SM0_PINCTRL_OUT_BASE_LSB)) |
363 ((out_base >> 4) << PIO_SM0_PINCTRL_OUT_BASE_LSB);
364#endif
365}
366
375static inline void sm_config_set_out_pin_count(pio_sm_config *c, uint out_count) {
376 valid_params_if(HARDWARE_PIO, out_count <= 32);
377 c->pinctrl = (c->pinctrl & ~PIO_SM0_PINCTRL_OUT_COUNT_BITS) |
378 (out_count << PIO_SM0_PINCTRL_OUT_COUNT_LSB);
379}
380
390static inline void sm_config_set_out_pins(pio_sm_config *c, uint out_base, uint out_count) {
391 sm_config_set_out_pin_base(c, out_base);
392 sm_config_set_out_pin_count(c, out_count);
393}
394
403static inline void sm_config_set_set_pin_base(pio_sm_config *c, uint set_base) {
404 check_pio_pin_param(set_base);
405 c->pinctrl = (c->pinctrl & ~PIO_SM0_PINCTRL_SET_BASE_BITS) |
406 ((set_base & 31) << PIO_SM0_PINCTRL_SET_BASE_LSB);
407#if PICO_PIO_USE_GPIO_BASE
408 c->pinhi = (c->pinhi & ~(31u << PIO_SM0_PINCTRL_SET_BASE_LSB)) |
409 ((set_base >> 4) << PIO_SM0_PINCTRL_SET_BASE_LSB);
410#endif
411}
412
421static inline void sm_config_set_set_pin_count(pio_sm_config *c, uint set_count) {
422 valid_params_if(HARDWARE_PIO, set_count <= 5);
423 c->pinctrl = (c->pinctrl & ~PIO_SM0_PINCTRL_SET_COUNT_BITS) |
424 (set_count << PIO_SM0_PINCTRL_SET_COUNT_LSB);
425}
426
436static inline void sm_config_set_set_pins(pio_sm_config *c, uint set_base, uint set_count) {
437 sm_config_set_set_pin_base(c, set_base);
438 sm_config_set_set_pin_count(c, set_count);
439}
440
449static inline void sm_config_set_in_pin_base(pio_sm_config *c, uint in_base) {
450 check_pio_pin_param(in_base);
451 c->pinctrl = (c->pinctrl & ~PIO_SM0_PINCTRL_IN_BASE_BITS) |
452 ((in_base & 31) << PIO_SM0_PINCTRL_IN_BASE_LSB);
453#if PICO_PIO_USE_GPIO_BASE
454 c->pinhi = (c->pinhi & ~(31u << PIO_SM0_PINCTRL_IN_BASE_LSB)) |
455 ((in_base >> 4) << PIO_SM0_PINCTRL_IN_BASE_LSB);
456#endif
457}
458
467static inline void sm_config_set_in_pins(pio_sm_config *c, uint in_base) {
468 sm_config_set_in_pin_base(c, in_base);
469}
470
484static inline void sm_config_set_in_pin_count(pio_sm_config *c, uint in_count) {
485#if PICO_PIO_VERSION == 0
486 // can't be changed from 32 on PIO v0
487 ((void)c);
488 valid_params_if(HARDWARE_PIO, in_count == 32);
489#else
490 valid_params_if(HARDWARE_PIO, in_count && in_count <= 32);
491 c->shiftctrl = (c->shiftctrl & ~PIO_SM0_SHIFTCTRL_IN_COUNT_BITS) |
492 ((in_count & 0x1fu) << PIO_SM0_SHIFTCTRL_IN_COUNT_LSB);
493#endif
494}
495
504static inline void sm_config_set_sideset_pin_base(pio_sm_config *c, uint sideset_base) {
505 check_pio_pin_param(sideset_base);
506 c->pinctrl = (c->pinctrl & ~PIO_SM0_PINCTRL_SIDESET_BASE_BITS) |
507 ((sideset_base & 31) << PIO_SM0_PINCTRL_SIDESET_BASE_LSB);
508#if PICO_PIO_USE_GPIO_BASE
509 c->pinhi = (c->pinhi & ~(31u << PIO_SM0_PINCTRL_SIDESET_BASE_LSB)) |
510 ((sideset_base >> 4) << PIO_SM0_PINCTRL_SIDESET_BASE_LSB);
511#endif
512}
513
525static inline void sm_config_set_sideset_pins(pio_sm_config *c, uint sideset_base) {
526 sm_config_set_sideset_pin_base(c, sideset_base);
527}
528
537static inline void sm_config_set_sideset(pio_sm_config *c, uint bit_count, bool optional, bool pindirs) {
538 valid_params_if(HARDWARE_PIO, bit_count <= 5);
539 valid_params_if(HARDWARE_PIO, !optional || bit_count >= 1);
540 c->pinctrl = (c->pinctrl & ~PIO_SM0_PINCTRL_SIDESET_COUNT_BITS) |
541 (bit_count << PIO_SM0_PINCTRL_SIDESET_COUNT_LSB);
542 c->execctrl = (c->execctrl & ~(PIO_SM0_EXECCTRL_SIDE_EN_BITS | PIO_SM0_EXECCTRL_SIDE_PINDIR_BITS)) |
543 (bool_to_bit(optional) << PIO_SM0_EXECCTRL_SIDE_EN_LSB) |
544 (bool_to_bit(pindirs) << PIO_SM0_EXECCTRL_SIDE_PINDIR_LSB);
545}
546
560static inline void sm_config_set_clkdiv_int_frac8(pio_sm_config *c, uint32_t div_int, uint8_t div_frac8) {
561 static_assert(REG_FIELD_WIDTH(PIO_SM0_CLKDIV_INT) == 16, "");
562 invalid_params_if(HARDWARE_PIO, div_int >> 16);
563 invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac8 != 0);
564 static_assert(REG_FIELD_WIDTH(PIO_SM0_CLKDIV_FRAC) == 8, "");
565 c->clkdiv =
566 (((uint)div_frac8) << PIO_SM0_CLKDIV_FRAC_LSB) |
567 (((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB);
568}
569
570// backwards compatibility
571static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_int, uint8_t div_frac8) {
572 sm_config_set_clkdiv_int_frac8(c, div_int, div_frac8);
573}
574
575static inline void pio_calculate_clkdiv8_from_float(float div, uint32_t *div_int, uint8_t *div_frac8) {
576 valid_params_if(HARDWARE_PIO, div >= 1 && div <= 65536);
577 const int frac_bit_count = REG_FIELD_WIDTH(PIO_SM0_CLKDIV_FRAC);
578#if PICO_PIO_CLKDIV_ROUND_NEAREST
579 div += 0.5f / (1 << frac_bit_count); // round to the nearest 1/256
580#endif
581 *div_int = (uint16_t)div;
582 // not a strictly necessary check, but if this changes, then this method should
583 // probably no longer be used in favor of one with a larger fraction
584 static_assert(REG_FIELD_WIDTH(PIO_SM0_CLKDIV_FRAC) == 8, "");
585 if (*div_int == 0) {
586 *div_frac8 = 0;
587 } else {
588 *div_frac8 = (uint8_t)((div - (float)*div_int) * (1u << frac_bit_count));
589 }
590}
591
592// backwards compatibility
593static inline void pio_calculate_clkdiv_from_float(float div, uint16_t *div_int16, uint8_t *div_frac8) {
594 uint32_t div_int;
595 pio_calculate_clkdiv8_from_float(div, &div_int, div_frac8);
596 *div_int16 = (uint16_t) div_int;
597}
598
614static inline void sm_config_set_clkdiv(pio_sm_config *c, float div) {
615 uint32_t div_int;
616 uint8_t div_frac8;
617 pio_calculate_clkdiv8_from_float(div, &div_int, &div_frac8);
618 sm_config_set_clkdiv_int_frac8(c, div_int, div_frac8);
619}
620
629static inline void sm_config_set_wrap(pio_sm_config *c, uint wrap_target, uint wrap) {
630 valid_params_if(HARDWARE_PIO, wrap < PIO_INSTRUCTION_COUNT);
631 valid_params_if(HARDWARE_PIO, wrap_target < PIO_INSTRUCTION_COUNT);
632 c->execctrl = (c->execctrl & ~(PIO_SM0_EXECCTRL_WRAP_TOP_BITS | PIO_SM0_EXECCTRL_WRAP_BOTTOM_BITS)) |
633 (wrap_target << PIO_SM0_EXECCTRL_WRAP_BOTTOM_LSB) |
634 (wrap << PIO_SM0_EXECCTRL_WRAP_TOP_LSB);
635}
636
643static inline void sm_config_set_jmp_pin(pio_sm_config *c, uint pin) {
644 check_pio_pin_param(pin);
645 c->execctrl = (c->execctrl & ~PIO_SM0_EXECCTRL_JMP_PIN_BITS) |
646 ((pin & 31) << PIO_SM0_EXECCTRL_JMP_PIN_LSB);
647#if PICO_PIO_USE_GPIO_BASE
648 c->pinhi = (c->pinhi & ~(31u << PINHI_EXECCTRL_LSB)) |
649 ((pin >> 4) << PINHI_EXECCTRL_LSB);
650#endif
651}
652
661static inline void sm_config_set_in_shift(pio_sm_config *c, bool shift_right, bool autopush, uint push_threshold) {
662 valid_params_if(HARDWARE_PIO, push_threshold <= 32);
663 c->shiftctrl = (c->shiftctrl &
664 ~(PIO_SM0_SHIFTCTRL_IN_SHIFTDIR_BITS |
665 PIO_SM0_SHIFTCTRL_AUTOPUSH_BITS |
666 PIO_SM0_SHIFTCTRL_PUSH_THRESH_BITS)) |
667 (bool_to_bit(shift_right) << PIO_SM0_SHIFTCTRL_IN_SHIFTDIR_LSB) |
668 (bool_to_bit(autopush) << PIO_SM0_SHIFTCTRL_AUTOPUSH_LSB) |
669 ((push_threshold & 0x1fu) << PIO_SM0_SHIFTCTRL_PUSH_THRESH_LSB);
670}
671
680static inline void sm_config_set_out_shift(pio_sm_config *c, bool shift_right, bool autopull, uint pull_threshold) {
681 valid_params_if(HARDWARE_PIO, pull_threshold <= 32);
682 c->shiftctrl = (c->shiftctrl &
683 ~(PIO_SM0_SHIFTCTRL_OUT_SHIFTDIR_BITS |
684 PIO_SM0_SHIFTCTRL_AUTOPULL_BITS |
685 PIO_SM0_SHIFTCTRL_PULL_THRESH_BITS)) |
686 (bool_to_bit(shift_right) << PIO_SM0_SHIFTCTRL_OUT_SHIFTDIR_LSB) |
687 (bool_to_bit(autopull) << PIO_SM0_SHIFTCTRL_AUTOPULL_LSB) |
688 ((pull_threshold & 0x1fu) << PIO_SM0_SHIFTCTRL_PULL_THRESH_LSB);
689}
690
697static inline void sm_config_set_fifo_join(pio_sm_config *c, enum pio_fifo_join join) {
698 valid_params_if(HARDWARE_PIO, join == PIO_FIFO_JOIN_NONE || join == PIO_FIFO_JOIN_TX || join == PIO_FIFO_JOIN_RX
699#if PICO_PIO_VERSION > 0
700 || join == PIO_FIFO_JOIN_TXPUT || join == PIO_FIFO_JOIN_TXGET || join == PIO_FIFO_JOIN_PUTGET
701#endif
702 );
703#if PICO_PIO_VERSION == 0
704 c->shiftctrl = (c->shiftctrl & (uint)~(PIO_SM0_SHIFTCTRL_FJOIN_TX_BITS | PIO_SM0_SHIFTCTRL_FJOIN_RX_BITS)) |
705 (((uint)join) << PIO_SM0_SHIFTCTRL_FJOIN_TX_LSB);
706#else
707 c->shiftctrl = (c->shiftctrl & (uint)~(PIO_SM0_SHIFTCTRL_FJOIN_TX_BITS | PIO_SM0_SHIFTCTRL_FJOIN_RX_BITS |
708 PIO_SM0_SHIFTCTRL_FJOIN_RX_PUT_BITS | PIO_SM0_SHIFTCTRL_FJOIN_RX_GET_BITS)) |
709 (((uint)(join & 3)) << PIO_SM0_SHIFTCTRL_FJOIN_TX_LSB) |
710 (((uint)(join >> 2)) << PIO_SM0_SHIFTCTRL_FJOIN_RX_GET_LSB);
711#endif
712}
713
722static inline void sm_config_set_out_special(pio_sm_config *c, bool sticky, bool has_enable_pin, uint enable_bit_index) {
723 c->execctrl = (c->execctrl &
724 (uint)~(PIO_SM0_EXECCTRL_OUT_STICKY_BITS | PIO_SM0_EXECCTRL_INLINE_OUT_EN_BITS |
725 PIO_SM0_EXECCTRL_OUT_EN_SEL_BITS)) |
726 (bool_to_bit(sticky) << PIO_SM0_EXECCTRL_OUT_STICKY_LSB) |
727 (bool_to_bit(has_enable_pin) << PIO_SM0_EXECCTRL_INLINE_OUT_EN_LSB) |
728 ((enable_bit_index << PIO_SM0_EXECCTRL_OUT_EN_SEL_LSB) & PIO_SM0_EXECCTRL_OUT_EN_SEL_BITS);
729}
730
738static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_status_type status_sel, uint status_n) {
739 valid_params_if(HARDWARE_PIO,
740 status_sel == STATUS_TX_LESSTHAN || status_sel == STATUS_RX_LESSTHAN
741#if PICO_PIO_VERSION > 0
742 || status_sel == STATUS_IRQ_SET
743#endif
744 );
745 c->execctrl = (c->execctrl
746 & ~(PIO_SM0_EXECCTRL_STATUS_SEL_BITS | PIO_SM0_EXECCTRL_STATUS_N_BITS))
747 | ((((uint)status_sel) << PIO_SM0_EXECCTRL_STATUS_SEL_LSB) & PIO_SM0_EXECCTRL_STATUS_SEL_BITS)
748 | ((status_n << PIO_SM0_EXECCTRL_STATUS_N_LSB) & PIO_SM0_EXECCTRL_STATUS_N_BITS);
749}
750
781 pio_sm_config c = {};
782#if PICO_PIO_USE_GPIO_BASE
783 c.pinhi = -1;
784#endif
786 sm_config_set_wrap(&c, 0, 31);
787 sm_config_set_in_shift(&c, true, false, 32);
788 sm_config_set_out_shift(&c, true, false, 32);
789 return c;
790}
791
802static inline uint pio_get_gpio_base(PIO pio) {
803#if PICO_PIO_USE_GPIO_BASE
804 return pio->gpiobase;
805#else
806 ((void)pio);
807 return 0;
808#endif
809}
810
811static inline void check_pio_pin_mask(__unused PIO pio, __unused uint sm, __unused uint32_t pinmask) {
812 // check no pins are set in the mask which are incompatible with the pio
813#if PICO_PIO_USE_GPIO_BASE
814 valid_params_if(HARDWARE_PIO, (pinmask & ~(0xffffffffu << pio_get_gpio_base(pio))) == 0);
815#endif
816}
817
818static inline void check_pio_pin_mask64(__unused PIO pio, __unused uint sm, __unused uint64_t pinmask) {
819 // check no pins are set in the mask which are incompatible with the pio
820#if PICO_PIO_USE_GPIO_BASE
821 valid_params_if(HARDWARE_PIO, (pinmask & ~(0xffffffffull << pio_get_gpio_base(pio))) == 0);
822#else
823 valid_params_if(HARDWARE_PIO, (pinmask & ~0xffffffffull) == 0);
824#endif
825}
826
838static inline int pio_sm_set_config(PIO pio, uint sm, const pio_sm_config *config) {
839 check_pio_param(pio);
840 check_sm_param(sm);
841 pio->sm[sm].clkdiv = config->clkdiv;
842 pio->sm[sm].shiftctrl = config->shiftctrl;
843#if PICO_PIO_USE_GPIO_BASE
844 // definition of the 5-bit fields within config->pinhi:
845 // 0b11111 - corresponding field not specified
846 // 0b00000 - pin is in range 0-15
847 // 0b00001 - pin is in range 16-31
848 // 0b00010 - pin is in range 32-47
849
850 // boolean (in bit 0 of each field) 1=field_used
851 uint32_t field_used_flags = (~config->pinhi >> 4) & PINHI_ALL_PIN_LSBS;
852 // note: if the field is used and no pins are used in the range 16-47, then by convention, pins 0-15 must be used
853 // boolean (in bit 0 of each field) 1=some_used_pins_0_to_15
854 uint32_t gpio_0_15_used_flags = (~config->pinhi) & (~config->pinhi >> 1) & field_used_flags;
855 // boolean (in bit 0 of each field) 1=some_used_pins_32_to_47
856 uint32_t gpio_32_47_used_flags = (config->pinhi >> 1) & field_used_flags;
857 uint gpio_base = pio_get_gpio_base(pio);
858 invalid_params_if_and_return(HARDWARE_PIO, gpio_0_15_used_flags && gpio_base, PICO_ERROR_BAD_ALIGNMENT);
859 invalid_params_if_and_return(HARDWARE_PIO, gpio_32_47_used_flags && !gpio_base, PICO_ERROR_BAD_ALIGNMENT);
860 // flip bit 4 of used (execctrl/pinctrl) values if gpio_base is non-zero (i.e. 16), to turn:
861 // pin | pin & 32 | pin & 0x1f || base | pin_value
862 // | | (stored) || | (configured)
863 // 16-31 | 0 + 16-31 -> 16 + 0-15
864 // 32-47 | 32 + 0-15 -> 16 + 16-31
865 //
866 // note, that for gpio_base of zero we have:
867 // pin | pin & 32 | pin & 0x1f || base | pin_value
868 // | | (stored) || | (configured)
869 // 0-15 | 0 + 0-15 -> 0 + 0-15
870 // 16-31 | 0 + 16-31 -> 0 + 16-31
871
872 // note we already checked (above) via static_assert( (1u << PINHI_EXECCTRL_LSB) > (PINHI_ALL_PINCTRL_LSBS * 0x1f), "")
873 // that PINHI_EXECTTRL_LSB is above all the pinctrl fields...
874
875 // ... so shift pinctrl bits off the bottom, and flip EXECCTRL_JMP_PIN_MSB if used
876 pio->sm[sm].execctrl = config->execctrl ^ (gpio_base ? ((field_used_flags >> PINHI_EXECCTRL_LSB) << PIO_SM0_EXECCTRL_JMP_PIN_MSB) : 0);
877 // ... so shift execctrl bits off the top, and flip pinctrl MSBs if used
878 pio->sm[sm].pinctrl = config->pinctrl ^ (gpio_base ? ((field_used_flags << (32 - PINHI_EXECCTRL_LSB)) >> (32 - PINHI_EXECCTRL_LSB - 4)) : 0);
879#else
880 pio->sm[sm].execctrl = config->execctrl;
881 pio->sm[sm].pinctrl = config->pinctrl;
882#endif
883 return PICO_OK;
884}
885
892static inline uint pio_get_index(PIO pio) {
893 check_pio_param(pio);
894 return PIO_NUM(pio);
895}
896
904static inline uint pio_get_funcsel(PIO pio) {
905 check_pio_param(pio);
906 return PIO_FUNCSEL_NUM(pio, 0); // note GPIO currently unused, so won't bother updating API
907}
908
915static inline PIO pio_get_instance(uint instance) {
916 invalid_params_if(HARDWARE_PIO, instance >= NUM_PIOS);
917 return PIO_INSTANCE(instance);
918}
919
948static inline void pio_gpio_init(PIO pio, uint pin) {
949 check_pio_param(pio);
950 valid_params_if(HARDWARE_PIO, pin < NUM_BANK0_GPIOS);
951 gpio_set_function(pin, PIO_FUNCSEL_NUM(pio, pin));
952}
953
961static inline uint pio_get_dreq(PIO pio, uint sm, bool is_tx) {
962 check_pio_param(pio);
963 check_sm_param(sm);
964 return PIO_DREQ_NUM(pio, sm, is_tx);
965}
966
976typedef struct pio_program {
977 const uint16_t *instructions;
978 uint8_t length;
979 int8_t origin;
980 uint8_t pio_version;
981#if PICO_PIO_VERSION > 0
982 uint8_t used_gpio_ranges;
983#endif
985
1000int pio_set_gpio_base(PIO pio, uint gpio_base);
1001
1010bool pio_can_add_program(PIO pio, const pio_program_t *program);
1011
1021bool pio_can_add_program_at_offset(PIO pio, const pio_program_t *program, uint offset);
1022
1033int pio_add_program(PIO pio, const pio_program_t *program);
1034
1046int pio_add_program_at_offset(PIO pio, const pio_program_t *program, uint offset);
1047
1055void pio_remove_program(PIO pio, const pio_program_t *program, uint loaded_offset);
1056
1062void pio_clear_instruction_memory(PIO pio);
1063
1086int pio_sm_init(PIO pio, uint sm, uint initial_pc, const pio_sm_config *config);
1087
1095static inline void pio_sm_set_enabled(PIO pio, uint sm, bool enabled) {
1096 check_pio_param(pio);
1097 check_sm_param(sm);
1098 pio->ctrl = (pio->ctrl & ~(1u << sm)) | (bool_to_bit(enabled) << sm);
1099}
1100
1114static inline void pio_set_sm_mask_enabled(PIO pio, uint32_t mask, bool enabled) {
1115 check_pio_param(pio);
1116 check_sm_mask(mask);
1117 pio->ctrl = (pio->ctrl & ~mask) | (enabled ? mask : 0u);
1118}
1119
1120#if PICO_PIO_VERSION > 0
1136static inline void pio_set_sm_multi_mask_enabled(PIO pio, uint32_t mask_prev, uint32_t mask, uint32_t mask_next, bool enabled) {
1137 check_pio_param(pio);
1138 check_sm_mask(mask_prev);
1139 check_sm_mask(mask);
1140 check_sm_mask(mask_next);
1141 pio->ctrl = (pio->ctrl & ~(mask << PIO_CTRL_SM_ENABLE_LSB)) |
1142 (enabled ? ((mask << PIO_CTRL_SM_ENABLE_LSB) & PIO_CTRL_SM_ENABLE_BITS) : 0) |
1143 (enabled ? PIO_CTRL_NEXTPREV_SM_ENABLE_BITS : PIO_CTRL_NEXTPREV_SM_DISABLE_BITS) |
1144 ((mask_prev << PIO_CTRL_PREV_PIO_MASK_LSB) & PIO_CTRL_PREV_PIO_MASK_BITS) |
1145 ((mask_next << PIO_CTRL_NEXT_PIO_MASK_LSB) & PIO_CTRL_NEXT_PIO_MASK_BITS);
1146
1147}
1148#endif
1149
1167static inline void pio_sm_restart(PIO pio, uint sm) {
1168 check_pio_param(pio);
1169 check_sm_param(sm);
1170 hw_set_bits(&pio->ctrl, 1u << (PIO_CTRL_SM_RESTART_LSB + sm));
1171}
1172
1184static inline void pio_restart_sm_mask(PIO pio, uint32_t mask) {
1185 check_pio_param(pio);
1186 check_sm_mask(mask);
1187 hw_set_bits(&pio->ctrl, (mask << PIO_CTRL_SM_RESTART_LSB) & PIO_CTRL_SM_RESTART_BITS);
1188}
1189
1211static inline void pio_sm_clkdiv_restart(PIO pio, uint sm) {
1212 check_pio_param(pio);
1213 check_sm_param(sm);
1214 hw_set_bits(&pio->ctrl, 1u << (PIO_CTRL_CLKDIV_RESTART_LSB + sm));
1215}
1216
1246static inline void pio_clkdiv_restart_sm_mask(PIO pio, uint32_t mask) {
1247 check_pio_param(pio);
1248 check_sm_mask(mask);
1249 hw_set_bits(&pio->ctrl, (mask << PIO_CTRL_CLKDIV_RESTART_LSB) & PIO_CTRL_CLKDIV_RESTART_BITS);
1250}
1251
1252#if PICO_PIO_VERSION > 0
1284static inline void pio_clkdiv_restart_sm_multi_mask(PIO pio, uint32_t mask_prev, uint32_t mask, uint32_t mask_next) {
1285 check_pio_param(pio);
1286 check_sm_mask(mask_prev);
1287 check_sm_mask(mask);
1288 check_sm_mask(mask_next);
1289 hw_set_bits(&pio->ctrl, ((mask << PIO_CTRL_CLKDIV_RESTART_LSB) & PIO_CTRL_CLKDIV_RESTART_BITS) |
1290 PIO_CTRL_NEXTPREV_CLKDIV_RESTART_BITS |
1291 ((mask_prev << PIO_CTRL_PREV_PIO_MASK_LSB) & PIO_CTRL_PREV_PIO_MASK_BITS) |
1292 ((mask_next << PIO_CTRL_NEXT_PIO_MASK_LSB) & PIO_CTRL_NEXT_PIO_MASK_BITS));
1293}
1294#endif
1295
1307static inline void pio_enable_sm_mask_in_sync(PIO pio, uint32_t mask) {
1308 check_pio_param(pio);
1309 check_sm_mask(mask);
1310 hw_set_bits(&pio->ctrl,
1311 ((mask << PIO_CTRL_CLKDIV_RESTART_LSB) & PIO_CTRL_CLKDIV_RESTART_BITS) |
1312 ((mask << PIO_CTRL_SM_ENABLE_LSB) & PIO_CTRL_SM_ENABLE_BITS));
1313}
1314
1315#if PICO_PIO_VERSION > 0
1329static inline void pio_enable_sm_multi_mask_in_sync(PIO pio, uint32_t mask_prev, uint32_t mask, uint32_t mask_next) {
1330 check_pio_param(pio);
1331 check_sm_mask(mask_prev);
1332 check_sm_mask(mask);
1333 check_sm_mask(mask_next);
1334 hw_set_bits(&pio->ctrl, ((mask << PIO_CTRL_CLKDIV_RESTART_LSB) & PIO_CTRL_CLKDIV_RESTART_BITS) |
1335 ((mask << PIO_CTRL_SM_ENABLE_LSB) & PIO_CTRL_SM_ENABLE_BITS) |
1336 PIO_CTRL_NEXTPREV_CLKDIV_RESTART_BITS | PIO_CTRL_NEXTPREV_SM_ENABLE_BITS |
1337 ((mask_prev << PIO_CTRL_PREV_PIO_MASK_LSB) & PIO_CTRL_PREV_PIO_MASK_BITS) |
1338 ((mask_next << PIO_CTRL_NEXT_PIO_MASK_LSB) & PIO_CTRL_NEXT_PIO_MASK_BITS));
1339}
1340#endif
1341
1346 pis_interrupt0 = PIO_INTR_SM0_LSB,
1347 pis_interrupt1 = PIO_INTR_SM1_LSB,
1348 pis_interrupt2 = PIO_INTR_SM2_LSB,
1349 pis_interrupt3 = PIO_INTR_SM3_LSB,
1350#if PICO_PIO_VERSION > 0
1351 pis_interrupt4 = PIO_INTR_SM4_LSB,
1352 pis_interrupt5 = PIO_INTR_SM5_LSB,
1353 pis_interrupt6 = PIO_INTR_SM6_LSB,
1354 pis_interrupt7 = PIO_INTR_SM7_LSB,
1355#endif
1356 pis_sm0_tx_fifo_not_full = PIO_INTR_SM0_TXNFULL_LSB,
1357 pis_sm1_tx_fifo_not_full = PIO_INTR_SM1_TXNFULL_LSB,
1358 pis_sm2_tx_fifo_not_full = PIO_INTR_SM2_TXNFULL_LSB,
1359 pis_sm3_tx_fifo_not_full = PIO_INTR_SM3_TXNFULL_LSB,
1360 pis_sm0_rx_fifo_not_empty = PIO_INTR_SM0_RXNEMPTY_LSB,
1361 pis_sm1_rx_fifo_not_empty = PIO_INTR_SM1_RXNEMPTY_LSB,
1362 pis_sm2_rx_fifo_not_empty = PIO_INTR_SM2_RXNEMPTY_LSB,
1363 pis_sm3_rx_fifo_not_empty = PIO_INTR_SM3_RXNEMPTY_LSB,
1365
1373static inline void pio_set_irq0_source_enabled(PIO pio, pio_interrupt_source_t source, bool enabled) {
1374 check_pio_param(pio);
1375 invalid_params_if(HARDWARE_PIO, source >= 32u || (1u << source) > PIO_INTR_BITS);
1376 if (enabled)
1377 hw_set_bits(&pio->inte0, 1u << source);
1378 else
1379 hw_clear_bits(&pio->inte0, 1u << source);
1380}
1381
1389static inline void pio_set_irq1_source_enabled(PIO pio, pio_interrupt_source_t source, bool enabled) {
1390 check_pio_param(pio);
1391 invalid_params_if(HARDWARE_PIO, source >= 32 || (1u << source) > PIO_INTR_BITS);
1392 if (enabled)
1393 hw_set_bits(&pio->inte1, 1u << source);
1394 else
1395 hw_clear_bits(&pio->inte1, 1u << source);
1396}
1397
1405static inline void pio_set_irq0_source_mask_enabled(PIO pio, uint32_t source_mask, bool enabled) {
1406 check_pio_param(pio);
1407 invalid_params_if(HARDWARE_PIO, source_mask > PIO_INTR_BITS);
1408 if (enabled) {
1409 hw_set_bits(&pio->inte0, source_mask);
1410 } else {
1411 hw_clear_bits(&pio->inte0, source_mask);
1412 }
1413}
1414
1422static inline void pio_set_irq1_source_mask_enabled(PIO pio, uint32_t source_mask, bool enabled) {
1423 check_pio_param(pio);
1424 invalid_params_if(HARDWARE_PIO, source_mask > PIO_INTR_BITS);
1425 if (enabled) {
1426 hw_set_bits(&pio->inte1, source_mask);
1427 } else {
1428 hw_clear_bits(&pio->inte1, source_mask);
1429 }
1430}
1431
1440static inline void pio_set_irqn_source_enabled(PIO pio, uint irq_index, pio_interrupt_source_t source, bool enabled) {
1441 invalid_params_if(HARDWARE_PIO, irq_index >= NUM_PIO_IRQS);
1442 invalid_params_if(HARDWARE_PIO, source >= 32 || (1u << source) > PIO_INTR_BITS);
1443 if (enabled)
1444 hw_set_bits(&pio->irq_ctrl[irq_index].inte, 1u << source);
1445 else
1446 hw_clear_bits(&pio->irq_ctrl[irq_index].inte, 1u << source);
1447}
1448
1457static inline void pio_set_irqn_source_mask_enabled(PIO pio, uint irq_index, uint32_t source_mask, bool enabled) {
1458 invalid_params_if(HARDWARE_PIO, irq_index >= NUM_PIO_IRQS);
1459 static_assert(NUM_PIO_IRQS == 2, "");
1460 invalid_params_if(HARDWARE_PIO, source_mask > PIO_INTR_BITS);
1461 if (enabled) {
1462 hw_set_bits(&pio->irq_ctrl[irq_index].inte, source_mask);
1463 } else {
1464 hw_clear_bits(&pio->irq_ctrl[irq_index].inte, source_mask);
1465 }
1466}
1467
1475static inline bool pio_interrupt_get(PIO pio, uint pio_interrupt_num) {
1476 check_pio_param(pio);
1477 invalid_params_if(HARDWARE_PIO, pio_interrupt_num >= 8);
1478 return pio->irq & (1u << pio_interrupt_num);
1479}
1480
1487static inline void pio_interrupt_clear(PIO pio, uint pio_interrupt_num) {
1488 check_pio_param(pio);
1489 invalid_params_if(HARDWARE_PIO, pio_interrupt_num >= 8);
1490 pio->irq = (1u << pio_interrupt_num);
1491}
1492
1500static inline uint8_t pio_sm_get_pc(PIO pio, uint sm) {
1501 check_pio_param(pio);
1502 check_sm_param(sm);
1503 return (uint8_t) pio->sm[sm].addr;
1504}
1505
1518inline static void pio_sm_exec(PIO pio, uint sm, uint instr) {
1519 check_pio_param(pio);
1520 check_sm_param(sm);
1521 pio->sm[sm].instr = instr;
1522}
1523
1531static inline bool pio_sm_is_exec_stalled(PIO pio, uint sm) {
1532 check_pio_param(pio);
1533 check_sm_param(sm);
1534 return pio->sm[sm].execctrl & PIO_SM0_EXECCTRL_EXEC_STALLED_BITS;
1535}
1536
1549static inline void pio_sm_exec_wait_blocking(PIO pio, uint sm, uint instr) {
1550 check_pio_param(pio);
1551 check_sm_param(sm);
1552 pio_sm_exec(pio, sm, instr);
1554}
1555
1565static inline void pio_sm_set_wrap(PIO pio, uint sm, uint wrap_target, uint wrap) {
1566 check_pio_param(pio);
1567 check_sm_param(sm);
1568 valid_params_if(HARDWARE_PIO, wrap < PIO_INSTRUCTION_COUNT);
1569 valid_params_if(HARDWARE_PIO, wrap_target < PIO_INSTRUCTION_COUNT);
1570 pio->sm[sm].execctrl =
1571 (pio->sm[sm].execctrl & ~(PIO_SM0_EXECCTRL_WRAP_TOP_BITS | PIO_SM0_EXECCTRL_WRAP_BOTTOM_BITS)) |
1572 (wrap_target << PIO_SM0_EXECCTRL_WRAP_BOTTOM_LSB) |
1573 (wrap << PIO_SM0_EXECCTRL_WRAP_TOP_LSB);
1574}
1575
1586static inline void pio_sm_set_out_pins(PIO pio, uint sm, uint out_base, uint out_count) {
1587 check_pio_param(pio);
1588 check_sm_param(sm);
1589#if PICO_PIO_USE_GPIO_BASE
1590 out_base -= pio_get_gpio_base(pio);
1591#endif
1592 valid_params_if(HARDWARE_PIO, out_base < 32);
1593 valid_params_if(HARDWARE_PIO, out_count <= 32);
1594 pio->sm[sm].pinctrl = (pio->sm[sm].pinctrl & ~(PIO_SM0_PINCTRL_OUT_BASE_BITS | PIO_SM0_PINCTRL_OUT_COUNT_BITS)) |
1595 (out_base << PIO_SM0_PINCTRL_OUT_BASE_LSB) |
1596 (out_count << PIO_SM0_PINCTRL_OUT_COUNT_LSB);
1597}
1598
1599
1610static inline void pio_sm_set_set_pins(PIO pio, uint sm, uint set_base, uint set_count) {
1611 check_pio_param(pio);
1612 check_sm_param(sm);
1613#if PICO_PIO_USE_GPIO_BASE
1614 set_base -= pio_get_gpio_base(pio);
1615#endif
1616 valid_params_if(HARDWARE_PIO, set_base < 32);
1617 valid_params_if(HARDWARE_PIO, set_count <= 5);
1618 pio->sm[sm].pinctrl = (pio->sm[sm].pinctrl & ~(PIO_SM0_PINCTRL_SET_BASE_BITS | PIO_SM0_PINCTRL_SET_COUNT_BITS)) |
1619 (set_base << PIO_SM0_PINCTRL_SET_BASE_LSB) |
1620 (set_count << PIO_SM0_PINCTRL_SET_COUNT_LSB);
1621}
1622
1632static inline void pio_sm_set_in_pins(PIO pio, uint sm, uint in_base) {
1633 check_pio_param(pio);
1634 check_sm_param(sm);
1635#if PICO_PIO_USE_GPIO_BASE
1636 in_base -= pio_get_gpio_base(pio);
1637#endif
1638 valid_params_if(HARDWARE_PIO, in_base < 32);
1639 pio->sm[sm].pinctrl = (pio->sm[sm].pinctrl & ~PIO_SM0_PINCTRL_IN_BASE_BITS) |
1640 (in_base << PIO_SM0_PINCTRL_IN_BASE_LSB);
1641}
1642
1652static inline void pio_sm_set_sideset_pins(PIO pio, uint sm, uint sideset_base) {
1653 check_pio_param(pio);
1654 check_sm_param(sm);
1655#if PICO_PIO_USE_GPIO_BASE
1656 sideset_base -= pio_get_gpio_base(pio);
1657#endif
1658 valid_params_if(HARDWARE_PIO, sideset_base < 32);
1659 pio->sm[sm].pinctrl = (pio->sm[sm].pinctrl & ~PIO_SM0_PINCTRL_SIDESET_BASE_BITS) |
1660 (sideset_base << PIO_SM0_PINCTRL_SIDESET_BASE_LSB);
1661}
1662
1670
1671static inline void pio_sm_set_jmp_pin(PIO pio, uint sm, uint pin) {
1672 check_pio_param(pio);
1673 check_sm_param(sm);
1674#if PICO_PIO_USE_GPIO_BASE
1675 pin -= pio_get_gpio_base(pio);
1676#endif
1677 valid_params_if(HARDWARE_PIO, pin < 32);
1678 pio->sm[sm].execctrl =
1679 (pio->sm[sm].execctrl & ~PIO_SM0_EXECCTRL_JMP_PIN_BITS)
1680 | (pin << PIO_SM0_EXECCTRL_JMP_PIN_LSB);
1681}
1682
1697static inline void pio_sm_put(PIO pio, uint sm, uint32_t data) {
1698 check_pio_param(pio);
1699 check_sm_param(sm);
1700 pio->txf[sm] = data;
1701}
1702
1718static inline uint32_t pio_sm_get(PIO pio, uint sm) {
1719 check_pio_param(pio);
1720 check_sm_param(sm);
1721 return pio->rxf[sm];
1722}
1723
1731static inline bool pio_sm_is_rx_fifo_full(PIO pio, uint sm) {
1732 check_pio_param(pio);
1733 check_sm_param(sm);
1734 return (pio->fstat & (1u << (PIO_FSTAT_RXFULL_LSB + sm))) != 0;
1735}
1736
1744static inline bool pio_sm_is_rx_fifo_empty(PIO pio, uint sm) {
1745 check_pio_param(pio);
1746 check_sm_param(sm);
1747 return (pio->fstat & (1u << (PIO_FSTAT_RXEMPTY_LSB + sm))) != 0;
1748}
1749
1757static inline uint pio_sm_get_rx_fifo_level(PIO pio, uint sm) {
1758 check_pio_param(pio);
1759 check_sm_param(sm);
1760 uint bitoffs = PIO_FLEVEL_RX0_LSB + sm * (PIO_FLEVEL_RX1_LSB - PIO_FLEVEL_RX0_LSB);
1761 const uint32_t mask = PIO_FLEVEL_RX0_BITS >> PIO_FLEVEL_RX0_LSB;
1762 return (pio->flevel >> bitoffs) & mask;
1763}
1764
1772static inline bool pio_sm_is_tx_fifo_full(PIO pio, uint sm) {
1773 check_pio_param(pio);
1774 check_sm_param(sm);
1775 return (pio->fstat & (1u << (PIO_FSTAT_TXFULL_LSB + sm))) != 0;
1776}
1777
1785static inline bool pio_sm_is_tx_fifo_empty(PIO pio, uint sm) {
1786 check_pio_param(pio);
1787 check_sm_param(sm);
1788 return (pio->fstat & (1u << (PIO_FSTAT_TXEMPTY_LSB + sm))) != 0;
1789}
1790
1798static inline uint pio_sm_get_tx_fifo_level(PIO pio, uint sm) {
1799 check_pio_param(pio);
1800 check_sm_param(sm);
1801 unsigned int bitoffs = PIO_FLEVEL_TX0_LSB + sm * (PIO_FLEVEL_TX1_LSB - PIO_FLEVEL_TX0_LSB);
1802 const uint32_t mask = PIO_FLEVEL_TX0_BITS >> PIO_FLEVEL_TX0_LSB;
1803 return (pio->flevel >> bitoffs) & mask;
1804}
1805
1813static inline void pio_sm_put_blocking(PIO pio, uint sm, uint32_t data) {
1814 check_pio_param(pio);
1815 check_sm_param(sm);
1817 pio_sm_put(pio, sm, data);
1818}
1819
1826static inline uint32_t pio_sm_get_blocking(PIO pio, uint sm) {
1827 check_pio_param(pio);
1828 check_sm_param(sm);
1830 return pio_sm_get(pio, sm);
1831}
1832
1846void pio_sm_drain_tx_fifo(PIO pio, uint sm);
1847
1856static inline void pio_sm_set_clkdiv_int_frac8(PIO pio, uint sm, uint32_t div_int, uint8_t div_frac8) {
1857 check_pio_param(pio);
1858 check_sm_param(sm);
1859 static_assert(REG_FIELD_WIDTH(PIO_SM0_CLKDIV_INT) == 16, "");
1860 invalid_params_if(HARDWARE_PIO, div_int >> 16);
1861 invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac8 != 0);
1862 static_assert(REG_FIELD_WIDTH(PIO_SM0_CLKDIV_FRAC) == 8, "");
1863 pio->sm[sm].clkdiv =
1864 (((uint)div_frac8) << PIO_SM0_CLKDIV_FRAC_LSB) |
1865 (((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB);
1866}
1867
1868// backwards compatibility
1869static inline void pio_sm_set_clkdiv_int_frac(PIO pio, uint sm, uint16_t div_int, uint8_t div_frac8) {
1870 pio_sm_set_clkdiv_int_frac8(pio, sm, div_int, div_frac8);
1871}
1872
1880static inline void pio_sm_set_clkdiv(PIO pio, uint sm, float div) {
1881 check_pio_param(pio);
1882 check_sm_param(sm);
1883 uint32_t div_int;
1884 uint8_t div_frac8;
1885 pio_calculate_clkdiv8_from_float(div, &div_int, &div_frac8);
1886 pio_sm_set_clkdiv_int_frac8(pio, sm, div_int, div_frac8);
1887}
1888
1895static inline void pio_sm_clear_fifos(PIO pio, uint sm) {
1896 // changing the FIFO join state clears the fifo
1897 check_pio_param(pio);
1898 check_sm_param(sm);
1899 hw_xor_bits(&pio->sm[sm].shiftctrl, PIO_SM0_SHIFTCTRL_FJOIN_RX_BITS);
1900 hw_xor_bits(&pio->sm[sm].shiftctrl, PIO_SM0_SHIFTCTRL_FJOIN_RX_BITS);
1901}
1902
1916void pio_sm_set_pins(PIO pio, uint sm, uint32_t pin_values);
1917
1930void pio_sm_set_pins64(PIO pio, uint sm, uint64_t pin_values);
1931
1946void pio_sm_set_pins_with_mask(PIO pio, uint sm, uint32_t pin_values, uint32_t pin_mask);
1947
1961void pio_sm_set_pins_with_mask64(PIO pio, uint sm, uint64_t pin_values, uint64_t pin_mask);
1962
1977void pio_sm_set_pindirs_with_mask(PIO pio, uint sm, uint32_t pin_dirs, uint32_t pin_mask);
1978
1992void pio_sm_set_pindirs_with_mask64(PIO pio, uint sm, uint64_t pin_dirs, uint64_t pin_mask);
1993
2009int pio_sm_set_consecutive_pindirs(PIO pio, uint sm, uint pins_base, uint pin_count, bool is_out);
2010
2018void pio_set_input_sync_bypass_with_mask(PIO pio, uint32_t bypass_enables, uint32_t pin_mask);
2019
2027void pio_set_input_sync_bypass_with_mask64(PIO pio, uint64_t bypass_enables, uint64_t pin_mask);
2028
2039void pio_sm_claim(PIO pio, uint sm);
2040
2051void pio_claim_sm_mask(PIO pio, uint sm_mask);
2052
2061void pio_sm_unclaim(PIO pio, uint sm);
2062
2071int pio_claim_unused_sm(PIO pio, bool required);
2072
2082bool pio_sm_is_claimed(PIO pio, uint sm);
2083
2094bool pio_claim_free_sm_and_add_program(const pio_program_t *program, PIO *pio_out, uint *sm_out, uint *offset_out);
2095
2122bool pio_claim_free_sm_and_add_program_for_gpio_range(const pio_program_t *program, PIO *pio_out, uint *sm_out, uint *offset_out, uint gpio_start, uint gpio_count, bool set_gpio_base);
2123
2133void pio_remove_program_and_unclaim_sm(const pio_program_t *program, PIO pio, uint sm, uint offset);
2134
2142static inline int pio_get_irq_num(PIO pio, uint irqn) {
2143 check_pio_param(pio);
2144 valid_params_if(HARDWARE_PIO, irqn < NUM_PIO_IRQS);
2145 return PIO_IRQ_NUM(pio, irqn);
2146}
2147
2155 check_sm_param(sm);
2157}
2158
2166 check_sm_param(sm);
2168}
2169
2170#ifdef __cplusplus
2171}
2172#endif
2173
2174#endif // _PIO_H_
static __force_inline void hw_set_bits(io_rw_32 *addr, uint32_t mask)
Atomically set the specified bits to 1 in a HW register.
Definition address_mapped.h:135
static __force_inline void hw_xor_bits(io_rw_32 *addr, uint32_t mask)
Atomically flip the specified bits in a HW register.
Definition address_mapped.h:155
static __force_inline void hw_clear_bits(io_rw_32 *addr, uint32_t mask)
Atomically clear the specified bits to 0 in a HW register.
Definition address_mapped.h:145
@ DREQ_PIO0_TX3
Select PIO0's TX FIFO 3 as DREQ.
Definition dreq.h:85
@ DREQ_PIO1_TX0
Select PIO1's TX FIFO 0 as DREQ.
Definition dreq.h:90
@ DREQ_PIO2_TX0
Select PIO2's TX FIFO 0 as DREQ.
Definition dreq.h:98
@ DREQ_PIO1_RX0
Select PIO1's RX FIFO 0 as DREQ.
Definition dreq.h:94
@ DREQ_PIO2_RX0
Select PIO2's RX FIFO 0 as DREQ.
Definition dreq.h:102
@ DREQ_PIO0_TX2
Select PIO0's TX FIFO 2 as DREQ.
Definition dreq.h:84
@ DREQ_PIO0_RX0
Select PIO0's RX FIFO 0 as DREQ.
Definition dreq.h:86
@ DREQ_PIO0_TX1
Select PIO0's TX FIFO 1 as DREQ.
Definition dreq.h:83
@ DREQ_PIO0_TX0
Select PIO0's TX FIFO 0 as DREQ.
Definition dreq.h:82
void gpio_set_function(uint gpio, gpio_function_t fn)
Select GPIO function.
Definition gpio.c:38
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.
Definition pio.h:1798
#define PIO_INSTANCE(instance)
Returns the PIO instance with the given PIO number.
Definition pio.h:187
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.
Definition pio.h:1440
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.
Definition pio.c:295
pio_interrupt_source
PIO interrupt source numbers for pio related IRQs.
Definition pio.h:1345
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.
Definition pio.h:1826
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.
Definition pio.c:224
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.
Definition pio.c:185
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
Definition pio.h:1856
static PIO pio_get_instance(uint instance)
Convert PIO instance to hardware instance.
Definition pio.h:915
void pio_set_input_sync_bypass_with_mask64(PIO pio, uint64_t bypass_enables, uint64_t pin_mask)
Enable/disable the input synchronizer bypass for multiple pins for the PIO instance.
Definition pio.c:362
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.
Definition pio.h:1549
static int pio_sm_set_config(PIO pio, uint sm, const pio_sm_config *config)
Apply a state machine configuration to a state machine.
Definition pio.h:838
static int pio_get_irq_num(PIO pio, uint irqn)
Return an IRQ for a PIO hardware instance.
Definition pio.h:2142
int pio_set_gpio_base(PIO pio, uint gpio_base)
Set the base GPIO base for the PIO instance.
Definition pio.c:94
bool pio_claim_free_sm_and_add_program_for_gpio_range(const pio_program_t *program, PIO *pio_out, uint *sm_out, uint *offset_out, uint gpio_start, uint gpio_count, bool set_gpio_base)
Finds a PIO and statemachine and adds a program into PIO memory.
Definition pio.c:454
pio_mov_status_type
MOV status types.
Definition pio.h:113
static bool pio_sm_is_tx_fifo_full(PIO pio, uint sm)
Determine if a state machine's TX FIFO is full.
Definition pio.h:1772
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.
Definition pio.h:961
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.
Definition pio.h:1389
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.
Definition pio.c:335
void pio_sm_drain_tx_fifo(PIO pio, uint sm)
Empty out a state machine's TX FIFO.
Definition pio.c:427
void pio_claim_sm_mask(PIO pio, uint sm_mask)
Mark multiple state machines as used.
Definition pio.c:36
struct pio_program pio_program_t
PIO program definition.
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.
Definition pio.c:256
int pio_claim_unused_sm(PIO pio, bool required)
Claim a free state machine on a PIO instance.
Definition pio.c:48
void pio_sm_unclaim(PIO pio, uint sm)
Mark a state machine as no longer used.
Definition pio.c:42
static void pio_clkdiv_restart_sm_mask(PIO pio, uint32_t mask)
Restart multiple state machines' clock dividers from a phase of 0.
Definition pio.h:1246
void pio_set_input_sync_bypass_with_mask(PIO pio, uint32_t bypass_enables, uint32_t pin_mask)
Enable/disable the input synchronizer bypass for multiple pins for the PIO instance.
Definition pio.c:345
bool pio_sm_is_claimed(PIO pio, uint sm)
Determine if a PIO state machine is claimed.
Definition pio.c:57
bool pio_claim_free_sm_and_add_program(const pio_program_t *program, PIO *pio_out, uint *sm_out, uint *offset_out)
Finds a PIO and statemachine and adds a program into PIO memory.
Definition pio.c:435
static void pio_interrupt_clear(PIO pio, uint pio_interrupt_num)
Clear a particular PIO interrupt.
Definition pio.h:1487
static uint32_t pio_sm_get(PIO pio, uint sm)
Read a word of data from a state machine's RX FIFO.
Definition pio.h:1718
static bool pio_sm_is_rx_fifo_full(PIO pio, uint sm)
Determine if a state machine's RX FIFO is full.
Definition pio.h:1731
static void pio_sm_set_wrap(PIO pio, uint sm, uint wrap_target, uint wrap)
Set the current wrap configuration for a state machine.
Definition pio.h:1565
#define PIO_NUM(pio)
Returns the PIO number for a PIO instance.
Definition pio.h:171
static void pio_sm_restart(PIO pio, uint sm)
Restart a state machine with a known internal state.
Definition pio.h:1167
pio_fifo_join
FIFO join states.
Definition pio.h:99
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.
Definition pio.h:1586
static void pio_sm_exec(PIO pio, uint sm, uint instr)
Immediately execute an instruction on a state machine.
Definition pio.h:1518
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.
Definition pio.h:1405
void pio_remove_program(PIO pio, const pio_program_t *program, uint loaded_offset)
Remove a program from a PIO instance's instruction memory.
Definition pio.c:192
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.
Definition pio.c:305
void pio_clear_instruction_memory(PIO pio)
Clears all of a PIO instance's instruction memory.
Definition pio.c:201
static void pio_sm_set_sideset_pins(PIO pio, uint sm, uint sideset_base)
Set the current 'sideset' pins for a state machine.
Definition pio.h:1652
static void pio_sm_set_clkdiv(PIO pio, uint sm, float div)
set the current clock divider for a state machine
Definition pio.h:1880
static uint pio_get_gpio_base(PIO pio)
Return the base GPIO base for the PIO instance.
Definition pio.h:802
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.
Definition pio.h:2154
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.
Definition pio.c:396
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.
Definition pio.h:1757
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.
Definition pio.c:265
static void pio_sm_set_jmp_pin(PIO pio, uint sm, uint pin)
Set the 'jmp' pin for a state machine.
Definition pio.h:1671
static uint8_t pio_sm_get_pc(PIO pio, uint sm)
Return the current program counter for a state machine.
Definition pio.h:1500
static uint pio_get_funcsel(PIO pio)
Return the funcsel number of a PIO instance.
Definition pio.h:904
#define PIO_FUNCSEL_NUM(pio, gpio)
Returns gpio_function_t needed to select the PIO function for the given PIO instance on the given GPI...
Definition pio.h:217
static void pio_sm_set_enabled(PIO pio, uint sm, bool enabled)
Enable or disable a PIO state machine.
Definition pio.h:1095
void pio_sm_claim(PIO pio, uint sm)
Mark a state machine as used.
Definition pio.c:24
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.
Definition pio.c:510
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.
Definition pio.c:139
static bool pio_interrupt_get(PIO pio, uint pio_interrupt_num)
Determine if a particular PIO interrupt is set.
Definition pio.h:1475
static bool pio_sm_is_exec_stalled(PIO pio, uint sm)
Determine if an instruction set by pio_sm_exec() is stalled executing.
Definition pio.h:1531
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 sta...
Definition pio.c:147
static void pio_sm_put(PIO pio, uint sm, uint32_t data)
Write a word of data to a state machine's TX FIFO.
Definition pio.h:1697
static void pio_sm_clear_fifos(PIO pio, uint sm)
Clear a state machine's TX and RX FIFOs.
Definition pio.h:1895
enum pio_interrupt_source pio_interrupt_source_t
PIO interrupt source numbers for pio related IRQs.
#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...
Definition pio.h:240
static void pio_enable_sm_mask_in_sync(PIO pio, uint32_t mask)
Enable multiple PIO state machines synchronizing their clock dividers.
Definition pio.h:1307
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.
Definition pio.h:1610
static void pio_sm_clkdiv_restart(PIO pio, uint sm)
Restart a state machine's clock divider from a phase of 0.
Definition pio.h:1211
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.
Definition pio.h:2165
#define PIO_IS_INSTANCE(pio)
Returns true if the PIO instance is one of the h/w PIO instances.
Definition pio.h:204
static bool pio_sm_is_rx_fifo_empty(PIO pio, uint sm)
Determine if a state machine's RX FIFO is empty.
Definition pio.h:1744
static bool pio_sm_is_tx_fifo_empty(PIO pio, uint sm)
Determine if a state machine's TX FIFO is empty.
Definition pio.h:1785
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.
Definition pio.h:1422
static void pio_restart_sm_mask(PIO pio, uint32_t mask)
Restart multiple state machines with a known internal state.
Definition pio.h:1184
static uint pio_get_index(PIO pio)
Return the instance number of a PIO instance.
Definition pio.h:892
#define PIO_IRQ_NUM(pio, irqn)
Returns the irq_num_t for processor interrupts from the given PIO instance.
Definition pio.h:252
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.
Definition pio.h:1813
static void pio_sm_set_in_pins(PIO pio, uint sm, uint in_base)
Set the current 'in' pins for a state machine.
Definition pio.h:1632
int pio_add_program(PIO pio, const pio_program_t *program)
Attempt to load the program.
Definition pio.c:175
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.
Definition pio.c:372
static void pio_set_sm_mask_enabled(PIO pio, uint32_t mask, bool enabled)
Enable or disable multiple PIO state machines.
Definition pio.h:1114
static void pio_gpio_init(PIO pio, uint pin)
Setup the function select for a GPIO to use output from the given PIO instance.
Definition pio.h:948
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.
Definition pio.h:1457
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.
Definition pio.h:1373
@ pis_interrupt2
PIO interrupt 2 is raised.
Definition pio.h:1348
@ pis_sm2_tx_fifo_not_full
State machine 2 TX FIFO is not full.
Definition pio.h:1358
@ pis_interrupt0
PIO interrupt 0 is raised.
Definition pio.h:1346
@ pis_sm1_tx_fifo_not_full
State machine 1 TX FIFO is not full.
Definition pio.h:1357
@ pis_sm3_tx_fifo_not_full
State machine 3 TX FIFO is not full.
Definition pio.h:1359
@ pis_interrupt1
PIO interrupt 1 is raised.
Definition pio.h:1347
@ pis_sm2_rx_fifo_not_empty
State machine 2 RX FIFO is not empty.
Definition pio.h:1362
@ pis_sm1_rx_fifo_not_empty
State machine 1 RX FIFO is not empty.
Definition pio.h:1361
@ pis_sm0_tx_fifo_not_full
State machine 0 TX FIFO is not full.
Definition pio.h:1356
@ pis_interrupt3
PIO interrupt 3 is raised.
Definition pio.h:1349
@ pis_sm0_rx_fifo_not_empty
State machine 0 RX FIFO is not empty.
Definition pio.h:1360
@ pis_sm3_rx_fifo_not_empty
State machine 3 RX FIFO is not empty.
Definition pio.h:1363
@ PIO_FIFO_JOIN_NONE
TX FIFO length=4 is used for transmit, RX FIFO length=4 is used for receive.
Definition pio.h:100
@ PIO_FIFO_JOIN_TX
TX FIFO length=8 is used for transmit, RX FIFO is disabled.
Definition pio.h:101
@ PIO_FIFO_JOIN_RX
RX FIFO length=8 is used for receive, TX FIFO is disabled.
Definition pio.h:102
@ PICO_OK
No error; the operation succeeded.
Definition error.h:23
@ PICO_ERROR_BAD_ALIGNMENT
Address was mis-aligned (usually not on word boundary).
Definition error.h:35
static __force_inline void tight_loop_contents(void)
No-op function for the body of tight loops.
Definition common.h:79
static void sm_config_set_out_pin_base(pio_sm_config *c, uint out_base)
Set the base of the 'out' pins in a state machine configuration.
Definition pio.h:357
static void sm_config_set_out_special(pio_sm_config *c, bool sticky, bool has_enable_pin, uint enable_bit_index)
Set special 'out' operations in a state machine configuration.
Definition pio.h:722
static void sm_config_set_set_pin_base(pio_sm_config *c, uint set_base)
Set the base of the 'set' pins in a state machine configuration.
Definition pio.h:403
static void sm_config_set_in_pin_count(pio_sm_config *c, uint in_count)
Set the count of 'in' pins in a state machine configuration.
Definition pio.h:484
static void sm_config_set_out_shift(pio_sm_config *c, bool shift_right, bool autopull, uint pull_threshold)
Setup 'out' shifting parameters in a state machine configuration.
Definition pio.h:680
static void sm_config_set_set_pin_count(pio_sm_config *c, uint set_count)
Set the count of 'set' pins in a state machine configuration.
Definition pio.h:421
static void sm_config_set_sideset_pin_base(pio_sm_config *c, uint sideset_base)
Set the base of the 'sideset' pins in a state machine configuration.
Definition pio.h:504
static void sm_config_set_clkdiv_int_frac8(pio_sm_config *c, uint32_t div_int, uint8_t div_frac8)
Set the state machine clock divider (from integer and fractional parts - 16:8) in a state machine con...
Definition pio.h:560
static void sm_config_set_in_pin_base(pio_sm_config *c, uint in_base)
Set the base of the 'in' pins in a state machine configuration.
Definition pio.h:449
static void sm_config_set_in_pins(pio_sm_config *c, uint in_base)
Set the base for the 'in' pins in a state machine configuration.
Definition pio.h:467
static void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_status_type status_sel, uint status_n)
Set source for 'mov status' in a state machine configuration.
Definition pio.h:738
static void sm_config_set_sideset_pins(pio_sm_config *c, uint sideset_base)
Set the 'sideset' pins in a state machine configuration.
Definition pio.h:525
static void sm_config_set_set_pins(pio_sm_config *c, uint set_base, uint set_count)
Set the 'set' pins in a state machine configuration.
Definition pio.h:436
static void sm_config_set_out_pin_count(pio_sm_config *c, uint out_count)
Set the number of 'out' pins in a state machine configuration.
Definition pio.h:375
static void sm_config_set_clkdiv(pio_sm_config *c, float div)
Set the state machine clock divider (from a floating point value) in a state machine configuration.
Definition pio.h:614
static void sm_config_set_in_shift(pio_sm_config *c, bool shift_right, bool autopush, uint push_threshold)
Setup 'in' shifting parameters in a state machine configuration.
Definition pio.h:661
static void sm_config_set_jmp_pin(pio_sm_config *c, uint pin)
Set the 'jmp' pin in a state machine configuration.
Definition pio.h:643
static pio_sm_config pio_get_default_sm_config(void)
Get the default state machine configuration.
Definition pio.h:780
static void sm_config_set_out_pins(pio_sm_config *c, uint out_base, uint out_count)
Set the 'out' pins in a state machine configuration.
Definition pio.h:390
static void sm_config_set_sideset(pio_sm_config *c, uint bit_count, bool optional, bool pindirs)
Set the 'sideset' options in a state machine configuration.
Definition pio.h:537
static void sm_config_set_wrap(pio_sm_config *c, uint wrap_target, uint wrap)
Set the wrap addresses in a state machine configuration.
Definition pio.h:629
static void sm_config_set_fifo_join(pio_sm_config *c, enum pio_fifo_join join)
Setup the FIFO joining in a state machine configuration.
Definition pio.h:697
Definition pio.h:147
PIO program definition.
Definition pio.h:976
int8_t origin
the required load offset in PIO instruction memory, or -1 if the program is relocatable and may be lo...
Definition pio.h:979
const uint16_t * instructions
the array of length encoded instructions that make up the program
Definition pio.h:977
uint8_t length
the number of instructions in instructions (also the amount of instruction memory the program occupie...
Definition pio.h:978
uint8_t pio_version
the minimum PIO hardware version the program requires (0 for any PIO); loading a program that require...
Definition pio.h:980
PIO Configuration structure.
Definition pio.h:307
uint32_t execctrl
Execution control register value.
Definition pio.h:309
uint32_t clkdiv
Clock divider register value.
Definition pio.h:308
uint32_t shiftctrl
Shift control register value.
Definition pio.h:310
uint32_t pinctrl
Pin control register value.
Definition pio.h:311