aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/dma/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/dma/mod.rs')
-rw-r--r--embassy-stm32/src/dma/mod.rs34
1 files changed, 30 insertions, 4 deletions
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index 5989bfd7c..05d9c2e51 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -3,6 +3,7 @@
3 3
4#[cfg(any(bdma, dma))] 4#[cfg(any(bdma, dma))]
5mod dma_bdma; 5mod dma_bdma;
6
6#[cfg(any(bdma, dma))] 7#[cfg(any(bdma, dma))]
7pub use dma_bdma::*; 8pub use dma_bdma::*;
8 9
@@ -24,9 +25,10 @@ pub(crate) use util::*;
24pub(crate) mod ringbuffer; 25pub(crate) mod ringbuffer;
25pub mod word; 26pub mod word;
26 27
27use embassy_hal_internal::{impl_peripheral, PeripheralType}; 28use embassy_hal_internal::{PeripheralType, impl_peripheral};
28 29
29use crate::interrupt; 30use crate::interrupt;
31use crate::rcc::StoppablePeripheral;
30 32
31/// The direction of a DMA transfer. 33/// The direction of a DMA transfer.
32#[derive(Debug, Copy, Clone, PartialEq, Eq)] 34#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -45,7 +47,7 @@ pub type Request = u8;
45#[cfg(not(any(dma_v2, bdma_v2, gpdma, dmamux)))] 47#[cfg(not(any(dma_v2, bdma_v2, gpdma, dmamux)))]
46pub type Request = (); 48pub type Request = ();
47 49
48pub(crate) trait SealedChannel { 50pub(crate) trait SealedChannel: StoppablePeripheral {
49 fn id(&self) -> u8; 51 fn id(&self) -> u8;
50} 52}
51 53
@@ -59,15 +61,28 @@ pub(crate) trait ChannelInterrupt {
59pub trait Channel: SealedChannel + PeripheralType + Into<AnyChannel> + 'static {} 61pub trait Channel: SealedChannel + PeripheralType + Into<AnyChannel> + 'static {}
60 62
61macro_rules! dma_channel_impl { 63macro_rules! dma_channel_impl {
62 ($channel_peri:ident, $index:expr) => { 64 ($channel_peri:ident, $index:expr, $stop_mode:ident) => {
65 impl crate::rcc::StoppablePeripheral for crate::peripherals::$channel_peri {
66 #[cfg(feature = "low-power")]
67 fn stop_mode(&self) -> crate::rcc::StopMode {
68 crate::rcc::StopMode::$stop_mode
69 }
70 }
71
63 impl crate::dma::SealedChannel for crate::peripherals::$channel_peri { 72 impl crate::dma::SealedChannel for crate::peripherals::$channel_peri {
64 fn id(&self) -> u8 { 73 fn id(&self) -> u8 {
65 $index 74 $index
66 } 75 }
67 } 76 }
77
68 impl crate::dma::ChannelInterrupt for crate::peripherals::$channel_peri { 78 impl crate::dma::ChannelInterrupt for crate::peripherals::$channel_peri {
69 unsafe fn on_irq() { 79 unsafe fn on_irq() {
70 crate::dma::AnyChannel { id: $index }.on_irq(); 80 crate::dma::AnyChannel {
81 id: $index,
82 #[cfg(feature = "low-power")]
83 stop_mode: crate::rcc::StopMode::$stop_mode,
84 }
85 .on_irq();
71 } 86 }
72 } 87 }
73 88
@@ -77,6 +92,8 @@ macro_rules! dma_channel_impl {
77 fn from(val: crate::peripherals::$channel_peri) -> Self { 92 fn from(val: crate::peripherals::$channel_peri) -> Self {
78 Self { 93 Self {
79 id: crate::dma::SealedChannel::id(&val), 94 id: crate::dma::SealedChannel::id(&val),
95 #[cfg(feature = "low-power")]
96 stop_mode: crate::rcc::StoppablePeripheral::stop_mode(&val),
80 } 97 }
81 } 98 }
82 } 99 }
@@ -86,6 +103,8 @@ macro_rules! dma_channel_impl {
86/// Type-erased DMA channel. 103/// Type-erased DMA channel.
87pub struct AnyChannel { 104pub struct AnyChannel {
88 pub(crate) id: u8, 105 pub(crate) id: u8,
106 #[cfg(feature = "low-power")]
107 pub(crate) stop_mode: crate::rcc::StopMode,
89} 108}
90impl_peripheral!(AnyChannel); 109impl_peripheral!(AnyChannel);
91 110
@@ -95,6 +114,13 @@ impl AnyChannel {
95 } 114 }
96} 115}
97 116
117impl StoppablePeripheral for AnyChannel {
118 #[cfg(feature = "low-power")]
119 fn stop_mode(&self) -> crate::rcc::StopMode {
120 self.stop_mode
121 }
122}
123
98impl SealedChannel for AnyChannel { 124impl SealedChannel for AnyChannel {
99 fn id(&self) -> u8 { 125 fn id(&self) -> u8 {
100 self.id 126 self.id