Thanks to visit codestin.com
Credit goes to github.com

Skip to content

rp2040: add a pio mode that can loop a buffer forever #6295

@jepler

Description

@jepler

There are a couple of use cases we have where you want to send the same data to a PIO peripheral indefinitely:

  • pimoroni-style "pwm cluster" / "servo cluster": control a whole group of pins according to "data and delay" pairs
  • "dithered" neopixels: as fast as possible, scan the neopixels with multiple sequences A/B/C/D. This expands the color resolution to 10 bits
  • other uses like periodic waveform generation

My first sketch of how these would look is something like

StateMachine:
    ...

    def continuous_write(self, buf: ReadableBuffer, ...) -> None:
        """Continuously write `buf` to the state machine in the background
        until stopped.  Internally, this uses a DMA channel.

        To atomically change from one buffer to another, simply call
        `StateMachine.continuous_write` again with a different buffer.
        The call will only return once outputting the new buffer has started.

        If the buffer is modified while it is being written out, the updated
        values will be used. However, because of interactions between CPU
        writes, DMA and the PIO FIFO are complex, it is difficult to predict
        the result of modifying multiple values. Instead, alternate between
        a pair of buffers.

        Other applicable arguments are as for `StateMachine.write`."""

    def end_continous_write(self) -> None:
        """Stop a continuous write if one is in progress"""

more investigation may change the final form of the API. Note that there's not a "call back into Python to generate the next buffer" option here, because we worry that generally speaking CircuitPython code isn't fast enough to generate these signals real-time. we can revisit the idea in the future.

A proof of concept implementation should come with at least one use-case implemented to show that it works, preferably two.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions