1#![macro_use]
2#![allow(unused_macros)]
3
4macro_rules! dma_trait {
5 ($signal:ident, $instance:path$(, $mode:path)?) => {
6 #[doc = concat!(stringify!($signal), " DMA request trait")]
7 pub trait $signal<T: $instance $(, M: $mode)?>: crate::dma::Channel {
8 #[doc = concat!("Get the DMA request number needed to use this channel as", stringify!($signal))]
9 fn request(&self) -> crate::dma::Request;
12 }
13 };
14}
15
16macro_rules! pin_trait {
29 ($signal:ident, $instance:path) => {
30 #[cfg(not(afio_h4))]
31 pub trait $signal<T: $instance, const REMAP: u8 = 0>: crate::gpio::Pin {}
32
33 #[cfg(afio_h4)]
34 pub trait $signal<T: $instance>: crate::gpio::Pin {
35 #[doc = concat!("AF number for `", stringify!($signal), "`.")]
36 fn af_num(&self) -> u8;
37 }
38 };
39}
40
41macro_rules! pin_trait_impl {
42 (crate::$mod:ident::$trait:ident, $instance:ident, $pin:ident, $n:expr) => {
43 #[cfg(not(afio_h4))]
44 impl crate::$mod::$trait<crate::peripherals::$instance, $n> for crate::peripherals::$pin {}
45
46 #[cfg(afio_h4)]
47 impl crate::$mod::$trait<crate::peripherals::$instance> for crate::peripherals::$pin {
48 fn af_num(&self) -> u8 {
49 $n
50 }
51 }
52 };
53}
54
55macro_rules! mco_pin_impl {
58 ($pin:ident, $n:expr) => {
59 #[cfg(not(afio_h4))]
60 impl crate::rcc::McoPin for crate::peripherals::$pin {}
61
62 #[cfg(afio_h4)]
63 impl crate::rcc::McoPin for crate::peripherals::$pin {
64 fn af_num(&self) -> u8 {
65 $n
66 }
67 }
68 };
69}
70
71#[cfg(not(afio_h4))]
72macro_rules! if_remap {
73 ($($t:tt)*) => {
74 $($t)*
75 };
76}
77
78#[cfg(afio_h4)]
79macro_rules! if_remap {
80 (impl $trait:ident<$a:ty, REMAP>) => {
81 impl $trait<$a>
82 };
83 (impl $trait:ident<$a:ty, $b:ty, REMAP>) => {
84 impl $trait<$a, $b>
85 };
86}
87
88macro_rules! apply_remap {
91 () => {
92 #[cfg(not(afio_h4))]
93 {
94 fn apply<P: crate::peripheral::RemapPeripheral, const R: u8>() {
95 P::set_remap(R);
96 }
97 apply::<T, REMAP>();
98 }
99 };
100}
101
102macro_rules! new_pin {
108 ($name:ident, $af_type:expr) => {{
109 let pin = $name;
110 pin.set_as_af(
111 #[cfg(afio_h4)]
112 pin.af_num(),
113 $af_type,
114 );
115 Some(pin.into())
116 }};
117}
118
119macro_rules! set_as_af {
121 ($pin:expr, $af_type:expr) => {{
122 $pin.set_as_af(
123 #[cfg(afio_h4)]
124 $pin.af_num(),
125 $af_type,
126 );
127 }};
128}
129
130#[allow(unused)]
131macro_rules! dma_trait_impl {
132 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {channel: $channel:ident}, $request:expr) => {
135 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel {
136 fn request(&self) -> crate::dma::Request {
137 $request
138 }
139 }
140 };
141 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => {
147 impl<C> crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for C
148 where
149 C: crate::dma::MuxChannel + crate::dma::Channel,
150 {
151 fn request(&self) -> crate::dma::Request {
152 $request
153 }
154 }
155 };
156}
157
158macro_rules! new_dma {
159 ($name:ident) => {{
160 let request = $name.request();
161 Some(crate::dma::ChannelAndRequest {
162 channel: $name.into(),
163 request,
164 })
165 }};
166}
167
168#[collapse_debuginfo(yes)]
169macro_rules! panic {
170 ($($x:tt)*) => {
171 {
172 #[cfg(not(feature = "defmt"))]
173 ::core::panic!($($x)*);
174 #[cfg(feature = "defmt")]
175 ::defmt::panic!($($x)*);
176 }
177 };
178}
179
180#[collapse_debuginfo(yes)]
181macro_rules! trace {
182 ($s:literal $(, $x:expr)* $(,)?) => {
183 {
184 #[cfg(feature = "defmt")]
185 ::defmt::trace!($s $(, $x)*);
186 #[cfg(not(feature = "defmt"))]
187 let _ = ($( & $x ),*);
188 }
189 };
190}
191
192#[collapse_debuginfo(yes)]
193macro_rules! debug {
194 ($s:literal $(, $x:expr)* $(,)?) => {
195 {
196 #[cfg(feature = "defmt")]
197 ::defmt::debug!($s $(, $x)*);
198 #[cfg(not(feature = "defmt"))]
199 let _ = ($( & $x ),*);
200 }
201 };
202}
203
204#[collapse_debuginfo(yes)]
205macro_rules! info {
206 ($s:literal $(, $x:expr)* $(,)?) => {
207 {
208 #[cfg(feature = "defmt")]
209 ::defmt::info!($s $(, $x)*);
210 #[cfg(not(feature = "defmt"))]
211 let _ = ($( & $x ),*);
212 }
213 };
214}
215
216#[collapse_debuginfo(yes)]
217macro_rules! warn {
218 ($s:literal $(, $x:expr)* $(,)?) => {
219 {
220 #[cfg(feature = "defmt")]
221 ::defmt::warn!($s $(, $x)*);
222 #[cfg(not(feature = "defmt"))]
223 let _ = ($( & $x ),*);
224 }
225 };
226}
227
228#[collapse_debuginfo(yes)]
229macro_rules! error {
230 ($s:literal $(, $x:expr)* $(,)?) => {
231 {
232 #[cfg(feature = "defmt")]
233 ::defmt::error!($s $(, $x)*);
234 #[cfg(not(feature = "defmt"))]
235 let _ = ($( & $x ),*);
236 }
237 };
238}
239
240#[collapse_debuginfo(yes)]
241macro_rules! unwrap {
242 ($e:expr) => {{
243 #[cfg(feature = "defmt")]
244 {
245 ::defmt::unwrap!($e)
246 }
247 #[cfg(not(feature = "defmt"))]
248 {
249 $e.unwrap()
250 }
251 }};
252}