Skip to content

Commit

Permalink
Add irq prev/next
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Sep 6, 2024
1 parent e9858c3 commit 4f98480
Showing 2 changed files with 30 additions and 10 deletions.
32 changes: 23 additions & 9 deletions adafruit_pioasm.py
Original file line number Diff line number Diff line change
@@ -325,19 +325,33 @@ def int_in_range(arg, low, high, what, radix=0):
if len(instruction) > 3:
assembled[-1] |= MOV_OPS.index(instruction[-2]) << 3
elif instruction[0] == "irq":
# instr delay z c w index
# instr delay z c w tp/idx
assembled.append(0b110_00000_0_0_0_00000)
if instruction[-1] == "rel":
assembled[-1] |= 0x10 # Set the high bit of the irq value

irq_type = 0
print(f"check prev/next/rel {instruction=}")
if instruction[-1] == "prev":
irq_type = 1
require_version(1, "irq prev")
instruction.pop()
elif instruction[-1] == "next":
irq_type = 3
require_version(1, "irq next")
instruction.pop()
elif instruction[-1] == "rel":
irq_type = 2
instruction.pop()
num = int(instruction[-1], 0)
if not 0 <= num <= 7:
raise RuntimeError("Interrupt index out of range")

assembled[-1] |= irq_type << 3

num = int_in_range(instruction[-1], 0, 8, "irq index")
assembled[-1] |= num
if len(instruction) == 3: # after rel has been removed
if instruction[1] == "wait":
instruction.pop()

if len(instruction) > 1: # after rel has been removed
if instruction[-1] == "wait":
assembled[-1] |= 0x20
elif instruction[1] == "clear":
elif instruction[-1] == "clear":
assembled[-1] |= 0x40
# All other values are the default of set without waiting
elif instruction[0] == "set":
8 changes: 7 additions & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
Tests version dependent instructions
"""

from pytest_helpers import assert_pio_kwargs, assert_assembly_fails
from pytest_helpers import assert_pio_kwargs, assert_assembly_fails, assert_assembles_to


def test_version() -> None:
@@ -107,3 +107,9 @@ def test_dot_set() -> None:
assert_pio_kwargs(
".pio_version 1\n.set 16 right", pio_version=1, sideset_enable=0, set_count=16
)


def test_irq_v1() -> None:
assert_assembly_fails("irq 7 next")
assert_assembles_to(".pio_version 1\nirq 5 next", [0b110_00000_0_0_0_11_101])
assert_assembles_to(".pio_version 1\nirq wait 1 prev", [0b110_00000_0_0_1_01_001])

0 comments on commit 4f98480

Please sign in to comment.