Skip to content

Commit 4f98480

Browse files
committed
Add irq prev/next
1 parent e9858c3 commit 4f98480

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

adafruit_pioasm.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,33 @@ def int_in_range(arg, low, high, what, radix=0):
325325
if len(instruction) > 3:
326326
assembled[-1] |= MOV_OPS.index(instruction[-2]) << 3
327327
elif instruction[0] == "irq":
328-
# instr delay z c w index
328+
# instr delay z c w tp/idx
329329
assembled.append(0b110_00000_0_0_0_00000)
330-
if instruction[-1] == "rel":
331-
assembled[-1] |= 0x10 # Set the high bit of the irq value
330+
331+
irq_type = 0
332+
print(f"check prev/next/rel {instruction=}")
333+
if instruction[-1] == "prev":
334+
irq_type = 1
335+
require_version(1, "irq prev")
336+
instruction.pop()
337+
elif instruction[-1] == "next":
338+
irq_type = 3
339+
require_version(1, "irq next")
340+
instruction.pop()
341+
elif instruction[-1] == "rel":
342+
irq_type = 2
332343
instruction.pop()
333-
num = int(instruction[-1], 0)
334-
if not 0 <= num <= 7:
335-
raise RuntimeError("Interrupt index out of range")
344+
345+
assembled[-1] |= irq_type << 3
346+
347+
num = int_in_range(instruction[-1], 0, 8, "irq index")
336348
assembled[-1] |= num
337-
if len(instruction) == 3: # after rel has been removed
338-
if instruction[1] == "wait":
349+
instruction.pop()
350+
351+
if len(instruction) > 1: # after rel has been removed
352+
if instruction[-1] == "wait":
339353
assembled[-1] |= 0x20
340-
elif instruction[1] == "clear":
354+
elif instruction[-1] == "clear":
341355
assembled[-1] |= 0x40
342356
# All other values are the default of set without waiting
343357
elif instruction[0] == "set":

tests/test_version.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Tests version dependent instructions
77
"""
88

9-
from pytest_helpers import assert_pio_kwargs, assert_assembly_fails
9+
from pytest_helpers import assert_pio_kwargs, assert_assembly_fails, assert_assembles_to
1010

1111

1212
def test_version() -> None:
@@ -107,3 +107,9 @@ def test_dot_set() -> None:
107107
assert_pio_kwargs(
108108
".pio_version 1\n.set 16 right", pio_version=1, sideset_enable=0, set_count=16
109109
)
110+
111+
112+
def test_irq_v1() -> None:
113+
assert_assembly_fails("irq 7 next")
114+
assert_assembles_to(".pio_version 1\nirq 5 next", [0b110_00000_0_0_0_11_101])
115+
assert_assembles_to(".pio_version 1\nirq wait 1 prev", [0b110_00000_0_0_1_01_001])

0 commit comments

Comments
 (0)