aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-12-02 22:05:44 +0000
committerGitHub <[email protected]>2024-12-02 22:05:44 +0000
commit8086fc4dff95245d7a10d03602ec24919291e53e (patch)
tree59cb47de91e661625682a349409a5ab389c50b33
parenta97439727e2190a607dd9f21708a43fffabd09e3 (diff)
parent5d2b38c979b045d69fee1e2b1bb7f209043ceece (diff)
Merge pull request #3588 from elagil/fix_sai_write_immediate
Right-align `write_immediate()` in ring buffers
-rw-r--r--embassy-stm32/src/dma/ringbuffer/mod.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/embassy-stm32/src/dma/ringbuffer/mod.rs b/embassy-stm32/src/dma/ringbuffer/mod.rs
index 25bdc7522..44ea497fe 100644
--- a/embassy-stm32/src/dma/ringbuffer/mod.rs
+++ b/embassy-stm32/src/dma/ringbuffer/mod.rs
@@ -252,9 +252,20 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> {
252 } 252 }
253 253
254 /// Write elements directly to the buffer. 254 /// Write elements directly to the buffer.
255 ///
256 /// Subsequent writes will overwrite the content of the buffer, so it is not useful to call this more than once.
257 /// Data is aligned towards the end of the buffer.
258 ///
259 /// In case of success, returns the written length, and the empty space in front of the written block.
260 /// Fails if the data to write exceeds the buffer capacity.
255 pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), Error> { 261 pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), Error> {
262 if buf.len() > self.cap() {
263 return Err(Error::Overrun);
264 }
265
266 let start = self.cap() - buf.len();
256 for (i, data) in buf.iter().enumerate() { 267 for (i, data) in buf.iter().enumerate() {
257 self.write_buf(i, *data) 268 self.write_buf(start + i, *data)
258 } 269 }
259 let written = buf.len().min(self.cap()); 270 let written = buf.len().min(self.cap());
260 Ok((written, self.cap() - written)) 271 Ok((written, self.cap() - written))