1
- use super :: { BuildError , EmptyToNone , SvdError , ValidateLevel } ;
1
+ use super :: { BuildError , EmptyToNone , EnumeratedValue , SvdError , ValidateLevel } ;
2
2
use std:: borrow:: Cow ;
3
3
4
4
/// Defines arrays and lists.
@@ -23,6 +23,44 @@ pub struct DimElement {
23
23
serde( default , skip_serializing_if = "Option::is_none" )
24
24
) ]
25
25
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 > ,
26
64
}
27
65
28
66
/// Builder for [`DimElement`]
@@ -31,6 +69,8 @@ pub struct DimElementBuilder {
31
69
dim : Option < u32 > ,
32
70
dim_increment : Option < u32 > ,
33
71
dim_index : Option < Vec < String > > ,
72
+ dim_name : Option < String > ,
73
+ dim_array_index : Option < DimArrayIndex > ,
34
74
}
35
75
36
76
impl From < DimElement > for DimElementBuilder {
@@ -39,26 +79,38 @@ impl From<DimElement> for DimElementBuilder {
39
79
dim : Some ( d. dim ) ,
40
80
dim_increment : Some ( d. dim_increment ) ,
41
81
dim_index : d. dim_index ,
82
+ dim_name : d. dim_name ,
83
+ dim_array_index : d. dim_array_index ,
42
84
}
43
85
}
44
86
}
45
87
46
88
impl DimElementBuilder {
47
- /// set the dim of the elements
89
+ /// Set the dim of the elements
48
90
pub fn dim ( mut self , value : u32 ) -> Self {
49
91
self . dim = Some ( value) ;
50
92
self
51
93
}
52
- /// set the dim increment of the elements
94
+ /// Set the dim increment of the elements
53
95
pub fn dim_increment ( mut self , value : u32 ) -> Self {
54
96
self . dim_increment = Some ( value) ;
55
97
self
56
98
}
57
- /// set the dim index of the elements
99
+ /// Set the dim index of the elements
58
100
pub fn dim_index ( mut self , value : Option < Vec < String > > ) -> Self {
59
101
self . dim_index = value;
60
102
self
61
103
}
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
+ }
62
114
/// Validate and build a [`DimElement`].
63
115
pub fn build ( self , lvl : ValidateLevel ) -> Result < DimElement , SvdError > {
64
116
let mut de = DimElement {
@@ -69,6 +121,8 @@ impl DimElementBuilder {
69
121
. dim_increment
70
122
. ok_or_else ( || BuildError :: Uninitialized ( "dim_increment" . to_string ( ) ) ) ?,
71
123
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 ,
72
126
} ;
73
127
if !lvl. is_disabled ( ) {
74
128
de. validate ( lvl) ?;
@@ -97,6 +151,12 @@ impl DimElement {
97
151
if builder. dim_index . is_some ( ) {
98
152
self . dim_index = builder. dim_index . empty_to_none ( ) ;
99
153
}
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
+ }
100
160
if !lvl. is_disabled ( ) {
101
161
self . validate ( lvl)
102
162
} else {
0 commit comments