@@ -13,7 +13,7 @@ use svd_parser::svd::{
13
13
WriteConstraintRange ,
14
14
} ;
15
15
use svd_parser:: SVDError :: DimIndexParse ;
16
- use svd_rs:: { DimElement , DimElementBuilder , MaybeArray } ;
16
+ use svd_rs:: { BitRange , DimElement , DimElementBuilder , MaybeArray } ;
17
17
use yaml_rust:: { yaml:: Hash , Yaml , YamlLoader } ;
18
18
19
19
use anyhow:: { anyhow, Context , Result } ;
@@ -422,22 +422,28 @@ fn make_field(fadd: &Hash) -> Result<FieldInfoBuilder> {
422
422
let mut fnew = FieldInfo :: builder ( )
423
423
. description ( fadd. get_string ( "description" ) ?)
424
424
. 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) ) ;
426
431
427
432
if let Some ( name) = fadd. get_str ( "name" ) ? {
428
433
fnew = fnew. name ( name. into ( ) ) ;
429
434
}
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
+ }
441
447
}
442
448
443
449
Ok ( fnew)
0 commit comments