Skip to content

Merge SpiDma and SpiDmaBus drivers#5272

Merged
bugadani merged 11 commits intoesp-rs:mainfrom
bugadani:spi-dma-driver
May 4, 2026
Merged

Merge SpiDma and SpiDmaBus drivers#5272
bugadani merged 11 commits intoesp-rs:mainfrom
bugadani:spi-dma-driver

Conversation

@bugadani
Copy link
Copy Markdown
Contributor

@bugadani bugadani commented Mar 26, 2026

We don't need two, when one can do the job. Further work needs to be done:

This PR allows using the buffer-based API together with drivers that require embedded-hal(-async) implementations. It's implemented by adding copy buffers to the global state of the SpiDma driver. These buffers are used in place of EmptyBuf, which is mostly unnecessary at this point.

@Dominaezzz
Copy link
Copy Markdown
Collaborator

It's implemented by adding copy buffers to the global state of the SpiDma driver

Ah that works. My first thought is how big is the buffer gonna be, but I'll just read the PR.

I guess you're closing #3125?

@bugadani
Copy link
Copy Markdown
Contributor Author

My first thought is how big is the buffer gonna be, but I'll just read the PR.

As much as you give it, with_buffers isn't going away just yet. But due to the 32000-some byte limit we also kinda just need 8 descriptors linked up if we don't need to copy data, so a good chunk of use cases can work without actually setting up buffers. How we'll end up explaining this is another matter...

I'm not ure about #3125 I'm not actually targeting that issue.

@bugadani bugadani force-pushed the spi-dma-driver branch 2 times, most recently from 46e339f to 53d4d59 Compare March 30, 2026 11:02
@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Mar 30, 2026
@github-actions
Copy link
Copy Markdown

New commits in main has made this PR unmergable. Please resolve the conflicts.

@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Mar 30, 2026
@github-actions
Copy link
Copy Markdown

New commits in main has made this PR unmergable. Please resolve the conflicts.

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Mar 31, 2026
@github-actions github-actions Bot added merge-conflict Merge conflict detected. Automatically added/removed by CI. and removed merge-conflict Merge conflict detected. Automatically added/removed by CI. labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown

New commits in main has made this PR unmergable. Please resolve the conflicts.

@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 1, 2026
@bugadani bugadani force-pushed the spi-dma-driver branch 2 times, most recently from df3e40d to cd81695 Compare April 1, 2026 10:50
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

New commits in main has made this PR unmergable. Please resolve the conflicts.

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 2, 2026
@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 7, 2026
@bugadani bugadani marked this pull request as ready for review April 27, 2026 06:30
Copilot AI review requested due to automatic review settings April 27, 2026 06:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates the SPI DMA driver surface by removing the separate SpiDmaBus type and making SpiDma directly support both the slice-based API (copying via internal buffers) and the externally-managed buffer API (via DmaRxBuf/DmaTxBuf), including embedded-hal(-async) trait implementations.

Changes:

  • Replace SpiDmaBus usage by moving copy-buffers into SpiDma global DMA state and exposing SpiDma::with_buffers(...) directly.
  • Rename DMA buffer-oriented APIs to _buffer / _buffers suffixed methods (e.g. read_buffer, transfer_buffers, half_duplex_read_buffer).
  • Update examples/tests to use the renamed buffer-based methods.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
qa-test/src/bin/qspi_flash.rs Update QSPI flash QA test to use half_duplex_{read,write}_buffer APIs.
hil-test/src/bin/spi_half_duplex_write_psram.rs Update HIL half-duplex PSRAM test to use half_duplex_write_buffer.
hil-test/src/bin/spi_half_duplex_slave_qspi.rs Update HIL QSPI slave test to use half_duplex_{read,write}_buffer.
hil-test/src/bin/spi_full_duplex.rs Update full-duplex DMA HIL tests to use read_buffer, write_buffer, transfer_buffers.
examples/peripheral/spi/loopback_dma_psram/src/main.rs Update loopback DMA+PSRAM example to use transfer_buffers.
esp-hal/src/spi/master/dma.rs Core refactor: merge SpiDmaBus into SpiDma, add embedded-hal(-async) trait impls, add async slice-based methods, and update buffer handling.

Comment thread esp-hal/src/spi/master/dma.rs Outdated
Comment thread esp-hal/src/spi/master/dma.rs
Comment thread esp-hal/src/spi/master/dma.rs Outdated
Comment thread esp-hal/src/spi/master/dma.rs Outdated
Copilot AI review requested due to automatic review settings April 28, 2026 15:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

/// buffers to be transferred. The buffer objects ensure that data is located in appropriate
/// memory regions. The buffers and the driver object are moved into transfer objects for the
/// duration of the transfer. These functions take [`DmaRxBuf`] and [`DmaTxBuf`] objects as
/// arguments as well as the number of bytes to transfer, and their names end with `_buffer`.
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The SpiDma docs say the buffer-based API method names end with _buffer, but one of the renamed methods is transfer_buffers (plural). Consider tweaking the wording to mention both _buffer and _buffers (or list the method names) to avoid confusion.

Suggested change
/// arguments as well as the number of bytes to transfer, and their names end with `_buffer`.
/// arguments as well as the number of bytes to transfer, and their names end with `_buffer` or
/// `_buffers`.

Copilot uses AI. Check for mistakes.
@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 30, 2026
@github-actions
Copy link
Copy Markdown

New commits in main have made this PR unmergeable. Please resolve the conflicts.

@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 30, 2026
@Dominaezzz Dominaezzz self-requested a review April 30, 2026 19:47
Copy link
Copy Markdown
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

Just some nits, overall LGTM!

Comment thread esp-hal/src/spi/master/dma.rs Outdated
Comment thread esp-hal/src/spi/master/dma.rs Outdated
Comment thread esp-hal/src/spi/master/dma.rs Outdated
}

fn flush(&mut self) -> Result<(), Self::Error> {
// All operations currently flush so this is no-op.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this a limitation, or a design decision we've made for our ease of impl? IIRC eh discourages early flushing because we can be more efficient by queuing up transfers, but I will admit this nugget of knowledge is a bit fuzzy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can't not flush with DMA if we want any semblance of soundness - we can't release the borrow on the buffers before the transfers finish.

@Dominaezzz Dominaezzz removed their request for review May 2, 2026 10:42
Copilot AI review requested due to automatic review settings May 4, 2026 07:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread hil-test/src/bin/spi_full_duplex.rs
Comment thread esp-hal/src/spi/master/dma.rs Outdated
@bugadani bugadani enabled auto-merge May 4, 2026 07:44
@bugadani bugadani added this pull request to the merge queue May 4, 2026
Merged via the queue into esp-rs:main with commit f986ef8 May 4, 2026
23 checks passed
@bugadani bugadani deleted the spi-dma-driver branch May 4, 2026 10:00
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.

4 participants