1
1
use crate :: svd:: {
2
- Access , BitRange , EnumeratedValues , Field , Peripheral , Register , RegisterProperties , Usage ,
3
- WriteConstraint ,
2
+ Access , BitRange , DeriveFrom , EnumeratedValues , Field , Peripheral , Register ,
3
+ RegisterProperties , Usage , WriteConstraint ,
4
4
} ;
5
5
use cast:: u64;
6
6
use core:: u64;
@@ -19,16 +19,15 @@ pub fn render(
19
19
defs : & RegisterProperties ,
20
20
config : & Config ,
21
21
) -> Result < TokenStream > {
22
- let access = util:: access_of ( register) ;
22
+ let properties = register. properties . derive_from ( defs) ;
23
+ let access = util:: access_of ( & properties, register. fields . as_deref ( ) ) ;
23
24
let name = util:: name_of ( register, config. ignore_groups ) ;
24
25
let span = Span :: call_site ( ) ;
25
26
let name_pc = Ident :: new ( & name. to_sanitized_upper_case ( ) , span) ;
26
27
let name_uc_spec = Ident :: new ( & format ! ( "{}_SPEC" , & name. to_sanitized_upper_case( ) ) , span) ;
27
28
let name_sc = Ident :: new ( & name. to_sanitized_snake_case ( ) , span) ;
28
- let rsize = register
29
- . properties
29
+ let rsize = properties
30
30
. size
31
- . or ( defs. size )
32
31
. ok_or_else ( || anyhow ! ( "Register {} has no `size` field" , register. name) ) ?;
33
32
let rsize = if rsize < 8 {
34
33
8
@@ -45,11 +44,6 @@ pub fn render(
45
44
} ) )
46
45
. as_ref ( ) ,
47
46
) ;
48
- let res_val = register
49
- . properties
50
- . reset_value
51
- . or ( defs. reset_value )
52
- . map ( |v| v as u64 ) ;
53
47
54
48
let mut mod_items = TokenStream :: new ( ) ;
55
49
let mut r_impl_items = TokenStream :: new ( ) ;
@@ -58,7 +52,7 @@ pub fn render(
58
52
59
53
let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ] . contains ( & access) ;
60
54
let can_write = access != Access :: ReadOnly ;
61
- let can_reset = res_val . is_some ( ) ;
55
+ let can_reset = properties . reset_value . is_some ( ) ;
62
56
63
57
if can_read {
64
58
let desc = format ! ( "Register `{}` reader" , register. name) ;
@@ -142,8 +136,8 @@ pub fn render(
142
136
peripheral,
143
137
all_peripherals,
144
138
& rty,
145
- res_val,
146
139
access,
140
+ & properties,
147
141
& mut mod_items,
148
142
& mut r_impl_items,
149
143
& mut w_impl_items,
@@ -262,7 +256,7 @@ pub fn render(
262
256
}
263
257
} ) ;
264
258
}
265
- if let Some ( rv) = res_val . map ( util:: hex) {
259
+ if let Some ( rv) = properties . reset_value . map ( util:: hex) {
266
260
let doc = format ! ( "`reset()` method sets {} to value {}" , register. name, & rv) ;
267
261
mod_items. extend ( quote ! {
268
262
#[ doc = #doc]
@@ -295,8 +289,8 @@ pub fn fields(
295
289
peripheral : & Peripheral ,
296
290
all_peripherals : & [ Peripheral ] ,
297
291
rty : & Ident ,
298
- reset_value : Option < u64 > ,
299
292
access : Access ,
293
+ properties : & RegisterProperties ,
300
294
mod_items : & mut TokenStream ,
301
295
r_impl_items : & mut TokenStream ,
302
296
w_impl_items : & mut TokenStream ,
@@ -315,7 +309,7 @@ pub fn fields(
315
309
let name_sc = Ident :: new ( & name. to_sanitized_snake_case ( ) , span) ;
316
310
let name_pc = name. to_sanitized_upper_case ( ) ;
317
311
let bits = Ident :: new ( if width == 1 { "bit" } else { "bits" } , span) ;
318
- let description_raw = f. description . as_ref ( ) . map ( |s| s . as_str ( ) ) . unwrap_or ( "" ) ; // raw description, if absent using empty string
312
+ let description_raw = f. description . as_deref ( ) . unwrap_or ( "" ) ; // raw description, if absent using empty string
319
313
let description = util:: respace ( & util:: escape_brackets ( description_raw) ) ;
320
314
321
315
let can_read = can_read
@@ -326,11 +320,11 @@ pub fn fields(
326
320
let mask = u64:: MAX >> ( 64 - width) ;
327
321
let hexmask = & util:: hex ( mask) ;
328
322
let offset = u64:: from ( offset) ;
329
- let rv = reset_value. map ( |rv| ( rv >> offset) & mask) ;
323
+ let rv = properties . reset_value . map ( |rv| ( rv >> offset) & mask) ;
330
324
let fty = width. to_ty ( ) ?;
331
325
let evs = & f. enumerated_values ;
332
326
333
- let use_mask = if let Some ( size) = parent . properties . size {
327
+ let use_mask = if let Some ( size) = properties. size {
334
328
size != width
335
329
} else {
336
330
true
@@ -450,7 +444,7 @@ pub fn fields(
450
444
Span :: call_site ( ) ,
451
445
) ;
452
446
let doc = util:: replace_suffix (
453
- & description_with_bits ( & description_raw, sub_offset, width) ,
447
+ & description_with_bits ( description_raw, sub_offset, width) ,
454
448
suffix,
455
449
) ;
456
450
r_impl_items. extend ( quote ! {
@@ -462,7 +456,7 @@ pub fn fields(
462
456
} ) ;
463
457
}
464
458
} else {
465
- let doc = description_with_bits ( & description_raw, offset, width) ;
459
+ let doc = description_with_bits ( description_raw, offset, width) ;
466
460
r_impl_items. extend ( quote ! {
467
461
#[ doc = #doc]
468
462
#inline
@@ -815,7 +809,7 @@ pub fn fields(
815
809
Span :: call_site ( ) ,
816
810
) ;
817
811
let doc = util:: replace_suffix (
818
- & description_with_bits ( & description_raw, sub_offset, width) ,
812
+ & description_with_bits ( description_raw, sub_offset, width) ,
819
813
suffix,
820
814
) ;
821
815
let sub_offset = util:: unsuffixed ( sub_offset as u64 ) ;
@@ -838,7 +832,7 @@ pub fn fields(
838
832
}
839
833
}
840
834
} else {
841
- let doc = description_with_bits ( & description_raw, offset, width) ;
835
+ let doc = description_with_bits ( description_raw, offset, width) ;
842
836
w_impl_items. extend ( quote ! {
843
837
#[ doc = #doc]
844
838
#inline
0 commit comments