Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add some miscellaneous examples for the ESP32-H2 (#548)
- Add initial support for PCNT in ESP32-H2 (#551)
- Add initial support for RMT in ESP32-H2 (#556)
- Add a fn to poll DMA transfers

### Fixed

Expand Down
4 changes: 4 additions & 0 deletions esp-hal-common/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,13 +846,17 @@ where
pub trait DmaTransfer<B, T>: Drop {
/// Wait for the transfer to finish.
fn wait(self) -> (B, T);
/// Check if the transfer is finished.
fn is_done(&self) -> bool;
}

/// Trait to be implemented for an in progress dma transfer.
#[allow(drop_bounds)]
pub trait DmaTransferRxTx<BR, BT, T>: Drop {
/// Wait for the transfer to finish.
fn wait(self) -> (BR, BT, T);
/// Check if the transfer is finished.
fn is_done(&self) -> bool;
}

#[cfg(feature = "async")]
Expand Down
10 changes: 10 additions & 0 deletions esp-hal-common/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ where
(buffer, payload)
}
}

/// Check if the DMA transfer is complete
fn is_done(&self) -> bool {
self.i2s_tx.tx_channel.is_done()
}
}

impl<'d, T, P, TX, BUFFER> Drop for I2sWriteDmaTransfer<T, P, TX, BUFFER>
Expand Down Expand Up @@ -451,6 +456,11 @@ where
(buffer, payload)
}
}

/// Check if the DMA transfer is complete
fn is_done(&self) -> bool {
self.i2s_rx.rx_channel.is_done()
}
}

impl<T, P, RX, BUFFER> Drop for I2sReadDmaTransfer<T, P, RX, BUFFER>
Expand Down
12 changes: 12 additions & 0 deletions esp-hal-common/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,12 @@ pub mod dma {
(rbuffer, tbuffer, payload)
}
}

/// Check if the DMA transfer is complete
fn is_done(&self) -> bool {
let ch = &self.spi_dma.channel;
ch.tx.is_done() && ch.rx.is_done()
}
}

impl<'d, T, TX, RX, P, RXBUF, TXBUF, M> Drop
Expand Down Expand Up @@ -918,6 +924,12 @@ pub mod dma {
(buffer, payload)
}
}

/// Check if the DMA transfer is complete
fn is_done(&self) -> bool {
let ch = &self.spi_dma.channel;
ch.tx.is_done() && ch.rx.is_done()
}
}

impl<'d, T, TX, RX, P, BUFFER, M> Drop for SpiDmaTransfer<'d, T, TX, RX, P, BUFFER, M>
Expand Down
7 changes: 7 additions & 0 deletions esp32-hal/examples/spi_loopback_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ fn main() -> ! {

let transfer = spi.dma_transfer(send, receive).unwrap();
// here we could do something else while DMA transfer is in progress
let mut i = 0;
// Check is_done until the transfer is almost done (32000 bytes at 100kHz is
// 2.56 seconds), then move to wait().
while !transfer.is_done() && i < 10 {
delay.delay_ms(250u32);
i += 1;
}
// the buffers and spi is moved into the transfer and we can get it back via
// `wait`
(receive, send, spi) = transfer.wait();
Expand Down
7 changes: 7 additions & 0 deletions esp32c2-hal/examples/spi_loopback_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ fn main() -> ! {

let transfer = spi.dma_transfer(send, receive).unwrap();
// here we could do something else while DMA transfer is in progress
let mut i = 0;
// Check is_done until the transfer is almost done (32000 bytes at 100kHz is
// 2.56 seconds), then move to wait().
while !transfer.is_done() && i < 10 {
delay.delay_ms(250u32);
i += 1;
}
// the buffers and spi is moved into the transfer and we can get it back via
// `wait`
(receive, send, spi) = transfer.wait();
Expand Down
7 changes: 7 additions & 0 deletions esp32c3-hal/examples/spi_loopback_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ fn main() -> ! {

let transfer = spi.dma_transfer(send, receive).unwrap();
// here we could do something else while DMA transfer is in progress
let mut i = 0;
// Check is_done until the transfer is almost done (32000 bytes at 100kHz is
// 2.56 seconds), then move to wait().
while !transfer.is_done() && i < 10 {
delay.delay_ms(250u32);
i += 1;
}
// the buffers and spi is moved into the transfer and we can get it back via
// `wait`
(receive, send, spi) = transfer.wait();
Expand Down
7 changes: 7 additions & 0 deletions esp32c6-hal/examples/spi_loopback_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ fn main() -> ! {

let transfer = spi.dma_transfer(send, receive).unwrap();
// here we could do something else while DMA transfer is in progress
let mut i = 0;
// Check is_done until the transfer is almost done (32000 bytes at 100kHz is
// 2.56 seconds), then move to wait().
while !transfer.is_done() && i < 10 {
delay.delay_ms(250u32);
i += 1;
}
// the buffers and spi is moved into the transfer and we can get it back via
// `wait`
(receive, send, spi) = transfer.wait();
Expand Down
7 changes: 7 additions & 0 deletions esp32s2-hal/examples/spi_loopback_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ fn main() -> ! {

let transfer = spi.dma_transfer(send, receive).unwrap();
// here we could do something else while DMA transfer is in progress
let mut i = 0;
// Check is_done until the transfer is almost done (32000 bytes at 100kHz is
// 2.56 seconds), then move to wait().
while !transfer.is_done() && i < 10 {
delay.delay_ms(250u32);
i += 1;
}
// the buffers and spi is moved into the transfer and we can get it back via
// `wait`
(receive, send, spi) = transfer.wait();
Expand Down
7 changes: 7 additions & 0 deletions esp32s3-hal/examples/spi_loopback_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ fn main() -> ! {

let transfer = spi.dma_transfer(send, receive).unwrap();
// here we could do something else while DMA transfer is in progress
let mut i = 0;
// Check is_done until the transfer is almost done (32000 bytes at 100kHz is
// 2.56 seconds), then move to wait().
while !transfer.is_done() && i < 10 {
delay.delay_ms(250u32);
i += 1;
}
// the buffers and spi is moved into the transfer and we can get it back via
// `wait`
(receive, send, spi) = transfer.wait();
Expand Down