Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stop_transfer method to DMA driver #2236

Merged
merged 1 commit into from
Sep 26, 2024
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
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 @@ -1328,6 +1328,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 @@ -1405,6 +1407,10 @@ where
}
}

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

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

Expand Down Expand Up @@ -1499,6 +1505,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 @@ -1572,6 +1582,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 @@ -1627,6 +1639,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 @@ -1733,6 +1749,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 @@ -1784,6 +1804,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 @@ -1808,6 +1829,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