@@ -13,7 +13,7 @@ use svd_parser::svd::{
1313 WriteConstraintRange ,
1414} ;
1515use svd_parser:: SVDError :: DimIndexParse ;
16- use svd_rs:: { DimElement , DimElementBuilder , MaybeArray } ;
16+ use svd_rs:: { BitRange , DimElement , DimElementBuilder , MaybeArray } ;
1717use yaml_rust:: { yaml:: Hash , Yaml , YamlLoader } ;
1818
1919use anyhow:: { anyhow, Context , Result } ;
@@ -422,22 +422,28 @@ fn make_field(fadd: &Hash) -> Result<FieldInfoBuilder> {
422422 let mut fnew = FieldInfo :: builder ( )
423423 . description ( fadd. get_string ( "description" ) ?)
424424 . derived_from ( fadd. get_string ( "derivedFrom" ) ?)
425- . access ( fadd. get_str ( "access" ) ?. and_then ( Access :: parse_str) ) ;
425+ . access ( fadd. get_str ( "access" ) ?. and_then ( Access :: parse_str) )
426+ . modified_write_values (
427+ fadd. get_str ( "modifiedWriteValues" ) ?
428+ . and_then ( ModifiedWriteValues :: parse_str) ,
429+ )
430+ . read_action ( fadd. get_str ( "readAction" ) ?. and_then ( ReadAction :: parse_str) ) ;
426431
427432 if let Some ( name) = fadd. get_str ( "name" ) ? {
428433 fnew = fnew. name ( name. into ( ) ) ;
429434 }
430- if let Some ( offset) = fadd. get_i64 ( "bitOffset" ) ? {
431- fnew = fnew. bit_offset ( offset as u32 )
432- }
433- if let Some ( width) = fadd. get_i64 ( "bitWidth" ) ? {
434- fnew = fnew. bit_width ( width as u32 )
435- }
436- if let Some ( modified_write_values) = fadd. get_str ( "modifiedWriteValues" ) ? {
437- fnew = fnew. modified_write_values ( ModifiedWriteValues :: parse_str ( modified_write_values) )
438- }
439- if let Some ( read_action) = fadd. get_str ( "readAction" ) ? {
440- fnew = fnew. read_action ( ReadAction :: parse_str ( read_action) )
435+ // NOTE: support only both `msb` and `lsb` passed together
436+ if let ( Some ( msb) , Some ( lsb) ) = ( fadd. get_i64 ( "msb" ) ?, fadd. get_i64 ( "lsb" ) ?) {
437+ fnew = fnew. bit_range ( BitRange :: from_msb_lsb ( msb as _ , lsb as _ ) ) ;
438+ } else if let Some ( bit_range) = fadd. get_str ( "bitRange" ) ?. and_then ( BitRange :: from_bit_range) {
439+ fnew = fnew. bit_range ( bit_range) ;
440+ } else {
441+ if let Some ( offset) = fadd. get_i64 ( "bitOffset" ) ? {
442+ fnew = fnew. bit_offset ( offset as u32 )
443+ }
444+ if let Some ( width) = fadd. get_i64 ( "bitWidth" ) ? {
445+ fnew = fnew. bit_width ( width as u32 )
446+ }
441447 }
442448
443449 Ok ( fnew)
0 commit comments