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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#![macro_use]
macro_rules! peri_trait {
(
$(irqs: [$($irq:ident),*],)?
) => {
#[allow(private_interfaces)]
pub(crate) trait SealedInstance {
#[allow(unused)]
fn info() -> &'static Info;
#[allow(unused)]
fn state() -> &'static State;
}
/// Peripheral instance trait.
#[allow(private_bounds)]
pub trait Instance: SealedInstance + crate::PeripheralType + crate::rcc::RccPeripheral {
$($(
/// Interrupt for this peripheral.
type $irq: crate::interrupt::typelevel::Interrupt;
)*)?
}
};
}
macro_rules! peri_trait_impl {
($instance:ident, $info:expr) => {
#[allow(private_interfaces)]
impl SealedInstance for crate::peripherals::$instance {
fn info() -> &'static Info {
static INFO: Info = $info;
&INFO
}
fn state() -> &'static State {
static STATE: State = State::new();
&STATE
}
}
impl Instance for crate::peripherals::$instance {}
};
}
macro_rules! pin_trait {
($signal:ident, $instance:path $(, $mode:path)?) => {
#[doc = concat!(stringify!($signal), " pin trait")]
pub trait $signal<T: $instance $(, M: $mode)?>: crate::gpio::Pin {
#[doc = concat!("Get the AF number needed to use this pin as ", stringify!($signal))]
fn af_num(&self) -> u8;
}
};
}
macro_rules! pin_trait_impl {
(crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $af:expr) => {
impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
};
}
#[allow(unused_macros)]
macro_rules! sel_trait_impl {
(crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $sel:expr) => {
impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$pin {
fn sel(&self) -> u8 {
$sel
}
}
};
}
// ====================
macro_rules! dma_trait {
($signal:ident, $instance:path$(, $mode:path)?) => {
#[doc = concat!(stringify!($signal), " DMA request trait")]
pub trait $signal<T: $instance $(, M: $mode)?>: crate::dma::Channel {
#[doc = concat!("Get the DMA request number needed to use this channel as", stringify!($signal))]
/// Note: in some chips, ST calls this the "channel", and calls channels "streams".
/// `embassy-stm32` always uses the "channel" and "request number" names.
fn request(&self) -> crate::dma::Request;
#[doc = "Remap the DMA channel"]
fn remap(&self);
}
};
}
#[allow(unused)]
macro_rules! dma_trait_impl {
(crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $channel:ident, $request:expr, $remap:expr) => {
impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel {
fn request(&self) -> crate::dma::Request {
$request
}
fn remap(&self) {
critical_section::with(|_| {
#[allow(unused_unsafe)]
unsafe {
$remap;
}
});
}
}
};
}
#[allow(unused)]
macro_rules! new_dma_nonopt {
($name:ident) => {{
let dma = $name;
let request = dma.request();
crate::dma::ChannelAndRequest {
channel: dma.into(),
request,
}
}};
}
macro_rules! new_dma {
($name:ident) => {{
let dma = $name;
dma.remap();
let request = dma.request();
Some(crate::dma::ChannelAndRequest {
channel: dma.into(),
request,
})
}};
}
macro_rules! new_pin {
($name:ident, $af_type:expr) => {{
let pin = $name;
pin.set_as_af(pin.af_num(), $af_type);
Some(pin.into())
}};
}
|