← index #7903PR #11390
Off-topic · high · value 2.016
QUERY · ISSUE

rp2 asm_pio parameterization

openby odewdneyopened 2021-10-15updated 2026-03-24
enhancementport-rp2

Hi,

I would like to pass parameters into the RP2 assembler to configure the generated code, eg adjust a delay loop, change number of bits shifted etc.

I propose an additional parameter to the asm_pio function decorator 'vars' that takes a dictionary, that gets added to the global context that assembler runs in eg:

@asm_pio(vars={"DELAY":10})
def statemachine():
  label("wait")
  set(x,DELAY)
  jmp(x_dec,"wait")

with an addition of gl.update(vars) in the asp_pio dec function

CANDIDATE · PULL REQUEST

rp2: Make rp2_state_machine_exec accept integers.

mergedby adamgreenopened 2023-05-01updated 2023-05-18
port-rp2

Currently rp2.StateMachine.exec(instr_in) requires that the instr_in parameter be a string representing the PIO assembly language instruction to be encoded by rp2.asm_pio_encode(). This commit allows the parameter to also be of integral type. This is useful if the exec() method is being called often where the use of pre-encoded machine code is desireable.

This PR still supports calls like:

    sm.exec("set(0, 1)")

It also now supports calls like:

    # Performed once earlier, maybe in __init__()
    assembled_instr = rp2.asm_pio_encode("out(y, 8)", 0)
    # Performed multiple times later as the PIO state machine is
    # configured for its next run.
    sm.exec(assembled_instr)

I didn't find any rp2 specific tests to run or extend but I did find 2 rp2 examples (examples/rp2/pio_exec.py and examples/rp2/pio_pwm.py) that exercise the rp2.StateMachine.exec() method. I ran those 2 examples to make sure that they weren't broken by my change.

I look forward to any feedback which helps improve this PR and its suitableness for merging.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied