refactor: update DMA transfer functions to support separate memory and peripheral word types
This commit is contained in:
parent
03dd50316c
commit
50e98a9a58
@ -143,27 +143,28 @@ impl<'a> Transfer<'a> {
|
||||
buf.len(),
|
||||
true,
|
||||
W::size(),
|
||||
W::size(),
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a new write DMA transfer (memory to peripheral).
|
||||
pub unsafe fn new_write<W: Word>(
|
||||
pub unsafe fn new_write<MW: Word, PW: Word>(
|
||||
channel: impl Peripheral<P = impl Channel> + 'a,
|
||||
request: Request,
|
||||
buf: &'a [W],
|
||||
peri_addr: *mut W,
|
||||
buf: &'a [MW],
|
||||
peri_addr: *mut PW,
|
||||
options: TransferOptions,
|
||||
) -> Self {
|
||||
Self::new_write_raw(channel, request, buf, peri_addr, options)
|
||||
}
|
||||
|
||||
/// Create a new write DMA transfer (memory to peripheral), using raw pointers.
|
||||
pub unsafe fn new_write_raw<W: Word>(
|
||||
pub unsafe fn new_write_raw<MW: Word, PW: Word>(
|
||||
channel: impl Peripheral<P = impl Channel> + 'a,
|
||||
request: Request,
|
||||
buf: *const [W],
|
||||
peri_addr: *mut W,
|
||||
buf: *const [MW],
|
||||
peri_addr: *mut PW,
|
||||
options: TransferOptions,
|
||||
) -> Self {
|
||||
into_ref!(channel);
|
||||
@ -173,21 +174,22 @@ impl<'a> Transfer<'a> {
|
||||
request,
|
||||
Dir::MemoryToPeripheral,
|
||||
peri_addr as *const u32,
|
||||
buf as *const W as *mut u32,
|
||||
buf as *const MW as *mut u32,
|
||||
buf.len(),
|
||||
true,
|
||||
W::size(),
|
||||
MW::size(),
|
||||
PW::size(),
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly.
|
||||
pub unsafe fn new_write_repeated<W: Word>(
|
||||
pub unsafe fn new_write_repeated<MW: Word, PW: Word>(
|
||||
channel: impl Peripheral<P = impl Channel> + 'a,
|
||||
request: Request,
|
||||
repeated: &'a W,
|
||||
repeated: &'a MW,
|
||||
count: usize,
|
||||
peri_addr: *mut W,
|
||||
peri_addr: *mut PW,
|
||||
options: TransferOptions,
|
||||
) -> Self {
|
||||
into_ref!(channel);
|
||||
@ -197,10 +199,11 @@ impl<'a> Transfer<'a> {
|
||||
request,
|
||||
Dir::MemoryToPeripheral,
|
||||
peri_addr as *const u32,
|
||||
repeated as *const W as *mut u32,
|
||||
repeated as *const MW as *mut u32,
|
||||
count,
|
||||
false,
|
||||
W::size(),
|
||||
MW::size(),
|
||||
PW::size(),
|
||||
options,
|
||||
)
|
||||
}
|
||||
@ -214,6 +217,7 @@ impl<'a> Transfer<'a> {
|
||||
mem_len: usize,
|
||||
incr_mem: bool,
|
||||
data_size: WordSize,
|
||||
dst_size: WordSize,
|
||||
_options: TransferOptions,
|
||||
) -> Self {
|
||||
// BNDT is specified as bytes, not as number of transfers.
|
||||
@ -234,7 +238,7 @@ impl<'a> Transfer<'a> {
|
||||
ch.llr().write(|_| {}); // no linked list
|
||||
ch.tr1().write(|w| {
|
||||
w.set_sdw(data_size.into());
|
||||
w.set_ddw(data_size.into());
|
||||
w.set_ddw(dst_size.into());
|
||||
w.set_sinc(dir == Dir::MemoryToPeripheral && incr_mem);
|
||||
w.set_dinc(dir == Dir::PeripheralToMemory && incr_mem);
|
||||
});
|
||||
|
||||
@ -416,8 +416,10 @@ macro_rules! impl_waveform_chx {
|
||||
}
|
||||
#[cfg(not(any(stm32l0)))]
|
||||
TimerBits::Bits32 => {
|
||||
#[cfg(not(any(bdma, gpdma)))]
|
||||
panic!("unsupported timer bits");
|
||||
|
||||
#[cfg(any(bdma, gpdma))]
|
||||
panic("unsupported timer bits");
|
||||
Transfer::new_write(
|
||||
&mut dma,
|
||||
req,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user