More piov2 updates

* As an extension, ".fifo auto" may be specified to request CircuitPython's
   auto fifo join behavior
 * bounds check on `.set` directive improved
 * redundant kwargs (e.g., out_count vs out_pin_count) fixed
This commit is contained in:
Jeff Epler 2024-09-10 14:09:34 -05:00
parent b379f05b29
commit 8a97f71b0c
3 changed files with 29 additions and 13 deletions

View file

@ -55,6 +55,11 @@ To install in a virtual environment in your current project:
source .venv/bin/activate source .venv/bin/activate
pip3 install adafruit-circuitpython-pioasm pip3 install adafruit-circuitpython-pioasm
CircuitPython Extensions
========================
* `.fifo auto`: By default, CircuitPython joins the TX and RX fifos if a PIO program only receives or transmits. The `.fifo auto` directive makes this explicit.
Usage Example Usage Example
============= =============

View file

@ -34,7 +34,15 @@ MOV_DESTINATIONS_V1 = ["pins", "x", "y", "pindirs", "exec", "pc", "isr", "osr"]
MOV_SOURCES = ["pins", "x", "y", "null", None, "status", "isr", "osr"] MOV_SOURCES = ["pins", "x", "y", "null", None, "status", "isr", "osr"]
MOV_OPS = [None, "~", "::", None] MOV_OPS = [None, "~", "::", None]
SET_DESTINATIONS = ["pins", "x", "y", None, "pindirs", None, None, None] SET_DESTINATIONS = ["pins", "x", "y", None, "pindirs", None, None, None]
FIFO_TYPES = {"txrx": 0, "tx": 0, "rx": 0, "txput": 1, "txget": 1, "putget": 1} FIFO_TYPES = {
"auto": 0,
"txrx": 0,
"tx": 0,
"rx": 0,
"txput": 1,
"txget": 1,
"putget": 1,
}
class Program: # pylint: disable=too-few-public-methods class Program: # pylint: disable=too-few-public-methods
@ -61,7 +69,7 @@ class Program: # pylint: disable=too-few-public-methods
wrap_target = None wrap_target = None
offset = -1 offset = -1
pio_version = 0 pio_version = 0
fifo_type = None fifo_type = "auto"
mov_status_type = None mov_status_type = None
mov_status_n = None mov_status_n = None
in_count = None in_count = None
@ -208,7 +216,7 @@ class Program: # pylint: disable=too-few-public-methods
elif words[0] == ".set": elif words[0] == ".set":
require_before_instruction() require_before_instruction()
set_count = int_in_range( set_count = int_in_range(
words[1], 32 if pio_version == 0 else 1, 33, ".set count" words[1], 5 if pio_version == 0 else 1, 6, ".set count"
) )
elif line.endswith(":"): elif line.endswith(":"):
@ -443,18 +451,18 @@ class Program: # pylint: disable=too-few-public-methods
if wrap_target is not None: if wrap_target is not None:
self.pio_kwargs["wrap_target"] = wrap_target self.pio_kwargs["wrap_target"] = wrap_target
if FIFO_TYPES.get(fifo_type): if fifo_type != "auto":
self.pio_kwargs["fifo_type"] = fifo_type self.pio_kwargs["fifo_type"] = fifo_type
if mov_status_type is not None: if mov_status_type is not None:
self.pio_kwargs["mov_status_type"] = mov_status_type self.pio_kwargs["mov_status_type"] = mov_status_type
self.pio_kwargs["mov_status_n"] = mov_status_n self.pio_kwargs["mov_status_n"] = mov_status_n
if set_count not in (None, 32): if set_count is not None:
self.pio_kwargs["set_count"] = set_count self.pio_kwargs["set_pin_count"] = set_count
if out_count not in (None, 32): if out_count not in (None, 32):
self.pio_kwargs["out_count"] = out_count self.pio_kwargs["out_pin_count"] = out_count
if out_shift_right is not None: if out_shift_right is not None:
self.pio_kwargs["out_shift_right"] = out_shift_right self.pio_kwargs["out_shift_right"] = out_shift_right
@ -466,7 +474,7 @@ class Program: # pylint: disable=too-few-public-methods
self.pio_kwargs["pull_threshold"] = pull_threshold self.pio_kwargs["pull_threshold"] = pull_threshold
if in_count not in (None, 32): if in_count not in (None, 32):
self.pio_kwargs["in_count"] = in_count self.pio_kwargs["in_pin_count"] = in_count
if in_shift_right is not None: if in_shift_right is not None:
self.pio_kwargs["in_shift_right"] = in_shift_right self.pio_kwargs["in_shift_right"] = in_shift_right

View file

@ -17,7 +17,8 @@ def test_version() -> None:
def test_fifo() -> None: def test_fifo() -> None:
assert_pio_kwargs(".fifo txrx", sideset_enable=0) assert_pio_kwargs(".fifo txrx", sideset_enable=0, fifo_type="txrx")
assert_pio_kwargs(".fifo auto", sideset_enable=0)
assert_assembly_fails(".fifo txput") assert_assembly_fails(".fifo txput")
assert_pio_kwargs( assert_pio_kwargs(
".pio_version 1\n.fifo txput", ".pio_version 1\n.fifo txput",
@ -80,7 +81,7 @@ def test_dot_in() -> None:
".pio_version 1\n.in 16 right", ".pio_version 1\n.in 16 right",
pio_version=1, pio_version=1,
sideset_enable=0, sideset_enable=0,
in_count=16, in_pin_count=16,
auto_push=False, auto_push=False,
in_shift_right=True, in_shift_right=True,
) )
@ -99,17 +100,19 @@ def test_dot_out() -> None:
".pio_version 1\n.out 16 right", ".pio_version 1\n.out 16 right",
pio_version=1, pio_version=1,
sideset_enable=0, sideset_enable=0,
out_count=16, out_pin_count=16,
auto_pull=False, auto_pull=False,
out_shift_right=True, out_shift_right=True,
) )
def test_dot_set() -> None: def test_dot_set() -> None:
assert_pio_kwargs(".set 32", sideset_enable=0) assert_pio_kwargs(".set 5", sideset_enable=0, set_pin_count=5)
assert_assembly_fails(".set 16") assert_assembly_fails(".set 16")
assert_assembly_fails(".pio_version 1\n.set 16")
assert_assembly_fails(".set 3")
assert_pio_kwargs( assert_pio_kwargs(
".pio_version 1\n.set 16 right", pio_version=1, sideset_enable=0, set_count=16 ".pio_version 1\n.set 3 right", pio_version=1, sideset_enable=0, set_pin_count=3
) )