@@ -2,7 +2,9 @@ use std::borrow::Cow;
22use std:: cmp:: Ordering ;
33use std:: collections:: HashMap ;
44
5- use crate :: svd:: { Cluster , ClusterInfo , Peripheral , Register , RegisterCluster , RegisterProperties } ;
5+ use crate :: svd:: {
6+ Cluster , ClusterInfo , DimElement , Peripheral , Register , RegisterCluster , RegisterProperties ,
7+ } ;
68use log:: warn;
79use proc_macro2:: TokenStream ;
810use proc_macro2:: { Ident , Punct , Spacing , Span } ;
@@ -701,6 +703,10 @@ fn expand_cluster(
701703 offset : info. address_offset ,
702704 size : cluster_size * array_info. dim ,
703705 } ) ;
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) ?) ;
704710 } else {
705711 for ( field_num, field) in expand_svd_cluster ( cluster, name) ?. iter ( ) . enumerate ( ) {
706712 cluster_expanded. push ( RegisterBlockField {
@@ -901,6 +907,30 @@ fn convert_svd_register(
901907 } )
902908}
903909
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+
904934/// Takes a svd::Cluster which may contain a register array, and turn in into
905935/// a list of syn::Field where the register arrays have been expanded.
906936fn expand_svd_cluster (
0 commit comments