@@ -3,8 +3,8 @@ use std::cmp::Ordering;
3
3
use std:: collections:: HashMap ;
4
4
5
5
use crate :: svd:: {
6
- Cluster , ClusterInfo , DeriveFrom , DimElement , Peripheral , Register , RegisterCluster ,
7
- RegisterProperties ,
6
+ array :: names , Cluster , ClusterInfo , DeriveFrom , DimElement , Peripheral , Register ,
7
+ RegisterCluster , RegisterProperties ,
8
8
} ;
9
9
use log:: { debug, trace, warn} ;
10
10
use proc_macro2:: { Ident , Punct , Spacing , Span , TokenStream } ;
@@ -43,52 +43,100 @@ pub fn render(
43
43
return Ok ( out) ;
44
44
}
45
45
46
+ let name = util:: name_of ( p, config. ignore_groups ) ;
46
47
let span = Span :: call_site ( ) ;
47
- let name_str = p . name . to_sanitized_upper_case ( ) ;
48
+ let name_str = name. to_sanitized_upper_case ( ) ;
48
49
let name_pc = Ident :: new ( & name_str, span) ;
49
50
let address = util:: hex ( p. base_address as u64 ) ;
50
51
let description = util:: respace ( p. description . as_ref ( ) . unwrap_or ( & p. name ) ) ;
51
52
52
- let name_sc = Ident :: new ( & p . name . to_sanitized_snake_case ( ) , span) ;
53
+ let name_sc = Ident :: new ( & name. to_sanitized_snake_case ( ) , span) ;
53
54
let ( derive_regs, base) = if let ( Some ( df) , None ) = ( p_derivedfrom, & p_original. registers ) {
54
55
( true , Ident :: new ( & df. name . to_sanitized_snake_case ( ) , span) )
55
56
} else {
56
57
( false , name_sc. clone ( ) )
57
58
} ;
58
59
59
- // Insert the peripheral structure
60
- out. extend ( quote ! {
61
- #[ doc = #description]
62
- pub struct #name_pc { _marker: PhantomData <* const ( ) > }
60
+ match p_original {
61
+ p @ Peripheral :: Array ( _, dim) if !config. const_generic => {
62
+ let names: Vec < Cow < str > > = names ( p, dim) . map ( |n| n. into ( ) ) . collect ( ) ;
63
+ let names_str = names. iter ( ) . map ( |n| n. to_sanitized_upper_case ( ) ) ;
64
+ let names_pc = names_str. clone ( ) . map ( |n| Ident :: new ( & n, span) ) ;
65
+ let addresses =
66
+ ( 0 ..=dim. dim ) . map ( |i| util:: hex ( p. base_address + ( i * dim. dim_increment ) as u64 ) ) ;
67
+
68
+ // Insert the peripherals structure
69
+ out. extend ( quote ! {
70
+ #(
71
+ #[ doc = #description]
72
+ pub struct #names_pc { _marker: PhantomData <* const ( ) > }
73
+
74
+ unsafe impl Send for #names_pc { }
75
+
76
+ impl #names_pc {
77
+ ///Pointer to the register block
78
+ pub const PTR : * const #base:: RegisterBlock = #addresses as * const _;
79
+
80
+ ///Return the pointer to the register block
81
+ #[ inline( always) ]
82
+ pub const fn ptr( ) -> * const #base:: RegisterBlock {
83
+ Self :: PTR
84
+ }
85
+ }
63
86
64
- unsafe impl Send for #name_pc { }
87
+ impl Deref for #names_pc {
88
+ type Target = #base:: RegisterBlock ;
65
89
66
- impl #name_pc {
67
- ///Pointer to the register block
68
- pub const PTR : * const #base:: RegisterBlock = #address as * const _;
90
+ #[ inline( always) ]
91
+ fn deref( & self ) -> & Self :: Target {
92
+ unsafe { & * Self :: PTR }
93
+ }
94
+ }
69
95
70
- ///Return the pointer to the register block
71
- #[ inline( always) ]
72
- pub const fn ptr( ) -> * const #base:: RegisterBlock {
73
- Self :: PTR
74
- }
96
+ impl core:: fmt:: Debug for #names_pc {
97
+ fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
98
+ f. debug_struct( #names_str) . finish( )
99
+ }
100
+ }
101
+ ) *
102
+ } ) ;
75
103
}
104
+ _ => {
105
+ // Insert the peripheral structure
106
+ out. extend ( quote ! {
107
+ #[ doc = #description]
108
+ pub struct #name_pc { _marker: PhantomData <* const ( ) > }
76
109
77
- impl Deref for #name_pc {
78
- type Target = #base:: RegisterBlock ;
110
+ unsafe impl Send for #name_pc { }
79
111
80
- #[ inline( always) ]
81
- fn deref( & self ) -> & Self :: Target {
82
- unsafe { & * Self :: PTR }
83
- }
84
- }
112
+ impl #name_pc {
113
+ ///Pointer to the register block
114
+ pub const PTR : * const #base:: RegisterBlock = #address as * const _;
85
115
86
- impl core:: fmt:: Debug for #name_pc {
87
- fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
88
- f. debug_struct( #name_str) . finish( )
89
- }
116
+ ///Return the pointer to the register block
117
+ #[ inline( always) ]
118
+ pub const fn ptr( ) -> * const #base:: RegisterBlock {
119
+ Self :: PTR
120
+ }
121
+ }
122
+
123
+ impl Deref for #name_pc {
124
+ type Target = #base:: RegisterBlock ;
125
+
126
+ #[ inline( always) ]
127
+ fn deref( & self ) -> & Self :: Target {
128
+ unsafe { & * Self :: PTR }
129
+ }
130
+ }
131
+
132
+ impl core:: fmt:: Debug for #name_pc {
133
+ fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
134
+ f. debug_struct( #name_str) . finish( )
135
+ }
136
+ }
137
+ } ) ;
90
138
}
91
- } ) ;
139
+ }
92
140
93
141
// Derived peripherals may not require re-implementation, and will instead
94
142
// use a single definition of the non-derived version.
@@ -195,8 +243,9 @@ pub fn render(
195
243
} ;
196
244
}
197
245
198
- let description =
199
- util:: escape_brackets ( util:: respace ( p. description . as_ref ( ) . unwrap_or ( & p. name ) ) . as_ref ( ) ) ;
246
+ let description = util:: escape_brackets (
247
+ util:: respace ( p. description . as_ref ( ) . unwrap_or ( & name. as_ref ( ) . to_owned ( ) ) ) . as_ref ( ) ,
248
+ ) ;
200
249
201
250
let open = Punct :: new ( '{' , Spacing :: Alone ) ;
202
251
let close = Punct :: new ( '}' , Spacing :: Alone ) ;
0 commit comments