@@ -7,8 +7,7 @@ use svd_parser::expand::{
7
7
} ;
8
8
9
9
use crate :: svd:: {
10
- array:: names, Cluster , ClusterInfo , MaybeArray , Peripheral , Register , RegisterCluster ,
11
- RegisterInfo ,
10
+ Cluster , ClusterInfo , MaybeArray , Peripheral , Register , RegisterCluster , RegisterInfo ,
12
11
} ;
13
12
use log:: { debug, trace, warn} ;
14
13
use proc_macro2:: { Ident , Punct , Spacing , Span , TokenStream } ;
@@ -74,36 +73,32 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
74
73
75
74
match & p {
76
75
Peripheral :: Array ( p, dim) => {
77
- let names: Vec < Cow < str > > = names ( p, dim) . map ( |n| n. into ( ) ) . collect ( ) ;
78
- let names_str = names. iter ( ) . map ( |n| n. to_sanitized_constant_case ( ) ) ;
79
- let names_constant_case = names_str. clone ( ) . map ( |n| Ident :: new ( & n, span) ) ;
80
- let addresses =
81
- ( 0 ..=dim. dim ) . map ( |i| util:: hex ( p. base_address + ( i * dim. dim_increment ) as u64 ) ) ;
82
- let snake_names = names
83
- . iter ( )
84
- . map ( |p_name| p_name. to_sanitized_snake_case ( ) )
85
- . collect :: < Vec < _ > > ( ) ;
86
- let feature_attribute_n = snake_names. iter ( ) . map ( |p_snake| {
87
- let mut feature_attribute = feature_attribute. clone ( ) ;
76
+ let mut snake_names = Vec :: with_capacity ( dim. dim as _ ) ;
77
+ for pi in crate :: svd:: peripheral:: expand ( p, dim) {
78
+ let name = & pi. name ;
79
+ let description = pi. description . as_deref ( ) . unwrap_or ( & p. name ) ;
80
+ let name_str = name. to_sanitized_constant_case ( ) ;
81
+ let name_constant_case = Ident :: new ( & name, span) ;
82
+ let address = util:: hex ( pi. base_address ) ;
83
+ let p_snake = name. to_sanitized_snake_case ( ) ;
84
+ snake_names. push ( p_snake. to_string ( ) ) ;
85
+ let mut feature_attribute_n = feature_attribute. clone ( ) ;
88
86
if config. feature_peripheral {
89
- feature_attribute . extend ( quote ! { #[ cfg( feature = #p_snake) ] } )
87
+ feature_attribute_n . extend ( quote ! { #[ cfg( feature = #p_snake) ] } )
90
88
} ;
91
- feature_attribute
92
- } ) ;
93
- // Insert the peripherals structure
94
- out. extend ( quote ! {
95
- #(
89
+ // Insert the peripherals structure
90
+ out. extend ( quote ! {
96
91
#[ doc = #description]
97
92
#feature_attribute_n
98
- pub struct #names_constant_case { _marker: PhantomData <* const ( ) > }
93
+ pub struct #name_constant_case { _marker: PhantomData <* const ( ) > }
99
94
100
95
#feature_attribute_n
101
- unsafe impl Send for #names_constant_case { }
96
+ unsafe impl Send for #name_constant_case { }
102
97
103
98
#feature_attribute_n
104
- impl #names_constant_case {
99
+ impl #name_constant_case {
105
100
///Pointer to the register block
106
- pub const PTR : * const #base:: RegisterBlock = #addresses as * const _;
101
+ pub const PTR : * const #base:: RegisterBlock = #address as * const _;
107
102
108
103
///Return the pointer to the register block
109
104
#[ inline( always) ]
@@ -115,7 +110,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
115
110
}
116
111
117
112
#feature_attribute_n
118
- impl Deref for #names_constant_case {
113
+ impl Deref for #name_constant_case {
119
114
type Target = #base:: RegisterBlock ;
120
115
121
116
#[ inline( always) ]
@@ -125,13 +120,13 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
125
120
}
126
121
127
122
#feature_attribute_n
128
- impl core:: fmt:: Debug for #names_constant_case {
123
+ impl core:: fmt:: Debug for #name_constant_case {
129
124
fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
130
- f. debug_struct( #names_str ) . finish( )
125
+ f. debug_struct( #name_str ) . finish( )
131
126
}
132
127
}
133
- ) *
134
- } ) ;
128
+ } ) ;
129
+ }
135
130
136
131
let feature_any_attribute = quote ! { #[ cfg( any( #( feature = #snake_names) , * ) ) ] } ;
137
132
@@ -1075,47 +1070,44 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
1075
1070
. is_some ( ) ;
1076
1071
1077
1072
let convert_list = match config. keep_list {
1078
- true => match & array_info. dim_name {
1079
- Some ( dim_name) => dim_name. contains ( "[%s]" ) ,
1080
- None => info. name . contains ( "[%s]" ) ,
1081
- } ,
1073
+ true => info. name . contains ( "[%s]" ) ,
1082
1074
false => true ,
1083
1075
} ;
1084
1076
1085
1077
let array_convertible = sequential_addresses && convert_list;
1086
1078
1087
1079
if array_convertible {
1080
+ let span = Span :: call_site ( ) ;
1081
+ let nb_name_sc = if let Some ( dim_name) = array_info. dim_name . as_ref ( ) {
1082
+ dim_name. to_snake_case_ident ( span)
1083
+ } else {
1084
+ ty_name. to_snake_case_ident ( span)
1085
+ } ;
1088
1086
let accessors = if sequential_indexes_from0 {
1089
1087
Vec :: new ( )
1090
1088
} else {
1091
- let span = Span :: call_site ( ) ;
1092
1089
let mut accessors = Vec :: new ( ) ;
1093
- let nb_name_cs = ty_name. to_snake_case_ident ( span) ;
1094
- for ( i, idx) in array_info. indexes ( ) . enumerate ( ) {
1095
- let idx_name =
1096
- util:: replace_suffix ( & info. name , & idx) . to_snake_case_ident ( span) ;
1090
+ for ( i, ci) in crate :: svd:: cluster:: expand ( info, array_info) . enumerate ( ) {
1091
+ let idx_name = ci. name . to_snake_case_ident ( span) ;
1097
1092
let comment = make_comment (
1098
1093
cluster_size,
1099
- info . address_offset + ( i as u32 ) * cluster_size / 8 ,
1100
- & description,
1094
+ ci . address_offset ,
1095
+ ci . description . as_deref ( ) . unwrap_or ( & ci . name ) ,
1101
1096
) ;
1102
1097
let i = unsuffixed ( i as _ ) ;
1103
1098
accessors. push ( ArrayAccessor {
1104
1099
doc : comment,
1105
1100
name : idx_name,
1106
1101
ty : ty. clone ( ) ,
1107
- basename : nb_name_cs . clone ( ) ,
1102
+ basename : nb_name_sc . clone ( ) ,
1108
1103
i,
1109
1104
} ) ;
1110
1105
}
1111
1106
accessors
1112
1107
} ;
1113
1108
let array_ty = new_syn_array ( ty, array_info. dim ) ;
1114
1109
cluster_expanded. push ( RegisterBlockField {
1115
- syn_field : new_syn_field (
1116
- ty_name. to_snake_case_ident ( Span :: call_site ( ) ) ,
1117
- array_ty,
1118
- ) ,
1110
+ syn_field : new_syn_field ( nb_name_sc, array_ty) ,
1119
1111
description,
1120
1112
offset : info. address_offset ,
1121
1113
size : cluster_size * array_info. dim ,
@@ -1135,15 +1127,14 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
1135
1127
accessors : Vec :: new ( ) ,
1136
1128
} ) ;
1137
1129
} else {
1138
- for ( field_num, idx) in array_info. indexes ( ) . enumerate ( ) {
1139
- let nb_name = util:: replace_suffix ( & info. name , & idx) ;
1130
+ for ci in crate :: svd:: cluster:: expand ( info, array_info) {
1140
1131
let syn_field =
1141
- new_syn_field ( nb_name . to_snake_case_ident ( Span :: call_site ( ) ) , ty. clone ( ) ) ;
1132
+ new_syn_field ( ci . name . to_snake_case_ident ( Span :: call_site ( ) ) , ty. clone ( ) ) ;
1142
1133
1143
1134
cluster_expanded. push ( RegisterBlockField {
1144
1135
syn_field,
1145
- description : description. clone ( ) ,
1146
- offset : info . address_offset + field_num as u32 * array_info . dim_increment ,
1136
+ description : ci . description . unwrap_or ( ci . name ) ,
1137
+ offset : ci . address_offset ,
1147
1138
size : cluster_size,
1148
1139
accessors : Vec :: new ( ) ,
1149
1140
} ) ;
@@ -1197,10 +1188,7 @@ fn expand_register(
1197
1188
|| ( register_size <= array_info. dim_increment * BITS_PER_BYTE ) ;
1198
1189
1199
1190
let convert_list = match config. keep_list {
1200
- true => match & array_info. dim_name {
1201
- Some ( dim_name) => dim_name. contains ( "[%s]" ) ,
1202
- None => info. name . contains ( "[%s]" ) ,
1203
- } ,
1191
+ true => info. name . contains ( "[%s]" ) ,
1204
1192
false => true ,
1205
1193
} ;
1206
1194
@@ -1234,26 +1222,32 @@ fn expand_register(
1234
1222
let ty = name_to_ty ( & ty_name) ;
1235
1223
1236
1224
if array_convertible || ( array_proxy_convertible && config. const_generic ) {
1225
+ let span = Span :: call_site ( ) ;
1226
+ let nb_name_sc = if let Some ( dim_name) = array_info. dim_name . as_ref ( ) {
1227
+ util:: fullname ( dim_name, & info. alternate_group , config. ignore_groups )
1228
+ . to_snake_case_ident ( span)
1229
+ } else {
1230
+ ty_name. to_snake_case_ident ( span)
1231
+ } ;
1237
1232
let accessors = if sequential_indexes_from0 {
1238
1233
Vec :: new ( )
1239
1234
} else {
1240
- let span = Span :: call_site ( ) ;
1241
1235
let mut accessors = Vec :: new ( ) ;
1242
- let nb_name_cs = ty_name. to_snake_case_ident ( span) ;
1243
- for ( i, idx) in array_info. indexes ( ) . enumerate ( ) {
1236
+ for ( i, ri) in crate :: svd:: register:: expand ( info, array_info) . enumerate ( ) {
1244
1237
let idx_name =
1245
- util:: replace_suffix ( & info_name, & idx) . to_snake_case_ident ( span) ;
1238
+ util:: fullname ( & ri. name , & info. alternate_group , config. ignore_groups )
1239
+ . to_snake_case_ident ( span) ;
1246
1240
let comment = make_comment (
1247
1241
register_size,
1248
- info . address_offset + ( i as u32 ) * register_size / 8 ,
1249
- & description,
1242
+ ri . address_offset ,
1243
+ ri . description . as_deref ( ) . unwrap_or ( & ri . name ) ,
1250
1244
) ;
1251
1245
let i = unsuffixed ( i as _ ) ;
1252
1246
accessors. push ( ArrayAccessor {
1253
1247
doc : comment,
1254
1248
name : idx_name,
1255
1249
ty : ty. clone ( ) ,
1256
- basename : nb_name_cs . clone ( ) ,
1250
+ basename : nb_name_sc . clone ( ) ,
1257
1251
i,
1258
1252
} ) ;
1259
1253
}
@@ -1264,8 +1258,7 @@ fn expand_register(
1264
1258
} else {
1265
1259
array_proxy_type ( ty, array_info)
1266
1260
} ;
1267
- let syn_field =
1268
- new_syn_field ( ty_name. to_snake_case_ident ( Span :: call_site ( ) ) , array_ty) ;
1261
+ let syn_field = new_syn_field ( nb_name_sc, array_ty) ;
1269
1262
register_expanded. push ( RegisterBlockField {
1270
1263
syn_field,
1271
1264
description,
@@ -1278,15 +1271,14 @@ fn expand_register(
1278
1271
accessors,
1279
1272
} ) ;
1280
1273
} else {
1281
- for ( field_num, idx) in array_info. indexes ( ) . enumerate ( ) {
1282
- let nb_name = util:: replace_suffix ( & info_name, & idx) ;
1274
+ for ri in crate :: svd:: register:: expand ( info, array_info) {
1283
1275
let syn_field =
1284
- new_syn_field ( nb_name . to_snake_case_ident ( Span :: call_site ( ) ) , ty. clone ( ) ) ;
1276
+ new_syn_field ( ri . name . to_snake_case_ident ( Span :: call_site ( ) ) , ty. clone ( ) ) ;
1285
1277
1286
1278
register_expanded. push ( RegisterBlockField {
1287
1279
syn_field,
1288
- description : description. clone ( ) ,
1289
- offset : info . address_offset + field_num as u32 * array_info . dim_increment ,
1280
+ description : ri . description . unwrap_or ( ri . name ) ,
1281
+ offset : ri . address_offset ,
1290
1282
size : register_size,
1291
1283
accessors : Vec :: new ( ) ,
1292
1284
} ) ;
0 commit comments