Skip to content

raspberry: StateMachine: Add support for wrap=, wrap_target= #6029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2022

Conversation

jepler
Copy link

@jepler jepler commented Feb 13, 2022

Together with adafruit/Adafruit_CircuitPython_PIOASM#35 this adds support for .wrap and .wrap_target pseudo-ops in pio programs. I've only compile-tested this code, though; it should be put through the paces before being used.

@jepler jepler marked this pull request as ready for review April 6, 2022 13:34
@jepler
Copy link
Author

jepler commented Apr 6, 2022

I finally got around to testing this. It works fine.

Test program:

import adafruit_pioasm
import rp2pio
import array

program = adafruit_pioasm.Program("""
        set x, 31 
        in x, 32 
        .wrap_target 
            jmp x--, f
        f:  
            in x, 32 
        .wrap 
            set x, 3
            in x, 32 
        """, build_debuginfo=True)

program.print_c_program("test")

b = array.array('L', [0]*6)
sm = rp2pio.StateMachine(program.assembled, **program.pio_kwargs, frequency=100_000_000, auto_push=True)
sm.readinto(b)

It should print array('L', [31, 30, 29, 28, 27, 26]), otherwise, the wrap is not taking effect correctly. For instance, if it printed [31, 30, 3, 31, 30, 3] then no wrapping is occurring. If the wrap or wrap target were off by one, the results would be different again.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dhalbert dhalbert merged commit 1a329cf into adafruit:main Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants