Skip to content

Commit

Permalink
Add stop_transfer method to DMA driver (#2236)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominic Fischer <[email protected]>
  • Loading branch information
Dominaezzz and Dominic Fischer authored Sep 26, 2024
1 parent c481c49 commit 00d892b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ impl<const N: u8> RegisterAccess for Channel<N> {
.modify(|_, w| w.outlink_start().set_bit());
}

fn stop_out() {
Self::ch()
.out_link()
.modify(|_, w| w.outlink_stop().set_bit());
}

fn last_out_dscr_address() -> usize {
Self::ch()
.out_eof_des_addr()
Expand Down Expand Up @@ -225,6 +231,12 @@ impl<const N: u8> RegisterAccess for Channel<N> {
.modify(|_, w| w.inlink_start().set_bit());
}

fn stop_in() {
Self::ch()
.in_link()
.modify(|_, w| w.inlink_stop().set_bit());
}

fn listen_out(interrupts: impl Into<EnumSet<DmaTxInterrupt>>) {
Self::out_int().ena().modify(|_, w| {
for interrupt in interrupts.into() {
Expand Down
22 changes: 22 additions & 0 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,8 @@ pub trait Rx: crate::private::Sealed {

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

fn stop_transfer(&mut self);

#[cfg(esp32s3)]
fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize);

Expand Down Expand Up @@ -1455,6 +1457,10 @@ where
}
}

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

fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker;
}

Expand Down Expand Up @@ -1549,6 +1555,10 @@ where
self.rx_impl.start_transfer()
}

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

#[cfg(esp32s3)]
fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize) {
CH::Channel::set_in_ext_mem_block_size(size);
Expand Down Expand Up @@ -1622,6 +1632,8 @@ pub trait Tx: crate::private::Sealed {

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

fn stop_transfer(&mut self);

#[cfg(esp32s3)]
fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize);

Expand Down Expand Up @@ -1677,6 +1689,10 @@ where
}
}

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

fn listen_out(&self, interrupts: impl Into<EnumSet<DmaTxInterrupt>>) {
R::listen_out(interrupts)
}
Expand Down Expand Up @@ -1783,6 +1799,10 @@ where
self.tx_impl.start_transfer()
}

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

#[cfg(esp32s3)]
fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize) {
CH::Channel::set_out_ext_mem_block_size(size);
Expand Down Expand Up @@ -1834,6 +1854,7 @@ pub trait RegisterAccess: crate::private::Sealed {
fn set_out_descriptors(address: u32);
fn set_out_peripheral(peripheral: u8);
fn start_out();
fn stop_out();

fn listen_out(interrupts: impl Into<EnumSet<DmaTxInterrupt>>);
fn unlisten_out(interrupts: impl Into<EnumSet<DmaTxInterrupt>>);
Expand All @@ -1858,6 +1879,7 @@ pub trait RegisterAccess: crate::private::Sealed {
fn set_in_descriptors(address: u32);
fn set_in_peripheral(peripheral: u8);
fn start_in();
fn stop_in();
}

/// DMA Channel
Expand Down
20 changes: 20 additions & 0 deletions esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ macro_rules! ImplSpiChannel {
spi.dma_out_link().modify(|_, w| w.outlink_start().set_bit());
}

fn stop_out() {
let spi = unsafe { &*crate::peripherals::[<SPI $num>]::PTR };
spi.dma_out_link().modify(|_, w| w.outlink_stop().set_bit());
}

fn last_out_dscr_address() -> usize {
let spi = unsafe { &*crate::peripherals::[<SPI $num>]::PTR };
spi.out_eof_des_addr().read().dma_out_eof_des_addr().bits() as usize
Expand Down Expand Up @@ -123,6 +128,11 @@ macro_rules! ImplSpiChannel {
spi.dma_in_link().modify(|_, w| w.inlink_start().set_bit());
}

fn stop_in() {
let spi = unsafe { &*crate::peripherals::[<SPI $num>]::PTR };
spi.dma_in_link().modify(|_, w| w.inlink_stop().set_bit());
}

fn listen_out(interrupts: impl Into<EnumSet<DmaTxInterrupt>>) {
let spi = unsafe { &*crate::peripherals::[<SPI $num>]::PTR };
spi.dma_int_ena().modify(|_, w| {
Expand Down Expand Up @@ -462,6 +472,11 @@ macro_rules! ImplI2sChannel {
reg_block.out_link().modify(|_, w| w.outlink_start().set_bit());
}

fn stop_out() {
let reg_block = unsafe { &*crate::peripherals::[<$peripheral>]::PTR };
reg_block.out_link().modify(|_, w| w.outlink_stop().set_bit());
}

fn last_out_dscr_address() -> usize {
let reg_block = unsafe { &*crate::peripherals::[<$peripheral>]::PTR };
reg_block.out_eof_des_addr().read().out_eof_des_addr().bits() as usize
Expand Down Expand Up @@ -510,6 +525,11 @@ macro_rules! ImplI2sChannel {
reg_block.in_link().modify(|_, w| w.inlink_start().set_bit());
}

fn stop_in() {
let reg_block = unsafe { &*crate::peripherals::[<$peripheral>]::PTR };
reg_block.in_link().modify(|_, w| w.inlink_stop().set_bit());
}

fn listen_out(interrupts: impl Into<EnumSet<DmaTxInterrupt>>) {
let reg_block = unsafe { &*crate::peripherals::[<$peripheral>]::PTR };
reg_block.int_ena().modify(|_, w| {
Expand Down

0 comments on commit 00d892b

Please sign in to comment.