@@ -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 ( ) ;
@@ -92,22 +111,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
92
111
Self :: PTR
93
112
}
94
113
95
- ///Steal an instance of this peripheral
96
- ///
97
- ///# Safety
98
- ///
99
- /// Ensure that the new instance of the peripheral cannot be used in a way
100
- /// that may race with any existing instances, for example by only
101
- /// accessing read-only or write-only registers, or by consuming the
102
- /// original peripheral and using critical sections to coordinate
103
- /// access between multiple new instances.
104
- ///
105
- /// Additionally, other software such as HALs may rely on only one
106
- /// peripheral instance existing to ensure memory safety; ensure
107
- /// no stolen instances are passed to such software.
108
- pub unsafe fn steal( ) -> Self {
109
- Self { _marker: PhantomData }
110
- }
114
+ #steal_fn
111
115
}
112
116
113
117
#feature_attribute_n
@@ -168,22 +172,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
168
172
Self :: PTR
169
173
}
170
174
171
- ///Steal an instance of this peripheral
172
- ///
173
- ///# Safety
174
- ///
175
- /// Ensure that the new instance of the peripheral cannot be used in a way
176
- /// that may race with any existing instances, for example by only
177
- /// accessing read-only or write-only registers, or by consuming the
178
- /// original peripheral and using critical sections to coordinate
179
- /// access between multiple new instances.
180
- ///
181
- /// Additionally, other software such as HALs may rely on only one
182
- /// peripheral instance existing to ensure memory safety; ensure
183
- /// no stolen instances are passed to such software.
184
- pub unsafe fn steal( ) -> Self {
185
- Self { _marker: PhantomData }
186
- }
175
+ #steal_fn
187
176
}
188
177
189
178
#feature_attribute
0 commit comments