diff options
| -rw-r--r-- | embassy-stm32/src/dma/ringbuffer/mod.rs | 13 |
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)) |
