1
1
use crate :: svd:: { array:: names, Device , Peripheral } ;
2
2
use proc_macro2:: { Span , TokenStream } ;
3
3
use quote:: { quote, ToTokens } ;
4
- use regex:: Regex ;
5
- use syn:: Ident ;
6
4
7
5
use log:: debug;
8
6
use std:: fs:: File ;
@@ -272,22 +270,8 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
272
270
}
273
271
}
274
272
275
- // Generate unique identifier to prevent linkage errors when using multiple devices.
276
- let mut id = String :: from ( "TAKEN_" ) ;
277
- let re = Regex :: new ( r"[^A-Za-z0-9_]" ) . unwrap ( ) ;
278
- let result = re. replace_all ( & d. name , "_" ) ;
279
- for ch in result. chars ( ) {
280
- id. extend ( ch. to_uppercase ( ) ) ;
281
- }
282
-
283
- let taken: Ident = syn:: parse_str ( & id) ?;
284
-
285
273
out. extend ( quote ! {
286
- // NOTE `no_mangle` is used here to prevent linking different minor versions of the device
287
- // crate as that would let you `take` the device peripherals more than once (one per minor
288
- // version)
289
- #[ no_mangle]
290
- static mut #taken: bool = false ;
274
+ static mut DEVICE_PERIPHERALS : bool = false ;
291
275
292
276
/// All the peripherals.
293
277
#[ allow( non_snake_case) ]
@@ -302,12 +286,12 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
302
286
pub fn take( ) -> Option <Self > {
303
287
critical_section:: with( |_| {
304
288
// SAFETY: We are in a critical section, so we have exclusive access
305
- // to `#taken `.
306
- if unsafe { #taken } {
289
+ // to `DEVICE_PERIPHERALS `.
290
+ if unsafe { DEVICE_PERIPHERALS } {
307
291
return None
308
292
}
309
293
310
- // SAFETY: `#taken ` is set to `true` by `Peripherals::steal`,
294
+ // SAFETY: `DEVICE_PERIPHERALS ` is set to `true` by `Peripherals::steal`,
311
295
// ensuring the peripherals can only be returned once.
312
296
Some ( unsafe { Peripherals :: steal( ) } )
313
297
} )
@@ -320,7 +304,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
320
304
/// Each of the returned peripherals must be used at most once.
321
305
#[ inline]
322
306
pub unsafe fn steal( ) -> Self {
323
- #taken = true ;
307
+ DEVICE_PERIPHERALS = true ;
324
308
325
309
Peripherals {
326
310
#exprs
0 commit comments