@@ -53,6 +53,25 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
5353 feature_attribute. extend ( quote ! { #[ cfg( feature = #feature_name) ] } ) ;
5454 } ;
5555
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+
5675 match & p {
5776 Peripheral :: Array ( p, dim) => {
5877 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
91110 pub const fn ptr( ) -> * const #base:: RegisterBlock {
92111 Self :: PTR
93112 }
113+
114+ #steal_fn
94115 }
95116
96117 #feature_attribute_n
@@ -150,6 +171,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
150171 pub const fn ptr( ) -> * const #base:: RegisterBlock {
151172 Self :: PTR
152173 }
174+
175+ #steal_fn
153176 }
154177
155178 #feature_attribute
0 commit comments