Skip to content

Commit

Permalink
Erase DMA type params
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 2, 2024
1 parent cde35f6 commit f4e745d
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 436 deletions.
53 changes: 10 additions & 43 deletions esp-hal/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ pub mod dma {
ChannelRx,
ChannelTx,
DescriptorChain,
DmaChannel,
DmaDescriptor,
DmaPeripheral,
DmaTransferRxTx,
Expand Down Expand Up @@ -272,14 +271,11 @@ pub mod dma {
}

/// A DMA capable AES instance.
pub struct AesDma<'d, C = AnyDmaChannel>
where
C: DmaChannel,
{
pub struct AesDma<'d> {
/// The underlying [`Aes`](super::Aes) driver
pub aes: super::Aes<'d>,

pub(crate) channel: Channel<'d, C, crate::Blocking>,
channel: Channel<'d, AnyDmaChannel, crate::Blocking>,
rx_chain: DescriptorChain,
tx_chain: DescriptorChain,
}
Expand All @@ -296,43 +292,23 @@ pub mod dma {
Self: Sized,
C: PeripheralDmaChannel,
C::P: AesPeripheral,
{
self.with_dma_typed(channel.degrade(), rx_descriptors, tx_descriptors)
}

/// Enable DMA for the current instance of the AES driver
pub fn with_dma_typed<C>(
self,
channel: Channel<'d, C, crate::Blocking>,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
) -> AesDma<'d, C>
where
C: PeripheralDmaChannel,
C::P: AesPeripheral,
{
AesDma {
aes: self,
channel,
channel: channel.degrade(),
rx_chain: DescriptorChain::new(rx_descriptors),
tx_chain: DescriptorChain::new(tx_descriptors),
}
}
}

impl<'d, C> core::fmt::Debug for AesDma<'d, C>
where
C: DmaChannel,
{
impl<'d> core::fmt::Debug for AesDma<'d> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("AesDma").finish()
}
}

