Skip to content

Commit 371f3ef

Browse files
committed
stm32/dma: solve overlapping impl on DmaCtrl on stm32h7
1 parent 21aa240 commit 371f3ef

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

embassy-stm32/src/dma/bdma.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,20 @@ impl<'a, C: Channel> Future for Transfer<'a, C> {
368368

369369
// ==============================
370370

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> {
372374
fn ndtr(&self) -> usize {
373-
let ch = self.regs().ch(self.num());
375+
let ch = self.0.regs().ch(self.0.num());
374376
unsafe { ch.ndtr().read() }.ndt() as usize
375377
}
376378

377379
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)
379381
}
380382

381383
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)
383385
}
384386
}
385387

@@ -451,13 +453,13 @@ impl<'a, C: Channel, W: Word> RingBuffer<'a, C, W> {
451453
}
452454

453455
pub fn clear(&mut self) {
454-
self.ringbuf.clear(&mut *self.channel);
456+
self.ringbuf.clear(DmaCtrlImpl(self.channel.reborrow()));
455457
}
456458

457459
/// Read bytes from the ring buffer
458460
/// OverrunError is returned if the portion to be read was overwritten by the DMA controller.
459461
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)
461463
}
462464

463465
pub fn is_empty(&self) -> bool {

embassy-stm32/src/dma/dma.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,18 +609,20 @@ impl<'a, C: Channel, W: Word> Drop for DoubleBuffered<'a, C, W> {
609609

610610
// ==============================
611611

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> {
613615
fn ndtr(&self) -> usize {
614-
let ch = self.regs().st(self.num());
616+
let ch = self.0.regs().st(self.0.num());
615617
unsafe { ch.ndtr().read() }.ndt() as usize
616618
}
617619

618620
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)
620622
}
621623

622624
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)
624626
}
625627
}
626628

@@ -707,13 +709,13 @@ impl<'a, C: Channel, W: Word> RingBuffer<'a, C, W> {
707709
}
708710

709711
pub fn clear(&mut self) {
710-
self.ringbuf.clear(&mut *self.channel);
712+
self.ringbuf.clear(DmaCtrlImpl(self.channel.reborrow()));
711713
}
712714

713715
/// Read bytes from the ring buffer
714716
/// OverrunError is returned if the portion to be read was overwritten by the DMA controller.
715717
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)
717719
}
718720

719721
pub fn is_empty(&self) -> bool {

embassy-stm32/src/dma/ringbuffer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a, W: Word> DmaRingBuffer<'a, W> {
6363
}
6464

6565
/// 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) {
6767
self.first = 0;
6868
self.ndtr = self.dma_buf.len();
6969
dma.reset_complete_count();
@@ -94,7 +94,7 @@ impl<'a, W: Word> DmaRingBuffer<'a, W> {
9494

9595
/// Read bytes from the ring buffer
9696
/// 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> {
9898
let end = self.end();
9999

100100
compiler_fence(Ordering::SeqCst);

0 commit comments

Comments
 (0)