Skip to content

Commit

Permalink
Explain cancel code
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Sep 25, 2024
1 parent 8390ced commit dd9c444
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 8 additions & 8 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ pub trait Rx: crate::private::Sealed {

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

fn stop_transfer(&mut self);
fn reset_state_machine(&mut self);

#[cfg(esp32s3)]
fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize);
Expand Down Expand Up @@ -1407,7 +1407,7 @@ where
}
}

fn stop_transfer(&mut self) {
fn reset_state_machine(&mut self) {
R::reset_in();
}

Expand Down Expand Up @@ -1505,8 +1505,8 @@ where
self.rx_impl.start_transfer()
}

fn stop_transfer(&mut self) {
self.rx_impl.stop_transfer();
fn reset_state_machine(&mut self) {
self.rx_impl.reset_state_machine();
}

#[cfg(esp32s3)]
Expand Down Expand Up @@ -1582,7 +1582,7 @@ pub trait Tx: crate::private::Sealed {

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

fn stop_transfer(&mut self);
fn reset_state_machine(&mut self);

#[cfg(esp32s3)]
fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize);
Expand Down Expand Up @@ -1639,7 +1639,7 @@ where
}
}

fn stop_transfer(&mut self) {
fn reset_state_machine(&mut self) {
R::reset_out();
}

Expand Down Expand Up @@ -1749,8 +1749,8 @@ where
self.tx_impl.start_transfer()
}

fn stop_transfer(&mut self) {
self.tx_impl.stop_transfer();
fn reset_state_machine(&mut self) {
self.tx_impl.reset_state_machine();
}

#[cfg(esp32s3)]
Expand Down
8 changes: 6 additions & 2 deletions esp-hal/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,19 +1512,23 @@ mod dma {
}

fn do_cancel(&mut self) {
// The SPI peripheral is controlling how much data we transfer, so let's
// update its counter.
// 0 doesn't take effect on ESP32 and cuts the currently transmitted byte
// immediately.
// 1 seems to stop after transmitting the current byte which is somewhat less
// impolite.
self.spi_dma.spi_mut().configure_datalen(1, 1);
self.spi_dma.spi_mut().update();

// We need to reset the DMA state machines for the DMA to also pick up the
// change.
if self.spi_dma.is_tx_in_progress() {
self.spi_dma.channel_mut().tx.stop_transfer();
self.spi_dma.channel_mut().tx.reset_state_machine();
self.spi_dma.set_tx_in_progress(false);
}
if self.spi_dma.is_rx_in_progress() {
self.spi_dma.channel_mut().rx.stop_transfer();
self.spi_dma.channel_mut().rx.reset_state_machine();
self.spi_dma.set_rx_in_progress(false);
}
}
Expand Down

0 comments on commit dd9c444

Please sign in to comment.