Skip to content

Commit a8fa218

Browse files
committed
Recognize .pio_version directive (integer arguments only)
1 parent be66c02 commit a8fa218

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

adafruit_pioasm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
5858
wrap = None
5959
wrap_target = None
6060
offset = -1
61+
pio_version = 0
62+
6163
for i, line in enumerate(text_program.split("\n")):
6264
line = line.strip()
6365
if not line:
@@ -68,6 +70,8 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
6870
if program_name:
6971
raise RuntimeError("Multiple programs not supported")
7072
program_name = line.split()[1]
73+
elif line.startswith(".pio_version"):
74+
pio_version = int(line.split()[1], 0)
7175
elif line.startswith(".origin"):
7276
offset = int(line.split()[1], 0)
7377
elif line.startswith(".wrap_target"):
@@ -247,6 +251,9 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
247251
if offset != -1:
248252
self.pio_kwargs["offset"] = offset
249253

254+
if pio_version != 0:
255+
self.pio_kwargs["pio_version"] = pio_version
256+
250257
if sideset_count != 0:
251258
self.pio_kwargs["sideset_pin_count"] = sideset_count
252259

tests/pytest_helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ def assert_assembly_fails(
4545

4646
def assert_pio_kwargs(source: str, **kw: Any) -> None:
4747
program = adafruit_pioasm.Program(source)
48-
assert kw == program.pio_kwargs
48+
assert (
49+
kw == program.pio_kwargs
50+
), f"Assembling {source!r}: Expected {kw}, got {program.pio_kwargs}"

tests/test_version.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2024 Jeff Epler, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Tests version dependent instructions
7+
"""
8+
9+
from pytest_helpers import assert_pio_kwargs, assert_assembly_fails
10+
11+
12+
def test_version() -> None:
13+
assert_pio_kwargs(".pio_version 0", sideset_enable=0)
14+
assert_pio_kwargs(".pio_version 1", pio_version=1, sideset_enable=0)
15+
assert_assembly_fails(".pio_version muffin", errtype=ValueError)

0 commit comments

Comments
 (0)