From 34a2b19b72ef8afa164ce78e80b652649a63d92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 6 Nov 2024 15:37:48 +0100 Subject: [PATCH] Redo DMA compatibility check using DmaEligible --- esp-hal/src/dma/gdma.rs | 5 +---- esp-hal/src/dma/mod.rs | 2 +- esp-hal/src/dma/pdma.rs | 30 ++++++++++++++++-------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/esp-hal/src/dma/gdma.rs b/esp-hal/src/dma/gdma.rs index 769b570e278..bff710a2ec8 100644 --- a/esp-hal/src/dma/gdma.rs +++ b/esp-hal/src/dma/gdma.rs @@ -475,10 +475,7 @@ pub struct ChannelCreator {} impl Channel<'_, CH, M> { /// Asserts that the channel is compatible with the given peripheral. - pub fn runtime_ensure_compatible( - &self, - _peripheral: &PeripheralRef<'_, P>, - ) { + pub fn runtime_ensure_compatible(&self, _peripheral: &PeripheralRef<'_, P>) { // No runtime checks; GDMA channels are compatible with any peripheral } } diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index c759f6a6cc0..f512ad05a24 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -2111,7 +2111,7 @@ pub trait RegisterAccess: crate::private::Sealed { fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize); #[cfg(pdma)] - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool; + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool; /// Configure the channel. fn configure(&self, burst_mode: bool, priority: DmaPriority) { diff --git a/esp-hal/src/dma/pdma.rs b/esp-hal/src/dma/pdma.rs index ab18f2387c0..1659eb5f95d 100644 --- a/esp-hal/src/dma/pdma.rs +++ b/esp-hal/src/dma/pdma.rs @@ -31,7 +31,7 @@ pub trait PdmaChannel: crate::private::Sealed { fn register_block(&self) -> &Self::RegisterBlock; fn tx_waker(&self) -> &'static AtomicWaker; fn rx_waker(&self) -> &'static AtomicWaker; - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool; + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool; } #[doc(hidden)] @@ -92,7 +92,7 @@ impl> RegisterAccess for SpiDma } } - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool { + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool { self.0.is_compatible_with(peripheral) } } @@ -236,7 +236,7 @@ impl> RegisterAccess for SpiDma } } - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool { + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool { self.0.is_compatible_with(peripheral) } } @@ -390,8 +390,8 @@ macro_rules! ImplSpiChannel { &WAKER } - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool { - peripheral.peripheral() == crate::system::Peripheral::[] + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool { + peripheral == DmaPeripheral::[] } } @@ -497,7 +497,7 @@ impl> RegisterAccess for I2sDma .modify(|_, w| w.check_owner().bit(check_owner.unwrap_or(true))); } - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool { + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool { self.0.is_compatible_with(peripheral) } } @@ -653,7 +653,7 @@ impl> RegisterAccess for I2sDma .modify(|_, w| w.check_owner().bit(check_owner.unwrap_or(true))); } - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool { + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool { self.0.is_compatible_with(peripheral) } } @@ -802,8 +802,8 @@ macro_rules! ImplI2sChannel { static WAKER: embassy_sync::waitqueue::AtomicWaker = embassy_sync::waitqueue::AtomicWaker::new(); &WAKER } - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool { - peripheral.peripheral() == crate::system::Peripheral::[] + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool { + peripheral == DmaPeripheral::[] } } @@ -909,11 +909,13 @@ where C: DmaChannel, { /// Asserts that the channel is compatible with the given peripheral. - pub fn runtime_ensure_compatible(&self, peripheral: &PeripheralRef<'_, impl PeripheralMarker>) { + pub fn runtime_ensure_compatible(&self, peripheral: &PeripheralRef<'_, impl DmaEligible>) { assert!( - self.tx.tx_impl.is_compatible_with(&**peripheral), + self.tx + .tx_impl + .is_compatible_with(peripheral.dma_peripheral()), "This DMA channel is not compatible with {:?}", - peripheral.peripheral() + peripheral.dma_peripheral() ); } } @@ -963,7 +965,7 @@ impl PdmaChannel for AnySpiDmaChannelInner { fn register_block(&self) -> &SpiRegisterBlock; fn tx_waker(&self) -> &'static AtomicWaker; fn rx_waker(&self) -> &'static AtomicWaker; - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool; + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool; } } } @@ -1017,7 +1019,7 @@ impl PdmaChannel for AnyI2sDmaChannelInner { fn register_block(&self) -> &I2sRegisterBlock; fn tx_waker(&self) -> &'static AtomicWaker; fn rx_waker(&self) -> &'static AtomicWaker; - fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool; + fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool; } } }