@@ -27,8 +27,29 @@ pub trait PeripheralExt: InterruptExt + RegisterBlockExt {
2727
2828/// Collecting methods for processing cluster contents
2929pub 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+
3045 /// Work through a cluster, handling all registers
3146 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 ;
3253}
3354
3455/// Collecting methods for processing peripheral interrupt contents
@@ -710,7 +731,7 @@ impl RegisterBlockExt for Peripheral {
710731}
711732
712733impl 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 {
714735 // Handle deletions
715736 if let Some ( deletions) = pmod. get ( & "_delete" . to_yaml ( ) ) {
716737 match deletions {
@@ -872,6 +893,12 @@ impl ClusterExt for Cluster {
872893 }
873894 }
874895
896+ Ok ( ( ) )
897+ }
898+
899+ fn process ( & mut self , pmod : & Hash , pname : & str , config : & Config ) -> PatchResult {
900+ self . pre_process ( pmod, pname, config) ?;
901+
875902 // Handle clusters
876903 for ( cspec, cluster) in pmod. hash_iter ( "_clusters" ) {
877904 let cspec = cspec. str ( ) ?;
@@ -890,6 +917,10 @@ impl ClusterExt for Cluster {
890917 }
891918 }
892919
920+ self . post_process ( pmod, pname, config)
921+ }
922+
923+ fn post_process ( & mut self , pmod : & Hash , _pname : & str , config : & Config ) -> PatchResult {
893924 // Expand register arrays
894925 for ( rspec, rmod) in pmod. hash_iter ( "_expand_array" ) {
895926 let rspec = rspec. str ( ) ?;
@@ -1365,7 +1396,7 @@ fn collect_in_cluster(
13651396
13661397 for ( rspec, rmod) in cmod {
13671398 let rspec = rspec. str ( ) ?;
1368- if rspec == "description" || rspec == "dimIncrement" {
1399+ if [ "description" , "dimIncrement" ] . contains ( & rspec ) || Cluster :: KEYWORDS . contains ( & rspec) {
13691400 continue ;
13701401 }
13711402 let mut registers = Vec :: new ( ) ;
@@ -1493,7 +1524,7 @@ fn collect_in_cluster(
14931524 . address_offset ( address_offset) ;
14941525 let mut config = config. clone ( ) ;
14951526 config. update_fields = true ;
1496- let cluster = if single {
1527+ let mut cluster = if single {
14971528 for ( _, ( rmod, mut registers) ) in rdict. into_iter ( ) {
14981529 let mut reg = registers. swap_remove ( 0 ) ;
14991530 let rmod = rmod. hash ( ) ?;
@@ -1538,6 +1569,8 @@ fn collect_in_cluster(
15381569 . build ( VAL_LVL ) ?,
15391570 )
15401571 } ;
1572+ cluster. pre_process ( cmod, cname, & config) ?;
1573+ cluster. post_process ( cmod, cname, & config) ?;
15411574 regs. insert ( place, RegisterCluster :: Cluster ( cluster) ) ;
15421575 Ok ( ( ) )
15431576}
0 commit comments