Skip to content

Commit 2924c65

Browse files
committed
Make register description optional as per svd spec
Fixes #59
1 parent 9d87a7b commit 2924c65

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/svd/registerinfo.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct RegisterInfo {
2424
pub alternate_group: Option<String>,
2525
pub alternate_register: Option<String>,
2626
pub derived_from: Option<String>,
27-
pub description: String,
27+
pub description: Option<String>,
2828
pub address_offset: u32,
2929
pub size: Option<u32>,
3030
pub access: Option<Access>,
@@ -60,7 +60,7 @@ impl RegisterInfo {
6060
alternate_group: tree.get_child_text_opt("alternateGroup")?,
6161
alternate_register: tree.get_child_text_opt("alternateRegister")?,
6262
derived_from: tree.get_child_text_opt("derivedFrom")?,
63-
description: tree.get_child_text("description")?,
63+
description: tree.get_child_text_opt("description")?,
6464
address_offset: tree.get_child_u32("addressOffset")?,
6565
size: parse::optional::<u32>("size", tree)?,
6666
access: parse::optional::<Access>("access", tree)?,
@@ -105,15 +105,22 @@ impl Encode for RegisterInfo {
105105
attributes: HashMap::new(),
106106
children: vec![
107107
new_element("name", Some(self.name.clone())),
108-
new_element("description", Some(self.description.clone())),
109108
new_element(
110109
"addressOffset",
111110
Some(format!("0x{:x}", self.address_offset)),
112111
),
113112
],
114113
text: None,
115114
};
116-
115+
match self.description {
116+
Some(ref v) => {
117+
elem.children.push(new_element(
118+
"description",
119+
Some(v.clone()),
120+
));
121+
}
122+
None => (),
123+
}
117124
match self.alternate_group {
118125
Some(ref v) => {
119126
elem.children.push(new_element(
@@ -227,7 +234,7 @@ mod tests {
227234
alternate_group: Some(String::from("alternate group")),
228235
alternate_register: Some(String::from("alternate register")),
229236
derived_from: Some(String::from("derived from")),
230-
description: String::from("Write Control Register"),
237+
description: Some(String::from("Write Control Register")),
231238
address_offset: 8,
232239
size: Some(32),
233240
access: Some(Access::ReadWrite),

0 commit comments

Comments
 (0)