Skip to content

Statemachine improvements #6360

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 7 commits into from
May 7, 2022
Merged

Conversation

jepler
Copy link

@jepler jepler commented May 6, 2022

  • Fix a problem when once=None and loop=None in background_write
  • Fix a problem where a zero-length buffer is passed in
  • Add support for byteswapping via the DMA peripheral
  • add ability to get, clear the txstall flag

This makes it possible to

  • actually wait for the transfer to FULLY complete (not just trickery like in the morse code example)
  • stop a background transfer after a full loop exactly
  • background write neopixels that 'act like' a pypixelbuf without manually swapping. It's soooo fast the rainbow looks white.

Closes: #6359, closes #6357

jepler added 5 commits May 5, 2022 14:40
This can be used to make sure a PIO has actually finished all data
it was schedule to receive via a 'once' background_write
Always use DMA if swap flag is enabled.

Improve docs a bit
jepler added a commit to jepler/Adafruit_CircuitPython_PIOASM that referenced this pull request May 6, 2022
Works in conjunction with adafruit/circuitpython#6360

 * get rid of the need for 'filler' in morse demo
 * make neopixels work super fast without explicit byteswapping
dhalbert
dhalbert previously approved these changes May 7, 2022
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.

I fixed a doc formatting issue (extra """). I added (reverse) in the documentation for the swap arguments, to clarify that the byte order is reversed, since swap is not so obvious for the 4-byte case. If you disagree with that, we can change it back. I will not merge pending your thoughts on that.

@@ -674,13 +674,26 @@ static bool _transfer(rp2pio_statemachine_obj_t *self,
size_t len = MAX(out_len, in_len);
bool tx = data_out != NULL;
bool rx = data_in != NULL;
if (len >= dma_min_size_threshold) {
bool use_dma = len >= dma_min_size_threshold || swap_out || swap_in;
Copy link
Member

Choose a reason for hiding this comment

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

Is there any risk that having DMAs for sizes less then the threshold that require swaps will cause either a speed issue for the small DMAs or potential exhaustion of DMAs? It may not be any concern just wanted to bring it up.

Rest looks great.

Copy link
Author

Choose a reason for hiding this comment

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

I don't really know. :) There are 12 DMAs; audio might claim 2 in the background, and this code now claims up to 2. so it looks like there should be plenty left over.

At first I wanted to say this was no change for existing code, but it IS a change. Before, if you had a LARGE buffer but couldn't allocate DMA, the code would fall back to copying in a CPU loop. Now, it will return an error.

@jepler
Copy link
Author

jepler commented May 7, 2022

@dhalbert thanks, the doc changes look fine to this human but I see the doc build is (still) failing.

@jepler jepler merged commit 5f4f667 into adafruit:main May 7, 2022
@jepler
Copy link
Author

jepler commented May 7, 2022

Now if only I knew how to write the core code to allow 'await state_machine.async_write(buf)`

@dhalbert
Copy link
Collaborator

dhalbert commented May 7, 2022

Now if only I knew how to write the core code to allow 'await state_machine.async_write(buf)`

For this, I think the easiest thing to do is to pass an asyncio.Event in to your code, and trigger it when the write is done. Then the Python code can await the Event change. The same idea can be used for other async trigger events.

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.

rp2: Support DMA byte-swapping mode for rp2pio rp2pio: background_write behaves weird when mixing write-once and looping writes
3 participants