Add more options to DMA
This commit is contained in:
@ -9,7 +9,7 @@ use crate::interrupt;
|
||||
use crate::pac;
|
||||
use crate::pac::dma::{regs, vals};
|
||||
|
||||
use super::{Request, Word, WordSize};
|
||||
use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize};
|
||||
|
||||
impl From<WordSize> for vals::Size {
|
||||
fn from(raw: WordSize) -> Self {
|
||||
@ -21,6 +21,26 @@ impl From<WordSize> for vals::Size {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Burst> for vals::Burst {
|
||||
fn from(burst: Burst) -> Self {
|
||||
match burst {
|
||||
Burst::Single => vals::Burst::SINGLE,
|
||||
Burst::Incr4 => vals::Burst::INCR4,
|
||||
Burst::Incr8 => vals::Burst::INCR8,
|
||||
Burst::Incr16 => vals::Burst::INCR16,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FlowControl> for vals::Pfctrl {
|
||||
fn from(flow: FlowControl) -> Self {
|
||||
match flow {
|
||||
FlowControl::Dma => vals::Pfctrl::DMA,
|
||||
FlowControl::Peripheral => vals::Pfctrl::PERIPHERAL,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct State {
|
||||
ch_wakers: [AtomicWaker; DMA_CHANNEL_COUNT],
|
||||
}
|
||||
@ -49,7 +69,7 @@ pub(crate) unsafe fn init() {
|
||||
foreach_dma_channel! {
|
||||
($channel_peri:ident, $dma_peri:ident, dma, $channel_num:expr, $index:expr, $dmamux:tt) => {
|
||||
impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {
|
||||
unsafe fn start_write<W: Word>(&mut self, request: Request, buf: *const [W], reg_addr: *mut W) {
|
||||
unsafe fn start_write<W: Word>(&mut self, request: Request, buf: *const [W], reg_addr: *mut W, options: TransferOptions) {
|
||||
let (ptr, len) = super::slice_ptr_parts(buf);
|
||||
low_level_api::start_transfer(
|
||||
pac::$dma_peri,
|
||||
@ -61,6 +81,7 @@ foreach_dma_channel! {
|
||||
len,
|
||||
true,
|
||||
vals::Size::from(W::bits()),
|
||||
options,
|
||||
#[cfg(dmamux)]
|
||||
<Self as super::dmamux::sealed::MuxChannel>::DMAMUX_REGS,
|
||||
#[cfg(dmamux)]
|
||||
@ -68,7 +89,7 @@ foreach_dma_channel! {
|
||||
)
|
||||
}
|
||||
|
||||
unsafe fn start_write_repeated<W: Word>(&mut self, request: Request, repeated: W, count: usize, reg_addr: *mut W) {
|
||||
unsafe fn start_write_repeated<W: Word>(&mut self, request: Request, repeated: W, count: usize, reg_addr: *mut W, options: TransferOptions) {
|
||||
let buf = [repeated];
|
||||
low_level_api::start_transfer(
|
||||
pac::$dma_peri,
|
||||
@ -80,6 +101,7 @@ foreach_dma_channel! {
|
||||
count,
|
||||
false,
|
||||
vals::Size::from(W::bits()),
|
||||
options,
|
||||
#[cfg(dmamux)]
|
||||
<Self as super::dmamux::sealed::MuxChannel>::DMAMUX_REGS,
|
||||
#[cfg(dmamux)]
|
||||
@ -87,7 +109,7 @@ foreach_dma_channel! {
|
||||
)
|
||||
}
|
||||
|
||||
unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *const W, buf: *mut [W]) {
|
||||
unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *const W, buf: *mut [W], options: TransferOptions) {
|
||||
let (ptr, len) = super::slice_ptr_parts_mut(buf);
|
||||
low_level_api::start_transfer(
|
||||
pac::$dma_peri,
|
||||
@ -99,6 +121,7 @@ foreach_dma_channel! {
|
||||
len,
|
||||
true,
|
||||
vals::Size::from(W::bits()),
|
||||
options,
|
||||
#[cfg(dmamux)]
|
||||
<Self as super::dmamux::sealed::MuxChannel>::DMAMUX_REGS,
|
||||
#[cfg(dmamux)]
|
||||
@ -146,6 +169,7 @@ mod low_level_api {
|
||||
mem_len: usize,
|
||||
incr_mem: bool,
|
||||
data_size: vals::Size,
|
||||
options: TransferOptions,
|
||||
#[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux,
|
||||
#[cfg(dmamux)] dmamux_ch_num: u8,
|
||||
) {
|
||||
@ -180,6 +204,10 @@ mod low_level_api {
|
||||
#[cfg(dma_v2)]
|
||||
w.set_chsel(request);
|
||||
|
||||
w.set_pburst(options.pburst.into());
|
||||
w.set_mburst(options.mburst.into());
|
||||
w.set_pfctrl(options.flow_ctrl.into());
|
||||
|
||||
w.set_en(true);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user