diff options
| -rw-r--r-- | embassy-stm32/src/dma/ringbuffer/mod.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/embassy-stm32/src/dma/ringbuffer/mod.rs b/embassy-stm32/src/dma/ringbuffer/mod.rs index 4dc1b51a9..44ea497fe 100644 --- a/embassy-stm32/src/dma/ringbuffer/mod.rs +++ b/embassy-stm32/src/dma/ringbuffer/mod.rs | |||
| @@ -253,10 +253,17 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> { | |||
| 253 | 253 | ||
| 254 | /// Write elements directly to the buffer. | 254 | /// Write elements directly to the buffer. |
| 255 | /// | 255 | /// |
| 256 | /// Subsequent writes will overwrite the content of the buffer, so it is not useful to call this more than once. | ||
| 256 | /// Data is aligned towards the end of the buffer. | 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. | ||
| 257 | 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> { |
| 258 | let start = self.cap() - buf.len(); | 262 | if buf.len() > self.cap() { |
| 263 | return Err(Error::Overrun); | ||
| 264 | } | ||
| 259 | 265 | ||
| 266 | let start = self.cap() - buf.len(); | ||
| 260 | for (i, data) in buf.iter().enumerate() { | 267 | for (i, data) in buf.iter().enumerate() { |
| 261 | self.write_buf(start + i, *data) | 268 | self.write_buf(start + i, *data) |
| 262 | } | 269 | } |
