Skip to content

Commit

Permalink
Redo DMA compatibility check using DmaEligible
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 6, 2024
1 parent 93e915c commit 34a2b19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
5 changes: 1 addition & 4 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,7 @@ pub struct ChannelCreator<const N: u8> {}

impl<CH: DmaChannel, M: Mode> Channel<'_, CH, M> {
/// Asserts that the channel is compatible with the given peripheral.
pub fn runtime_ensure_compatible<P: PeripheralMarker + DmaEligible>(
&self,
_peripheral: &PeripheralRef<'_, P>,
) {
pub fn runtime_ensure_compatible<P: DmaEligible>(&self, _peripheral: &PeripheralRef<'_, P>) {
// No runtime checks; GDMA channels are compatible with any peripheral
}
}
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 16 additions & 14 deletions esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<C: PdmaChannel<RegisterBlock = SpiRegisterBlock>> 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)
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ impl<C: PdmaChannel<RegisterBlock = SpiRegisterBlock>> 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)
}
}
Expand Down Expand Up @@ -390,8 +390,8 @@ macro_rules! ImplSpiChannel {
&WAKER
}

fn is_compatible_with(&self, peripheral: &impl PeripheralMarker) -> bool {
peripheral.peripheral() == crate::system::Peripheral::[<Spi $num>]
fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool {
peripheral == DmaPeripheral::[<Spi $num>]
}
}

Expand Down Expand Up @@ -497,7 +497,7 @@ impl<C: PdmaChannel<RegisterBlock = I2sRegisterBlock>> 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)
}
}
Expand Down Expand Up @@ -653,7 +653,7 @@ impl<C: PdmaChannel<RegisterBlock = I2sRegisterBlock>> 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)
}
}
Expand Down Expand Up @@ -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::[<I2s $num>]
fn is_compatible_with(&self, peripheral: DmaPeripheral) -> bool {
peripheral == DmaPeripheral::[<I2s $num>]
}
}

Expand Down Expand Up @@ -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()
);
}
}
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 34a2b19

Please sign in to comment.