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 #10027.

Signed-off-by: Markus Gyger <markus@gyger.org>
This commit is contained in:
Markus Gyger
2024-12-31 15:34:17 +07:00
committed by Damien George
parent 9d0a5ac7e9
commit 0662c55121
2 changed files with 10 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ The ``rp2`` module includes functions for assembling PIO programs.
For running PIO programs, see :class:`rp2.StateMachine`. For running PIO programs, see :class:`rp2.StateMachine`.
.. 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) .. 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)
Assemble a PIO program. Assemble a PIO program.
@@ -35,8 +35,10 @@ For running PIO programs, see :class:`rp2.StateMachine`.
- *out_init* configures the pins used for ``out()`` instructions. - *out_init* configures the pins used for ``out()`` instructions.
- *set_init* configures the pins used for ``set()`` instructions. There can - *set_init* configures the pins used for ``set()`` instructions. There can
be at most 5. be at most 5.
- *sideset_init* configures the pins used side-setting. There can be at - *sideset_init* configures the pins used for ``.side()`` modifiers. There
most 5. can be at most 5.
- *side_pindir* when set to ``True`` configures ``.side()`` modifiers to be
used for pin directions, instead of pin values (the default, when ``False``).
The following parameters are used by default, but can be overridden in The following parameters are used by default, but can be overridden in
`StateMachine.init()`: `StateMachine.init()`:

View File

@@ -26,20 +26,21 @@ class PIOASMEmit:
out_init=None, out_init=None,
set_init=None, set_init=None,
sideset_init=None, sideset_init=None,
in_shiftdir=0, side_pindir=False,
out_shiftdir=0, in_shiftdir=PIO.SHIFT_LEFT,
out_shiftdir=PIO.SHIFT_LEFT,
autopush=False, autopush=False,
autopull=False, autopull=False,
push_thresh=32, push_thresh=32,
pull_thresh=32, pull_thresh=32,
fifo_join=0, fifo_join=PIO.JOIN_NONE,
): ):
# array is a built-in module so importing it here won't require # array is a built-in module so importing it here won't require
# scanning the filesystem. # scanning the filesystem.
from array import array from array import array
self.labels = {} self.labels = {}
execctrl = 0 execctrl = side_pindir << 29
shiftctrl = ( shiftctrl = (
fifo_join << 30 fifo_join << 30
| (pull_thresh & 0x1F) << 25 | (pull_thresh & 0x1F) << 25