stm32/dma: impl all variants
This commit is contained in:
committed by
Bob McWhirter
parent
69fb1b5418
commit
3d1391ef2d
@@ -1,9 +1,62 @@
|
||||
#![macro_use]
|
||||
|
||||
#[cfg_attr(dma_v1, path = "v1.rs")]
|
||||
#[cfg_attr(dma_v2, path = "v2.rs")]
|
||||
mod _version;
|
||||
|
||||
#[cfg(bdma)]
|
||||
mod bdma;
|
||||
#[cfg(dma)]
|
||||
#[allow(unused)]
|
||||
pub use _version::*;
|
||||
mod dma;
|
||||
#[cfg(dmamux)]
|
||||
mod dmamux;
|
||||
|
||||
use core::future::Future;
|
||||
use embassy::util::Unborrow;
|
||||
|
||||
#[cfg(any(bdma_v2, dma_v2, dmamux))]
|
||||
pub type Request = u8;
|
||||
#[cfg(not(any(bdma_v2, dma_v2, dmamux)))]
|
||||
pub type Request = ();
|
||||
|
||||
pub(crate) mod sealed {
|
||||
pub trait Channel {}
|
||||
}
|
||||
|
||||
pub trait Channel: sealed::Channel {
|
||||
type ReadFuture<'a>: Future<Output = ()> + 'a
|
||||
where
|
||||
Self: 'a;
|
||||
|
||||
type WriteFuture<'a>: Future<Output = ()> + 'a
|
||||
where
|
||||
Self: 'a;
|
||||
|
||||
fn read<'a>(
|
||||
&'a mut self,
|
||||
request: Request,
|
||||
src: *mut u8,
|
||||
buf: &'a mut [u8],
|
||||
) -> Self::ReadFuture<'a>;
|
||||
|
||||
fn write<'a>(
|
||||
&'a mut self,
|
||||
request: Request,
|
||||
buf: &'a [u8],
|
||||
dst: *mut u8,
|
||||
) -> Self::WriteFuture<'a>;
|
||||
}
|
||||
|
||||
pub struct NoDma;
|
||||
|
||||
unsafe impl Unborrow for NoDma {
|
||||
type Target = NoDma;
|
||||
|
||||
unsafe fn unborrow(self) -> Self::Target {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
// safety: must be called only once at startup
|
||||
pub(crate) unsafe fn init() {
|
||||
#[cfg(bdma)]
|
||||
bdma::init();
|
||||
#[cfg(dma)]
|
||||
dma::init();
|
||||
#[cfg(dmamux)]
|
||||
dmamux::init();
|
||||
}
|
||||
|
Reference in New Issue
Block a user