embassy/embassy-stm32/src/dma/mod.rs

86 lines
1.8 KiB
Rust
Raw Normal View History

2021-07-15 05:42:06 +02:00
#[cfg(bdma)]
mod bdma;
#[cfg(dma)]
mod dma;
#[cfg(dmamux)]
mod dmamux;
2021-05-16 02:57:46 +02:00
#[cfg(dmamux)]
pub use dmamux::*;
2021-07-15 05:42:06 +02:00
use core::future::Future;
2021-09-29 00:59:11 +02:00
use core::task::Waker;
2021-07-15 05:42:06 +02:00
use embassy::util::Unborrow;
2021-07-15 05:42:06 +02:00
#[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>;
fn write_x<'a>(
&'a mut self,
request: Request,
word: &u8,
num: usize,
dst: *mut u8,
) -> Self::WriteFuture<'a>;
2021-09-29 00:59:11 +02:00
2021-09-30 03:19:01 +02:00
/// Stops this channel.
2021-09-29 00:59:11 +02:00
fn stop<'a>(&'a mut self);
2021-09-30 03:19:01 +02:00
/// Returns whether this channel is active or stopped.
2021-09-29 00:59:11 +02:00
fn is_stopped<'a>(&self) -> bool;
2021-09-30 03:19:01 +02:00
/// Returns the total number of remaining transfers .
fn remaining_transfers<'a>(&'a mut self) -> u16;
2021-09-30 03:19:01 +02:00
/// Sets the waker that is called when this channel completes/
2021-09-29 00:59:11 +02:00
fn set_waker(&mut self, waker: &Waker);
2021-09-30 03:19:01 +02:00
/// Starts this channel.
fn start<'a>(&'a mut self, request: Request, buf: &'a [u8], dst: *mut u8);
2021-07-15 05:42:06 +02:00
}
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();
}