n32g4xx_hal/
lib.rs

1//! Multi device hardware abstraction on top of the peripheral access API for the Nations Technologies N32G4 series microcontrollers.
2//!
3//! ## Feature flags
4// #![doc = document_features::document_features!()]
5#![no_std]
6#![allow(non_camel_case_types)]
7#![feature(associated_type_defaults)]
8#![feature(impl_trait_in_assoc_type)]
9#![feature(negative_impls)]
10#![feature(min_specialization)]
11#![feature(macro_metavar_expr)]
12#![feature(more_qualified_paths)]
13#![feature(adt_const_params)]
14#![feature(trivial_bounds)]
15
16use enumflags2::{BitFlag, BitFlags};
17
18pub use embedded_hal as hal;
19pub use embedded_hal_02 as hal_02;
20
21pub use nb;
22pub use nb::block;
23
24#[cfg(feature = "n32g401")]
25/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g401 peripherals.
26pub use n32g4::n32g401 as pac;
27
28#[cfg(feature = "n32g432")]
29/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g432 peripherals.
30pub use n32g4::n32g432 as pac;
31
32#[cfg(feature = "n32g435")]
33/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g435 peripherals.
34pub use n32g4::n32g435 as pac;
35
36#[cfg(feature = "n32g451")]
37/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g451 peripherals.
38pub use n32g4::n32g451 as pac;
39
40#[cfg(feature = "n32g452")]
41/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g452 peripherals.
42pub use n32g4::n32g452 as pac;
43
44#[cfg(feature = "n32g455")]
45/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g455 peripherals.
46pub use n32g4::n32g455 as pac;
47
48#[cfg(feature = "n32g457")]
49/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g457 peripherals.
50pub use n32g4::n32g457 as pac;
51
52#[cfg(feature = "n32g4fr")]
53/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the n32g4fr peripherals.
54pub use n32g4::n32g4fr as pac;
55
56pub mod adc;
57pub mod afio;
58pub mod bb;
59#[cfg(any(feature = "n32g451",feature = "n32g452",feature = "n32g455",feature = "n32g457",feature = "n32g4fr"))]
60pub mod bkp;
61pub mod can;
62pub mod crc;
63pub mod delay;
64pub mod dma;
65pub mod fmc;
66pub mod gpio;
67pub mod i2c;
68pub mod pwm;
69pub mod sac;
70pub mod serial;
71pub mod spi;
72pub mod rcc;
73pub mod time;
74pub mod timer;
75pub mod prelude;
76pub mod pwr;
77pub mod usb;
78mod sealed {
79pub trait Sealed {}
80}
81pub(crate) use sealed::Sealed;
82
83fn stripped_type_name<T>() -> &'static str {
84    let s = core::any::type_name::<T>();
85    let p = s.split("::");
86    p.last().unwrap()
87}
88
89pub trait ReadFlags {
90    /// Enum of bit flags
91    type Flag: BitFlag;
92
93    /// Get all interrupts flags a once.
94    fn flags(&self) -> BitFlags<Self::Flag>;
95}
96
97pub trait ClearFlags {
98    /// Enum of manually clearable flags
99    type Flag: BitFlag;
100
101    /// Clear interrupts flags with `Self::Flags`s
102    ///
103    /// If event flag is not cleared, it will immediately retrigger interrupt
104    /// after interrupt handler has finished.
105    fn clear_flags(&mut self, flags: impl Into<BitFlags<Self::Flag>>);
106
107    /// Clears all interrupts flags
108    #[inline(always)]
109    fn clear_all_flags(&mut self) {
110        self.clear_flags(BitFlags::ALL)
111    }
112}
113
114pub trait Listen {
115    /// Enum of bit flags associated with events
116    type Event: BitFlag;
117
118    /// Start listening for `Event`s
119    ///
120    /// Note, you will also have to enable the appropriate interrupt in the NVIC to start
121    /// receiving events.
122    fn listen(&mut self, event: impl Into<BitFlags<Self::Event>>);
123
124    /// Start listening for `Event`s, stop all other
125    ///
126    /// Note, you will also have to enable the appropriate interrupt in the NVIC to start
127    /// receiving events.
128    fn listen_only(&mut self, event: impl Into<BitFlags<Self::Event>>);
129
130    /// Stop listening for `Event`s
131    fn unlisten(&mut self, event: impl Into<BitFlags<Self::Event>>);
132
133    /// Start listening all `Event`s
134    #[inline(always)]
135    fn listen_all(&mut self) {
136        self.listen(BitFlags::ALL)
137    }
138
139    /// Stop listening all `Event`s
140    #[inline(always)]
141    fn unlisten_all(&mut self) {
142        self.unlisten(BitFlags::ALL)
143    }
144}
145