@@ -25,7 +25,7 @@ use svd_parser::{
25
25
expand:: { derive_peripheral, Index } ,
26
26
svd:: { Access , Cluster , Register , RegisterInfo , WriteConstraint } ,
27
27
} ;
28
- use svd_rs:: { EnumeratedValue , EnumeratedValues } ;
28
+ use svd_rs:: { EnumeratedValue , EnumeratedValues , ModifiedWriteValues , ReadAction } ;
29
29
30
30
fn sanitize ( input : & str ) -> String {
31
31
use once_cell:: sync:: Lazy ;
@@ -95,6 +95,31 @@ fn short_access(accs: &str) -> &str {
95
95
}
96
96
}
97
97
98
+ fn short_mwv ( mwv : ModifiedWriteValues ) -> & ' static str {
99
+ use ModifiedWriteValues :: * ;
100
+ match mwv {
101
+ OneToClear => "w1c" ,
102
+ OneToSet => "w1s" ,
103
+ OneToToggle => "w1t" ,
104
+ ZeroToClear => "w0c" ,
105
+ ZeroToSet => "w0s" ,
106
+ ZeroToToggle => "w0t" ,
107
+ Clear => "wc" ,
108
+ Set => "ws" ,
109
+ Modify => "w" ,
110
+ }
111
+ }
112
+
113
+ fn short_ra ( ra : Option < ReadAction > ) -> & ' static str {
114
+ match ra {
115
+ None => "r" ,
116
+ Some ( ReadAction :: Clear ) => "rc" ,
117
+ Some ( ReadAction :: Set ) => "rs" ,
118
+ Some ( ReadAction :: Modify ) => "rm" ,
119
+ Some ( ReadAction :: ModifyExternal ) => "re" ,
120
+ }
121
+ }
122
+
98
123
trait GetI64 {
99
124
fn get_i64 ( & self , key : & str ) -> Option < i64 > ;
100
125
fn get_str ( & self , key : & str ) -> Option < Cow < str > > ;
@@ -328,7 +353,19 @@ fn parse_register(
328
353
for ( ftag, _) in flds. iter ( ) . rev ( ) {
329
354
let foffset = ftag. bit_offset ( ) ;
330
355
let faccs = ftag. access . map ( Access :: as_str) . unwrap_or ( raccs) ;
331
- let access = short_access ( faccs) ;
356
+ let mut access = short_access ( faccs) . to_string ( ) ;
357
+ let mwv = ftag
358
+ . modified_write_values
359
+ . unwrap_or ( ModifiedWriteValues :: Modify ) ;
360
+ let ra = ftag. read_action ;
361
+ if access != "N/A" {
362
+ match ( faccs, mwv, ra) {
363
+ ( _, ModifiedWriteValues :: Modify , None ) => { }
364
+ ( "read-only" , _, ra) => access = short_ra ( ra) . to_string ( ) ,
365
+ ( "write-only" , mwv, _) => access = short_mwv ( mwv) . to_string ( ) ,
366
+ ( _, mwv, ra) => access = format ! ( "{}/{}" , short_ra( ra) , short_mwv( mwv) ) ,
367
+ } ;
368
+ }
332
369
let fwidth = ftag. bit_width ( ) ;
333
370
if foffset + fwidth > rsize {
334
371
return Err ( anyhow ! ( "Wrong field offset/width" ) ) ;
0 commit comments