Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add an is_done() poll method to DMA transfers
Implement it by forwarding to the DMA channel's existing is_done mehod.
Add the implementation to both SPI and I2S DMA transfer structs.
  • Loading branch information
BryanKadzban committed May 25, 2023
commit 8baf4df20b858bee34e152be4d6a6510938e8f45
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