diff --git a/adafruit_pioasm.py b/adafruit_pioasm.py index dc943e6..6458c4c 100644 --- a/adafruit_pioasm.py +++ b/adafruit_pioasm.py @@ -68,6 +68,10 @@ class Program: # pylint: disable=too-few-public-methods in_shift_right = None auto_push = None push_threshold = None + out_count = None + out_shift_right = None + auto_pull = None + pull_threshold = None def require_before_instruction(): if len(instructions) != 0: @@ -140,6 +144,29 @@ class Program: # pylint: disable=too-few-public-methods raise RuntimeError(f"Invalid {line})") mov_status_count = int(words[idx + 1]) require_version(required_version, line) + elif words[0] == ".out": + require_before_instruction() + out_count = int_in_range( + words[1], 32 if pio_version == 0 else 1, 33, ".out count" + ) + auto_pull = False + + idx = 2 + if idx < len(words) and words[idx] == "left": + out_shift_right = False + idx += 1 + elif idx < len(words) and words[idx] == "right": + out_shift_right = True + idx += 1 + + if idx < len(words) and words[idx] == "auto": + auto_pull = True + idx += 1 + + if idx < len(words): + pull_threshold = int_in_range(words[idx], 1, 33, ".out threshold") + idx += 1 + elif words[0] == ".in": require_before_instruction() in_count = int_in_range( @@ -350,6 +377,18 @@ class Program: # pylint: disable=too-few-public-methods self.pio_kwargs["mov_status_count"] = mov_status_count self.pio_kwargs["mov_status_param"] = mov_status_param + if out_count not in (None, 32): + self.pio_kwargs["out_count"] = out_count + + if out_shift_right is not None: + self.pio_kwargs["out_shift_right"] = out_shift_right + + if auto_pull is not None: + self.pio_kwargs["auto_pull"] = auto_pull + + if pull_threshold is not None: + self.pio_kwargs["pull_threshold"] = pull_threshold + if in_count not in (None, 32): self.pio_kwargs["in_count"] = in_count diff --git a/tests/test_version.py b/tests/test_version.py index 50de635..9d31388 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -80,3 +80,22 @@ def test_dot_in() -> None: auto_push=False, in_shift_right=True, ) + + +def test_dot_out() -> None: + assert_pio_kwargs( + ".out 32 left auto 11", + sideset_enable=0, + auto_pull=True, + pull_threshold=11, + out_shift_right=False, + ) + assert_assembly_fails(".out 16") + assert_pio_kwargs( + ".pio_version 1\n.out 16 right", + pio_version=1, + sideset_enable=0, + out_count=16, + auto_pull=False, + out_shift_right=True, + )