aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/dma/mod.rs
blob: 4f1a58ae2133bf4a71dcb7615d159f39f7bf537c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#[cfg(dma)]
pub(crate) mod dma;
#[cfg(dma)]
pub use dma::*;

// stm32h7 has both dma and bdma. In that case, we export dma as "main" dma,
// and bdma as "secondary", under `embassy_stm32::dma::bdma`.
#[cfg(all(bdma, dma))]
pub mod bdma;

#[cfg(all(bdma, not(dma)))]
pub(crate) mod bdma;
#[cfg(all(bdma, not(dma)))]
pub use bdma::*;

#[cfg(gpdma)]
pub(crate) mod gpdma;
#[cfg(gpdma)]
pub use gpdma::*;

#[cfg(dmamux)]
mod dmamux;

pub(crate) mod ringbuffer;
pub mod word;

use core::mem;

use embassy_hal_internal::impl_peripheral;

#[cfg(dmamux)]
pub use self::dmamux::*;
use crate::interrupt::Priority;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
enum Dir {
    MemoryToPeripheral,
    PeripheralToMemory,
}

pub struct NoDma;

impl_peripheral!(NoDma);

// TODO: replace transmutes with core::ptr::metadata once it's stable
#[allow(unused)]
pub(crate) fn slice_ptr_parts<T>(slice: *const [T]) -> (usize, usize) {
    unsafe { mem::transmute(slice) }
}

#[allow(unused)]
pub(crate) fn slice_ptr_parts_mut<T>(slice: *mut [T]) -> (usize, usize) {
    unsafe { mem::transmute(slice) }
}

// safety: must be called only once at startup
pub(crate) unsafe fn init(
    #[cfg(bdma)] bdma_priority: Priority,
    #[cfg(dma)] dma_priority: Priority,
    #[cfg(gpdma)] gpdma_priority: Priority,
) {
    #[cfg(bdma)]
    bdma::init(bdma_priority);
    #[cfg(dma)]
    dma::init(dma_priority);
    #[cfg(gpdma)]
    gpdma::init(gpdma_priority);
    #[cfg(dmamux)]
    dmamux::init();
}