Skip to content

Commit

Permalink
Implement I2S type erasure
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 19, 2024
1 parent 572fb23 commit 9be2749
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 41 deletions.
47 changes: 47 additions & 0 deletions esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,15 @@ macro_rules! ImplI2sChannel {
}
}

impl DmaChannelConvert<AnyI2sDmaChannel> for [<I2s $num DmaChannel>] {
fn degrade_rx(rx: I2sDmaRxChannelImpl<Self>) -> I2sDmaRxChannelImpl<AnyI2sDmaChannelInner> {
I2sDmaRxChannelImpl(rx.0.into())
}
fn degrade_tx(tx: I2sDmaTxChannelImpl<Self>) -> I2sDmaTxChannelImpl<AnyI2sDmaChannelInner> {
I2sDmaTxChannelImpl(tx.0.into())
}
}

#[doc = concat!("Creates a channel for I2S", $num)]
pub struct [<I2s $num DmaChannelCreator>] {}

Expand Down Expand Up @@ -942,3 +951,41 @@ impl PdmaChannel for AnySpiDmaChannelInner {
}
}
}

/// A marker for I2S-compatible type-erased DMA channels.
pub struct AnyI2sDmaChannel;

impl crate::private::Sealed for AnyI2sDmaChannel {}

impl DmaChannel for AnyI2sDmaChannel {
type Rx = I2sDmaRxChannelImpl<AnyI2sDmaChannelInner>;
type Tx = I2sDmaTxChannelImpl<AnyI2sDmaChannelInner>;
}

crate::any_enum! {
#[doc(hidden)]
pub enum AnyI2sDmaChannelInner {
I2s0(I2s0DmaChannel),
#[cfg(i2s1)]
I2s1(I2s1DmaChannel),
}
}

impl crate::private::Sealed for AnyI2sDmaChannelInner {}

impl PdmaChannel for AnyI2sDmaChannelInner {
type RegisterBlock = I2sRegisterBlock;

delegate::delegate! {
to match self {
AnyI2sDmaChannelInner::I2s0(channel) => channel,
#[cfg(i2s1)]
AnyI2sDmaChannelInner::I2s1(channel) => channel,
} {
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;
}
}
}
Loading

0 comments on commit 9be2749

Please sign in to comment.