impl<'d, C> DmaSupport for AesDma<'d, C>
where
C: DmaChannel,
{
impl<'d> DmaSupport for AesDma<'d> {
fn peripheral_wait_dma(&mut self, _is_rx: bool, _is_tx: bool) {
while self.aes.aes.state().read().state().bits() != 2 // DMA status DONE == 2
&& !self.channel.tx.is_done()
Expand All @@ -348,11 +324,8 @@ pub mod dma {
}
}

impl<'d, C> DmaSupportTx for AesDma<'d, C>
where
C: DmaChannel,
{
type TX = ChannelTx<'d, C>;
impl<'d> DmaSupportTx for AesDma<'d> {
type TX = ChannelTx<'d, AnyDmaChannel>;

fn tx(&mut self) -> &mut Self::TX {
&mut self.channel.tx
Expand All @@ -363,11 +336,8 @@ pub mod dma {
}
}

impl<'d, C> DmaSupportRx for AesDma<'d, C>
where
C: DmaChannel,
{
type RX = ChannelRx<'d, C>;
impl<'d> DmaSupportRx for AesDma<'d> {
type RX = ChannelRx<'d, AnyDmaChannel>;

fn rx(&mut self) -> &mut Self::RX {
&mut self.channel.rx
Expand All @@ -378,10 +348,7 @@ pub mod dma {
}
}

impl<'d, C> AesDma<'d, C>
where
C: DmaChannel,
{
impl<'d> AesDma<'d> {
/// Writes the encryption key to the AES hardware, checking that its
/// length matches expected constraints.
pub fn write_key<K>(&mut self, key: K)
Expand Down
87 changes: 48 additions & 39 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,51 +709,56 @@ pub use m2m::*;
mod m2m {
#[cfg(esp32s3)]
use crate::dma::DmaExtMemBKSize;
use crate::dma::{
dma_private::{DmaSupport, DmaSupportRx},
Channel,
ChannelRx,
DescriptorChain,
DmaChannel,
DmaDescriptor,
DmaEligible,
DmaError,
DmaPeripheral,
DmaTransferRx,
ReadBuffer,
Rx,
Tx,
WriteBuffer,
use crate::{
dma::{
dma_private::{DmaSupport, DmaSupportRx},
AnyDmaChannel,
Channel,
ChannelRx,
DescriptorChain,
DmaChannel,
DmaDescriptor,
DmaEligible,
DmaError,
DmaPeripheral,
DmaTransferRx,
ReadBuffer,
Rx,
Tx,
WriteBuffer,
},
Mode,
};

/// DMA Memory to Memory pseudo-Peripheral
///
/// This is a pseudo-peripheral that allows for memory to memory transfers.
/// It is not a real peripheral, but a way to use the DMA engine for memory
/// to memory transfers.
pub struct Mem2Mem<'d, C, MODE>
pub struct Mem2Mem<'d, M>
where
C: DmaChannel,
MODE: crate::Mode,
M: Mode,
{
channel: Channel<'d, C, MODE>,
channel: Channel<'d, AnyDmaChannel, M>,
rx_chain: DescriptorChain,
tx_chain: DescriptorChain,
peripheral: DmaPeripheral,
}

impl<'d, C, MODE> Mem2Mem<'d, C, MODE>
impl<'d, M> Mem2Mem<'d, M>
where
C: DmaChannel,
MODE: crate::Mode,
M: Mode,
{
/// Create a new Mem2Mem instance.
pub fn new(
channel: Channel<'d, C, MODE>,
pub fn new<CH>(
channel: Channel<'d, CH, M>,
peripheral: impl DmaEligible,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
) -> Result<Self, DmaError> {
) -> Result<Self, DmaError>
where
CH: DmaChannel,
{
unsafe {
Self::new_unsafe(
channel,
Expand All @@ -766,13 +771,16 @@ mod m2m {
}

/// Create a new Mem2Mem instance with specific chunk size.
pub fn new_with_chunk_size(
channel: Channel<'d, C, MODE>,
pub fn new_with_chunk_size<CH>(
channel: Channel<'d, CH, M>,
peripheral: impl DmaEligible,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
chunk_size: usize,
) -> Result<Self, DmaError> {
) -> Result<Self, DmaError>
where
CH: DmaChannel,
{
unsafe {
Self::new_unsafe(
channel,
Expand All @@ -790,21 +798,24 @@ mod m2m {
///
/// You must ensure that your not using DMA for the same peripheral and
/// that your the only one using the DmaPeripheral.
pub unsafe fn new_unsafe(
channel: Channel<'d, C, MODE>,
pub unsafe fn new_unsafe<CH>(
channel: Channel<'d, CH, M>,
peripheral: DmaPeripheral,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
chunk_size: usize,
) -> Result<Self, DmaError> {
) -> Result<Self, DmaError>
where
CH: DmaChannel,
{
if !(1..=4092).contains(&chunk_size) {
return Err(DmaError::InvalidChunkSize);
}
if tx_descriptors.is_empty() || rx_descriptors.is_empty() {
return Err(DmaError::OutOfDescriptors);
}
Ok(Mem2Mem {
channel,
channel: channel.degrade(),
peripheral,
rx_chain: DescriptorChain::new_with_chunk_size(rx_descriptors, chunk_size),
tx_chain: DescriptorChain::new_with_chunk_size(tx_descriptors, chunk_size),
Expand Down Expand Up @@ -855,10 +866,9 @@ mod m2m {
}
}

impl<'d, C, MODE> DmaSupport for Mem2Mem<'d, C, MODE>
impl<'d, MODE> DmaSupport for Mem2Mem<'d, MODE>
where
C: DmaChannel,
MODE: crate::Mode,
MODE: Mode,
{
fn peripheral_wait_dma(&mut self, _is_rx: bool, _is_tx: bool) {
while !self.channel.rx.is_done() {}
Expand All @@ -869,12 +879,11 @@ mod m2m {
}
}

impl<'d, C, MODE> DmaSupportRx for Mem2Mem<'d, C, MODE>
impl<'d, MODE> DmaSupportRx for Mem2Mem<'d, MODE>
where
C: DmaChannel,
MODE: crate::Mode,
MODE: Mode,
{
type RX = ChannelRx<'d, C>;
type RX = ChannelRx<'d, AnyDmaChannel>;

fn rx(&mut self) -> &mut Self::RX {
&mut self.channel.rx
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ macro_rules! ImplI2sChannel {
}

fn set_isr(handler: InterruptHandler) {
let interrupt = $crate::peripherals::Interrupt::[< I2S $num >];
let interrupt = $crate::peripherals::Interrupt::[< I2S $num >];
unsafe {
crate::interrupt::bind_interrupt(interrupt, handler.handler());
}
Expand Down
Loading

0 comments on commit f4e745d

Please sign in to comment.