stm32/dma: solve overlapping impl on DmaCtrl on stm32h7
This commit is contained in:
		| @@ -368,18 +368,20 @@ impl<'a, C: Channel> Future for Transfer<'a, C> { | ||||
|  | ||||
| // ============================== | ||||
|  | ||||
| impl<C: Channel> DmaCtrl for C { | ||||
| struct DmaCtrlImpl<'a, C: Channel>(PeripheralRef<'a, C>); | ||||
|  | ||||
| impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> { | ||||
|     fn ndtr(&self) -> usize { | ||||
|         let ch = self.regs().ch(self.num()); | ||||
|         let ch = self.0.regs().ch(self.0.num()); | ||||
|         unsafe { ch.ndtr().read() }.ndt() as usize | ||||
|     } | ||||
|  | ||||
|     fn get_complete_count(&self) -> usize { | ||||
|         STATE.complete_count[self.index()].load(Ordering::Acquire) | ||||
|         STATE.complete_count[self.0.index()].load(Ordering::Acquire) | ||||
|     } | ||||
|  | ||||
|     fn reset_complete_count(&mut self) -> usize { | ||||
|         STATE.complete_count[self.index()].swap(0, Ordering::AcqRel) | ||||
|         STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -451,13 +453,13 @@ impl<'a, C: Channel, W: Word> RingBuffer<'a, C, W> { | ||||
|     } | ||||
|  | ||||
|     pub fn clear(&mut self) { | ||||
|         self.ringbuf.clear(&mut *self.channel); | ||||
|         self.ringbuf.clear(DmaCtrlImpl(self.channel.reborrow())); | ||||
|     } | ||||
|  | ||||
|     /// Read bytes from the ring buffer | ||||
|     /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. | ||||
|     pub fn read(&mut self, buf: &mut [W]) -> Result<usize, OverrunError> { | ||||
|         self.ringbuf.read(&mut *self.channel, buf) | ||||
|         self.ringbuf.read(DmaCtrlImpl(self.channel.reborrow()), buf) | ||||
|     } | ||||
|  | ||||
|     pub fn is_empty(&self) -> bool { | ||||
|   | ||||
| @@ -609,18 +609,20 @@ impl<'a, C: Channel, W: Word> Drop for DoubleBuffered<'a, C, W> { | ||||
|  | ||||
| // ============================== | ||||
|  | ||||
| impl<C: Channel> DmaCtrl for C { | ||||
| struct DmaCtrlImpl<'a, C: Channel>(PeripheralRef<'a, C>); | ||||
|  | ||||
| impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> { | ||||
|     fn ndtr(&self) -> usize { | ||||
|         let ch = self.regs().st(self.num()); | ||||
|         let ch = self.0.regs().st(self.0.num()); | ||||
|         unsafe { ch.ndtr().read() }.ndt() as usize | ||||
|     } | ||||
|  | ||||
|     fn get_complete_count(&self) -> usize { | ||||
|         STATE.complete_count[self.index()].load(Ordering::Acquire) | ||||
|         STATE.complete_count[self.0.index()].load(Ordering::Acquire) | ||||
|     } | ||||
|  | ||||
|     fn reset_complete_count(&mut self) -> usize { | ||||
|         STATE.complete_count[self.index()].swap(0, Ordering::AcqRel) | ||||
|         STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -707,13 +709,13 @@ impl<'a, C: Channel, W: Word> RingBuffer<'a, C, W> { | ||||
|     } | ||||
|  | ||||
|     pub fn clear(&mut self) { | ||||
|         self.ringbuf.clear(&mut *self.channel); | ||||
|         self.ringbuf.clear(DmaCtrlImpl(self.channel.reborrow())); | ||||
|     } | ||||
|  | ||||
|     /// Read bytes from the ring buffer | ||||
|     /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. | ||||
|     pub fn read(&mut self, buf: &mut [W]) -> Result<usize, OverrunError> { | ||||
|         self.ringbuf.read(&mut *self.channel, buf) | ||||
|         self.ringbuf.read(DmaCtrlImpl(self.channel.reborrow()), buf) | ||||
|     } | ||||
|  | ||||
|     pub fn is_empty(&self) -> bool { | ||||
|   | ||||
| @@ -63,7 +63,7 @@ impl<'a, W: Word> DmaRingBuffer<'a, W> { | ||||
|     } | ||||
|  | ||||
|     /// Reset the ring buffer to its initial state | ||||
|     pub fn clear(&mut self, dma: &mut impl DmaCtrl) { | ||||
|     pub fn clear(&mut self, mut dma: impl DmaCtrl) { | ||||
|         self.first = 0; | ||||
|         self.ndtr = self.dma_buf.len(); | ||||
|         dma.reset_complete_count(); | ||||
| @@ -94,7 +94,7 @@ impl<'a, W: Word> DmaRingBuffer<'a, W> { | ||||
|  | ||||
|     /// Read bytes from the ring buffer | ||||
|     /// OverrunError is returned if the portion to be read was overwritten by the DMA controller. | ||||
|     pub fn read(&mut self, dma: &mut impl DmaCtrl, buf: &mut [W]) -> Result<usize, OverrunError> { | ||||
|     pub fn read(&mut self, mut dma: impl DmaCtrl, buf: &mut [W]) -> Result<usize, OverrunError> { | ||||
|         let end = self.end(); | ||||
|  | ||||
|         compiler_fence(Ordering::SeqCst); | ||||
| @@ -244,7 +244,7 @@ mod tests { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     impl DmaCtrl for TestCtrl { | ||||
|     impl DmaCtrl for &mut TestCtrl { | ||||
|         fn ndtr(&self) -> usize { | ||||
|             self.next_ndtr.borrow_mut().unwrap() | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user