@@ -2,7 +2,9 @@ use std::borrow::Cow;
2
2
use std:: cmp:: Ordering ;
3
3
use std:: collections:: HashMap ;
4
4
5
- use crate :: svd:: { Cluster , ClusterInfo , Peripheral , Register , RegisterCluster , RegisterProperties } ;
5
+ use crate :: svd:: {
6
+ Cluster , ClusterInfo , DimElement , Peripheral , Register , RegisterCluster , RegisterProperties ,
7
+ } ;
6
8
use log:: warn;
7
9
use proc_macro2:: TokenStream ;
8
10
use proc_macro2:: { Ident , Punct , Spacing , Span } ;
@@ -701,6 +703,10 @@ fn expand_cluster(
701
703
offset : info. address_offset ,
702
704
size : cluster_size * array_info. dim ,
703
705
} ) ;
706
+ } else if sequential_indexes {
707
+ // Include a ZST ArrayProxy giving indexed access to the
708
+ // elements.
709
+ cluster_expanded. push ( array_proxy ( info, array_info, name) ?) ;
704
710
} else {
705
711
for ( field_num, field) in expand_svd_cluster ( cluster, name) ?. iter ( ) . enumerate ( ) {
706
712
cluster_expanded. push ( RegisterBlockField {
@@ -901,6 +907,30 @@ fn convert_svd_register(
901
907
} )
902
908
}
903
909
910
+ /// Return an syn::Type for an ArrayProxy.
911
+ fn array_proxy (
912
+ info : & ClusterInfo ,
913
+ array_info : & DimElement ,
914
+ name : Option < & str > ,
915
+ ) -> Result < RegisterBlockField , syn:: Error > {
916
+ let ty_name = util:: replace_suffix ( & info. name , "" ) ;
917
+ let tys = name_to_ty_str ( & ty_name, name) ;
918
+
919
+ let ap_path = parse_str :: < syn:: TypePath > ( & format ! (
920
+ "crate::ArrayProxy<{}, {}, {}>" ,
921
+ tys,
922
+ array_info. dim,
923
+ util:: hex( array_info. dim_increment as u64 )
924
+ ) ) ?;
925
+
926
+ Ok ( RegisterBlockField {
927
+ field : new_syn_field ( & ty_name. to_sanitized_snake_case ( ) , ap_path. into ( ) ) ,
928
+ description : info. description . as_ref ( ) . unwrap_or ( & info. name ) . into ( ) ,
929
+ offset : info. address_offset ,
930
+ size : 0 ,
931
+ } )
932
+ }
933
+
904
934
/// Takes a svd::Cluster which may contain a register array, and turn in into
905
935
/// a list of syn::Field where the register arrays have been expanded.
906
936
fn expand_svd_cluster (
0 commit comments