@@ -53,6 +53,25 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
53
53
feature_attribute. extend ( quote ! { #[ cfg( feature = #feature_name) ] } ) ;
54
54
} ;
55
55
56
+ let steal_fn = quote ! {
57
+ /// Steal an instance of this peripheral
58
+ ///
59
+ /// # Safety
60
+ ///
61
+ /// Ensure that the new instance of the peripheral cannot be used in a way
62
+ /// that may race with any existing instances, for example by only
63
+ /// accessing read-only or write-only registers, or by consuming the
64
+ /// original peripheral and using critical sections to coordinate
65
+ /// access between multiple new instances.
66
+ ///
67
+ /// Additionally, other software such as HALs may rely on only one
68
+ /// peripheral instance existing to ensure memory safety; ensure
69
+ /// no stolen instances are passed to such software.
70
+ pub unsafe fn steal( ) -> Self {
71
+ Self { _marker: PhantomData }
72
+ }
73
+ } ;
74
+
56
75
match & p {
57
76
Peripheral :: Array ( p, dim) => {
58
77
let names: Vec < Cow < str > > = names ( p, dim) . map ( |n| n. into ( ) ) . collect ( ) ;
@@ -91,6 +110,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
91
110
pub const fn ptr( ) -> * const #base:: RegisterBlock {
92
111
Self :: PTR
93
112
}
113
+
114
+ #steal_fn
94
115
}
95
116
96
117
#feature_attribute_n
@@ -150,6 +171,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
150
171
pub const fn ptr( ) -> * const #base:: RegisterBlock {
151
172
Self :: PTR
152
173
}
174
+
175
+ #steal_fn
153
176
}
154
177
155
178
#feature_attribute
0 commit comments