Skip to content

Commit 0662c55

Browse files
magy00dpgeorge
authored andcommitted
rp2/rp2_pio: Add side_pindir support for PIO.
Side-setting can also be used to change pin directions instead of pin values. This adds a parameter `side_pindir` to decorator `asm_pio()` to configure it. Also replaces a few close-by 0s with corresponding PIO.* constants. Addresses issue adafruit#10027. Signed-off-by: Markus Gyger <[email protected]>
1 parent 9d0a5ac commit 0662c55

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

docs/library/rp2.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The ``rp2`` module includes functions for assembling PIO programs.
2323

2424
For running PIO programs, see :class:`rp2.StateMachine`.
2525

26-
.. function:: asm_pio(*, out_init=None, set_init=None, sideset_init=None, in_shiftdir=0, out_shiftdir=0, autopush=False, autopull=False, push_thresh=32, pull_thresh=32, fifo_join=PIO.JOIN_NONE)
26+
.. function:: asm_pio(*, out_init=None, set_init=None, sideset_init=None, side_pindir=False, in_shiftdir=PIO.SHIFT_LEFT, out_shiftdir=PIO.SHIFT_LEFT, autopush=False, autopull=False, push_thresh=32, pull_thresh=32, fifo_join=PIO.JOIN_NONE)
2727

2828
Assemble a PIO program.
2929

@@ -35,8 +35,10 @@ For running PIO programs, see :class:`rp2.StateMachine`.
3535
- *out_init* configures the pins used for ``out()`` instructions.
3636
- *set_init* configures the pins used for ``set()`` instructions. There can
3737
be at most 5.
38-
- *sideset_init* configures the pins used side-setting. There can be at
39-
most 5.
38+
- *sideset_init* configures the pins used for ``.side()`` modifiers. There
39+
can be at most 5.
40+
- *side_pindir* when set to ``True`` configures ``.side()`` modifiers to be
41+
used for pin directions, instead of pin values (the default, when ``False``).
4042

4143
The following parameters are used by default, but can be overridden in
4244
`StateMachine.init()`:

ports/rp2/modules/rp2.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ def __init__(
2626
out_init=None,
2727
set_init=None,
2828
sideset_init=None,
29-
in_shiftdir=0,
30-
out_shiftdir=0,
29+
side_pindir=False,
30+
in_shiftdir=PIO.SHIFT_LEFT,
31+
out_shiftdir=PIO.SHIFT_LEFT,
3132
autopush=False,
3233
autopull=False,
3334
push_thresh=32,
3435
pull_thresh=32,
35-
fifo_join=0,
36+
fifo_join=PIO.JOIN_NONE,
3637
):
3738
# array is a built-in module so importing it here won't require
3839
# scanning the filesystem.
3940
from array import array
4041

4142
self.labels = {}
42-
execctrl = 0
43+
execctrl = side_pindir << 29
4344
shiftctrl = (
4445
fifo_join << 30
4546
| (pull_thresh & 0x1F) << 25

0 commit comments

Comments
 (0)