@@ -32,6 +32,8 @@ pub(crate) trait PeripheralExt: InterruptExt + RegisterBlockExt {
32
32
"_copy" ,
33
33
"_strip" ,
34
34
"_strip_end" ,
35
+ "_prefix" ,
36
+ "_suffix" ,
35
37
"_modify" ,
36
38
"_clear_fields" ,
37
39
"_add" ,
@@ -57,6 +59,8 @@ pub(crate) trait ClusterExt: RegisterBlockExt {
57
59
"_copy" ,
58
60
"_strip" ,
59
61
"_strip_end" ,
62
+ "_prefix" ,
63
+ "_suffix" ,
60
64
"_modify" ,
61
65
"_clear_fields" ,
62
66
"_add" ,
@@ -568,6 +572,34 @@ pub(crate) trait RegisterBlockExt: Name {
568
572
Ok ( ( ) )
569
573
}
570
574
575
+ /// Add prefix at the beginning of register names inside ptag
576
+ fn add_prefix ( & mut self , prefix : & str ) -> PatchResult {
577
+ for rtag in self . regs_mut ( ) {
578
+ rtag. name . insert_str ( 0 , prefix) ;
579
+ if let Some ( dname) = rtag. display_name . as_mut ( ) {
580
+ dname. insert_str ( 0 , prefix) ;
581
+ }
582
+ if let Some ( name) = rtag. alternate_register . as_mut ( ) {
583
+ name. insert_str ( 0 , prefix) ;
584
+ }
585
+ }
586
+ Ok ( ( ) )
587
+ }
588
+
589
+ /// Add suffix at the ending of register names inside ptag
590
+ fn add_suffix ( & mut self , suffix : & str ) -> PatchResult {
591
+ for rtag in self . regs_mut ( ) {
592
+ rtag. name . push_str ( suffix) ;
593
+ if let Some ( dname) = rtag. display_name . as_mut ( ) {
594
+ dname. push_str ( suffix) ;
595
+ }
596
+ if let Some ( name) = rtag. alternate_register . as_mut ( ) {
597
+ name. push_str ( suffix) ;
598
+ }
599
+ }
600
+ Ok ( ( ) )
601
+ }
602
+
571
603
/// Collect same registers in peripheral into register array
572
604
fn collect_in_array (
573
605
& mut self ,
@@ -1078,6 +1110,15 @@ impl PeripheralExt for Peripheral {
1078
1110
. with_context ( || format ! ( "Stripping suffix `{suffix}` from register names" ) ) ?;
1079
1111
}
1080
1112
1113
+ if let Some ( prefix) = pmod. get_str ( "_prefix" ) ? {
1114
+ self . add_prefix ( prefix)
1115
+ . with_context ( || format ! ( "Adding prefix `{prefix}` to register names" ) ) ?;
1116
+ }
1117
+ if let Some ( suffix) = pmod. get_str ( "_suffix" ) ? {
1118
+ self . add_suffix ( suffix)
1119
+ . with_context ( || format ! ( "Adding suffix `{suffix}` to register names" ) ) ?;
1120
+ }
1121
+
1081
1122
// Handle modifications
1082
1123
for ( rspec, rmod) in pmod. hash_iter ( "_modify" ) {
1083
1124
let rmod = rmod. hash ( ) ?;
@@ -1386,6 +1427,15 @@ impl ClusterExt for Cluster {
1386
1427
. with_context ( || format ! ( "Stripping suffix `{suffix}` from register names" ) ) ?;
1387
1428
}
1388
1429
1430
+ if let Some ( prefix) = cmod. get_str ( "_prefix" ) ? {
1431
+ self . add_prefix ( prefix)
1432
+ . with_context ( || format ! ( "Adding prefix `{prefix}` to register names" ) ) ?;
1433
+ }
1434
+ if let Some ( suffix) = cmod. get_str ( "_suffix" ) ? {
1435
+ self . add_suffix ( suffix)
1436
+ . with_context ( || format ! ( "Adding suffix `{suffix}` to register names" ) ) ?;
1437
+ }
1438
+
1389
1439
// Handle modifications
1390
1440
for ( rspec, rmod) in cmod. hash_iter ( "_modify" ) {
1391
1441
let rmod = rmod. hash ( ) ?;
0 commit comments