@@ -3,8 +3,8 @@ use std::cmp::Ordering;
33use std:: collections:: HashMap ;
44
55use crate :: svd:: {
6- Cluster , ClusterInfo , DeriveFrom , DimElement , Peripheral , Register , RegisterCluster ,
7- RegisterProperties ,
6+ array :: names , Cluster , ClusterInfo , DeriveFrom , DimElement , Peripheral , Register ,
7+ RegisterCluster , RegisterProperties ,
88} ;
99use log:: { debug, trace, warn} ;
1010use proc_macro2:: { Ident , Punct , Spacing , Span , TokenStream } ;
@@ -43,52 +43,100 @@ pub fn render(
4343 return Ok ( out) ;
4444 }
4545
46+ let name = util:: name_of ( p, config. ignore_groups ) ;
4647 let span = Span :: call_site ( ) ;
47- let name_str = p . name . to_sanitized_upper_case ( ) ;
48+ let name_str = name. to_sanitized_upper_case ( ) ;
4849 let name_pc = Ident :: new ( & name_str, span) ;
4950 let address = util:: hex ( p. base_address as u64 ) ;
5051 let description = util:: respace ( p. description . as_ref ( ) . unwrap_or ( & p. name ) ) ;
5152
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) ;
5354 let ( derive_regs, base) = if let ( Some ( df) , None ) = ( p_derivedfrom, & p_original. registers ) {
5455 ( true , Ident :: new ( & df. name . to_sanitized_snake_case ( ) , span) )
5556 } else {
5657 ( false , name_sc. clone ( ) )
5758 } ;
5859
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+ }
6386
64- unsafe impl Send for #name_pc { }
87+ impl Deref for #names_pc {
88+ type Target = #base:: RegisterBlock ;
6589
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+ }
6995
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+ } ) ;
75103 }
104+ _ => {
105+ // Insert the peripheral structure
106+ out. extend ( quote ! {
107+ #[ doc = #description]
108+ pub struct #name_pc { _marker: PhantomData <* const ( ) > }
76109
77- impl Deref for #name_pc {
78- type Target = #base:: RegisterBlock ;
110+ unsafe impl Send for #name_pc { }
79111
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 _;
85115
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+ } ) ;
90138 }
91- } ) ;
139+ }
92140
93141 // Derived peripherals may not require re-implementation, and will instead
94142 // use a single definition of the non-derived version.
@@ -195,8 +243,9 @@ pub fn render(
195243 } ;
196244 }
197245
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+ ) ;
200249
201250 let open = Punct :: new ( '{' , Spacing :: Alone ) ;
202251 let close = Punct :: new ( '}' , Spacing :: Alone ) ;
0 commit comments