1- use super :: { BuildError , EmptyToNone , SvdError , ValidateLevel } ;
1+ use super :: { BuildError , EmptyToNone , EnumeratedValue , SvdError , ValidateLevel } ;
22use std:: borrow:: Cow ;
33
44/// Defines arrays and lists.
@@ -23,6 +23,44 @@ pub struct DimElement {
2323 serde( default , skip_serializing_if = "Option::is_none" )
2424 ) ]
2525 pub dim_index : Option < Vec < String > > ,
26+
27+ /// Specify the name of the structure. If not defined, then the entry of the `name` element is used
28+ #[ cfg_attr(
29+ feature = "serde" ,
30+ serde( default , skip_serializing_if = "Option::is_none" )
31+ ) ]
32+ pub dim_name : Option < String > ,
33+
34+ /// Grouping element to create enumerations in the header file
35+ #[ cfg_attr(
36+ feature = "serde" ,
37+ serde( default , skip_serializing_if = "Option::is_none" )
38+ ) ]
39+ pub dim_array_index : Option < DimArrayIndex > ,
40+ }
41+
42+ /// Grouping element to create enumerations in the header file
43+ ///
44+ /// This information is used for generating an enum in the device header file.
45+ /// The debugger may use this information to display the identifier string
46+ /// as well as the description. Just like symbolic constants making source
47+ /// code more readable, the system view in the debugger becomes more instructive
48+ #[ cfg_attr(
49+ feature = "serde" ,
50+ derive( serde:: Deserialize , serde:: Serialize ) ,
51+ serde( rename_all = "camelCase" )
52+ ) ]
53+ #[ derive( Clone , Debug , PartialEq ) ]
54+ pub struct DimArrayIndex {
55+ /// Specify the base name of enumerations
56+ #[ cfg_attr(
57+ feature = "serde" ,
58+ serde( default , skip_serializing_if = "Option::is_none" )
59+ ) ]
60+ pub header_enum_name : Option < String > ,
61+
62+ /// Specify the values contained in the enumeration
63+ pub values : Vec < EnumeratedValue > ,
2664}
2765
2866/// Builder for [`DimElement`]
@@ -31,6 +69,8 @@ pub struct DimElementBuilder {
3169 dim : Option < u32 > ,
3270 dim_increment : Option < u32 > ,
3371 dim_index : Option < Vec < String > > ,
72+ dim_name : Option < String > ,
73+ dim_array_index : Option < DimArrayIndex > ,
3474}
3575
3676impl From < DimElement > for DimElementBuilder {
@@ -39,26 +79,38 @@ impl From<DimElement> for DimElementBuilder {
3979 dim : Some ( d. dim ) ,
4080 dim_increment : Some ( d. dim_increment ) ,
4181 dim_index : d. dim_index ,
82+ dim_name : d. dim_name ,
83+ dim_array_index : d. dim_array_index ,
4284 }
4385 }
4486}
4587
4688impl DimElementBuilder {
47- /// set the dim of the elements
89+ /// Set the dim of the elements
4890 pub fn dim ( mut self , value : u32 ) -> Self {
4991 self . dim = Some ( value) ;
5092 self
5193 }
52- /// set the dim increment of the elements
94+ /// Set the dim increment of the elements
5395 pub fn dim_increment ( mut self , value : u32 ) -> Self {
5496 self . dim_increment = Some ( value) ;
5597 self
5698 }
57- /// set the dim index of the elements
99+ /// Set the dim index of the elements
58100 pub fn dim_index ( mut self , value : Option < Vec < String > > ) -> Self {
59101 self . dim_index = value;
60102 self
61103 }
104+ /// Set the dim name of the elements
105+ pub fn dim_name ( mut self , value : Option < String > ) -> Self {
106+ self . dim_name = value;
107+ self
108+ }
109+ /// Set the dim_array_index of the elements
110+ pub fn dim_array_index ( mut self , value : Option < DimArrayIndex > ) -> Self {
111+ self . dim_array_index = value;
112+ self
113+ }
62114 /// Validate and build a [`DimElement`].
63115 pub fn build ( self , lvl : ValidateLevel ) -> Result < DimElement , SvdError > {
64116 let mut de = DimElement {
@@ -69,6 +121,8 @@ impl DimElementBuilder {
69121 . dim_increment
70122 . ok_or_else ( || BuildError :: Uninitialized ( "dim_increment" . to_string ( ) ) ) ?,
71123 dim_index : self . dim_index . empty_to_none ( ) ,
124+ dim_name : self . dim_name . empty_to_none ( ) ,
125+ dim_array_index : self . dim_array_index ,
72126 } ;
73127 if !lvl. is_disabled ( ) {
74128 de. validate ( lvl) ?;
@@ -97,6 +151,12 @@ impl DimElement {
97151 if builder. dim_index . is_some ( ) {
98152 self . dim_index = builder. dim_index . empty_to_none ( ) ;
99153 }
154+ if builder. dim_name . is_some ( ) {
155+ self . dim_name = builder. dim_name . empty_to_none ( ) ;
156+ }
157+ if builder. dim_array_index . is_some ( ) {
158+ self . dim_array_index = builder. dim_array_index ;
159+ }
100160 if !lvl. is_disabled ( ) {
101161 self . validate ( lvl)
102162 } else {
0 commit comments