rp2-pio/piolib: add nonblocking DMA transfer API to Parallel - #61
Draft
davecheney wants to merge 1 commit into
Draft
davecheney wants to merge 1 commit into
davecheney wants to merge 1 commit into
Conversation
Add Tx8Async/Tx16Async/Tx32Async plus IsTxAsyncBusy/WaitTxAsync to piolib.Parallel so callers can start a DMA-backed parallel bus transfer and poll or wait for completion later, instead of blocking for the whole transfer as Tx8/Tx16/Tx32 do. - dmaPush is split into dmaPushStart (configure + trigger, no wait) and the existing blocking dmaPush (dmaPushStart + wait), so Tx8/ Tx16/Tx32 behavior and timing are unchanged. - helperPushStart/helperPushBusy/helperPushWait in all_generate.go provide the async push/poll/wait primitives shared by the *Async methods. - Parallel tracks asyncPending so a new async transfer started while one is still in flight returns errBusy instead of corrupting DMA/PIO state; IsTxAsyncBusy/WaitTxAsync clear it once the DMA channel is idle and the PIO TX FIFO has stalled (fully drained to the pins). - Starting an async transfer without DMA enabled returns errAsyncRequiresDMA.
davecheney
marked this pull request as draft
September 11, 2026 03:15
Collaborator
|
What's the outlook on this? At a glance I feel like I would have approached this with a boolean flag on dmaChannel so the code can be more efficently reused and also simplified greatly func dmaPushHelper[]( ... , async bool) {
...
dma.async = async
if !async {
deadline := ch.dl.newDeadline()
for ch.busy() {
if deadline.expired() {
ch.abort()
return errTimeout
}
gosched()
}
ch.HW().CTRL_TRIG.ClearBits(rp.DMA_CH0_CTRL_TRIG_EN_Msk)
}
}
func (dma) AsyncPending() bool {
if !dma.async {
return false
}
dma.async = dma.isTxBusy()
return dma.async
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a nonblocking DMA transfer API to
rp2-pio/piolib.Parallelso callers can start a DMA-backed parallel bus transfer and later poll or wait for completion, instead of blocking for the whole transfer asTx8/Tx16/Tx32do today.This allows display and frame drivers (such as parallel ST7789 displays on RP2040 boards like the Tufty 2040) to start a frame's parallel DMA transfer and continue CPU computation while the previous frame is still being clocked out over the 8-bit bus.
New API
Semantics
EnableDMA(true)beforehand; otherwise returnserrAsyncRequiresDMA.errBusyrather than reconfiguring DMA/PIO registers out from under the in-flight transfer.IsTxAsyncBusy/WaitTxAsyncaccount for both, so callers can safely release chip-select or reuse/free the buffer once either reports done.datamust not be modified, reused for another transfer, or garbage collected until completion is observed, since the DMA engine reads directly from its backing array in the background.Tx8/Tx16/Tx32behavior and timing are unchanged:dmaPushis refactored into a new nonblockingdmaPushStart(configure + trigger) plus a wait loop, and the blocking methods just call the same helper as before.Validation
tinygo build -target=tufty2040 ./rp2-pio/examples/parallel/tufty— passestinygo build -target=pico2 ./rp2-pio/examples/parallel/tufty— passes (RP2350)go test ./rp2-pio/...— passes for the host-buildable core packagegofmt -l— clean on touched files-scheduler=coresneeded).