-
Notifications
You must be signed in to change notification settings - Fork 215
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
Introduce traits for the DMA buffer objects #1976
Conversation
I'm wondering how useful this will be in reality. I understand the premise, but for example, the way spidmabus currently works it can only "hold" one dma buffer type for tx and rx (because it's encoded in the state enum). My hope was to be able to optimize these copies away: esp-hal/esp-hal/src/spi/master.rs Line 1744 in 84a0600
As it stands, if we added a How do we go about solving that? |
The usefulness of the trait doesn't show very well for SPI. I think it really shines for LCD_CAM, where you're more likely to get creative with framebuffers. About the zero copy thing. In the RFC, the plan was to always do the copy in the high level wrapper and anyone who wanted performance would just use the move based API. There's also the option of adding more traits of course. |
# Conflicts: # esp-hal/src/spi/master.rs
Oh wait, after re-reading your comment I think I have a better understanding of what you're looking for. Having understood better, I have a decent solution. Another trait 😄. trait SpiDmaTxThingy : DmaTxBuffer {
fn fill(&mut self, data: &mut [u8]);
}
impl SpiDmaTxThingy for DmaTxBuf { /* do memcpy */ }
impl SpiDmaTxThingy for DmaConstTxBuf { /* no memcpy, connect buf to descriptors */ }
What do you think of that? |
@MabezDev are there any objections to these traits themselves? The problem of optimizing those copies away is orthogonal to them. I can look into optimizing away the copies but that will need either a separate trait or a dedicated struct for managing the optional memcpy (depending on what you're picturing). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MabezDev are there any objections to these traits themselves? The problem of optimizing those copies away is orthogonal to them.
You're right I did get a bit side tracked with that, sorry 😅. It would be nice to have zero copy by default where possible though.
I don't have an objection perse, I think they're a good idea, my real concern is that these are encoded in the public SpiDma
and SpiDmaTransfer
types. Now, I know that's already the case, so I won't block the PR on that but IMO these traits should offer some "shared" format (the preparation struct is already close), where anything that impls the dma traits can be converted to a concrete struct which is then passed to the Dma APIs, meaning eventually we can hide the impl details completely (remove the generic params).
I'm kind of rambling a little bit 😅 but I hope that makes sense. Let me know if you need anything clarified.
TL;DR: This looks fine as is, after a rebase, but I hope we can get to some kind of concrete intermediate format to reduce the number of generics associated with this.
Yeah it makes sense, less generics is better in general. I'm planning on moving these to the dma module in the next few PRs, so the SPI driver won't have these buffers encoded in the driver types at least. |
# Conflicts: # esp-hal/src/dma/mod.rs # esp-hal/src/spi/master.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess at some point we need to align things between the DMA-capable peripherals - we now have WriteBuffer
/ReadBuffer
, DmaTxBuf
/DmaRxBuf
and DmaTxBuffer
/DmaRxBuffer
(and its implementations)
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
Introduces
DmaTxBuffer
andDmaRxBuffer
. These are implemented byDmaTxBuf
,DmaRxBuf
andDmaTxRxBuf
.This also opens the door to other buffer types like ones that live in PSRAM, flash (ESP32-P4), IRAM, etc. with different alignments and burst modes/sizes. (I won't be implementing these enhancements anytime soon, I'm just opening the door)
Naming is hard, I'm happy to rename things to something else. 🙂
EDIT: This PR also allows
DmaTxRxBuf
to be used for TX-only or RX-only transfers. This will be convenient for bidirectional but half duplex peripherals.Testing
Ran the SPI examples.
(I couldn't run the HIL tests myself, my probe-rs setup seems to be broken.... CI should check now though)