From c4b8db8631b06af9d7039b1efc7acb098f9a1777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 15 Nov 2024 15:07:09 +0100 Subject: [PATCH] Move DMA channels into Peripherals --- esp-hal/src/dma/gdma.rs | 64 +++++------------- esp-hal/src/dma/mod.rs | 27 +++++--- esp-hal/src/dma/pdma.rs | 67 +++++++------------ esp-hal/src/i2s/master.rs | 9 +-- esp-hal/src/lcd_cam/cam.rs | 6 +- esp-hal/src/lcd_cam/lcd/i8080.rs | 7 +- esp-hal/src/peripheral.rs | 16 ++++- esp-hal/src/soc/esp32/peripherals.rs | 7 +- esp-hal/src/soc/esp32c2/peripherals.rs | 4 +- esp-hal/src/soc/esp32c3/peripherals.rs | 6 +- esp-hal/src/soc/esp32c6/peripherals.rs | 6 +- esp-hal/src/soc/esp32h2/peripherals.rs | 6 +- esp-hal/src/soc/esp32s2/peripherals.rs | 6 +- esp-hal/src/soc/esp32s3/peripherals.rs | 8 ++- esp-hal/src/spi/slave.rs | 6 +- examples/src/bin/dma_extmem2mem.rs | 10 +-- examples/src/bin/dma_mem2mem.rs | 28 ++++---- examples/src/bin/embassy_i2s_parallel.rs | 8 +-- examples/src/bin/embassy_i2s_read.rs | 13 ++-- examples/src/bin/embassy_i2s_sound.rs | 13 ++-- examples/src/bin/embassy_parl_io_rx.rs | 14 ++-- examples/src/bin/embassy_parl_io_tx.rs | 14 ++-- examples/src/bin/embassy_spi.rs | 8 +-- examples/src/bin/i2s_parallel.rs | 5 +- examples/src/bin/i2s_read.rs | 13 ++-- examples/src/bin/i2s_sound.rs | 13 ++-- examples/src/bin/lcd_cam_ov2640.rs | 5 +- examples/src/bin/lcd_i8080.rs | 6 +- examples/src/bin/parl_io_rx.rs | 13 ++-- examples/src/bin/parl_io_tx.rs | 13 ++-- examples/src/bin/qspi_flash.rs | 8 +-- examples/src/bin/spi_loopback_dma.rs | 8 +-- examples/src/bin/spi_loopback_dma_psram.rs | 7 +- examples/src/bin/spi_slave_dma.rs | 6 +- hil-test/tests/aes_dma.rs | 13 ++-- hil-test/tests/dma_mem2mem.rs | 5 +- hil-test/tests/embassy_interrupt_spi_dma.rs | 18 +++-- hil-test/tests/i2s.rs | 9 +-- hil-test/tests/lcd_cam_i8080.rs | 30 +++------ hil-test/tests/lcd_cam_i8080_async.rs | 15 ++--- hil-test/tests/parl_io_tx.rs | 5 +- hil-test/tests/parl_io_tx_async.rs | 5 +- hil-test/tests/qspi.rs | 10 ++- hil-test/tests/spi_full_duplex.rs | 10 ++- hil-test/tests/spi_half_duplex_read.rs | 10 ++- hil-test/tests/spi_half_duplex_write.rs | 9 ++- hil-test/tests/spi_half_duplex_write_psram.rs | 5 +- hil-test/tests/spi_slave.rs | 9 +-- 48 files changed, 267 insertions(+), 336 deletions(-) diff --git a/esp-hal/src/dma/gdma.rs b/esp-hal/src/dma/gdma.rs index ed1c6951b1b..9335d227d8a 100644 --- a/esp-hal/src/dma/gdma.rs +++ b/esp-hal/src/dma/gdma.rs @@ -750,51 +750,21 @@ crate::impl_dma_eligible! { } } -/// GDMA Peripheral -/// -/// This offers the available DMA channels. -pub struct Dma<'d> { - _inner: PeripheralRef<'d, crate::peripherals::DMA>, - /// Channel 0 - pub channel0: DmaChannel0, - /// Channel 1 - #[cfg(not(esp32c2))] - pub channel1: DmaChannel1, - /// Channel 2 - #[cfg(not(esp32c2))] - pub channel2: DmaChannel2, - /// Channel 3 - #[cfg(esp32s3)] - pub channel3: DmaChannel3, - /// Channel 4 - #[cfg(esp32s3)] - pub channel4: DmaChannel4, -} - -impl<'d> Dma<'d> { - /// Create a DMA instance. - pub fn new(dma: impl Peripheral

