1#![doc = document_features::document_features!()]
5#![no_std]
6#![allow(non_camel_case_types)]
7
8use enumflags2::{BitFlag, BitFlags};
9
10pub mod pacext;
11
12pub use embedded_hal as hal;
13pub use embedded_hal_02 as hal_02;
14
15pub use nb;
16pub use nb::block;
17
18#[cfg(feature = "stm32f401")]
19pub use stm32f4::stm32f401 as pac;
21
22#[cfg(feature = "stm32f405")]
23pub use stm32f4::stm32f405 as pac;
25
26#[cfg(feature = "stm32f407")]
27pub use stm32f4::stm32f407 as pac;
29
30#[cfg(feature = "stm32f410")]
31pub use stm32f4::stm32f410 as pac;
33
34#[cfg(feature = "stm32f411")]
35pub use stm32f4::stm32f411 as pac;
37
38#[cfg(feature = "stm32f412")]
39pub use stm32f4::stm32f412 as pac;
41
42#[cfg(feature = "stm32f413")]
43pub use stm32f4::stm32f413 as pac;
45
46#[cfg(feature = "stm32f415")]
47pub use stm32f4::stm32f405 as pac;
49
50#[cfg(feature = "stm32f417")]
51pub use stm32f4::stm32f407 as pac;
53
54#[cfg(feature = "stm32f423")]
55pub use stm32f4::stm32f413 as pac;
57
58#[cfg(feature = "stm32f427")]
59pub use stm32f4::stm32f427 as pac;
61
62#[cfg(feature = "stm32f429")]
63pub use stm32f4::stm32f429 as pac;
65
66#[cfg(feature = "stm32f437")]
67pub use stm32f4::stm32f427 as pac;
69
70#[cfg(feature = "stm32f439")]
71pub use stm32f4::stm32f429 as pac;
73
74#[cfg(feature = "stm32f446")]
75pub use stm32f4::stm32f446 as pac;
77
78#[cfg(feature = "stm32f469")]
79pub use stm32f4::stm32f469 as pac;
81
82#[cfg(feature = "stm32f479")]
83pub use stm32f4::stm32f469 as pac;
85use stm32f4::Periph;
86
87pub use crate::pac::interrupt;
89
90pub mod adc;
91pub mod bb;
92#[cfg(all(feature = "can", any(feature = "can1", feature = "can2")))]
93pub mod can;
94pub mod crc32;
95#[cfg(feature = "dac")]
96pub mod dac;
97#[cfg(feature = "fmpi2c1")]
98pub mod fmpi2c;
99pub mod gpio;
100pub mod i2c;
101pub mod i2s;
102#[cfg(all(feature = "usb_fs", feature = "otg-fs"))]
103pub mod otg_fs;
104#[cfg(all(any(feature = "usb_hs", docsrs), feature = "otg-hs"))]
105pub mod otg_hs;
106
107#[cfg(feature = "rng")]
108pub mod rng;
109
110pub mod dma;
111#[cfg(feature = "dsihost")]
112pub mod dsi;
113pub mod dwt;
114pub mod flash;
115#[cfg(any(feature = "fmc", feature = "fsmc"))]
116#[cfg(feature = "stm32-fmc")]
117pub mod fmc;
118#[cfg(all(feature = "fsmc_lcd", any(feature = "fmc", feature = "fsmc")))]
119pub mod fsmc_lcd;
120#[cfg(all(feature = "dma2d", feature = "ltdc"))]
121pub mod ltdc;
122pub mod prelude;
123pub mod qei;
124#[cfg(feature = "quadspi")]
125pub mod qspi;
126pub mod rcc;
127pub mod rtc;
128#[cfg(feature = "sai")]
129pub mod sai;
130#[cfg(all(feature = "sdio-host", feature = "sdio"))]
131pub mod sdio;
132pub mod serial;
133pub mod signature;
134pub mod spi;
135pub mod syscfg;
136pub mod time;
137pub mod timer;
138pub mod watchdog;
139
140mod sealed {
141 pub trait Sealed {}
142}
143pub(crate) use sealed::Sealed;
144
145fn stripped_type_name<T>() -> &'static str {
146 let s = core::any::type_name::<T>();
147 let p = s.split("::");
148 p.last().unwrap()
149}
150
151pub trait ReadFlags {
152 type Flag: BitFlag;
154
155 fn flags(&self) -> BitFlags<Self::Flag>;
157}
158
159pub trait ClearFlags {
160 type Flag: BitFlag;
162
163 fn clear_flags(&mut self, flags: impl Into<BitFlags<Self::Flag>>);
168
169 #[inline(always)]
171 fn clear_all_flags(&mut self) {
172 self.clear_flags(BitFlags::ALL)
173 }
174}
175
176pub trait Listen {
177 type Event: BitFlag;
179
180 fn listen(&mut self, event: impl Into<BitFlags<Self::Event>>);
185
186 fn listen_only(&mut self, event: impl Into<BitFlags<Self::Event>>);
191
192 fn unlisten(&mut self, event: impl Into<BitFlags<Self::Event>>);
194
195 #[inline(always)]
197 fn listen_all(&mut self) {
198 self.listen(BitFlags::ALL)
199 }
200
201 #[inline(always)]
203 fn unlisten_all(&mut self) {
204 self.unlisten(BitFlags::ALL)
205 }
206}
207
208impl<RB, const A: usize> Sealed for Periph<RB, A> {}
209
210pub trait Ptr: Sealed {
211 type RB;
213 const PTR: *const Self::RB;
215 #[inline(always)]
217 fn ptr() -> *const Self::RB {
218 Self::PTR
219 }
220}
221
222impl<RB, const A: usize> Ptr for Periph<RB, A> {
223 type RB = RB;
224 const PTR: *const Self::RB = Self::PTR;
225}
226
227pub trait Steal: Sealed {
228 unsafe fn steal() -> Self;
242}
243
244impl<RB, const A: usize> Steal for Periph<RB, A> {
245 #[inline(always)]
246 unsafe fn steal() -> Self {
247 Self::steal()
248 }
249}
250
251#[allow(unused)]
252const fn max_u32(first: u32, second: u32) -> u32 {
253 if second > first {
254 second
255 } else {
256 first
257 }
258}
259
260const fn min_u32(first: u32, second: u32) -> u32 {
261 if second < first {
262 second
263 } else {
264 first
265 }
266}