Raspberry Pi Pico Python SDK
3. initial GPIO direction (in or out pin)
4. initial GPIO value (high or low)
In the design of the Python API for PIO these 4 items are split into "declaration" (items 2-4) and "instantiation" (item 1). In
other words, a program is written with items 2-4 fixed for that program (eg a WS2812 driver would have 1 output pin) and
item 1 is free to change without changing the program (eg which pin the WS2812 is connected to).
So in the
@asm_pio
1). That makes it easy to define a single program and instantiate it multiple times on different pins (you can't really
change items 2-4 for a different instantiation of the same program, it doesn't really make sense to do that).
And the same keyword arg (in the case about it's
that they are linked.
To declare multiple pins in the decorator (the count, ie item 2 above), you use a tuple/list of values. And each item in the
tuple/list specified items 3 and 4. For example:
1 @asm_pio(set_pins=(PIO.OUT_LOW, PIO.OUT_HIGH, PIO.IN_LOW), sideset_pins=PIO.OUT_LOW)
2
def
foo():
3
....
4
5 sm = StateMachine(0, foo, freq=10000, set_pins=Pin(15), sideset_pins=Pin(22))
In this example:
•
there are 3 set pins connected to the SM, and their initial state (set when the StateMachine is created) is: output low,
output high, input low (used for open-drain)
•
there is 1 sideset pin, initial state is output low
•
the 3 set pins start at Pin(15)
•
the 1 sideset pin starts at Pin(22)
The reason to have the constants
before the start of the PIO program (instead of wasting instruction words to do
3.9.1. IRQ
There is support for PIO IRQs, e.g.
Pico MicroPython Examples:
1
import
2
import
3
4 @rp2.asm_pio()
5
def
irq_test():
6
wrap_target()
7
nop()
8
nop()
9
nop()
10
nop()
11
irq(0)
12
nop()
13
nop()
14
nop()
15
nop()
16
irq(1)
17
wrap()
3.9. PIO Support
decorator you declare items 2-4, and in the
OUT_LOW
,
OUT_HIGH
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio/pio_irq.py
time
rp2
[31]
[31]
[31]
[31]
[31]
[31]
[31]
[31]
StateMachine
constructor you say which base pin to use (item
sideset_pins
) is used for both the declaration and instantiation, to show
,
IN_LOW
and
IN_HIGH
is so that the pin value and dir are automatically set
set(pindirs, 1)
Lines 1 - 25
etc at the start).
19
Need help?
Do you have a question about the Pico Python SDK and is the answer not in the manual?