+ 'd) -> Dma<'d> { - crate::into_ref!(dma); - - PeripheralClockControl::enable(system::Peripheral::Gdma); - dma.misc_conf().modify(|_, w| w.ahbm_rst_inter().set_bit()); - dma.misc_conf() - .modify(|_, w| w.ahbm_rst_inter().clear_bit()); - dma.misc_conf().modify(|_, w| w.clk_en().set_bit()); - - unsafe { - Dma { - _inner: dma, - channel0: DmaChannel0::steal(), - #[cfg(not(esp32c2))] - channel1: DmaChannel1::steal(), - #[cfg(not(esp32c2))] - channel2: DmaChannel2::steal(), - #[cfg(esp32s3)] - channel3: DmaChannel3::steal(), - #[cfg(esp32s3)] - channel4: DmaChannel4::steal(), - } - } - } +pub(super) fn init_dma() { + use portable_atomic::{AtomicBool, Ordering}; + static INITED: AtomicBool = AtomicBool::new(false); + + if INITED + .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) + .is_err() + { + return; + } + + PeripheralClockControl::enable(system::Peripheral::Gdma); + let dma = unsafe { crate::soc::peripherals::DMA::steal() }; + dma.misc_conf().modify(|_, w| w.ahbm_rst_inter().set_bit()); + dma.misc_conf() + .modify(|_, w| w.ahbm_rst_inter().clear_bit()); + dma.misc_conf().modify(|_, w| w.clk_en().set_bit()); } diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 95141d776ad..7d380e16fe8 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -19,10 +19,11 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::dma_buffers; //! # use esp_hal::spi::{master::{Config, Spi}, SpiMode}; -//! # use esp_hal::dma::Dma; -//! let dma = Dma::new(peripherals.DMA); -#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.spi2channel;")] -#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")] +#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = peripherals.DMA_SPI2;")] +#![cfg_attr( + not(any(esp32, esp32s2)), + doc = "let dma_channel = peripherals.DMA_CH0;" +)] //! let sclk = peripherals.GPIO0; //! let miso = peripherals.GPIO2; //! let mosi = peripherals.GPIO4; @@ -40,7 +41,7 @@ //! .with_mosi(mosi) //! .with_miso(miso) //! .with_cs(cs) -//! .with_dma(dma_channel); +//! .with_dma(peripherals.DMA_SPI2); //! # } //! ``` //! @@ -1639,7 +1640,7 @@ impl DmaChannelConvert for DEG { #[cfg_attr(pdma, doc = "")] #[cfg_attr( pdma, - doc = "Note that using mismatching channels (e.g. trying to use `spi2channel` with SPI3) may compile, but will panic in runtime." + doc = "Note that using mismatching channels (e.g. trying to use `DMA_SPI2` with SPI3) may compile, but will panic in runtime." )] #[cfg_attr(pdma, doc = "")] /// ## Example @@ -1652,14 +1653,12 @@ impl DmaChannelConvert for DEG { /// use esp_hal::spi::master::{Spi, Config, Instance as SpiInstance}; /// use esp_hal::dma::CompatibleWith; /// use esp_hal::Blocking; -/// use esp_hal::dma::Dma; /// /// fn takes_spi(spi: Spi<'_, Blocking, S>, channel: impl /// CompatibleWith) {} -/// -/// let dma = Dma::new(peripherals.DMA); -#[cfg_attr(pdma, doc = "let dma_channel = dma.spi2channel;")] -#[cfg_attr(gdma, doc = "let dma_channel = dma.channel0;")] +#[doc = ""] +#[cfg_attr(pdma, doc = "let dma_channel = peripherals.DMA_SPI2;")] +#[cfg_attr(gdma, doc = "let dma_channel = peripherals.DMA_CH0;")] #[doc = ""] /// let spi = Spi::new_with_config( /// peripherals.SPI2, @@ -1773,6 +1772,9 @@ where /// Creates a new RX channel half. pub fn new(rx_impl: impl Peripheral

+ 'a) -> Self { crate::into_ref!(rx_impl); + + init_dma(); + #[cfg(gdma)] // clear the mem2mem mode to avoid failed DMA if this // channel was previously used for a mem2mem transfer. @@ -2067,6 +2069,9 @@ where /// Creates a new TX channel half. pub fn new(tx_impl: impl Peripheral

+ 'a) -> Self { crate::into_ref!(tx_impl); + + init_dma(); + if let Some(interrupt) = tx_impl.peripheral_interrupt() { for cpu in Cpu::all() { crate::interrupt::disable(cpu, interrupt); diff --git a/esp-hal/src/dma/pdma.rs b/esp-hal/src/dma/pdma.rs index bbf0bd5ea5b..5eb4a3c5622 100644 --- a/esp-hal/src/dma/pdma.rs +++ b/esp-hal/src/dma/pdma.rs @@ -915,50 +915,29 @@ crate::impl_dma_eligible!([I2s0DmaChannel] I2S0 => I2s0); #[cfg(i2s1)] crate::impl_dma_eligible!([I2s1DmaChannel] I2S1 => I2s1); -/// DMA Peripheral -/// -/// This offers the available DMA channels. -pub struct Dma<'d> { - _inner: PeripheralRef<'d, crate::peripherals::DMA>, - /// DMA channel for SPI2 - pub spi2channel: Spi2DmaChannel, - /// DMA channel for SPI3 - pub spi3channel: Spi3DmaChannel, - /// DMA channel for I2S0 - pub i2s0channel: I2s0DmaChannel, - /// DMA channel for I2S1 - #[cfg(i2s1)] - pub i2s1channel: I2s1DmaChannel, -} - -impl<'d> Dma<'d> { - /// Create a DMA instance. - pub fn new(dma: impl Peripheral

+ 'd) -> Dma<'d> { - PeripheralClockControl::enable(system::Peripheral::Dma); - - #[cfg(esp32)] - { - // (only) on ESP32 we need to configure DPORT for the SPI DMA channels - // This assignes the DMA channels to the SPI peripherals, which is more - // restrictive than necessary but we currently support the same - // number of SPI peripherals as SPI DMA channels so it's not a big - // deal. - let dport = unsafe { &*crate::peripherals::DPORT::PTR }; - dport.spi_dma_chan_sel().modify(|_, w| unsafe { - w.spi2_dma_chan_sel().bits(1).spi3_dma_chan_sel().bits(2) - }); - } - - unsafe { - Dma { - _inner: dma.into_ref(), - spi2channel: Spi2DmaChannel::steal(), - spi3channel: Spi3DmaChannel::steal(), - i2s0channel: I2s0DmaChannel::steal(), - #[cfg(i2s1)] - i2s1channel: I2s1DmaChannel::steal(), - } - } +pub(super) fn init_dma() { + static INITED: AtomicBool = AtomicBool::new(false); + + if INITED + .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) + .is_err() + { + return; + } + + PeripheralClockControl::enable(system::Peripheral::Dma); + + #[cfg(esp32)] + { + // (only) on ESP32 we need to configure DPORT for the SPI DMA channels + // This assignes the DMA channels to the SPI peripherals, which is more + // restrictive than necessary but we currently support the same + // number of SPI peripherals as SPI DMA channels so it's not a big + // deal. + let dport = unsafe { crate::peripherals::DPORT::steal() }; + dport + .spi_dma_chan_sel() + .modify(|_, w| unsafe { w.spi2_dma_chan_sel().bits(1).spi3_dma_chan_sel().bits(2) }); } } diff --git a/esp-hal/src/i2s/master.rs b/esp-hal/src/i2s/master.rs index e4ddaf3b848..286d174bb3f 100644 --- a/esp-hal/src/i2s/master.rs +++ b/esp-hal/src/i2s/master.rs @@ -31,10 +31,11 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::i2s::master::{I2s, Standard, DataFormat}; //! # use esp_hal::dma_buffers; -//! # use esp_hal::dma::Dma; -//! let dma = Dma::new(peripherals.DMA); -#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.i2s0channel;")] -#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")] +#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = peripherals.DMA_I2S0;")] +#![cfg_attr( + not(any(esp32, esp32s2)), + doc = "let dma_channel = peripherals.DMA_CH0;" +)] //! let (mut rx_buffer, rx_descriptors, _, tx_descriptors) = //! dma_buffers!(0, 4 * 4092); //! diff --git a/esp-hal/src/lcd_cam/cam.rs b/esp-hal/src/lcd_cam/cam.rs index c1123d24c8b..8117c030bd7 100644 --- a/esp-hal/src/lcd_cam/cam.rs +++ b/esp-hal/src/lcd_cam/cam.rs @@ -19,10 +19,6 @@ //! # use esp_hal::lcd_cam::{cam::{Camera, RxEightBits}, LcdCam}; //! # use fugit::RateExtU32; //! # use esp_hal::dma_rx_stream_buffer; -//! # use esp_hal::dma::Dma; -//! -//! # let dma = Dma::new(peripherals.DMA); -//! # let channel = dma.channel0; //! //! # let dma_buf = dma_rx_stream_buffer!(20 * 1000, 1000); //! @@ -44,7 +40,7 @@ //! let lcd_cam = LcdCam::new(peripherals.LCD_CAM); //! let mut camera = Camera::new( //! lcd_cam.cam, -//! channel, +//! peripherals.DMA_CH0, //! data_pins, //! 20u32.MHz(), //! ) diff --git a/esp-hal/src/lcd_cam/lcd/i8080.rs b/esp-hal/src/lcd_cam/lcd/i8080.rs index 7aba94f5f68..a5e2f8682f4 100644 --- a/esp-hal/src/lcd_cam/lcd/i8080.rs +++ b/esp-hal/src/lcd_cam/lcd/i8080.rs @@ -17,10 +17,7 @@ #![doc = crate::before_snippet!()] //! # use esp_hal::lcd_cam::{LcdCam, lcd::i8080::{Config, I8080, TxEightBits}}; //! # use esp_hal::dma_tx_buffer; -//! # use esp_hal::dma::{Dma, DmaTxBuf}; -//! -//! # let dma = Dma::new(peripherals.DMA); -//! # let channel = dma.channel0; +//! # use esp_hal::dma::DmaTxBuf; //! //! # let mut dma_buf = dma_tx_buffer!(32678).unwrap(); //! @@ -38,7 +35,7 @@ //! //! let mut i8080 = I8080::new( //! lcd_cam.lcd, -//! channel, +//! peripherals.DMA_CH0, //! tx_pins, //! 20.MHz(), //! Config::default(), diff --git a/esp-hal/src/peripheral.rs b/esp-hal/src/peripheral.rs index 622470d859b..4a817111a84 100644 --- a/esp-hal/src/peripheral.rs +++ b/esp-hal/src/peripheral.rs @@ -246,10 +246,15 @@ mod peripheral_macros { peripherals: [ $( $name:ident <= $from_pac:tt $(($($interrupt:ident),*))? - ), *$(,)? + ),* $(,)? ], pins: [ $( ( $pin:literal, $($pin_tokens:tt)* ) )* + ], + dma_channels: [ + $( + $channel_name:ident : $channel_ty:path + ),* $(,)? ] ) => { @@ -280,6 +285,11 @@ mod peripheral_macros { #[doc = concat!("GPIO", stringify!($pin))] pub []: $crate::gpio::GpioPin<$pin>, )* + + $( + #[doc = concat!(stringify!($channel_name), " DMA channel.")] + pub $channel_name: $crate::dma::$channel_ty, + )* } impl Peripherals { @@ -313,6 +323,10 @@ mod peripheral_macros { $( []: $crate::gpio::GpioPin::<$pin>::steal(), )* + + $( + $channel_name: $crate::dma::$channel_ty::steal(), + )* } } } diff --git a/esp-hal/src/soc/esp32/peripherals.rs b/esp-hal/src/soc/esp32/peripherals.rs index 2bfa72fc05e..cc58dd71561 100644 --- a/esp-hal/src/soc/esp32/peripherals.rs +++ b/esp-hal/src/soc/esp32/peripherals.rs @@ -30,7 +30,6 @@ crate::peripherals! { CPU_CTRL <= virtual, DAC1 <= virtual, DAC2 <= virtual, - DMA <= virtual, EFUSE <= EFUSE, FLASH_ENCRYPTION <= FLASH_ENCRYPTION, FRC_TIMER <= FRC_TIMER, @@ -112,5 +111,11 @@ crate::peripherals! { (37, [Input, Analog, RtcIoInput]) (38, [Input, Analog, RtcIoInput]) (39, [Input, Analog, RtcIoInput]) + ], + dma_channels: [ + DMA_SPI2: Spi2DmaChannel, + DMA_SPI3: Spi3DmaChannel, + DMA_I2S0: I2s0DmaChannel, + DMA_I2S1: I2s1DmaChannel, ] } diff --git a/esp-hal/src/soc/esp32c2/peripherals.rs b/esp-hal/src/soc/esp32c2/peripherals.rs index 6748f4e6ce5..03db06e0a0e 100644 --- a/esp-hal/src/soc/esp32c2/peripherals.rs +++ b/esp-hal/src/soc/esp32c2/peripherals.rs @@ -25,7 +25,6 @@ crate::peripherals! { APB_CTRL <= APB_CTRL, ASSIST_DEBUG <= ASSIST_DEBUG, BT <= virtual, - DMA <= DMA (DMA_CH0), ECC <= ECC, EFUSE <= EFUSE, EXTMEM <= EXTMEM, @@ -72,5 +71,8 @@ crate::peripherals! { (18, [Input, Output]) (19, [Input, Output]) (20, [Input, Output] (0 => U0RXD) ()) + ], + dma_channels: [ + DMA_CH0: DmaChannel0, ] } diff --git a/esp-hal/src/soc/esp32c3/peripherals.rs b/esp-hal/src/soc/esp32c3/peripherals.rs index f4a52d4fc08..00e6548a294 100644 --- a/esp-hal/src/soc/esp32c3/peripherals.rs +++ b/esp-hal/src/soc/esp32c3/peripherals.rs @@ -27,7 +27,6 @@ crate::peripherals! { APB_CTRL <= APB_CTRL, ASSIST_DEBUG <= ASSIST_DEBUG, BT <= virtual, - DMA <= DMA (DMA_CH0,DMA_CH1,DMA_CH2), DS <= DS, EFUSE <= EFUSE, EXTMEM <= EXTMEM, @@ -85,5 +84,10 @@ crate::peripherals! { (19, [Input, Output]) (20, [Input, Output] (0 => U0RXD) ()) (21, [Input, Output] () (0 => U0TXD)) + ], + dma_channels: [ + DMA_CH0: DmaChannel0, + DMA_CH1: DmaChannel1, + DMA_CH2: DmaChannel2, ] } diff --git a/esp-hal/src/soc/esp32c6/peripherals.rs b/esp-hal/src/soc/esp32c6/peripherals.rs index b521161faf9..666e7a252a6 100644 --- a/esp-hal/src/soc/esp32c6/peripherals.rs +++ b/esp-hal/src/soc/esp32c6/peripherals.rs @@ -26,7 +26,6 @@ crate::peripherals! { ASSIST_DEBUG <= ASSIST_DEBUG, ATOMIC <= ATOMIC, BT <= virtual, - DMA <= DMA (DMA_IN_CH0,DMA_IN_CH1,DMA_IN_CH2,DMA_OUT_CH0,DMA_OUT_CH1,DMA_OUT_CH2), DS <= DS, ECC <= ECC, EFUSE <= EFUSE, @@ -130,5 +129,10 @@ crate::peripherals! { (28, [Input, Output] (0 => SPIHD) (0 => SPIHD)) (29, [Input, Output] () (0 => SPICLK_MUX)) (30, [Input, Output] (0 => SPID) (0 => SPID)) + ], + dma_channels: [ + DMA_CH0: DmaChannel0, + DMA_CH1: DmaChannel1, + DMA_CH2: DmaChannel2, ] } diff --git a/esp-hal/src/soc/esp32h2/peripherals.rs b/esp-hal/src/soc/esp32h2/peripherals.rs index 9f2c0cdb7df..b5743079885 100644 --- a/esp-hal/src/soc/esp32h2/peripherals.rs +++ b/esp-hal/src/soc/esp32h2/peripherals.rs @@ -25,7 +25,6 @@ crate::peripherals! { AES <= AES, ASSIST_DEBUG <= ASSIST_DEBUG, BT <= virtual, - DMA <= DMA (DMA_IN_CH0,DMA_IN_CH1,DMA_IN_CH2,DMA_OUT_CH0,DMA_OUT_CH1,DMA_OUT_CH2), DS <= DS, ECC <= ECC, EFUSE <= EFUSE, @@ -117,5 +116,10 @@ crate::peripherals! { (25, [Input, Output] () (2 => FSPICS3)) (26, [Input, Output] () (2 => FSPICS4)) (27, [Input, Output] () (2 => FSPICS5)) + ], + dma_channels: [ + DMA_CH0: DmaChannel0, + DMA_CH1: DmaChannel1, + DMA_CH2: DmaChannel2, ] } diff --git a/esp-hal/src/soc/esp32s2/peripherals.rs b/esp-hal/src/soc/esp32s2/peripherals.rs index fc0cf5917fd..868dd4c1ff5 100644 --- a/esp-hal/src/soc/esp32s2/peripherals.rs +++ b/esp-hal/src/soc/esp32s2/peripherals.rs @@ -26,7 +26,6 @@ crate::peripherals! { AES <= AES, DAC1 <= virtual, DAC2 <= virtual, - DMA <= virtual, DEDICATED_GPIO <= DEDICATED_GPIO, DS <= DS, EFUSE <= EFUSE, @@ -115,5 +114,10 @@ crate::peripherals! { (44, [Input, Output]) (45, [Input, Output]) (46, [Input, Output]) + ], + dma_channels: [ + DMA_SPI2: Spi2DmaChannel, + DMA_SPI3: Spi3DmaChannel, + DMA_I2S0: I2s0DmaChannel, ] } diff --git a/esp-hal/src/soc/esp32s3/peripherals.rs b/esp-hal/src/soc/esp32s3/peripherals.rs index c6ab886c9bf..c27239702c8 100644 --- a/esp-hal/src/soc/esp32s3/peripherals.rs +++ b/esp-hal/src/soc/esp32s3/peripherals.rs @@ -28,7 +28,6 @@ crate::peripherals! { ASSIST_DEBUG <= ASSIST_DEBUG, BT <= virtual, CPU_CTRL <= virtual, - DMA <= DMA (DMA_IN_CH0,DMA_IN_CH1,DMA_IN_CH2,DMA_IN_CH3,DMA_IN_CH4,DMA_OUT_CH0,DMA_OUT_CH1,DMA_OUT_CH2,DMA_OUT_CH3,DMA_OUT_CH4), DS <= DS, EFUSE <= EFUSE, EXTMEM <= EXTMEM, @@ -126,5 +125,12 @@ crate::peripherals! { (46, [Input, Output]) (47, [Input, Output]) (48, [Input, Output]) + ], + dma_channels: [ + DMA_CH0: DmaChannel0, + DMA_CH1: DmaChannel1, + DMA_CH2: DmaChannel2, + DMA_CH3: DmaChannel3, + DMA_CH4: DmaChannel4, ] } diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index 556cd4b1b70..20cfa338b55 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -18,10 +18,8 @@ //! # use esp_hal::dma_buffers; //! # use esp_hal::spi::SpiMode; //! # use esp_hal::spi::slave::Spi; -//! # use esp_hal::dma::Dma; -//! let dma = Dma::new(peripherals.DMA); -#![cfg_attr(pdma, doc = "let dma_channel = dma.spi2channel;")] -#![cfg_attr(gdma, doc = "let dma_channel = dma.channel0;")] +#![cfg_attr(pdma, doc = "let dma_channel = peripherals.DMA_SPI2;")] +#![cfg_attr(gdma, doc = "let dma_channel = peripherals.DMA_CH0;")] //! let sclk = peripherals.GPIO0; //! let miso = peripherals.GPIO1; //! let mosi = peripherals.GPIO2; diff --git a/examples/src/bin/dma_extmem2mem.rs b/examples/src/bin/dma_extmem2mem.rs index 4fab1087c77..4641fea4d83 100644 --- a/examples/src/bin/dma_extmem2mem.rs +++ b/examples/src/bin/dma_extmem2mem.rs @@ -9,12 +9,7 @@ use aligned::{Aligned, A64}; use esp_alloc as _; use esp_backtrace as _; -use esp_hal::{ - delay::Delay, - dma::{Dma, Mem2Mem}, - dma_descriptors_chunk_size, - prelude::*, -}; +use esp_hal::{delay::Delay, dma::Mem2Mem, dma_descriptors_chunk_size, prelude::*}; use log::{error, info}; extern crate alloc; @@ -67,11 +62,10 @@ fn main() -> ! { let mut intram_buffer = dma_buffer_aligned!(DATA_SIZE, A64); let (rx_descriptors, tx_descriptors) = dma_descriptors_chunk_size!(DATA_SIZE, CHUNK_SIZE); - let dma = Dma::new(peripherals.DMA); let dma_peripheral = peripherals.SPI2; let mut mem2mem = Mem2Mem::new_with_chunk_size( - dma.channel0, + peripherals.DMA_CH0, dma_peripheral, rx_descriptors, tx_descriptors, diff --git a/examples/src/bin/dma_mem2mem.rs b/examples/src/bin/dma_mem2mem.rs index 23dda706764..7a0b9341819 100644 --- a/examples/src/bin/dma_mem2mem.rs +++ b/examples/src/bin/dma_mem2mem.rs @@ -7,12 +7,7 @@ #![no_main] use esp_backtrace as _; -use esp_hal::{ - delay::Delay, - dma::{Dma, Mem2Mem}, - dma_buffers, - prelude::*, -}; +use esp_hal::{delay::Delay, dma::Mem2Mem, dma_buffers, prelude::*}; use log::{error, info}; const DATA_SIZE: usize = 1024 * 10; @@ -27,14 +22,21 @@ fn main() -> ! { let (mut rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(DATA_SIZE); - let dma = Dma::new(peripherals.DMA); - #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] - let dma_peripheral = peripherals.SPI2; - #[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] - let dma_peripheral = peripherals.MEM2MEM1; + cfg_if::cfg_if! { + if #[cfg(any(features = "esp32c2", features = "esp32c3", features = "esp32s3"))] { + let dma_peripheral = peripherals.SPI2; + } else { + let dma_peripheral = peripherals.MEM2MEM1; + } + } - let mut mem2mem = - Mem2Mem::new(dma.channel0, dma_peripheral, rx_descriptors, tx_descriptors).unwrap(); + let mut mem2mem = Mem2Mem::new( + peripherals.DMA_CH0, + dma_peripheral, + rx_descriptors, + tx_descriptors, + ) + .unwrap(); for i in 0..core::mem::size_of_val(tx_buffer) { tx_buffer[i] = (i % 256) as u8; diff --git a/examples/src/bin/embassy_i2s_parallel.rs b/examples/src/bin/embassy_i2s_parallel.rs index 3ece585c35c..fe4b35ce40e 100644 --- a/examples/src/bin/embassy_i2s_parallel.rs +++ b/examples/src/bin/embassy_i2s_parallel.rs @@ -18,7 +18,7 @@ use embassy_executor::Spawner; use embassy_time::Timer; use esp_backtrace as _; use esp_hal::{ - dma::{Dma, DmaTxBuf}, + dma::DmaTxBuf, dma_buffers, i2s::parallel::{I2sParallel, TxEightBits}, prelude::*, @@ -33,15 +33,12 @@ async fn main(_spawner: Spawner) { esp_println::logger::init_logger(log::LevelFilter::Info); info!("Starting!"); let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); let timg0 = TimerGroup::new(peripherals.TIMG0); info!("init embassy"); esp_hal_embassy::init(timg0.timer0); - let dma_channel = dma.i2s1channel; - let i2s = peripherals.I2S1; let clock = peripherals.GPIO25; let pins = TxEightBits::new( @@ -56,7 +53,8 @@ async fn main(_spawner: Spawner) { ); let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, BUFFER_SIZE); - let mut parallel = I2sParallel::new(i2s, dma_channel, 1.MHz(), pins, clock).into_async(); + let mut parallel = + I2sParallel::new(peripherals.I2S1, peripherals.DMA_I2S1, 1.MHz(), pins, clock).into_async(); for (i, data) in tx_buffer.chunks_mut(4).enumerate() { let offset = i * 4; diff --git a/examples/src/bin/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs index a60ab718326..88ab1eccbca 100644 --- a/examples/src/bin/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -20,7 +20,6 @@ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ - dma::Dma, dma_buffers, i2s::master::{DataFormat, I2s, Standard}, prelude::*, @@ -36,11 +35,13 @@ async fn main(_spawner: Spawner) { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_hal_embassy::init(timg0.timer0); - let dma = Dma::new(peripherals.DMA); - #[cfg(any(feature = "esp32", feature = "esp32s2"))] - let dma_channel = dma.i2s0channel; - #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] - let dma_channel = dma.channel0; + cfg_if::cfg_if! { + if #[cfg(any(features = "esp32", features = "esp32s2"))] { + let dma_channel = peripherals.DMA_I2S0; + } else { + let dma_channel = peripherals.CH0; + } + } let (rx_buffer, rx_descriptors, _, tx_descriptors) = dma_buffers!(4092 * 4, 0); diff --git a/examples/src/bin/embassy_i2s_sound.rs b/examples/src/bin/embassy_i2s_sound.rs index 3809bb7eb44..32308a53cfd 100644 --- a/examples/src/bin/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -34,7 +34,6 @@ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ - dma::Dma, dma_buffers, i2s::master::{DataFormat, I2s, Standard}, prelude::*, @@ -58,11 +57,13 @@ async fn main(_spawner: Spawner) { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_hal_embassy::init(timg0.timer0); - let dma = Dma::new(peripherals.DMA); - #[cfg(any(feature = "esp32", feature = "esp32s2"))] - let dma_channel = dma.i2s0channel; - #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] - let dma_channel = dma.channel0; + cfg_if::cfg_if! { + if #[cfg(any(features = "esp32", features = "esp32s2"))] { + let dma_channel = peripherals.DMA_I2S0; + } else { + let dma_channel = peripherals.CH0; + } + } let (_, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(0, 32000); diff --git a/examples/src/bin/embassy_parl_io_rx.rs b/examples/src/bin/embassy_parl_io_rx.rs index 5117252fa8d..5c517fffcad 100644 --- a/examples/src/bin/embassy_parl_io_rx.rs +++ b/examples/src/bin/embassy_parl_io_rx.rs @@ -14,7 +14,6 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - dma::Dma, dma_buffers, gpio::NoPin, parl_io::{BitPackOrder, ParlIoRxOnly, RxFourBits}, @@ -33,8 +32,6 @@ async fn main(_spawner: Spawner) { let (rx_buffer, rx_descriptors, _, _) = dma_buffers!(32000, 0); - let dma = Dma::new(peripherals.DMA); - let mut rx_pins = RxFourBits::new( peripherals.GPIO1, peripherals.GPIO2, @@ -43,9 +40,14 @@ async fn main(_spawner: Spawner) { ); let mut rx_clk_pin = NoPin; - let parl_io = ParlIoRxOnly::new(peripherals.PARL_IO, dma.channel0, rx_descriptors, 1.MHz()) - .unwrap() - .into_async(); + let parl_io = ParlIoRxOnly::new( + peripherals.PARL_IO, + peripherals.DMA_CH0, + rx_descriptors, + 1.MHz(), + ) + .unwrap() + .into_async(); let mut parl_io_rx = parl_io .rx diff --git a/examples/src/bin/embassy_parl_io_tx.rs b/examples/src/bin/embassy_parl_io_tx.rs index ca5c3a2aa59..c69bb753ec8 100644 --- a/examples/src/bin/embassy_parl_io_tx.rs +++ b/examples/src/bin/embassy_parl_io_tx.rs @@ -18,7 +18,6 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - dma::Dma, dma_buffers, parl_io::{ BitPackOrder, @@ -43,8 +42,6 @@ async fn main(_spawner: Spawner) { let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, 32000); - let dma = Dma::new(peripherals.DMA); - let tx_pins = TxFourBits::new( peripherals.GPIO1, peripherals.GPIO2, @@ -54,9 +51,14 @@ async fn main(_spawner: Spawner) { let mut pin_conf = TxPinConfigWithValidPin::new(tx_pins, peripherals.GPIO5); - let parl_io = ParlIoTxOnly::new(peripherals.PARL_IO, dma.channel0, tx_descriptors, 1.MHz()) - .unwrap() - .into_async(); + let parl_io = ParlIoTxOnly::new( + peripherals.PARL_IO, + peripherals.DMA_CH0, + tx_descriptors, + 1.MHz(), + ) + .unwrap() + .into_async(); let mut clock_pin = ClkOutPin::new(peripherals.GPIO8); diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index becc3e96134..1d7e8f9fd31 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -22,7 +22,7 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - dma::*, + dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, prelude::*, spi::{ @@ -45,13 +45,11 @@ async fn main(_spawner: Spawner) { let mosi = peripherals.GPIO4; let cs = peripherals.GPIO5; - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { - let dma_channel = dma.spi2channel; + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/examples/src/bin/i2s_parallel.rs b/examples/src/bin/i2s_parallel.rs index 6d4d8a2633f..9d54e2541dd 100644 --- a/examples/src/bin/i2s_parallel.rs +++ b/examples/src/bin/i2s_parallel.rs @@ -16,7 +16,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaTxBuf}, + dma::DmaTxBuf, dma_buffers, i2s::parallel::{I2sParallel, TxEightBits}, prelude::*, @@ -30,11 +30,10 @@ fn main() -> ! { esp_println::logger::init_logger(log::LevelFilter::Info); info!("Starting!"); let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); let delay = Delay::new(); - let dma_channel = dma.i2s1channel; + let dma_channel = peripherals.DMA_I2S1; let i2s = peripherals.I2S1; let clock = peripherals.GPIO25; diff --git a/examples/src/bin/i2s_read.rs b/examples/src/bin/i2s_read.rs index 1e5cdc5503b..7fddb14dad5 100644 --- a/examples/src/bin/i2s_read.rs +++ b/examples/src/bin/i2s_read.rs @@ -18,7 +18,6 @@ use esp_backtrace as _; use esp_hal::{ - dma::Dma, dma_buffers, i2s::master::{DataFormat, I2s, Standard}, prelude::*, @@ -29,11 +28,13 @@ use esp_println::println; fn main() -> ! { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); - #[cfg(any(feature = "esp32", feature = "esp32s2"))] - let dma_channel = dma.i2s0channel; - #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] - let dma_channel = dma.channel0; + cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { + let dma_channel = peripherals.DMA_SPI2; + } else { + let dma_channel = peripherals.DMA_CH0; + } + } let (mut rx_buffer, rx_descriptors, _, tx_descriptors) = dma_buffers!(4 * 4092, 0); diff --git a/examples/src/bin/i2s_sound.rs b/examples/src/bin/i2s_sound.rs index 6cf407c4a50..a1b926b588e 100644 --- a/examples/src/bin/i2s_sound.rs +++ b/examples/src/bin/i2s_sound.rs @@ -32,7 +32,6 @@ use esp_backtrace as _; use esp_hal::{ - dma::Dma, dma_buffers, i2s::master::{DataFormat, I2s, Standard}, prelude::*, @@ -50,11 +49,13 @@ const SINE: [i16; 64] = [ fn main() -> ! { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); - #[cfg(any(feature = "esp32", feature = "esp32s2"))] - let dma_channel = dma.i2s0channel; - #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] - let dma_channel = dma.channel0; + cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { + let dma_channel = peripherals.DMA_SPI2; + } else { + let dma_channel = peripherals.DMA_CH0; + } + } let (_, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(0, 32000); diff --git a/examples/src/bin/lcd_cam_ov2640.rs b/examples/src/bin/lcd_cam_ov2640.rs index 73a07095c33..67a3033cb47 100644 --- a/examples/src/bin/lcd_cam_ov2640.rs +++ b/examples/src/bin/lcd_cam_ov2640.rs @@ -26,7 +26,6 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::Dma, dma_rx_stream_buffer, i2c::{ self, @@ -45,8 +44,6 @@ use esp_println::{print, println}; fn main() -> ! { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); - let dma_rx_buf = dma_rx_stream_buffer!(20 * 1000, 1000); let cam_siod = peripherals.GPIO4; @@ -67,7 +64,7 @@ fn main() -> ! { ); let lcd_cam = LcdCam::new(peripherals.LCD_CAM); - let camera = Camera::new(lcd_cam.cam, dma.channel0, cam_data_pins, 20u32.MHz()) + let camera = Camera::new(lcd_cam.cam, peripherals.DMA_CH0, cam_data_pins, 20u32.MHz()) .with_master_clock(cam_xclk) .with_pixel_clock(cam_pclk) .with_ctrl_pins(cam_vsync, cam_href); diff --git a/examples/src/bin/lcd_i8080.rs b/examples/src/bin/lcd_i8080.rs index 5e7f1f1d893..ce659b9f033 100644 --- a/examples/src/bin/lcd_i8080.rs +++ b/examples/src/bin/lcd_i8080.rs @@ -25,7 +25,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaTxBuf}, + dma::DmaTxBuf, dma_tx_buffer, gpio::{Input, Level, Output, Pull}, lcd_cam::{ @@ -47,8 +47,6 @@ fn main() -> ! { let lcd_wr = peripherals.GPIO47; // Write clock let lcd_te = peripherals.GPIO48; // Frame sync - let dma = Dma::new(peripherals.DMA); - let dma_tx_buf = dma_tx_buffer!(4000).unwrap(); let delay = Delay::new(); @@ -71,7 +69,7 @@ fn main() -> ! { let lcd_cam = LcdCam::new(peripherals.LCD_CAM); let i8080 = I8080::new( lcd_cam.lcd, - dma.channel0, + peripherals.DMA_CH0, tx_pins, 20.MHz(), Config::default(), diff --git a/examples/src/bin/parl_io_rx.rs b/examples/src/bin/parl_io_rx.rs index 3fddcde318b..9baa1a5bf64 100644 --- a/examples/src/bin/parl_io_rx.rs +++ b/examples/src/bin/parl_io_rx.rs @@ -12,7 +12,6 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::Dma, dma_buffers, gpio::NoPin, parl_io::{BitPackOrder, ParlIoRxOnly, RxFourBits}, @@ -26,9 +25,6 @@ fn main() -> ! { let (rx_buffer, rx_descriptors, _, _) = dma_buffers!(32000, 0); - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - let mut rx_pins = RxFourBits::new( peripherals.GPIO1, peripherals.GPIO2, @@ -37,8 +33,13 @@ fn main() -> ! { ); let mut rx_clk_pin = NoPin; - let parl_io = - ParlIoRxOnly::new(peripherals.PARL_IO, dma_channel, rx_descriptors, 1.MHz()).unwrap(); + let parl_io = ParlIoRxOnly::new( + peripherals.PARL_IO, + peripherals.DMA_CH0, + rx_descriptors, + 1.MHz(), + ) + .unwrap(); let mut parl_io_rx = parl_io .rx diff --git a/examples/src/bin/parl_io_tx.rs b/examples/src/bin/parl_io_tx.rs index 9e7a441d3d7..4036cbf3f63 100644 --- a/examples/src/bin/parl_io_tx.rs +++ b/examples/src/bin/parl_io_tx.rs @@ -16,7 +16,6 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::Dma, dma_buffers, parl_io::{ BitPackOrder, @@ -36,9 +35,6 @@ fn main() -> ! { let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, 32000); - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - let tx_pins = TxFourBits::new( peripherals.GPIO1, peripherals.GPIO2, @@ -48,8 +44,13 @@ fn main() -> ! { let mut pin_conf = TxPinConfigWithValidPin::new(tx_pins, peripherals.GPIO5); - let parl_io = - ParlIoTxOnly::new(peripherals.PARL_IO, dma_channel, tx_descriptors, 1.MHz()).unwrap(); + let parl_io = ParlIoTxOnly::new( + peripherals.PARL_IO, + peripherals.DMA_CH0, + tx_descriptors, + 1.MHz(), + ) + .unwrap(); let mut clock_pin = ClkOutPin::new(peripherals.GPIO6); diff --git a/examples/src/bin/qspi_flash.rs b/examples/src/bin/qspi_flash.rs index 46552163fa9..861a3f4eb67 100644 --- a/examples/src/bin/qspi_flash.rs +++ b/examples/src/bin/qspi_flash.rs @@ -30,7 +30,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaRxBuf, DmaTxBuf}, + dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, prelude::*, spi::{ @@ -63,13 +63,11 @@ fn main() -> ! { } } - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { - let dma_channel = dma.spi2channel; + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/examples/src/bin/spi_loopback_dma.rs b/examples/src/bin/spi_loopback_dma.rs index 2d1e0567b91..84b3516aed1 100644 --- a/examples/src/bin/spi_loopback_dma.rs +++ b/examples/src/bin/spi_loopback_dma.rs @@ -21,7 +21,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaRxBuf, DmaTxBuf}, + dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, prelude::*, spi::{ @@ -40,13 +40,11 @@ fn main() -> ! { let mosi = peripherals.GPIO4; let cs = peripherals.GPIO5; - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { - let dma_channel = dma.spi2channel; + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/examples/src/bin/spi_loopback_dma_psram.rs b/examples/src/bin/spi_loopback_dma_psram.rs index 21016621186..8318c56ada8 100644 --- a/examples/src/bin/spi_loopback_dma_psram.rs +++ b/examples/src/bin/spi_loopback_dma_psram.rs @@ -25,7 +25,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{BurstTransfer, Dma, DmaRxBuf, DmaTxBuf, ExternalBurstSize}, + dma::{BurstTransfer, DmaRxBuf, DmaTxBuf, ExternalBurstSize}, peripheral::Peripheral, prelude::*, spi::{ @@ -67,9 +67,6 @@ fn main() -> ! { let miso = unsafe { mosi.clone_unchecked() }; let cs = peripherals.GPIO38; - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - let (_, tx_descriptors) = esp_hal::dma_descriptors_chunk_size!(0, DMA_BUFFER_SIZE, DMA_CHUNK_SIZE); let tx_buffer = dma_alloc_buffer!(DMA_BUFFER_SIZE, DMA_ALIGNMENT as usize); @@ -110,7 +107,7 @@ fn main() -> ! { .with_miso(miso) .with_mosi(mosi) .with_cs(cs) - .with_dma(dma_channel); + .with_dma(peripherals.DMA_CH0); delay.delay_millis(100); // delay to let the above messages display diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index eaee969c415..5f92755e2eb 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -32,7 +32,6 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::Dma, dma_buffers, gpio::{Input, Level, Output, Pull}, prelude::*, @@ -54,12 +53,11 @@ fn main() -> ! { let slave_mosi = peripherals.GPIO2; let slave_cs = peripherals.GPIO3; - let dma = Dma::new(peripherals.DMA); cfg_if::cfg_if! { if #[cfg(feature = "esp32s2")] { - let dma_channel = dma.spi2channel; + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/hil-test/tests/aes_dma.rs b/hil-test/tests/aes_dma.rs index e560e041dd3..be8eb3d804e 100644 --- a/hil-test/tests/aes_dma.rs +++ b/hil-test/tests/aes_dma.rs @@ -7,7 +7,6 @@ use esp_hal::{ aes::{dma::CipherMode, Aes, Mode}, - dma::Dma, dma_buffers, peripherals::Peripherals, }; @@ -27,8 +26,7 @@ mod tests { #[test] fn test_aes_128_dma_encryption(peripherals: Peripherals) { - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); @@ -66,8 +64,7 @@ mod tests { #[test] fn test_aes_128_dma_decryption(peripherals: Peripherals) { - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); @@ -104,8 +101,7 @@ mod tests { #[test] fn test_aes_256_dma_encryption(peripherals: Peripherals) { - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); @@ -143,8 +139,7 @@ mod tests { #[test] fn test_aes_256_dma_decryption(peripherals: Peripherals) { - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); diff --git a/hil-test/tests/dma_mem2mem.rs b/hil-test/tests/dma_mem2mem.rs index 20ac1cfe89b..09961d2517a 100644 --- a/hil-test/tests/dma_mem2mem.rs +++ b/hil-test/tests/dma_mem2mem.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{AnyGdmaChannel, Dma, DmaChannelConvert, DmaError, Mem2Mem}, + dma::{AnyGdmaChannel, DmaChannelConvert, DmaError, Mem2Mem}, dma_buffers, dma_buffers_chunk_size, dma_descriptors, @@ -37,8 +37,7 @@ mod tests { fn init() -> Context { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; cfg_if::cfg_if! { if #[cfg(any(esp32c2, esp32c6, esp32h2))] { diff --git a/hil-test/tests/embassy_interrupt_spi_dma.rs b/hil-test/tests/embassy_interrupt_spi_dma.rs index caf7b1b4084..69a96187164 100644 --- a/hil-test/tests/embassy_interrupt_spi_dma.rs +++ b/hil-test/tests/embassy_interrupt_spi_dma.rs @@ -9,7 +9,7 @@ use embassy_time::{Duration, Instant, Ticker}; use esp_hal::{ - dma::{Dma, DmaRxBuf, DmaTxBuf}, + dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, interrupt::{software::SoftwareInterruptControl, Priority}, peripheral::Peripheral, @@ -83,7 +83,6 @@ mod test { #[timeout(3)] async fn dma_does_not_lock_up_when_used_in_different_executors() { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); cfg_if::cfg_if! { if #[cfg(systimer)] { @@ -104,12 +103,12 @@ mod test { } cfg_if::cfg_if! { - if #[cfg(pdma)] { - let dma_channel1 = dma.spi2channel; - let dma_channel2 = dma.spi3channel; + if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { + let dma_channel1 = peripherals.DMA_SPI2; + let dma_channel2 = peripherals.DMA_SPI3; } else { - let dma_channel1 = dma.channel0; - let dma_channel2 = dma.channel1; + let dma_channel1 = peripherals.DMA_CH0; + let dma_channel2 = peripherals.DMA_CH1; } } @@ -253,7 +252,6 @@ mod test { } let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); cfg_if::cfg_if! { if #[cfg(systimer)] { @@ -275,9 +273,9 @@ mod test { cfg_if::cfg_if! { if #[cfg(pdma)] { - let dma_channel = dma.spi2channel; + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/hil-test/tests/i2s.rs b/hil-test/tests/i2s.rs index e5191581085..77bb587e1c5 100644 --- a/hil-test/tests/i2s.rs +++ b/hil-test/tests/i2s.rs @@ -12,7 +12,6 @@ use esp_hal::{ delay::Delay, - dma::Dma, dma_buffers, gpio::{AnyPin, NoPin, Pin}, i2s::master::{DataFormat, I2s, I2sTx, Standard}, @@ -112,13 +111,11 @@ mod tests { fn init() -> Context { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { - if #[cfg(any(esp32, esp32s2))] { - let dma_channel = dma.i2s0channel; + if #[cfg(pdma)] { + let dma_channel = peripherals.DMA_I2S0; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/hil-test/tests/lcd_cam_i8080.rs b/hil-test/tests/lcd_cam_i8080.rs index da5ad4df11f..0ce6e842cd6 100644 --- a/hil-test/tests/lcd_cam_i8080.rs +++ b/hil-test/tests/lcd_cam_i8080.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaTxBuf}, + dma::{DmaChannel0, DmaTxBuf}, dma_buffers, gpio::{GpioPin, NoPin}, lcd_cam::{ @@ -38,7 +38,7 @@ struct Context<'d> { lcd_cam: LcdCam<'d, Blocking>, pcnt: Pcnt<'d>, pins: Pins, - dma: Dma<'d>, + dma: DmaChannel0, dma_buf: DmaTxBuf, } @@ -50,7 +50,6 @@ mod tests { #[init] fn init() -> Context<'static> { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); let lcd_cam = LcdCam::new(peripherals.LCD_CAM); let pcnt = Pcnt::new(peripherals.PCNT); @@ -59,7 +58,7 @@ mod tests { Context { lcd_cam, - dma, + dma: peripherals.DMA_CH0, pcnt, pins: Pins { GPIO8: peripherals.GPIO8, @@ -76,13 +75,7 @@ mod tests { fn test_i8080_8bit(ctx: Context<'static>) { let pins = TxEightBits::new(NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin); - let i8080 = I8080::new( - ctx.lcd_cam.lcd, - ctx.dma.channel0, - pins, - 20.MHz(), - Config::default(), - ); + let i8080 = I8080::new(ctx.lcd_cam.lcd, ctx.dma, pins, 20.MHz(), Config::default()); let xfer = i8080.send(Command::::None, 0, ctx.dma_buf).unwrap(); xfer.wait().0.unwrap(); @@ -139,15 +132,9 @@ mod tests { NoPin, ); - let mut i8080 = I8080::new( - ctx.lcd_cam.lcd, - ctx.dma.channel0, - pins, - 20.MHz(), - Config::default(), - ) - .with_cs(cs_signal) - .with_ctrl_pins(NoPin, NoPin); + let mut i8080 = I8080::new(ctx.lcd_cam.lcd, ctx.dma, pins, 20.MHz(), Config::default()) + .with_cs(cs_signal) + .with_ctrl_pins(NoPin, NoPin); // This is to make the test values look more intuitive. i8080.set_bit_order(BitOrder::Inverted); @@ -238,7 +225,6 @@ mod tests { .channel0 .set_input_mode(EdgeMode::Hold, EdgeMode::Increment); - let channel = ctx.dma.channel0; let pins = TxSixteenBits::new( NoPin, NoPin, @@ -258,7 +244,7 @@ mod tests { unit3_signal, ); - let mut i8080 = I8080::new(ctx.lcd_cam.lcd, channel, pins, 20.MHz(), Config::default()) + let mut i8080 = I8080::new(ctx.lcd_cam.lcd, ctx.dma, pins, 20.MHz(), Config::default()) .with_cs(cs_signal) .with_ctrl_pins(NoPin, NoPin); diff --git a/hil-test/tests/lcd_cam_i8080_async.rs b/hil-test/tests/lcd_cam_i8080_async.rs index b2da394fb0c..f9c49f8f4f0 100644 --- a/hil-test/tests/lcd_cam_i8080_async.rs +++ b/hil-test/tests/lcd_cam_i8080_async.rs @@ -7,7 +7,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaTxBuf}, + dma::{DmaChannel0, DmaTxBuf}, dma_buffers, gpio::NoPin, lcd_cam::{ @@ -23,7 +23,7 @@ const DATA_SIZE: usize = 1024 * 10; struct Context<'d> { lcd_cam: LcdCam<'d, Async>, - dma: Dma<'d>, + dma: DmaChannel0, dma_buf: DmaTxBuf, } @@ -36,14 +36,13 @@ mod tests { async fn init() -> Context<'static> { let peripherals = esp_hal::init(esp_hal::Config::default()); - let dma = Dma::new(peripherals.DMA); let lcd_cam = LcdCam::new(peripherals.LCD_CAM).into_async(); let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, DATA_SIZE); let dma_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); Context { lcd_cam, - dma, + dma: peripherals.DMA_CH0, dma_buf, } } @@ -52,13 +51,7 @@ mod tests { async fn test_i8080_8bit(ctx: Context<'static>) { let pins = TxEightBits::new(NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin); - let i8080 = I8080::new( - ctx.lcd_cam.lcd, - ctx.dma.channel0, - pins, - 20.MHz(), - Config::default(), - ); + let i8080 = I8080::new(ctx.lcd_cam.lcd, ctx.dma, pins, 20.MHz(), Config::default()); let mut transfer = i8080.send(Command::::None, 0, ctx.dma_buf).unwrap(); diff --git a/hil-test/tests/parl_io_tx.rs b/hil-test/tests/parl_io_tx.rs index 54fbe1f27ba..501d6a07775 100644 --- a/hil-test/tests/parl_io_tx.rs +++ b/hil-test/tests/parl_io_tx.rs @@ -7,7 +7,7 @@ #[cfg(esp32c6)] use esp_hal::parl_io::{TxPinConfigWithValidPin, TxSixteenBits}; use esp_hal::{ - dma::{Dma, DmaChannel0}, + dma::DmaChannel0, gpio::{ interconnect::{InputSignal, OutputSignal}, NoPin, @@ -57,8 +57,7 @@ mod tests { let (valid_loopback, valid) = valid.split(); let pcnt = Pcnt::new(peripherals.PCNT); let pcnt_unit = pcnt.unit0; - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; let parl_io = peripherals.PARL_IO; diff --git a/hil-test/tests/parl_io_tx_async.rs b/hil-test/tests/parl_io_tx_async.rs index ab7b202003b..8b9a6a8a04e 100644 --- a/hil-test/tests/parl_io_tx_async.rs +++ b/hil-test/tests/parl_io_tx_async.rs @@ -9,7 +9,7 @@ #[cfg(esp32c6)] use esp_hal::parl_io::{TxPinConfigWithValidPin, TxSixteenBits}; use esp_hal::{ - dma::{Dma, DmaChannel0}, + dma::DmaChannel0, gpio::{ interconnect::{InputSignal, OutputSignal}, NoPin, @@ -59,8 +59,7 @@ mod tests { let (valid_loopback, valid) = valid.split(); let pcnt = Pcnt::new(peripherals.PCNT); let pcnt_unit = pcnt.unit0; - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; let parl_io = peripherals.PARL_IO; diff --git a/hil-test/tests/qspi.rs b/hil-test/tests/qspi.rs index 8960f767dea..1c9f46fc371 100644 --- a/hil-test/tests/qspi.rs +++ b/hil-test/tests/qspi.rs @@ -8,7 +8,7 @@ #[cfg(pcnt)] use esp_hal::pcnt::{channel::EdgeMode, unit::Unit, Pcnt}; use esp_hal::{ - dma::{Dma, DmaRxBuf, DmaTxBuf}, + dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{AnyPin, Input, Level, Output, Pull}, prelude::*, @@ -192,13 +192,11 @@ mod tests { let _ = Input::new(&mut pin_mirror, Pull::Down); let _ = Input::new(&mut unconnected_pin, Pull::Down); - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { - if #[cfg(any(esp32, esp32s2))] { - let dma_channel = dma.spi2channel; + if #[cfg(pdma)] { + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index 35a9209acc0..756833d9cc4 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -12,7 +12,7 @@ use embedded_hal::spi::SpiBus; #[cfg(pcnt)] use embedded_hal_async::spi::SpiBus as SpiBusAsync; use esp_hal::{ - dma::{Dma, DmaDescriptor, DmaRxBuf, DmaTxBuf}, + dma::{DmaDescriptor, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{Level, NoPin}, peripheral::Peripheral, @@ -61,13 +61,11 @@ mod tests { let sclk = peripherals.GPIO0; let (_, mosi) = hil_test::common_test_pins!(peripherals); - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { - if #[cfg(any(esp32, esp32s2))] { - let dma_channel = dma.spi2channel; + if #[cfg(pdma)] { + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/hil-test/tests/spi_half_duplex_read.rs b/hil-test/tests/spi_half_duplex_read.rs index 12b77d1b065..c1c92da8be9 100644 --- a/hil-test/tests/spi_half_duplex_read.rs +++ b/hil-test/tests/spi_half_duplex_read.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaRxBuf, DmaTxBuf}, + dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{Level, Output}, prelude::*, @@ -38,13 +38,11 @@ mod tests { let miso_mirror = Output::new(miso_mirror, Level::High); - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { - let dma_channel = dma.spi2channel; + if #[cfg(pdma)] { + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/hil-test/tests/spi_half_duplex_write.rs b/hil-test/tests/spi_half_duplex_write.rs index a07ecd65ca5..a847e276500 100644 --- a/hil-test/tests/spi_half_duplex_write.rs +++ b/hil-test/tests/spi_half_duplex_write.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaRxBuf, DmaTxBuf}, + dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::interconnect::InputSignal, pcnt::{channel::EdgeMode, unit::Unit, Pcnt}, @@ -39,13 +39,12 @@ mod tests { let (mosi, _) = hil_test::common_test_pins!(peripherals); let pcnt = Pcnt::new(peripherals.PCNT); - let dma = Dma::new(peripherals.DMA); cfg_if::cfg_if! { - if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { - let dma_channel = dma.spi2channel; + if #[cfg(pdma)] { + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } } diff --git a/hil-test/tests/spi_half_duplex_write_psram.rs b/hil-test/tests/spi_half_duplex_write_psram.rs index d8f25f70d94..c3cf3f9151b 100644 --- a/hil-test/tests/spi_half_duplex_write_psram.rs +++ b/hil-test/tests/spi_half_duplex_write_psram.rs @@ -7,7 +7,7 @@ use defmt::error; use esp_alloc as _; use esp_hal::{ - dma::{BurstTransfer, Dma, DmaRxBuf, DmaTxBuf, ExternalBurstSize, InternalBurstTransfer}, + dma::{BurstTransfer, DmaRxBuf, DmaTxBuf, ExternalBurstSize, InternalBurstTransfer}, dma_buffers, dma_descriptors_chunk_size, gpio::interconnect::InputSignal, @@ -57,9 +57,8 @@ mod tests { let (mosi, _) = hil_test::common_test_pins!(peripherals); let pcnt = Pcnt::new(peripherals.PCNT); - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; let (mosi_loopback, mosi) = mosi.split(); diff --git a/hil-test/tests/spi_slave.rs b/hil-test/tests/spi_slave.rs index 299a592a2b4..5a0472619bc 100644 --- a/hil-test/tests/spi_slave.rs +++ b/hil-test/tests/spi_slave.rs @@ -9,7 +9,6 @@ #![no_main] use esp_hal::{ - dma::Dma, dma_buffers, gpio::{Input, Level, Output, Pull}, peripheral::Peripheral, @@ -107,13 +106,11 @@ mod tests { let (sclk_pin, _) = hil_test::common_test_pins!(peripherals); let cs_pin = hil_test::unconnected_pin!(peripherals); - let dma = Dma::new(peripherals.DMA); - cfg_if::cfg_if! { - if #[cfg(any(esp32, esp32s2))] { - let dma_channel = dma.spi2channel; + if #[cfg(pdma)] { + let dma_channel = peripherals.DMA_SPI2; } else { - let dma_channel = dma.channel0; + let dma_channel = peripherals.DMA_CH0; } }