1#![macro_use]
7
8use embassy_hal_internal::{impl_peripheral, Peripheral};
9
10mod dma;
11pub use dma::*;
12
13mod util;
14pub(crate) use util::*;
15
16pub(crate) mod ringbuffer;
17pub mod word;
18
19pub use crate::_generated::Request;
20pub(crate) trait SealedChannel {
21 fn id(&self) -> u8;
22}
23
24pub(crate) trait ChannelInterrupt {
25 #[cfg_attr(not(feature = "rt"), allow(unused))]
26 unsafe fn on_irq();
27}
28
29#[allow(private_bounds)]
31pub trait Channel: SealedChannel + Peripheral<P = Self> + Into<AnyChannel> + 'static {
32 #[inline]
38 fn degrade(self) -> AnyChannel {
39 AnyChannel { id: self.id() }
40 }
41}
42
43pub struct AnyChannel {
45 pub(crate) id: u8,
46}
47impl_peripheral!(AnyChannel);
48
49impl AnyChannel {
51 fn info(&self) -> ChannelInfo {
52 ChannelInfo { dma: crate::pac::DMAC1, num: self.id as _ }
53 }
54}
55
56impl SealedChannel for AnyChannel {
57 fn id(&self) -> u8 {
58 self.id
59 }
60}
61
62macro_rules! dma_channel_impl {
63 ($channel_peri:ident, $index:expr) => {
64 impl crate::dma::SealedChannel for crate::peripherals::$channel_peri {
65 fn id(&self) -> u8 {
66 $index
67 }
68 }
69 impl crate::dma::ChannelInterrupt for crate::peripherals::$channel_peri {
70 unsafe fn on_irq() {
71 crate::dma::AnyChannel { id: $index }.on_irq();
72 }
73 }
74
75 impl crate::dma::Channel for crate::peripherals::$channel_peri {}
76
77 impl From<crate::peripherals::$channel_peri> for crate::dma::AnyChannel {
78 fn from(x: crate::peripherals::$channel_peri) -> Self {
79 crate::dma::Channel::degrade(x)
80 }
81 }
82 };
83}
84
85impl Channel for AnyChannel {}
86
87use crate::_generated::CHANNEL_COUNT;
88static STATE: [dma::ChannelState; CHANNEL_COUNT] = [dma::ChannelState::NEW; CHANNEL_COUNT];
89
90pub(crate) unsafe fn init(cs: critical_section::CriticalSection) {
91 dma::init(cs);
92}
93
94pub struct NoDma;
102
103impl_peripheral!(NoDma);
104
105
106