Skip to content

Commit

Permalink
add Mem2MemN values for gdma on non-esp32s3
Browse files Browse the repository at this point in the history
tested on esp32c3,esp32c6 (will have an esp32h2 in a few days)
  • Loading branch information
liebman committed Jun 29, 2024
1 parent 045c6bd commit 7bb4da6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
42 changes: 29 additions & 13 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,29 +381,45 @@ pub enum DmaPriority {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[doc(hidden)]
pub enum DmaPeripheral {
Spi2 = 0,
Spi2 = 0,
#[cfg(any(pdma, esp32s3))]
Spi3 = 1,
Spi3 = 1,
#[cfg(any(esp32c3, esp32c6, esp32h2))]
Mem2Mem1 = 1,
#[cfg(any(esp32c3, esp32c6, esp32h2, esp32s3))]
Uhci0 = 2,
Uhci0 = 2,
#[cfg(any(esp32, esp32s2, esp32c3, esp32c6, esp32h2, esp32s3))]
I2s0 = 3,
I2s0 = 3,
#[cfg(any(esp32, esp32s3))]
I2s1 = 4,
I2s1 = 4,
#[cfg(any(esp32c3, esp32c6, esp32h2))]
Mem2Mem4 = 4,
#[cfg(esp32s3)]
LcdCam = 5,
LcdCam = 5,
#[cfg(any(esp32c3, esp32c6, esp32h2))]
Mem2Mem5 = 5,
#[cfg(not(esp32c2))]
Aes = 6,
Aes = 6,
#[cfg(gdma)]
Sha = 7,
Sha = 7,
#[cfg(any(esp32c3, esp32c6, esp32h2, esp32s3))]
Adc = 8,
Adc = 8,
#[cfg(esp32s3)]
Rmt = 9,
Rmt = 9,
#[cfg(parl_io)]
ParlIo = 9,
#[cfg(gdma)]
Mem2Mem = 10, // taken from esp32c6 TRM
ParlIo = 9,
#[cfg(any(esp32c6, esp32h2))]
Mem2Mem10 = 10,
#[cfg(any(esp32c6, esp32h2))]
Mem2Mem11 = 11,
#[cfg(any(esp32c6, esp32h2))]
Mem2Mem12 = 12,
#[cfg(any(esp32c6, esp32h2))]
Mem2Mem13 = 13,
#[cfg(any(esp32c6, esp32h2))]
Mem2Mem14 = 14,
#[cfg(any(esp32c6, esp32h2))]
Mem2Mem15 = 15,
}

#[derive(PartialEq, PartialOrd)]
Expand Down
11 changes: 8 additions & 3 deletions examples/src/bin/dma_mem2mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//% FEATURES: esp-hal/log
//% CHIPS: esp32s3
//% CHIPS: esp32s3 esp32c3 esp32c6 esp32h2

#![no_std]
#![no_main]
Expand All @@ -19,6 +19,12 @@ use esp_hal::{
};
use log::{error, info};

const DATA_SIZE: usize = 1024 * 100;
#[cfg(feature = "esp32s3")]
const DMA_PERIPHERAL: DmaPeripheral = DmaPeripheral::Adc;
#[cfg(not(feature = "esp32s3"))]
const DMA_PERIPHERAL: DmaPeripheral = DmaPeripheral::Mem2Mem1;

#[entry]
fn main() -> ! {
esp_println::logger::init_logger(log::LevelFilter::Info);
Expand All @@ -28,14 +34,13 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let delay = Delay::new(&clocks);

const DATA_SIZE: usize = 1024 * 100;
let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers!(DATA_SIZE);

let dma = Dma::new(peripherals.DMA);
let channel = dma.channel0.configure(false, DmaPriority::Priority0);

let mut mem2mem =
unsafe { Mem2Mem::new(channel, DmaPeripheral::Adc, tx_descriptors, rx_descriptors) };
unsafe { Mem2Mem::new(channel, DMA_PERIPHERAL, tx_descriptors, rx_descriptors) };

for i in 0..core::mem::size_of_val(tx_buffer) {
tx_buffer[i] = (i % 256) as u8;
Expand Down

0 comments on commit 7bb4da6

Please sign in to comment.