diff options
| -rw-r--r-- | embassy-stm32/src/dma/bdma.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/dma.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/ringbuffer.rs | 6 |
3 files changed, 19 insertions, 15 deletions
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 88df76ba7..0202ec379 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs | |||
| @@ -368,18 +368,20 @@ impl<'a, C: Channel> Future for Transfer<'a, C> { | |||
| 368 | 368 | ||
| 369 | // ============================== | 369 | // ============================== |
| 370 | 370 | ||
| 371 | impl<C: Channel> DmaCtrl for C { | 371 | struct DmaCtrlImpl<'a, C: Channel>(PeripheralRef<'a, C>); |
| 372 | |||
| 373 | impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> { | ||
| 372 | fn ndtr(&self) -> usize { | 374 | fn ndtr(&self) -> usize { |
| 373 | let ch = self.regs().ch(self.num()); | 375 | let ch = self.0.regs().ch(self.0.num()); |
| 374 | unsafe { ch.ndtr().read() }.ndt() as usize | 376 | unsafe { ch.ndtr().read() }.ndt() as usize |
| 375 | } | 377 | } |
| 376 | 378 | ||
| 377 | fn get_complete_count(&self) -> usize { | 379 | fn get_complete_count(&self) -> usize { |
| 378 | STATE.complete_count[self.index()].load(Ordering::Acquire) | 380 | STATE.complete_count[self.0.index()].load(Ordering::Acquire) |
| 379 | } | 381 | } |
| 380 | 382 | ||
| 381 | fn reset_complete_count(&mut self) -> usize { | 383 | fn reset_complete_count(&mut self) -> usize { |
| 382 | STATE.complete_count[self.index()].swap(0, Ordering::AcqRel) | 384 | STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel) |
| 383 | } | 385 | } |
| 384 | } | 386 | } |
| 385 | 387 | ||
| @@ -451,13 +453,13 @@ impl<'a, C: Channel, W: Word> RingBuffer<'a, C, W> { | |||
| 451 | } | 453 | } |
| 452 | 454 | ||
| 453 | pub fn clear(&mut self) { | 455 | pub fn clear(&mut self) { |
| 454 | self.ringbuf.clear(&mut *self.channel); | 456 | self.ringbuf.clear(DmaCtrlImpl(self.channel.reborrow())); |
| 455 | } | 457 | } |
| 456 | 458 | ||
| 457 | /// Read bytes from the ring buffer | 459 | /// Read bytes from the ring buffer |
| 458 | /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. | 460 | /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. |
| 459 | pub fn read(&mut self, buf: &mut [W]) -> Result<usize, OverrunError> { | 461 | pub fn read(&mut self, buf: &mut [W]) -> Result<usize, OverrunError> { |
| 460 | self.ringbuf.read(&mut *self.channel, buf) | 462 | self.ringbuf.read(DmaCtrlImpl(self.channel.reborrow()), buf) |
| 461 | } | 463 | } |
| 462 | 464 | ||
| 463 | pub fn is_empty(&self) -> bool { | 465 | pub fn is_empty(&self) -> bool { |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 69a5ec4e4..7b17d9e49 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -609,18 +609,20 @@ impl<'a, C: Channel, W: Word> Drop for DoubleBuffered<'a, C, W> { | |||
| 609 | 609 | ||
| 610 | // ============================== | 610 | // ============================== |
| 611 | 611 | ||
| 612 | impl<C: Channel> DmaCtrl for C { | 612 | struct DmaCtrlImpl<'a, C: Channel>(PeripheralRef<'a, C>); |
| 613 | |||
| 614 | impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> { | ||
| 613 | fn ndtr(&self) -> usize { | 615 | fn ndtr(&self) -> usize { |
| 614 | let ch = self.regs().st(self.num()); | 616 | let ch = self.0.regs().st(self.0.num()); |
| 615 | unsafe { ch.ndtr().read() }.ndt() as usize | 617 | unsafe { ch.ndtr().read() }.ndt() as usize |
| 616 | } | 618 | } |
| 617 | 619 | ||
| 618 | fn get_complete_count(&self) -> usize { | 620 | fn get_complete_count(&self) -> usize { |
| 619 | STATE.complete_count[self.index()].load(Ordering::Acquire) | 621 | STATE.complete_count[self.0.index()].load(Ordering::Acquire) |
| 620 | } | 622 | } |
| 621 | 623 | ||
| 622 | fn reset_complete_count(&mut self) -> usize { | 624 | fn reset_complete_count(&mut self) -> usize { |
| 623 | STATE.complete_count[self.index()].swap(0, Ordering::AcqRel) | 625 | STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel) |
| 624 | } | 626 | } |
| 625 | } | 627 | } |
| 626 | 628 | ||
| @@ -707,13 +709,13 @@ impl<'a, C: Channel, W: Word> RingBuffer<'a, C, W> { | |||
| 707 | } | 709 | } |
| 708 | 710 | ||
| 709 | pub fn clear(&mut self) { | 711 | pub fn clear(&mut self) { |
| 710 | self.ringbuf.clear(&mut *self.channel); | 712 | self.ringbuf.clear(DmaCtrlImpl(self.channel.reborrow())); |
| 711 | } | 713 | } |
| 712 | 714 | ||
| 713 | /// Read bytes from the ring buffer | 715 | /// Read bytes from the ring buffer |
| 714 | /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. | 716 | /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. |
| 715 | pub fn read(&mut self, buf: &mut [W]) -> Result<usize, OverrunError> { | 717 | pub fn read(&mut self, buf: &mut [W]) -> Result<usize, OverrunError> { |
| 716 | self.ringbuf.read(&mut *self.channel, buf) | 718 | self.ringbuf.read(DmaCtrlImpl(self.channel.reborrow()), buf) |
| 717 | } | 719 | } |
| 718 | 720 | ||
| 719 | pub fn is_empty(&self) -> bool { | 721 | pub fn is_empty(&self) -> bool { |
diff --git a/embassy-stm32/src/dma/ringbuffer.rs b/embassy-stm32/src/dma/ringbuffer.rs index 02964eb62..38cc87ae9 100644 --- a/embassy-stm32/src/dma/ringbuffer.rs +++ b/embassy-stm32/src/dma/ringbuffer.rs | |||
| @@ -63,7 +63,7 @@ impl<'a, W: Word> DmaRingBuffer<'a, W> { | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /// Reset the ring buffer to its initial state | 65 | /// Reset the ring buffer to its initial state |
| 66 | pub fn clear(&mut self, dma: &mut impl DmaCtrl) { | 66 | pub fn clear(&mut self, mut dma: impl DmaCtrl) { |
| 67 | self.first = 0; | 67 | self.first = 0; |
| 68 | self.ndtr = self.dma_buf.len(); | 68 | self.ndtr = self.dma_buf.len(); |
| 69 | dma.reset_complete_count(); | 69 | dma.reset_complete_count(); |
| @@ -94,7 +94,7 @@ impl<'a, W: Word> DmaRingBuffer<'a, W> { | |||
| 94 | 94 | ||
| 95 | /// Read bytes from the ring buffer | 95 | /// Read bytes from the ring buffer |
| 96 | /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. | 96 | /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. |
| 97 | pub fn read(&mut self, dma: &mut impl DmaCtrl, buf: &mut [W]) -> Result<usize, OverrunError> { | 97 | pub fn read(&mut self, mut dma: impl DmaCtrl, buf: &mut [W]) -> Result<usize, OverrunError> { |
| 98 | let end = self.end(); | 98 | let end = self.end(); |
| 99 | 99 | ||
| 100 | compiler_fence(Ordering::SeqCst); | 100 | compiler_fence(Ordering::SeqCst); |
| @@ -244,7 +244,7 @@ mod tests { | |||
| 244 | } | 244 | } |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | impl DmaCtrl for TestCtrl { | 247 | impl DmaCtrl for &mut TestCtrl { |
| 248 | fn ndtr(&self) -> usize { | 248 | fn ndtr(&self) -> usize { |
| 249 | self.next_ndtr.borrow_mut().unwrap() | 249 | self.next_ndtr.borrow_mut().unwrap() |
| 250 | } | 250 | } |
