embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.54k stars 769 forks source link

Feature Idea: DMA/BDMA/RingBuf: read_with_map for avoiding extra copies #1605

Open alexferro opened 1 year ago

alexferro commented 1 year ago

I'm using the DMA RingBuf in my audio processing application, and while writing my code around it, I was thinking about how to avoid an extra copy of the data. It hit me that if the API supported some way to do the equivalent of iterator::map on the read data, I could fold in the u32 to f32 conversion (or anything really) my logic does inside the read loop.

Based on looking at the code, I'm not sure if it'd be easy or performant to implement this, since it'd disrupt copy_to in the code base, and it may be superseded by whatever solution #702 gains in the future. It's also a specialized use case, for a peripheral that is less common, and I cannot think of any applicability to the usart driver that spawned the existence of the ring buffer. But I thought I'd get it out there for the folks with more embedded Rust experience to think about.

tyler-gilbert commented 1 year ago

@alexferro, I have done a lot of audio streaming on the STM32 (in C). I usually use the half complete/complete interrupts with a ring buffer to read/write the data. I created #1879 to track the issue. Do you think that approach would work for your use case? Are you using I2S/SAI or ADC/DAC?

alexferro commented 1 year ago

@tyler-gilbert See my comment on your issue you opened.