adafruit / Adafruit_CircuitPython_PIOASM

Simple assembler to convert pioasm to bytes
MIT License
27 stars 17 forks source link

Store other program metadata in a Program class #28

Closed jepler closed 2 years ago

jepler commented 2 years ago

Sketch:

class Program:
    def __init__(self, text_program):
        """Converts pioasm text to encoded instruction bytes"""
        ... # all of old 'assemble()' is here
        self.assembled = array.array("H", assembled)
        self.sideset_count = sideset_count
        self.sideset_enable = sideset_enable
        # automatic loop target values, etc

    def make_state_machine(self, ...):
        import rp2pio # defer import so module can be used on std python
        return rp2pio.StateMachine(..., sideset_enable=self.sideset_enable, ...)

def assemble(text_program):
    return Program(text_program).assembled
jepler commented 2 years ago

This could also help when adding support for wrap / wrap_target, the values would be members of Program and passed to StateMachine via Program.make_state_machine.

tannewt commented 2 years ago

The other thing I was considering was a function that produces the appropriate kwargs.

def get_kwargs(pio_source):
    ...

sm = rp2pio.StateMachine(pin=board.FOO, **get_kwargs(src))