-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathlib.rs
More file actions
281 lines (235 loc) · 8.18 KB
/
lib.rs
File metadata and controls
281 lines (235 loc) · 8.18 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//! Multi device hardware abstraction on top of the peripheral access API for the STMicro STM32F4 series microcontrollers.
//!
//! ## Feature flags
#![doc = document_features::document_features!()]
#![no_std]
#![allow(non_camel_case_types)]
use enumflags2::{BitFlag, BitFlags};
pub mod pacext;
pub use embedded_hal as hal;
pub use embedded_hal_02 as hal_02;
pub use nb;
pub use nb::block;
#[cfg(feature = "stm32f401")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f401 peripherals.
pub use stm32f4::stm32f401 as pac;
#[cfg(feature = "stm32f405")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f405 peripherals.
pub use stm32f4::stm32f405 as pac;
#[cfg(feature = "stm32f407")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f407 peripherals.
pub use stm32f4::stm32f407 as pac;
#[cfg(feature = "stm32f410")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f410 peripherals.
pub use stm32f4::stm32f410 as pac;
#[cfg(feature = "stm32f411")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f411 peripherals.
pub use stm32f4::stm32f411 as pac;
#[cfg(feature = "stm32f412")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f412 peripherals.
pub use stm32f4::stm32f412 as pac;
#[cfg(feature = "stm32f413")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f413 peripherals.
pub use stm32f4::stm32f413 as pac;
#[cfg(feature = "stm32f415")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f405 peripherals.
pub use stm32f4::stm32f405 as pac;
#[cfg(feature = "stm32f417")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f407 peripherals.
pub use stm32f4::stm32f407 as pac;
#[cfg(feature = "stm32f423")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f413 peripherals.
pub use stm32f4::stm32f413 as pac;
#[cfg(feature = "stm32f427")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f427 peripherals.
pub use stm32f4::stm32f427 as pac;
#[cfg(feature = "stm32f429")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f429 peripherals.
pub use stm32f4::stm32f429 as pac;
#[cfg(feature = "stm32f437")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f427 peripherals.
pub use stm32f4::stm32f427 as pac;
#[cfg(feature = "stm32f439")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f429 peripherals.
pub use stm32f4::stm32f429 as pac;
#[cfg(feature = "stm32f446")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f446 peripherals.
pub use stm32f4::stm32f446 as pac;
#[cfg(feature = "stm32f469")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f469 peripherals.
pub use stm32f4::stm32f469 as pac;
#[cfg(feature = "stm32f479")]
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f469 peripherals.
pub use stm32f4::stm32f469 as pac;
use stm32f4::Periph;
// Enable use of interrupt macro
pub use crate::pac::interrupt;
pub mod adc;
pub mod bb;
#[cfg(all(feature = "can", any(feature = "can1", feature = "can2")))]
pub mod can;
pub mod crc32;
#[cfg(feature = "dac")]
pub mod dac;
#[cfg(feature = "fmpi2c1")]
pub mod fmpi2c;
pub mod gpio;
pub mod i2c;
pub mod i2s;
#[cfg(all(feature = "usb_fs", feature = "otg-fs"))]
pub mod otg_fs;
#[cfg(all(any(feature = "usb_hs", docsrs), feature = "otg-hs"))]
pub mod otg_hs;
#[cfg(feature = "rng")]
pub mod rng;
pub mod dma;
#[cfg(feature = "dsihost")]
pub mod dsi;
pub mod dwt;
pub mod flash;
#[cfg(any(feature = "fmc", feature = "fsmc"))]
#[cfg(feature = "stm32-fmc")]
pub mod fmc;
#[cfg(all(feature = "fsmc_lcd", any(feature = "fmc", feature = "fsmc")))]
pub mod fsmc_lcd;
#[cfg(all(feature = "dma2d", feature = "ltdc"))]
pub mod ltdc;
pub mod prelude;
pub mod qei;
#[cfg(feature = "quadspi")]
pub mod qspi;
pub mod rcc;
pub mod rtc;
#[cfg(feature = "sai")]
pub mod sai;
#[cfg(all(feature = "sdio-host", feature = "sdio"))]
pub mod sdio;
pub mod serial;
pub mod signature;
pub mod spi;
pub mod syscfg;
pub mod time;
pub mod timer;
pub mod watchdog;
mod sealed {
pub trait Sealed {}
}
pub(crate) use sealed::Sealed;
fn stripped_type_name<T>() -> &'static str {
let s = core::any::type_name::<T>();
let p = s.split("::");
p.last().unwrap()
}
pub trait ReadFlags {
/// Enum of bit flags
type Flag: BitFlag;
/// Get all interrupts flags a once.
fn flags(&self) -> BitFlags<Self::Flag>;
}
pub trait ClearFlags {
/// Enum of manually clearable flags
type Flag: BitFlag;
/// Clear interrupts flags with `Self::Flags`s
///
/// If event flag is not cleared, it will immediately retrigger interrupt
/// after interrupt handler has finished.
fn clear_flags(&mut self, flags: impl Into<BitFlags<Self::Flag>>);
/// Clears all interrupts flags
#[inline(always)]
fn clear_all_flags(&mut self) {
self.clear_flags(BitFlags::ALL)
}
}
pub trait Listen {
/// Enum of bit flags associated with events
type Event: BitFlag;
#[doc(hidden)]
fn listen_event(
&mut self,
disable: Option<BitFlags<Self::Event>>,
enable: Option<BitFlags<Self::Event>>,
);
/// Start listening for `Event`s
///
/// Note, you will also have to enable the appropriate interrupt in the NVIC to start
/// receiving events.
#[inline(always)]
fn listen(&mut self, event: impl Into<BitFlags<Self::Event>>) {
self.listen_event(None, Some(event.into()));
}
/// Start listening for `Event`s, stop all other
///
/// Note, you will also have to enable the appropriate interrupt in the NVIC to start
/// receiving events.
#[inline(always)]
fn listen_only(&mut self, event: impl Into<BitFlags<Self::Event>>) {
self.listen_event(Some(BitFlags::ALL), Some(event.into()));
}
/// Stop listening for `Event`s
fn unlisten(&mut self, event: impl Into<BitFlags<Self::Event>>) {
self.listen_event(Some(event.into()), None);
}
/// Start listening all `Event`s
#[inline(always)]
fn listen_all(&mut self) {
self.listen(BitFlags::ALL)
}
/// Stop listening all `Event`s
#[inline(always)]
fn unlisten_all(&mut self) {
self.unlisten(BitFlags::ALL)
}
}
impl<RB, const A: usize> Sealed for Periph<RB, A> {}
pub trait Ptr: Sealed {
/// RegisterBlock structure
type RB;
/// Pointer to the register block
const PTR: *const Self::RB;
/// Return the pointer to the register block
#[inline(always)]
fn ptr() -> *const Self::RB {
Self::PTR
}
}
impl<RB, const A: usize> Ptr for Periph<RB, A> {
type RB = RB;
const PTR: *const Self::RB = Self::PTR;
}
pub trait Steal: Sealed {
/// Steal an instance of this peripheral
///
/// # Safety
///
/// Ensure that the new instance of the peripheral cannot be used in a way
/// that may race with any existing instances, for example by only
/// accessing read-only or write-only registers, or by consuming the
/// original peripheral and using critical sections to coordinate
/// access between multiple new instances.
///
/// Additionally the HAL may rely on only one
/// peripheral instance existing to ensure memory safety; ensure
/// no stolen instances are passed to such software.
unsafe fn steal() -> Self;
}
impl<RB, const A: usize> Steal for Periph<RB, A> {
#[inline(always)]
unsafe fn steal() -> Self {
Self::steal()
}
}
#[allow(unused)]
const fn max_u32(first: u32, second: u32) -> u32 {
if second > first {
second
} else {
first
}
}
const fn min_u32(first: u32, second: u32) -> u32 {
if second < first {
second
} else {
first
}
}