stm32f1_hal/common/mod.rs
1//! We use the [`mutex-traits`](https://crates.io/crates/mutex-traits) crate to provide mutex functionality.
2//! You need to select an appropriate mutex implementation based on your needs.
3//!
4//! And you can implement your own mutex by implementing the `RawMutex` trait from the `mutex-traits` crate.
5//!
6//! ```
7//! use stm32f1_hal::mutex;
8//! cfg_if::cfg_if! {
9//! if #[cfg(feature = "std")] {
10//! use mutex::StdRawMutex;
11//! type Mutex<T> = mutex::Mutex<StdRawMutex, T>;
12//! } else {
13//! use mutex::FakeRawMutex;
14//! type Mutex<T> = mutex::Mutex<FakeRawMutex, T>;
15//! }
16//! }
17//!
18//! let mutex = Mutex::<u32>::new(0);
19//!
20//! let mut guard = mutex.try_lock().unwrap();
21//! assert_eq!(*guard, 0);
22//! *guard = 4;
23//! drop(guard);
24//!
25//! mutex
26//! .try_with_lock(|data| {
27//! assert_eq!(*data, 4);
28//! *data = 5;
29//! })
30//! .unwrap();
31//! ```
32
33pub mod dma;
34pub mod os;
35pub mod ringbuf;
36pub mod simplest_heap;
37pub mod timer;
38pub mod uart;
39pub mod wrap_trait;
40
41cfg_if::cfg_if! {
42 if #[cfg(all(feature = "std", not(feature = "custom-std-mutex")))] {
43 pub mod std_mutex;
44 pub use std_mutex as mutex;
45 } else {
46 pub mod mutex;
47 }
48}