Skip to content

Commit 4deafa6

Browse files
committed
Add and test .in directive
1 parent ff1f57d commit 4deafa6

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
@@ -64,6 +64,10 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
6464
mov_status_type = None
6565
mov_status_count = None
6666
mov_status_param = None
67+
in_count = None
68+
in_shift_right = None
69+
auto_push = None
70+
push_threshold = None
6771

6872
def require_before_instruction():
6973
if len(instructions) != 0:
@@ -139,6 +143,29 @@ def int_in_range(arg, low, high, what, radix=0):
139143
if not 0 <= mov_status_count < 16:
140144
raise RuntimeError(f"Invalid mov_status count {mov_status_count}")
141145
require_version(required_version, line)
146+
elif words[0] == ".in":
147+
require_before_instruction()
148+
in_count = int_in_range(
149+
words[1], 32 if pio_version == 0 else 1, 33, ".in count"
150+
)
151+
auto_push = False
152+
153+
idx = 2
154+
if idx < len(words) and words[idx] == "left":
155+
in_shift_right = False
156+
idx += 1
157+
elif idx < len(words) and words[idx] == "right":
158+
in_shift_right = True
159+
idx += 1
160+
161+
if idx < len(words) and words[idx] == "auto":
162+
auto_push = True
163+
idx += 1
164+
165+
if idx < len(words):
166+
push_threshold = int_in_range(words[idx], 1, 33, ".in threshold")
167+
idx += 1
168+
142169
elif line.endswith(":"):
143170
label = line[:-1]
144171
if label in labels:
@@ -326,6 +353,18 @@ def int_in_range(arg, low, high, what, radix=0):
326353
self.pio_kwargs["mov_status_count"] = mov_status_count
327354
self.pio_kwargs["mov_status_param"] = mov_status_param
328355

356+
if in_count not in (None, 32):
357+
self.pio_kwargs["in_count"] = in_count
358+
359+
if in_shift_right is not None:
360+
self.pio_kwargs["in_shift_right"] = in_shift_right
361+
362+
if auto_push is not None:
363+
self.pio_kwargs["auto_push"] = auto_push
364+
365+
if push_threshold is not None:
366+
self.pio_kwargs["push_threshold"] = push_threshold
367+
329368
self.assembled = array.array("H", assembled)
330369

331370
self.debuginfo = (linemap, text_program) if build_debuginfo else None

tests/test_version.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,22 @@ def test_mov_status() -> None:
6161
mov_status_count=3,
6262
mov_status_param=0,
6363
)
64+
65+
66+
def test_dot_in() -> None:
67+
assert_pio_kwargs(
68+
".in 32 left auto 11",
69+
sideset_enable=0,
70+
auto_push=True,
71+
push_threshold=11,
72+
in_shift_right=False,
73+
)
74+
assert_assembly_fails(".in 16")
75+
assert_pio_kwargs(
76+
".pio_version 1\n.in 16 right",
77+
pio_version=1,
78+
sideset_enable=0,
79+
in_count=16,
80+
auto_push=False,
81+
in_shift_right=True,
82+
)

0 commit comments

Comments
 (0)