Skip to content

Commit

Permalink
rp2/rp2_pio: Add side_pindir support for PIO.
Browse files Browse the repository at this point in the history
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 micropython#10027.

Signed-off-by: Markus Gyger <[email protected]>
  • Loading branch information
magy00 authored and dpgeorge committed Feb 8, 2025
1 parent 9d0a5ac commit 0662c55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions docs/library/rp2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The ``rp2`` module includes functions for assembling PIO programs.

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.

Expand All @@ -35,8 +35,10 @@ For running PIO programs, see :class:`rp2.StateMachine`.
- *out_init* configures the pins used for ``out()`` instructions.
- *set_init* configures the pins used for ``set()`` instructions. There can
be at most 5.
- *sideset_init* configures the pins used side-setting. There can be at
most 5.
- *sideset_init* configures the pins used for ``.side()`` modifiers. There
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
`StateMachine.init()`:
Expand Down
9 changes: 5 additions & 4 deletions ports/rp2/modules/rp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ def __init__(
out_init=None,
set_init=None,
sideset_init=None,
in_shiftdir=0,
out_shiftdir=0,
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=0,
fifo_join=PIO.JOIN_NONE,
):
# array is a built-in module so importing it here won't require
# scanning the filesystem.
from array import array

self.labels = {}
execctrl = 0
execctrl = side_pindir << 29
shiftctrl = (
fifo_join << 30
| (pull_thresh & 0x1F) << 25
Expand Down

0 comments on commit 0662c55

Please sign in to comment.