Skip to content

Commit f4e745d

Browse files
committed
Erase DMA type params
1 parent cde35f6 commit f4e745d

File tree

9 files changed

+299
-436
lines changed

9 files changed

+299
-436
lines changed

esp-hal/src/aes/mod.rs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ pub mod dma {
241241
ChannelRx,
242242
ChannelTx,
243243
DescriptorChain,
244-
DmaChannel,
245244
DmaDescriptor,
246245
DmaPeripheral,
247246
DmaTransferRxTx,
@@ -272,14 +271,11 @@ pub mod dma {
272271
}
273272

274273
/// A DMA capable AES instance.
275-
pub struct AesDma<'d, C = AnyDmaChannel>
276-
where
277-
C: DmaChannel,
278-
{
274+
pub struct AesDma<'d> {
279275
/// The underlying [`Aes`](super::Aes) driver
280276
pub aes: super::Aes<'d>,
281277

282-
pub(crate) channel: Channel<'d, C, crate::Blocking>,
278+
channel: Channel<'d, AnyDmaChannel, crate::Blocking>,
283279
rx_chain: DescriptorChain,
284280
tx_chain: DescriptorChain,
285281
}
@@ -296,43 +292,23 @@ pub mod dma {
296292
Self: Sized,
297293
C: PeripheralDmaChannel,
298294
C::P: AesPeripheral,
299-
{
300-
self.with_dma_typed(channel.degrade(), rx_descriptors, tx_descriptors)
301-
}
302-
303-
/// Enable DMA for the current instance of the AES driver
304-
pub fn with_dma_typed<C>(
305-
self,
306-
channel: Channel<'d, C, crate::Blocking>,
307-
rx_descriptors: &'static mut [DmaDescriptor],
308-
tx_descriptors: &'static mut [DmaDescriptor],
309-
) -> AesDma<'d, C>
310-
where
311-
C: PeripheralDmaChannel,
312-
C::P: AesPeripheral,
313295
{
314296
AesDma {
315297
aes: self,
316-
channel,
298+
channel: channel.degrade(),
317299
rx_chain: DescriptorChain::new(rx_descriptors),
318300
tx_chain: DescriptorChain::new(tx_descriptors),
319301
}
320302
}
321303
}
322304

323-
impl<'d, C> core::fmt::Debug for AesDma<'d, C>
324-
where
325-
C: DmaChannel,
326-
{
305+
impl<'d> core::fmt::Debug for AesDma<'d> {
327306
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
328307
f.debug_struct("AesDma").finish()
329308
}
330309
}
331310

332-
impl<'d, C> DmaSupport for AesDma<'d, C>
333-
where
334-
C: DmaChannel,
335-
{
311+
impl<'d> DmaSupport for AesDma<'d> {
336312
fn peripheral_wait_dma(&mut self, _is_rx: bool, _is_tx: bool) {
337313
while self.aes.aes.state().read().state().bits() != 2 // DMA status DONE == 2
338314
&& !self.channel.tx.is_done()
@@ -348,11 +324,8 @@ pub mod dma {
348324
}
349325
}
350326

351-
impl<'d, C> DmaSupportTx for AesDma<'d, C>
352-
where
353-
C: DmaChannel,
354-
{
355-
type TX = ChannelTx<'d, C>;
327+
impl<'d> DmaSupportTx for AesDma<'d> {
328+
type TX = ChannelTx<'d, AnyDmaChannel>;
356329

357330
fn tx(&mut self) -> &mut Self::TX {
358331
&mut self.channel.tx
@@ -363,11 +336,8 @@ pub mod dma {
363336
}
364337
}
365338

366-
impl<'d, C> DmaSupportRx for AesDma<'d, C>
367-
where
368-
C: DmaChannel,
369-
{
370-
type RX = ChannelRx<'d, C>;
339+
impl<'d> DmaSupportRx for AesDma<'d> {
340+
type RX = ChannelRx<'d, AnyDmaChannel>;
371341

372342
fn rx(&mut self) -> &mut Self::RX {
373343
&mut self.channel.rx
@@ -378,10 +348,7 @@ pub mod dma {
378348
}
379349
}
380350

381-
impl<'d, C> AesDma<'d, C>
382-
where
383-
C: DmaChannel,
384-
{
351+
impl<'d> AesDma<'d> {
385352
/// Writes the encryption key to the AES hardware, checking that its
386353
/// length matches expected constraints.
387354
pub fn write_key<K>(&mut self, key: K)

esp-hal/src/dma/gdma.rs

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -709,51 +709,56 @@ pub use m2m::*;
709709
mod m2m {
710710
#[cfg(esp32s3)]
711711
use crate::dma::DmaExtMemBKSize;
712-
use crate::dma::{
713-
dma_private::{DmaSupport, DmaSupportRx},
714-
Channel,
715-
ChannelRx,
716-
DescriptorChain,
717-
DmaChannel,
718-
DmaDescriptor,
719-
DmaEligible,
720-
DmaError,
721-
DmaPeripheral,
722-
DmaTransferRx,
723-
ReadBuffer,
724-
Rx,
725-
Tx,
726-
WriteBuffer,
712+
use crate::{
713+
dma::{
714+
dma_private::{DmaSupport, DmaSupportRx},
715+
AnyDmaChannel,
716+
Channel,
717+
ChannelRx,
718+
DescriptorChain,
719+
DmaChannel,
720+
DmaDescriptor,
721+
DmaEligible,
722+
DmaError,
723+
DmaPeripheral,
724+
DmaTransferRx,
725+
ReadBuffer,
726+
Rx,
727+
Tx,
728+
WriteBuffer,
729+
},
730+
Mode,
727731
};
728732

729733
/// DMA Memory to Memory pseudo-Peripheral
730734
///
731735
/// This is a pseudo-peripheral that allows for memory to memory transfers.
732736
/// It is not a real peripheral, but a way to use the DMA engine for memory
733737
/// to memory transfers.
734-
pub struct Mem2Mem<'d, C, MODE>
738+
pub struct Mem2Mem<'d, M>
735739
where
736-
C: DmaChannel,
737-
MODE: crate::Mode,
740+
M: Mode,
738741
{
739-
channel: Channel<'d, C, MODE>,
742+
channel: Channel<'d, AnyDmaChannel, M>,
740743
rx_chain: DescriptorChain,
741744
tx_chain: DescriptorChain,
742745
peripheral: DmaPeripheral,
743746
}
744747

745-
impl<'d, C, MODE> Mem2Mem<'d, C, MODE>
748+
impl<'d, M> Mem2Mem<'d, M>
746749
where
747-
C: DmaChannel,
748-
MODE: crate::Mode,
750+
M: Mode,
749751
{
750752
/// Create a new Mem2Mem instance.
751-
pub fn new(
752-
channel: Channel<'d, C, MODE>,
753+
pub fn new<CH>(
754+
channel: Channel<'d, CH, M>,
753755
peripheral: impl DmaEligible,
754756
rx_descriptors: &'static mut [DmaDescriptor],
755757
tx_descriptors: &'static mut [DmaDescriptor],
756-
) -> Result<Self, DmaError> {
758+
) -> Result<Self, DmaError>
759+
where
760+
CH: DmaChannel,
761+
{
757762
unsafe {
758763
Self::new_unsafe(
759764
channel,
@@ -766,13 +771,16 @@ mod m2m {
766771
}
767772

768773
/// Create a new Mem2Mem instance with specific chunk size.
769-
pub fn new_with_chunk_size(
770-
channel: Channel<'d, C, MODE>,
774+
pub fn new_with_chunk_size<CH>(
775+
channel: Channel<'d, CH, M>,
771776
peripheral: impl DmaEligible,
772777
rx_descriptors: &'static mut [DmaDescriptor],
773778
tx_descriptors: &'static mut [DmaDescriptor],
774779
chunk_size: usize,
775-
) -> Result<Self, DmaError> {
780+
) -> Result<Self, DmaError>
781+
where
782+
CH: DmaChannel,
783+
{
776784
unsafe {
777785
Self::new_unsafe(
778786
channel,
@@ -790,21 +798,24 @@ mod m2m {
790798
///
791799
/// You must ensure that your not using DMA for the same peripheral and
792800
/// that your the only one using the DmaPeripheral.
793-
pub unsafe fn new_unsafe(
794-
channel: Channel<'d, C, MODE>,
801+
pub unsafe fn new_unsafe<CH>(
802+
channel: Channel<'d, CH, M>,
795803
peripheral: DmaPeripheral,
796804
rx_descriptors: &'static mut [DmaDescriptor],
797805
tx_descriptors: &'static mut [DmaDescriptor],
798806
chunk_size: usize,
799-
) -> Result<Self, DmaError> {
807+
) -> Result<Self, DmaError>
808+
where
809+
CH: DmaChannel,
810+
{
800811
if !(1..=4092).contains(&chunk_size) {
801812
return Err(DmaError::InvalidChunkSize);
802813
}
803814
if tx_descriptors.is_empty() || rx_descriptors.is_empty() {
804815
return Err(DmaError::OutOfDescriptors);
805816
}
806817
Ok(Mem2Mem {
807-
channel,
818+
channel: channel.degrade(),
808819
peripheral,
809820
rx_chain: DescriptorChain::new_with_chunk_size(rx_descriptors, chunk_size),
810821
tx_chain: DescriptorChain::new_with_chunk_size(tx_descriptors, chunk_size),
@@ -855,10 +866,9 @@ mod m2m {
855866
}
856867
}
857868

858-
impl<'d, C, MODE> DmaSupport for Mem2Mem<'d, C, MODE>
869+
impl<'d, MODE> DmaSupport for Mem2Mem<'d, MODE>
859870
where
860-
C: DmaChannel,
861-
MODE: crate::Mode,
871+
MODE: Mode,
862872
{
863873
fn peripheral_wait_dma(&mut self, _is_rx: bool, _is_tx: bool) {
864874
while !self.channel.rx.is_done() {}
@@ -869,12 +879,11 @@ mod m2m {
869879
}
870880
}
871881

872-
impl<'d, C, MODE> DmaSupportRx for Mem2Mem<'d, C, MODE>
882+
impl<'d, MODE> DmaSupportRx for Mem2Mem<'d, MODE>
873883
where
874-
C: DmaChannel,
875-
MODE: crate::Mode,
884+
MODE: Mode,
876885
{
877-
type RX = ChannelRx<'d, C>;
886+
type RX = ChannelRx<'d, AnyDmaChannel>;
878887

879888
fn rx(&mut self) -> &mut Self::RX {
880889
&mut self.channel.rx

esp-hal/src/dma/pdma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ macro_rules! ImplI2sChannel {
915915
}
916916

917917
fn set_isr(handler: InterruptHandler) {
918-
let interrupt = $crate::peripherals::Interrupt::[< I2S $num >];
918+
let interrupt = $crate::peripherals::Interrupt::[< I2S $num >];
919919
unsafe {
920920
crate::interrupt::bind_interrupt(interrupt, handler.handler());
921921
}

0 commit comments

Comments
 (0)