@@ -27,8 +27,29 @@ pub trait PeripheralExt: InterruptExt + RegisterBlockExt {
27
27
28
28
/// Collecting methods for processing cluster contents
29
29
pub trait ClusterExt : RegisterBlockExt {
30
+ const KEYWORDS : & ' static [ & ' static str ] = & [
31
+ "_add" ,
32
+ "_copy" ,
33
+ "_delete" ,
34
+ "_derive" ,
35
+ "_modify" ,
36
+ "_strip" ,
37
+ "_strip_end" ,
38
+ "_expand_array" ,
39
+ "_expand_cluster" ,
40
+ "_array" ,
41
+ "_cluster" ,
42
+ "_clusters" ,
43
+ ] ;
44
+
30
45
/// Work through a cluster, handling all registers
31
46
fn process ( & mut self , peripheral : & Hash , pname : & str , config : & Config ) -> PatchResult ;
47
+
48
+ /// Work through a cluster, handling all registers
49
+ fn pre_process ( & mut self , peripheral : & Hash , pname : & str , config : & Config ) -> PatchResult ;
50
+
51
+ /// Work through a cluster, handling all registers
52
+ fn post_process ( & mut self , peripheral : & Hash , pname : & str , config : & Config ) -> PatchResult ;
32
53
}
33
54
34
55
/// Collecting methods for processing peripheral interrupt contents
@@ -710,7 +731,7 @@ impl RegisterBlockExt for Peripheral {
710
731
}
711
732
712
733
impl ClusterExt for Cluster {
713
- fn process ( & mut self , pmod : & Hash , _pname : & str , config : & Config ) -> PatchResult {
734
+ fn pre_process ( & mut self , pmod : & Hash , _pname : & str , _config : & Config ) -> PatchResult {
714
735
// Handle deletions
715
736
if let Some ( deletions) = pmod. get ( & "_delete" . to_yaml ( ) ) {
716
737
match deletions {
@@ -872,6 +893,12 @@ impl ClusterExt for Cluster {
872
893
}
873
894
}
874
895
896
+ Ok ( ( ) )
897
+ }
898
+
899
+ fn process ( & mut self , pmod : & Hash , pname : & str , config : & Config ) -> PatchResult {
900
+ self . pre_process ( pmod, pname, config) ?;
901
+
875
902
// Handle clusters
876
903
for ( cspec, cluster) in pmod. hash_iter ( "_clusters" ) {
877
904
let cspec = cspec. str ( ) ?;
@@ -890,6 +917,10 @@ impl ClusterExt for Cluster {
890
917
}
891
918
}
892
919
920
+ self . post_process ( pmod, pname, config)
921
+ }
922
+
923
+ fn post_process ( & mut self , pmod : & Hash , _pname : & str , config : & Config ) -> PatchResult {
893
924
// Expand register arrays
894
925
for ( rspec, rmod) in pmod. hash_iter ( "_expand_array" ) {
895
926
let rspec = rspec. str ( ) ?;
@@ -1365,7 +1396,7 @@ fn collect_in_cluster(
1365
1396
1366
1397
for ( rspec, rmod) in cmod {
1367
1398
let rspec = rspec. str ( ) ?;
1368
- if rspec == "description" || rspec == "dimIncrement" {
1399
+ if [ "description" , "dimIncrement" ] . contains ( & rspec ) || Cluster :: KEYWORDS . contains ( & rspec) {
1369
1400
continue ;
1370
1401
}
1371
1402
let mut registers = Vec :: new ( ) ;
@@ -1493,7 +1524,7 @@ fn collect_in_cluster(
1493
1524
. address_offset ( address_offset) ;
1494
1525
let mut config = config. clone ( ) ;
1495
1526
config. update_fields = true ;
1496
- let cluster = if single {
1527
+ let mut cluster = if single {
1497
1528
for ( _, ( rmod, mut registers) ) in rdict. into_iter ( ) {
1498
1529
let mut reg = registers. swap_remove ( 0 ) ;
1499
1530
let rmod = rmod. hash ( ) ?;
@@ -1538,6 +1569,8 @@ fn collect_in_cluster(
1538
1569
. build ( VAL_LVL ) ?,
1539
1570
)
1540
1571
} ;
1572
+ cluster. pre_process ( cmod, cname, & config) ?;
1573
+ cluster. post_process ( cmod, cname, & config) ?;
1541
1574
regs. insert ( place, RegisterCluster :: Cluster ( cluster) ) ;
1542
1575
Ok ( ( ) )
1543
1576
}
0 commit comments