aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-02-09 20:05:41 +0000
committerGitHub <[email protected]>2024-02-09 20:05:41 +0000
commit1641f8a27e472d8d501dbb263b292ac943bd9449 (patch)
treede1eda3546e35568e891a985681fdc971655854f
parentc4f3e0dfd505889066f2ea1706d6da3aa244395b (diff)
parent994b77e6843d70db34c59c0723b7718d52f3fd52 (diff)
Merge pull request #2397 from tyler-gilbert/add-write-immediate-api-dma-ring-buffer
Add write_immediate() function to STM32 DMA ringbufer API
-rw-r--r--embassy-stm32/src/dma/bdma.rs7
-rw-r--r--embassy-stm32/src/dma/dma.rs7
-rw-r--r--embassy-stm32/src/dma/ringbuffer.rs11
3 files changed, 25 insertions, 0 deletions
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs
index a2b83716d..077cfdcd9 100644
--- a/embassy-stm32/src/dma/bdma.rs
+++ b/embassy-stm32/src/dma/bdma.rs
@@ -664,6 +664,13 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> {
664 self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow())); 664 self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow()));
665 } 665 }
666 666
667 /// Write elements directly to the raw buffer.
668 /// This can be used to fill the buffer before starting the DMA transfer.
669 #[allow(dead_code)]
670 pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
671 self.ringbuf.write_immediate(buf)
672 }
673
667 /// Write elements to the ring buffer 674 /// Write elements to the ring buffer
668 /// Return a tuple of the length written and the length remaining in the buffer 675 /// Return a tuple of the length written and the length remaining in the buffer
669 pub fn write(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> { 676 pub fn write(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs
index 16d02f273..ef9bb3d78 100644
--- a/embassy-stm32/src/dma/dma.rs
+++ b/embassy-stm32/src/dma/dma.rs
@@ -934,6 +934,13 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> {
934 self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow())); 934 self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow()));
935 } 935 }
936 936
937 /// Write elements directly to the raw buffer.
938 /// This can be used to fill the buffer before starting the DMA transfer.
939 #[allow(dead_code)]
940 pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
941 self.ringbuf.write_immediate(buf)
942 }
943
937 /// Write elements from the ring buffer 944 /// Write elements from the ring buffer
938 /// Return a tuple of the length written and the length remaining in the buffer 945 /// Return a tuple of the length written and the length remaining in the buffer
939 pub fn write(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> { 946 pub fn write(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
diff --git a/embassy-stm32/src/dma/ringbuffer.rs b/embassy-stm32/src/dma/ringbuffer.rs
index c9f7a3026..c5b42060a 100644
--- a/embassy-stm32/src/dma/ringbuffer.rs
+++ b/embassy-stm32/src/dma/ringbuffer.rs
@@ -263,6 +263,17 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> {
263 self.cap() - dma.get_remaining_transfers() 263 self.cap() - dma.get_remaining_transfers()
264 } 264 }
265 265
266 /// Write elements directly to the buffer. This must be done before the DMA is started
267 /// or after the buffer has been cleared using `clear()`.
268 pub fn write_immediate(&mut self, buffer: &[W]) -> Result<(usize, usize), OverrunError> {
269 if self.end != 0 {
270 return Err(OverrunError);
271 }
272 let written = self.copy_from(buffer, 0..self.cap());
273 self.end = written % self.cap();
274 Ok((written, self.cap() - written))
275 }
276
266 /// Write an exact number of elements to the ringbuffer. 277 /// Write an exact number of elements to the ringbuffer.
267 pub async fn write_exact(&mut self, dma: &mut impl DmaCtrl, buffer: &[W]) -> Result<usize, OverrunError> { 278 pub async fn write_exact(&mut self, dma: &mut impl DmaCtrl, buffer: &[W]) -> Result<usize, OverrunError> {
268 let mut written_data = 0; 279 let mut written_data = 0;