Skip to content

Commit ed74947

Browse files
committed
Add .out directive
1 parent 5659a26 commit ed74947

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

adafruit_pioasm.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
6868
in_shift_right = None
6969
auto_push = None
7070
push_threshold = None
71+
out_count = None
72+
out_shift_right = None
73+
auto_pull = None
74+
pull_threshold = None
7175

7276
def require_before_instruction():
7377
if len(instructions) != 0:
@@ -140,6 +144,29 @@ def int_in_range(arg, low, high, what, radix=0):
140144
raise RuntimeError(f"Invalid {line})")
141145
mov_status_count = int(words[idx + 1])
142146
require_version(required_version, line)
147+
elif words[0] == ".out":
148+
require_before_instruction()
149+
out_count = int_in_range(
150+
words[1], 32 if pio_version == 0 else 1, 33, ".out count"
151+
)
152+
auto_pull = False
153+
154+
idx = 2
155+
if idx < len(words) and words[idx] == "left":
156+
out_shift_right = False
157+
idx += 1
158+
elif idx < len(words) and words[idx] == "right":
159+
out_shift_right = True
160+
idx += 1
161+
162+
if idx < len(words) and words[idx] == "auto":
163+
auto_pull = True
164+
idx += 1
165+
166+
if idx < len(words):
167+
pull_threshold = int_in_range(words[idx], 1, 33, ".out threshold")
168+
idx += 1
169+
143170
elif words[0] == ".in":
144171
require_before_instruction()
145172
in_count = int_in_range(
@@ -350,6 +377,18 @@ def int_in_range(arg, low, high, what, radix=0):
350377
self.pio_kwargs["mov_status_count"] = mov_status_count
351378
self.pio_kwargs["mov_status_param"] = mov_status_param
352379

380+
if out_count not in (None, 32):
381+
self.pio_kwargs["out_count"] = out_count
382+
383+
if out_shift_right is not None:
384+
self.pio_kwargs["out_shift_right"] = out_shift_right
385+
386+
if auto_pull is not None:
387+
self.pio_kwargs["auto_pull"] = auto_pull
388+
389+
if pull_threshold is not None:
390+
self.pio_kwargs["pull_threshold"] = pull_threshold
391+
353392
if in_count not in (None, 32):
354393
self.pio_kwargs["in_count"] = in_count
355394

tests/test_version.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,22 @@ def test_dot_in() -> None:
8080
auto_push=False,
8181
in_shift_right=True,
8282
)
83+
84+
85+
def test_dot_out() -> None:
86+
assert_pio_kwargs(
87+
".out 32 left auto 11",
88+
sideset_enable=0,
89+
auto_pull=True,
90+
pull_threshold=11,
91+
out_shift_right=False,
92+
)
93+
assert_assembly_fails(".out 16")
94+
assert_pio_kwargs(
95+
".pio_version 1\n.out 16 right",
96+
pio_version=1,
97+
sideset_enable=0,
98+
out_count=16,
99+
auto_pull=False,
100+
out_shift_right=True,
101+
)

0 commit comments

Comments
 (0)