@@ -9,7 +9,7 @@ use svd_parser::svd::{
99 AddressBlockUsage , ClusterInfo , ClusterInfoBuilder , Cpu , CpuBuilder , Endian , EnumeratedValue ,
1010 EnumeratedValues , EnumeratedValuesBuilder , FieldInfo , FieldInfoBuilder , Interrupt ,
1111 PeripheralInfo , PeripheralInfoBuilder , RegisterCluster , RegisterInfo , RegisterInfoBuilder ,
12- RegisterProperties , Usage , ValidateLevel ,
12+ RegisterProperties , Usage , ValidateLevel , WriteConstraint , WriteConstraintRange ,
1313} ;
1414use svd_parser:: SVDError :: DimIndexParse ;
1515use svd_rs:: { DimElement , DimElementBuilder , MaybeArray } ;
@@ -423,6 +423,32 @@ fn make_register(radd: &Hash) -> Result<RegisterInfoBuilder> {
423423 if let Some ( address_offset) = radd. get_i64 ( "addressOffset" ) ? {
424424 rnew = rnew. address_offset ( address_offset as u32 ) ;
425425 }
426+
427+ if let Some ( write_constraint) = radd
428+ . get ( & "_write_constraint" . to_yaml ( ) )
429+ . or_else ( || radd. get ( & "writeConstraint" . to_yaml ( ) ) )
430+ {
431+ let wc = match write_constraint {
432+ Yaml :: String ( s) if s == "none" => {
433+ // Completely remove the existing writeConstraint
434+ None
435+ }
436+ Yaml :: String ( s) if s == "enum" => {
437+ // Only allow enumerated values
438+ Some ( WriteConstraint :: UseEnumeratedValues ( true ) )
439+ }
440+ Yaml :: Array ( a) => {
441+ // Allow a certain range
442+ Some ( WriteConstraint :: Range ( WriteConstraintRange {
443+ min : a[ 0 ] . i64 ( ) ? as u64 ,
444+ max : a[ 1 ] . i64 ( ) ? as u64 ,
445+ } ) )
446+ }
447+ _ => return Err ( anyhow ! ( "Unknown writeConstraint type {write_constraint:?}" ) ) ,
448+ } ;
449+ rnew = rnew. write_constraint ( wc) ;
450+ }
451+
426452 Ok ( rnew)
427453}
428454
0 commit comments