@@ -255,10 +255,10 @@ pub fn fields(
255
255
} = f. bit_range ;
256
256
let sc = f. name . to_sanitized_snake_case ( ) ;
257
257
let pc = f. name . to_sanitized_upper_case ( ) ;
258
- let pc_r = Ident :: from ( & * format ! ( "{}R " , pc) ) ;
258
+ let pc_r = Ident :: from ( & * format ! ( "{}_A " , pc) ) ;
259
259
let _pc_r = Ident :: from ( & * format ! ( "{}_R" , pc) ) ;
260
- let pc_w = Ident :: from ( & * format ! ( "{}W " , pc) ) ;
261
- let _pc_w = Ident :: from ( & * format ! ( "_{}W " , pc) ) ;
260
+ let pc_w = Ident :: from ( & * format ! ( "{}_AW " , pc) ) ;
261
+ let _pc_w = Ident :: from ( & * format ! ( "{}_W " , pc) ) ;
262
262
let _sc = Ident :: from ( & * format ! ( "_{}" , sc) ) ;
263
263
let bits = if width == 1 {
264
264
Ident :: from ( "bit" )
@@ -319,6 +319,15 @@ pub fn fields(
319
319
all_peripherals,
320
320
) ?;
321
321
322
+
323
+ let pc_r = & f. pc_r ;
324
+ let mut pc_w = & f. pc_r ;
325
+
326
+ let mut evs_r = None ;
327
+
328
+ let _pc_r = & f. _pc_r ;
329
+ let _pc_w = & f. _pc_w ;
330
+
322
331
if can_read {
323
332
let cast = if f. width == 1 {
324
333
quote ! { != 0 }
@@ -336,10 +345,9 @@ pub fn fields(
336
345
}
337
346
} ;
338
347
339
- let pc_r = & f. pc_r ;
340
- let _pc_r = & f. _pc_r ;
341
-
342
348
if let Some ( ( evs, base) ) = lookup_filter ( & lookup_results, Usage :: Read ) {
349
+ evs_r = Some ( evs. clone ( ) ) ;
350
+
343
351
let description = & util:: escape_brackets ( & f. description ) ;
344
352
let sc = & f. sc ;
345
353
r_impl_items. push ( quote ! {
@@ -352,8 +360,13 @@ pub fn fields(
352
360
353
361
if let Some ( base) = & base {
354
362
let pc = base. field . to_sanitized_upper_case ( ) ;
355
- let base_pc_r = Ident :: from ( & * format ! ( "{}_R" , pc) ) ;
356
- derive_from_base ( mod_items, & base, & _pc_r, & base_pc_r, f. name ) ;
363
+ let base_pc_r = Ident :: from ( & * format ! ( "{}_A" , pc) ) ;
364
+ let base_pc_r = derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, f. name ) ;
365
+
366
+ mod_items. push ( quote ! {
367
+ ///Reader of the field
368
+ pub type #_pc_r = crate :: FR <#fty, #base_pc_r>;
369
+ } ) ;
357
370
}
358
371
359
372
if base. is_none ( ) {
@@ -471,16 +484,19 @@ pub fn fields(
471
484
if variants. len ( ) == 1 << f. width {
472
485
unsafety = None ;
473
486
}
474
- let pc_w = & f. pc_w ;
475
487
476
- let base_pc_w = base. as_ref ( ) . map ( |base| {
477
- let pc = base. field . to_sanitized_upper_case ( ) ;
478
- let base_pc_w = Ident :: from ( & * format ! ( "{}W" , pc) ) ;
479
- derive_from_base ( mod_items, & base, & pc_w, & base_pc_w, f. name )
480
- } ) ;
488
+ if Some ( evs) != evs_r. as_ref ( ) {
489
+ pc_w = & f. pc_w ;
481
490
482
- if base. is_none ( ) {
483
- add_from_variants ( mod_items, & variants, pc_w, & f) ;
491
+ base. as_ref ( ) . map ( |base| {
492
+ let pc = base. field . to_sanitized_upper_case ( ) ;
493
+ let base_pc_w = Ident :: from ( & * format ! ( "{}_AW" , pc) ) ;
494
+ derive_from_base ( mod_items, & base, & pc_w, & base_pc_w, f. name )
495
+ } ) ;
496
+
497
+ if base. is_none ( ) {
498
+ add_from_variants ( mod_items, & variants, pc_w, & f) ;
499
+ }
484
500
}
485
501
486
502
proxy_items. push ( quote ! {
@@ -499,23 +515,13 @@ pub fn fields(
499
515
let sc = & v. sc ;
500
516
501
517
let doc = util:: escape_brackets ( util:: respace ( & v. doc ) . as_ref ( ) ) ;
502
- if let Some ( enum_) = base_pc_w. as_ref ( ) {
503
- proxy_items. push ( quote ! {
504
- #[ doc = #doc]
505
- #[ inline( always) ]
506
- pub fn #sc( self ) -> & ' a mut W {
507
- self . variant( #enum_:: #pc)
508
- }
509
- } ) ;
510
- } else {
511
518
proxy_items. push ( quote ! {
512
519
#[ doc = #doc]
513
520
#[ inline( always) ]
514
521
pub fn #sc( self ) -> & ' a mut W {
515
522
self . variant( #pc_w:: #pc)
516
523
}
517
524
} ) ;
518
- }
519
525
}
520
526
}
521
527
@@ -556,7 +562,6 @@ pub fn fields(
556
562
}
557
563
} ) ;
558
564
559
- let _pc_w = & f. _pc_w ;
560
565
mod_items. push ( quote ! {
561
566
///Proxy
562
567
pub struct #_pc_w<' a> {
@@ -680,7 +685,7 @@ fn add_from_variants(mod_items: &mut Vec<Tokens>, variants: &Vec<Variant>, pc: &
680
685
} ) ;
681
686
}
682
687
683
- fn derive_from_base ( mod_items : & mut Vec < Tokens > , base : & Base , pc : & Ident , base_pc : & Ident , fname : & str ) -> quote :: Tokens {
688
+ fn derive_from_base ( mod_items : & mut Vec < Tokens > , base : & Base , pc : & Ident , base_pc : & Ident , fname : & str ) {
684
689
let desc = format ! ( "Possible values of the field `{}`" , fname, ) ;
685
690
686
691
if let ( Some ( peripheral) , Some ( register) ) = ( & base. peripheral , & base. register ) {
@@ -694,10 +699,6 @@ fn derive_from_base(mod_items: &mut Vec<Tokens>, base: &Base, pc: &Ident, base_p
694
699
pub type #pc =
695
700
crate :: #pmod_:: #rmod_:: #base_pc;
696
701
} ) ;
697
-
698
- quote ! {
699
- crate :: #pmod_:: #rmod_:: #base_pc
700
- }
701
702
} else if let Some ( register) = & base. register {
702
703
let mod_ = register. to_sanitized_snake_case ( ) ;
703
704
let mod_ = Ident :: from ( & * mod_) ;
@@ -707,19 +708,11 @@ fn derive_from_base(mod_items: &mut Vec<Tokens>, base: &Base, pc: &Ident, base_p
707
708
pub type #pc =
708
709
super :: #mod_:: #base_pc;
709
710
} ) ;
710
-
711
- quote ! {
712
- super :: #mod_:: #base_pc
713
- }
714
711
} else {
715
712
mod_items. push ( quote ! {
716
713
#[ doc = #desc]
717
714
pub type #pc = #base_pc;
718
715
} ) ;
719
-
720
- quote ! {
721
- #base_pc
722
- }
723
716
}
724
717
}
725
718
0 commit comments