Skip to content

Commit 69e54fc

Browse files
committed
make Device match specification
1 parent 8bfae9c commit 69e54fc

File tree

5 files changed

+253
-74
lines changed

5 files changed

+253
-74
lines changed

svd-encoder/src/device.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,51 @@ impl Encode for Device {
66

77
fn encode(&self) -> Result<Element, EncodeError> {
88
let mut elem = Element::new("device");
9+
if let Some(v) = &self.vendor {
10+
elem.children.push(new_node("vendor", v.clone()));
11+
}
12+
if let Some(v) = &self.vendor_id {
13+
elem.children.push(new_node("vendorID", v.clone()));
14+
}
15+
916
elem.children.push(new_node("name", self.name.clone()));
1017

11-
if let Some(v) = &self.version {
12-
elem.children.push(new_node("version", v.clone()));
18+
if let Some(v) = &self.series {
19+
elem.children.push(new_node("series", v.clone()));
1320
}
1421

15-
if let Some(v) = &self.description {
16-
elem.children.push(new_node("description", v.clone()));
22+
elem.children
23+
.push(new_node("version", self.version.clone()));
24+
25+
elem.children
26+
.push(new_node("description", self.description.clone()));
27+
28+
if let Some(v) = &self.license_text {
29+
elem.children.push(new_node("licenseText", v.clone()));
1730
}
1831

1932
if let Some(v) = &self.cpu {
2033
elem.children.push(XMLNode::Element(v.encode()?));
2134
}
2235

23-
if let Some(v) = &self.address_unit_bits {
36+
if let Some(v) = &self.header_system_filename {
2437
elem.children
25-
.push(new_node("addressUnitBits", format!("{}", v)));
38+
.push(new_node("headerSystemFilename", v.clone()));
2639
}
2740

28-
if let Some(v) = &self.width {
29-
elem.children.push(new_node("width", format!("{}", v)));
41+
if let Some(v) = &self.header_definitions_prefix {
42+
elem.children
43+
.push(new_node("header_definitions_prefix", v.clone()));
3044
}
3145

46+
elem.children.push(new_node(
47+
"addressUnitBits",
48+
format!("{}", self.address_unit_bits),
49+
));
50+
51+
elem.children
52+
.push(new_node("width", format!("{}", self.width)));
53+
3254
elem.children
3355
.extend(self.default_register_properties.encode()?);
3456

@@ -43,20 +65,14 @@ impl Encode for Device {
4365
XMLNode::Element(e)
4466
});
4567

68+
elem.attributes
69+
.insert(String::from("schemaVersion"), self.schema_version.clone());
70+
elem.attributes
71+
.insert(String::from("xmlns:xs"), self.xmlns_xs.clone());
4672
elem.attributes.insert(
47-
String::from("xmlns:xs"),
48-
String::from("http://www.w3.org/2001/XMLSchema-instance"),
73+
String::from("xs:noNamespaceSchemaLocation"),
74+
self.no_namespace_schema_location.clone(),
4975
);
50-
if let Some(schema_version) = &self.schema_version {
51-
elem.attributes
52-
.insert(String::from("schemaVersion"), schema_version.to_string());
53-
}
54-
if let Some(schema_version) = &self.schema_version {
55-
elem.attributes.insert(
56-
String::from("xs:noNamespaceSchemaLocation"),
57-
format!("CMSIS-SVD_Schema_{}.xsd", schema_version.replace(".", "_")),
58-
);
59-
}
6076

6177
Ok(elem)
6278
}

svd-parser/src/device.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ impl Parse for Device {
1414
return Err(SVDError::NotExpectedTag("device".to_string()).at(tree.id()));
1515
}
1616

17-
Device::builder()
17+
let mut device = Device::builder()
18+
.vendor(tree.get_child_text_opt("vendor")?)
19+
.vendor_id(tree.get_child_text_opt("vendorID")?)
1820
.name(tree.get_child_text("name")?)
19-
.version(tree.get_child_text_opt("version")?)
20-
.description(tree.get_child_text_opt("description")?)
21+
.series(tree.get_child_text_opt("series")?)
22+
.version(tree.get_child_text("version")?)
23+
.description(tree.get_child_text("description")?)
24+
.license_text(tree.get_child_text_opt("licenseText")?)
2125
.cpu(optional::<Cpu>("cpu", tree, config)?)
22-
.address_unit_bits(optional::<u32>("addressUnitBits", tree, &())?)
23-
.width(optional::<u32>("width", tree, &())?)
26+
.header_system_filename(tree.get_child_text_opt("headerSystemFilename")?)
27+
.header_definitions_prefix(tree.get_child_text_opt("headerDefinitionsPrefix")?)
28+
.address_unit_bits(tree.get_child_u32("addressUnitBits")?)
29+
.width(tree.get_child_u32("width")?)
2430
.default_register_properties(RegisterProperties::parse(tree, config)?)
2531
.peripherals({
2632
let ps: Result<Vec<_>, _> = tree
@@ -30,8 +36,17 @@ impl Parse for Device {
3036
.map(|t| Peripheral::parse(&t, config))
3137
.collect();
3238
ps?
33-
})
34-
.schema_version(tree.attribute("schemaVersion").map(|s| s.to_string()))
39+
});
40+
if let Some(xmlns_xs) = tree.attribute("xmlns:xs") {
41+
device = device.xmlns_xs(xmlns_xs.to_string());
42+
}
43+
if let Some(location) = tree.attribute("xs:noNamespaceSchemaLocation") {
44+
device = device.no_namespace_schema_location(location.to_string());
45+
}
46+
if let Some(schema_version) = tree.attribute("schemaVersion") {
47+
device = device.schema_version(schema_version.to_string());
48+
}
49+
device
3550
.build(config.validate_level)
3651
.map_err(|e| SVDError::from(e).at(tree.id()))
3752
}

svd-rs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
- add missing fields in `Device`, require `version`, `description`, `address_unit_bits` and `width`,
11+
also `schema_version` is required, but skipped during (de)serialization
1012
- merge `register` with `registerinfo` modules same as other `info`s
1113
- `EnumeratedValues.usage()` now return `None` if it is derived, fix bug in usage check
1214
- Use generic `SingleArray` enum for types which can be either collected into SVD arrays or have only one instance

svd-rs/src/derive_from.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl DeriveFrom for ClusterInfo {
2929
impl DeriveFrom for EnumeratedValues {
3030
fn derive_from(&self, other: &Self) -> Self {
3131
let mut derived = self.clone();
32-
derived.usage = derived.usage.or_else(|| other.usage.clone());
32+
derived.usage = derived.usage.or(other.usage);
3333
if derived.values.is_empty() {
3434
derived.values = other.values.clone();
3535
}
@@ -80,7 +80,7 @@ impl DeriveFrom for RegisterInfo {
8080

8181
impl DeriveFrom for RegisterProperties {
8282
fn derive_from(&self, other: &Self) -> Self {
83-
let mut derived = self.clone();
83+
let mut derived = *self;
8484
derived.size = derived.size.or(other.size);
8585
derived.access = derived.access.or(other.access);
8686
derived.protection = derived.protection.or(other.protection);

0 commit comments

Comments
 (0)