Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SYSTIMER ETM functionality (#828)
- Adding async support for RSA peripheral(doesn't work properly for `esp32` chip - issue will be created)(#790)
- Added sleep support for ESP32-C3 with timer and GPIO wakeups (#795)
- Add bare-bones SPI slave support, DMA only (#580)

### Changed

Expand Down
30 changes: 18 additions & 12 deletions esp-hal-common/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,24 @@ pub mod dma {
self.channel.tx.is_done();
self.channel.rx.is_done();

self.channel.tx.prepare_transfer(
self.dma_peripheral(),
false,
write_buffer_ptr,
write_buffer_len,
)?;
self.channel.rx.prepare_transfer(
false,
self.dma_peripheral(),
read_buffer_ptr,
read_buffer_len,
)?;
self.channel
.tx
.prepare_transfer_without_start(
self.dma_peripheral(),
false,
write_buffer_ptr,
write_buffer_len,
)
.and_then(|_| self.channel.tx.start_transfer())?;
self.channel
.rx
.prepare_transfer_without_start(
false,
self.dma_peripheral(),
read_buffer_ptr,
read_buffer_len,
)
.and_then(|_| self.channel.rx.start_transfer())?;
self.enable_dma(true);
self.enable_interrupt();
self.set_mode(mode);
Expand Down
48 changes: 32 additions & 16 deletions esp-hal-common/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,16 @@ pub trait RxPrivate {

fn init_channel(&mut self);

fn prepare_transfer(
fn prepare_transfer_without_start(
&mut self,
circular: bool,
peri: DmaPeripheral,
data: *mut u8,
len: usize,
) -> Result<(), DmaError>;

fn start_transfer(&mut self) -> Result<(), DmaError>;

fn listen_ch_in_done(&self);

fn clear_ch_in_done(&self);
Expand Down Expand Up @@ -331,7 +333,7 @@ where
R::set_in_priority(priority);
}

fn prepare_transfer(
fn prepare_transfer_without_start(
&mut self,
descriptors: &mut [u32],
circular: bool,
Expand Down Expand Up @@ -382,13 +384,16 @@ where
R::reset_in();
R::set_in_descriptors(descriptors.as_ptr() as u32);
R::set_in_peripheral(peri as u8);
Ok(())
}
fn start_transfer(&mut self) -> Result<(), DmaError> {
R::start_in();

if R::has_in_descriptor_error() {
return Err(DmaError::DescriptorError);
Err(DmaError::DescriptorError)
} else {
Ok(())
}

Ok(())
}

fn is_done(&self) -> bool {
Expand Down Expand Up @@ -435,7 +440,7 @@ where
self.rx_impl.init(burst_mode, priority);
}

fn prepare_transfer(
fn prepare_transfer_without_start(
&mut self,
circular: bool,
peri: DmaPeripheral,
Expand Down Expand Up @@ -464,8 +469,11 @@ where
self.read_buffer_start = data;

self.rx_impl
.prepare_transfer(self.descriptors, circular, peri, data, len)?;
Ok(())
.prepare_transfer_without_start(self.descriptors, circular, peri, data, len)
}

fn start_transfer(&mut self) -> Result<(), DmaError> {
self.rx_impl.start_transfer()
}

fn listen_ch_in_done(&self) {
Expand Down Expand Up @@ -616,14 +624,16 @@ pub trait TxPrivate {

fn init_channel(&mut self);

fn prepare_transfer(
fn prepare_transfer_without_start(
&mut self,
peri: DmaPeripheral,
circular: bool,
data: *const u8,
len: usize,
) -> Result<(), DmaError>;

fn start_transfer(&mut self) -> Result<(), DmaError>;

fn clear_ch_out_done(&self);

fn is_ch_out_done_set(&self) -> bool;
Expand Down Expand Up @@ -661,7 +671,7 @@ where
R::set_out_priority(priority);
}

fn prepare_transfer(
fn prepare_transfer_without_start(
&mut self,
descriptors: &mut [u32],
circular: bool,
Expand Down Expand Up @@ -712,13 +722,17 @@ where
R::reset_out();
R::set_out_descriptors(descriptors.as_ptr() as u32);
R::set_out_peripheral(peri as u8);
Ok(())
}

fn start_transfer(&mut self) -> Result<(), DmaError> {
R::start_out();

if R::has_out_descriptor_error() {
return Err(DmaError::DescriptorError);
Err(DmaError::DescriptorError)
} else {
Ok(())
}

Ok(())
}

fn clear_ch_out_done(&self) {
Expand Down Expand Up @@ -800,7 +814,7 @@ where
R::init_channel();
}

fn prepare_transfer(
fn prepare_transfer_without_start(
&mut self,
peri: DmaPeripheral,
circular: bool,
Expand All @@ -827,9 +841,11 @@ where
self.buffer_len = len;

self.tx_impl
.prepare_transfer(self.descriptors, circular, peri, data, len)?;
.prepare_transfer_without_start(self.descriptors, circular, peri, data, len)
}

Ok(())
fn start_transfer(&mut self) -> Result<(), DmaError> {
self.tx_impl.start_transfer()
}

fn clear_ch_out_done(&self) {
Expand Down
84 changes: 48 additions & 36 deletions esp-hal-common/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,14 @@ where
// Enable corresponding interrupts if needed

// configure DMA outlink
self.tx_channel.prepare_transfer(
self.register_access.get_dma_peripheral(),
false,
ptr,
data.len(),
)?;
self.tx_channel
.prepare_transfer_without_start(
self.register_access.get_dma_peripheral(),
false,
ptr,
data.len(),
)
.and_then(|_| self.tx_channel.start_transfer())?;

// set I2S_TX_STOP_EN if needed

Expand Down Expand Up @@ -832,12 +834,14 @@ where
// Enable corresponding interrupts if needed

// configure DMA outlink
self.tx_channel.prepare_transfer(
self.register_access.get_dma_peripheral(),
circular,
ptr,
len,
)?;
self.tx_channel
.prepare_transfer_without_start(
self.register_access.get_dma_peripheral(),
circular,
ptr,
len,
)
.and_then(|_| self.tx_channel.start_transfer())?;

// set I2S_TX_STOP_EN if needed

Expand Down Expand Up @@ -870,12 +874,14 @@ where
// Enable corresponding interrupts if needed

// configure DMA outlink
self.tx_channel.prepare_transfer(
self.register_access.get_dma_peripheral(),
circular,
ptr,
len,
)?;
self.tx_channel
.prepare_transfer_without_start(
self.register_access.get_dma_peripheral(),
circular,
ptr,
len,
)
.and_then(|_| self.tx_channel.start_transfer())?;

// set I2S_TX_STOP_EN if needed

Expand Down Expand Up @@ -964,12 +970,14 @@ where
// Enable corresponding interrupts if needed

// configure DMA outlink
self.rx_channel.prepare_transfer(
false,
self.register_access.get_dma_peripheral(),
ptr,
data.len(),
)?;
self.rx_channel
.prepare_transfer_without_start(
false,
self.register_access.get_dma_peripheral(),
ptr,
data.len(),
)
.and_then(|_| self.rx_channel.start_transfer())?;

// set I2S_TX_STOP_EN if needed

Expand Down Expand Up @@ -1002,12 +1010,14 @@ where
// Enable corresponding interrupts if needed

// configure DMA outlink
self.rx_channel.prepare_transfer(
circular,
self.register_access.get_dma_peripheral(),
ptr,
len,
)?;
self.rx_channel
.prepare_transfer_without_start(
circular,
self.register_access.get_dma_peripheral(),
ptr,
len,
)
.and_then(|_| self.rx_channel.start_transfer())?;

// set I2S_TX_STOP_EN if needed

Expand Down Expand Up @@ -1047,12 +1057,14 @@ where
// Enable corresponding interrupts if needed

// configure DMA outlink
self.rx_channel.prepare_transfer(
circular,
self.register_access.get_dma_peripheral(),
ptr,
len,
)?;
self.rx_channel
.prepare_transfer_without_start(
circular,
self.register_access.get_dma_peripheral(),
ptr,
len,
)
.and_then(|_| self.rx_channel.start_transfer())?;

// set I2S_TX_STOP_EN if needed

Expand Down
2 changes: 2 additions & 0 deletions esp-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ pub mod rtc_cntl;
pub mod sha;
#[cfg(any(spi0, spi1, spi2, spi3))]
pub mod spi;
#[cfg(all(any(spi0, spi1, spi2, spi3), not(pdma)))]
pub mod spi_slave;
#[cfg(any(dport, pcr, system))]
pub mod system;
#[cfg(systimer)]
Expand Down
6 changes: 4 additions & 2 deletions esp-hal-common/src/parl_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,8 @@ where
self.tx_channel.is_done();

self.tx_channel
.prepare_transfer(DmaPeripheral::ParlIo, false, ptr, len)?;
.prepare_transfer_without_start(DmaPeripheral::ParlIo, false, ptr, len)
.and_then(|_| self.tx_channel.start_transfer())?;

loop {
if Instance::is_tx_ready() {
Expand Down Expand Up @@ -1331,7 +1332,8 @@ where
Instance::set_rx_bytes(len as u16);

self.rx_channel
.prepare_transfer(false, DmaPeripheral::ParlIo, ptr, len)?;
.prepare_transfer_without_start(false, DmaPeripheral::ParlIo, ptr, len)
.and_then(|_| self.rx_channel.start_transfer())?;

Instance::set_rx_reg_update();

Expand Down
6 changes: 6 additions & 0 deletions esp-hal-common/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ pub use crate::spi::{
Instance as _esp_hal_spi_Instance,
InstanceDma as _esp_hal_spi_InstanceDma,
};
#[cfg(all(any(spi0, spi1, spi2, spi3), not(pdma)))]
pub use crate::spi_slave::{
dma::WithDmaSpi2 as _esp_hal_spi_slave_dma_WithDmaSpi2,
Instance as _esp_hal_spi_slave_Instance,
InstanceDma as _esp_hal_spi_slave_InstanceDma,
};
#[cfg(any(dport, pcr, system))]
pub use crate::system::SystemExt as _esp_hal_system_SystemExt;
#[cfg(any(timg0, timg1))]
Expand Down
16 changes: 10 additions & 6 deletions esp-hal-common/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1901,18 +1901,20 @@ where
self.update();

reset_dma_before_load_dma_dscr(reg_block);
tx.prepare_transfer(
tx.prepare_transfer_without_start(
self.dma_peripheral(),
false,
write_buffer_ptr,
write_buffer_len,
)?;
rx.prepare_transfer(
)
.and_then(|_| tx.start_transfer())?;
rx.prepare_transfer_without_start(
false,
self.dma_peripheral(),
read_buffer_ptr,
read_buffer_len,
)?;
)
.and_then(|_| rx.start_transfer())?;

self.clear_dma_interrupts();
reset_dma_before_usr_cmd(reg_block);
Expand Down Expand Up @@ -1948,7 +1950,8 @@ where
self.update();

reset_dma_before_load_dma_dscr(reg_block);
tx.prepare_transfer(self.dma_peripheral(), false, ptr, len)?;
tx.prepare_transfer_without_start(self.dma_peripheral(), false, ptr, len)
.and_then(|_| tx.start_transfer())?;

self.clear_dma_interrupts();
reset_dma_before_usr_cmd(reg_block);
Expand All @@ -1973,7 +1976,8 @@ where
self.update();

reset_dma_before_load_dma_dscr(reg_block);
rx.prepare_transfer(false, self.dma_peripheral(), ptr, len)?;
rx.prepare_transfer_without_start(false, self.dma_peripheral(), ptr, len)
.and_then(|_| rx.start_transfer())?;

self.clear_dma_interrupts();
reset_dma_before_usr_cmd(reg_block);
Expand Down
Loading