imxrt_ral/
lib.rs

1# ! [doc = include_str ! ("../doc.md")]
2#![no_std]
3#![allow(
4    non_camel_case_types,
5    non_snake_case,
6    non_upper_case_globals,
7    clippy::self_named_constructors,
8    clippy::module_inception
9)]
10pub use ral_registers::{modify_reg, read_reg, write_reg, RORegister, RWRegister, WORegister};
11#[doc = r" An owned peripheral of type `T`, instance `N`."]
12#[doc = r""]
13#[doc = r" Fabricating an `Instance` is always `unsafe`. An owner of an"]
14#[doc = r" `Instance` may assume that"]
15#[doc = r""]
16#[doc = r" - the underlying pointer points to a static register block of type `T`."]
17#[doc = r" - the instance number `N` properly describes the peripheral instance."]
18#[doc = r" - they own _all_ registers pointed at by `T`."]
19#[doc = r""]
20#[doc = r" Owners use this guarantee to safely access the peripheral registers."]
21#[doc = r" However, nothing guarantees any of these except for your diligence."]
22#[doc = r""]
23#[doc = r" Constructing an `Instance` is zero cost. Additionally, `Instance` is transparent"]
24#[doc = r" and amenable to null-pointer optimizations."]
25#[doc = r""]
26#[doc = r" See the package-level documentation for more information on fabricating"]
27#[doc = r" instances."]
28#[doc = r""]
29#[doc = r" # Safety of `new()`."]
30#[doc = r""]
31#[doc = r" By calling `new()`, you claim"]
32#[doc = r""]
33#[doc = r" 1. `ptr` points to static memory that can be described by a type `T`."]
34#[doc = r" 2. The instance number `N` correctly describes `ptr`."]
35#[doc = r" 3. You are becoming the sole owner of this instance."]
36#[doc = r""]
37#[doc = r" # Safety of `instance()`"]
38#[doc = r""]
39#[doc = r" The various `instance()` methods handle safety concerns 1 and 2 from `new()`."]
40#[doc = r" By their construction, each `instance()` implementation provides a pointer to valid"]
41#[doc = r" peripheral memory, and associates the correct `N` with that pointer. Therefore,"]
42#[doc = r" you're only responsible for ensuring safety concern 3 from `new()`."]
43#[repr(transparent)]
44pub struct Instance<T, const N: u8> {
45    ptr: core::ptr::NonNull<T>,
46}
47impl<T, const N: u8> core::ops::Deref for Instance<T, N> {
48    type Target = T;
49    #[inline]
50    fn deref(&self) -> &Self::Target {
51        unsafe { self.ptr.as_ref() }
52    }
53}
54impl<T, const N: u8> Instance<T, N> {
55    #[doc = r" Create an arbitrary `Instance` from a pointer to `T`."]
56    #[doc = r""]
57    #[doc = r" # Safety"]
58    #[doc = r""]
59    #[doc = r" See [the struct docs](Instance) for the safety contract."]
60    #[inline]
61    pub const unsafe fn new(ptr: *const T) -> Self {
62        Self {
63            ptr: core::ptr::NonNull::new_unchecked(ptr as *mut _),
64        }
65    }
66}
67unsafe impl<T, const N: u8> Send for Instance<T, N> {}
68#[doc = r" The instance number for a peripheral singleton."]
69#[doc = r""]
70#[doc = r" If your peripheral only has one instance, it's given"]
71#[doc = r" this number. The CCM peripheral is a good example of"]
72#[doc = r" a peripheral that uses this constant."]
73#[doc = r""]
74#[doc = r" See the package documentation for more information on"]
75#[doc = r" this constant."]
76pub const SOLE_INSTANCE: u8 = 0u8;
77mod private {
78    pub trait Sealed {}
79}
80#[doc = r" Vouches for an `Instance<T, N>`'s validity."]
81#[doc = r""]
82#[doc = r" This trait is implemented for all `Instance<T, N>` supported"]
83#[doc = r" by your chip. Note that the implementation may change when"]
84#[doc = r" selecting new chip features. For instance, i.MX RT 1011 chips"]
85#[doc = r" do not have LPUART 4 through 8. So, `Valid` is _not_ implemented"]
86#[doc = r" for `lpuart::Instance<4>` through `lpuart::Instance<8>`."]
87#[doc = r""]
88#[doc = r" See the package documentation for more information on how"]
89#[doc = r" to use this trait in your APIs."]
90pub trait Valid: private::Sealed {}
91#[cfg(feature = "imxrt1011")]
92#[path = "imxrt1011.rs"]
93mod imxrt1011;
94#[cfg(feature = "imxrt1011")]
95pub use imxrt1011::*;
96#[cfg(feature = "imxrt1015")]
97#[path = "imxrt1015.rs"]
98mod imxrt1015;
99#[cfg(feature = "imxrt1015")]
100pub use imxrt1015::*;
101#[cfg(feature = "imxrt1021")]
102#[path = "imxrt1021.rs"]
103mod imxrt1021;
104#[cfg(feature = "imxrt1021")]
105pub use imxrt1021::*;
106#[cfg(feature = "imxrt1051")]
107#[path = "imxrt1051.rs"]
108mod imxrt1051;
109#[cfg(feature = "imxrt1051")]
110pub use imxrt1051::*;
111#[cfg(feature = "imxrt1052")]
112#[path = "imxrt1052.rs"]
113mod imxrt1052;
114#[cfg(feature = "imxrt1052")]
115pub use imxrt1052::*;
116#[cfg(feature = "imxrt1061")]
117#[path = "imxrt1061.rs"]
118mod imxrt1061;
119#[cfg(feature = "imxrt1061")]
120pub use imxrt1061::*;
121#[cfg(feature = "imxrt1062")]
122#[path = "imxrt1062.rs"]
123mod imxrt1062;
124#[cfg(feature = "imxrt1062")]
125pub use imxrt1062::*;
126#[cfg(feature = "imxrt1064")]
127#[path = "imxrt1064.rs"]
128mod imxrt1064;
129#[cfg(feature = "imxrt1064")]
130pub use imxrt1064::*;
131#[cfg(feature = "imxrt1176_cm4")]
132#[path = "imxrt1176_cm4.rs"]
133mod imxrt1176_cm4;
134#[cfg(feature = "imxrt1176_cm4")]
135pub use imxrt1176_cm4::*;
136#[cfg(feature = "imxrt1176_cm7")]
137#[path = "imxrt1176_cm7.rs"]
138mod imxrt1176_cm7;
139#[cfg(feature = "imxrt1176_cm7")]
140pub use imxrt1176_cm7::*;