Skip to content

Commit b971202

Browse files
bors[bot]burrbull
andauthored
Merge #168
168: add some absent entries for peripheral and cluster r=Emilgardis a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 4d18aef + 9a497f9 commit b971202

File tree

8 files changed

+133
-5
lines changed

8 files changed

+133
-5
lines changed

svd-encoder/src/clusterinfo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ impl Encode for ClusterInfo {
1414
e.children.push(new_node("description", v.clone()));
1515
}
1616

17+
if let Some(v) = &self.alternate_cluster {
18+
e.children.push(new_node("alternateCluster", v.clone()));
19+
}
20+
1721
if let Some(v) = &self.header_struct_name {
1822
e.children.push(new_node("headerStructName", v.clone()));
1923
}

svd-encoder/src/peripheralinfo.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,28 @@ impl Encode for PeripheralInfo {
2121
elem.children.push(new_node("description", v.to_string()));
2222
}
2323

24+
if let Some(v) = &self.alternate_peripheral {
25+
elem.children
26+
.push(new_node("alternatePeripheral", v.to_string()));
27+
}
28+
2429
if let Some(v) = &self.group_name {
2530
elem.children.push(new_node("groupName", v.to_string()));
2631
}
32+
33+
if let Some(v) = &self.prepend_to_name {
34+
elem.children.push(new_node("prependToName", v.to_string()));
35+
}
36+
37+
if let Some(v) = &self.append_to_name {
38+
elem.children.push(new_node("appendToName", v.to_string()));
39+
}
40+
41+
if let Some(v) = &self.header_struct_name {
42+
elem.children
43+
.push(new_node("headerStructName", v.to_string()));
44+
}
45+
2746
elem.children.push(new_node(
2847
"baseAddress",
2948
format!("0x{:.08X}", self.base_address),

svd-parser/src/clusterinfo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl Parse for ClusterInfo {
1010
ClusterInfo::builder()
1111
.name(tree.get_child_text("name")?)
1212
.description(tree.get_child_text_opt("description")?)
13+
.alternate_cluster(tree.get_child_text_opt("alternateCluster")?)
1314
.header_struct_name(tree.get_child_text_opt("headerStructName")?)
1415
.address_offset(tree.get_child_u32("addressOffset")?)
1516
.default_register_properties(RegisterProperties::parse(tree, config)?)

svd-parser/src/peripheralinfo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ impl Parse for PeripheralInfo {
1616
.display_name(tree.get_child_text_opt("displayName")?)
1717
.version(tree.get_child_text_opt("version")?)
1818
.description(tree.get_child_text_opt("description")?)
19+
.alternate_peripheral(tree.get_child_text_opt("alternatePeripheral")?)
1920
.group_name(tree.get_child_text_opt("groupName")?)
21+
.prepend_to_name(tree.get_child_text_opt("prependToName")?)
22+
.append_to_name(tree.get_child_text_opt("appendToName")?)
23+
.header_struct_name(tree.get_child_text_opt("headerStructName")?)
2024
.base_address(tree.get_child_u64("baseAddress")?)
2125
.default_register_properties(RegisterProperties::parse(tree, config)?)
2226
.address_block({

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 `alternate_peripheral`, `prepend_to_name`, `append_to_name`,
11+
`header_struct_name` to `PeripheralInfo`, `alternate_cluster` to `ClusterInfo`
1012
- Add `protection` to `RegisterProperties` and `AddressBlock`
1113
- Add `readAction` to `RegisterInfo` and `FieldInfo`
1214
- Add `single` and `array` for `Info` types,

svd-rs/src/clusterinfo.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ pub struct ClusterInfo {
3232
)]
3333
pub description: Option<String>,
3434

35-
// alternateCluster
35+
/// Specify the name of the original cluster if this cluster provides an alternative description
36+
#[cfg_attr(
37+
feature = "serde",
38+
serde(default, skip_serializing_if = "Option::is_none")
39+
)]
40+
pub alternate_cluster: Option<String>,
41+
3642
/// Specify the struct type name created in the device header file
3743
#[cfg_attr(
3844
feature = "serde",
@@ -64,6 +70,7 @@ pub struct ClusterInfo {
6470
pub struct ClusterInfoBuilder {
6571
name: Option<String>,
6672
description: Option<String>,
73+
alternate_cluster: Option<String>,
6774
header_struct_name: Option<String>,
6875
address_offset: Option<u32>,
6976
default_register_properties: RegisterProperties,
@@ -76,6 +83,7 @@ impl From<ClusterInfo> for ClusterInfoBuilder {
7683
Self {
7784
name: Some(c.name),
7885
description: c.description,
86+
alternate_cluster: c.alternate_cluster,
7987
header_struct_name: c.header_struct_name,
8088
address_offset: Some(c.address_offset),
8189
default_register_properties: c.default_register_properties,
@@ -96,6 +104,11 @@ impl ClusterInfoBuilder {
96104
self.description = value;
97105
self
98106
}
107+
/// Set the alternate cluster.
108+
pub fn alternate_cluster(mut self, value: Option<String>) -> Self {
109+
self.alternate_cluster = value;
110+
self
111+
}
99112
/// Set the struct type name of the cluster. If not specified, the name of the cluster should be used.
100113
pub fn header_struct_name(mut self, value: Option<String>) -> Self {
101114
self.header_struct_name = value;
@@ -128,6 +141,7 @@ impl ClusterInfoBuilder {
128141
.name
129142
.ok_or_else(|| BuildError::Uninitialized("name".to_string()))?,
130143
description: self.description.empty_to_none(),
144+
alternate_cluster: self.alternate_cluster.empty_to_none(),
131145
header_struct_name: self.header_struct_name.empty_to_none(),
132146
address_offset: self
133147
.address_offset
@@ -170,6 +184,9 @@ impl ClusterInfo {
170184
if builder.description.is_some() {
171185
self.description = builder.description.empty_to_none();
172186
}
187+
if builder.alternate_cluster.is_some() {
188+
self.alternate_cluster = builder.alternate_cluster.empty_to_none();
189+
}
173190
if builder.header_struct_name.is_some() {
174191
self.header_struct_name = builder.header_struct_name.empty_to_none();
175192
}

svd-rs/src/derive_from.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,18 @@ impl DeriveFrom for EnumeratedValues {
4040
impl DeriveFrom for PeripheralInfo {
4141
fn derive_from(&self, other: &Self) -> Self {
4242
let mut derived = self.clone();
43-
derived.group_name = derived.group_name.or_else(|| other.group_name.clone());
43+
derived.version = derived.version.or_else(|| other.version.clone());
4444
derived.description = derived.description.or_else(|| other.description.clone());
45+
derived.group_name = derived.group_name.or_else(|| other.group_name.clone());
46+
derived.prepend_to_name = derived
47+
.prepend_to_name
48+
.or_else(|| other.prepend_to_name.clone());
49+
derived.append_to_name = derived
50+
.append_to_name
51+
.or_else(|| other.append_to_name.clone());
52+
derived.header_struct_name = derived
53+
.header_struct_name
54+
.or_else(|| other.header_struct_name.clone());
4555
derived.default_register_properties = derived
4656
.default_register_properties
4757
.derive_from(&other.default_register_properties);
@@ -72,9 +82,10 @@ impl DeriveFrom for RegisterProperties {
7282
fn derive_from(&self, other: &Self) -> Self {
7383
let mut derived = self.clone();
7484
derived.size = derived.size.or(other.size);
85+
derived.access = derived.access.or(other.access);
86+
derived.protection = derived.protection.or(other.protection);
7587
derived.reset_value = derived.reset_value.or(other.reset_value);
7688
derived.reset_mask = derived.reset_mask.or(other.reset_mask);
77-
derived.access = derived.access.or(other.access);
7889
derived
7990
}
8091
}

svd-rs/src/peripheralinfo.rs

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,41 @@ pub struct PeripheralInfo {
4545
)]
4646
pub description: Option<String>,
4747

48-
// alternatePeripheral
48+
/// Specifies peripheral assigned to the same address blocks
49+
#[cfg_attr(
50+
feature = "serde",
51+
serde(default, skip_serializing_if = "Option::is_none")
52+
)]
53+
pub alternate_peripheral: Option<String>,
54+
4955
/// Assigns this peripheral to a group of peripherals. This is only used bye the System View
5056
#[cfg_attr(
5157
feature = "serde",
5258
serde(default, skip_serializing_if = "Option::is_none")
5359
)]
5460
pub group_name: Option<String>,
5561

56-
// headerStructName
62+
/// Define a string as prefix. All register names of this peripheral get this prefix
63+
#[cfg_attr(
64+
feature = "serde",
65+
serde(default, skip_serializing_if = "Option::is_none")
66+
)]
67+
pub prepend_to_name: Option<String>,
68+
69+
/// Define a string as suffix. All register names of this peripheral get this suffix
70+
#[cfg_attr(
71+
feature = "serde",
72+
serde(default, skip_serializing_if = "Option::is_none")
73+
)]
74+
pub append_to_name: Option<String>,
75+
76+
/// Specify the struct type name created in the device header file
77+
#[cfg_attr(
78+
feature = "serde",
79+
serde(default, skip_serializing_if = "Option::is_none")
80+
)]
81+
pub header_struct_name: Option<String>,
82+
5783
/// Lowest address reserved or used by the peripheral
5884
pub base_address: u64,
5985

@@ -98,7 +124,11 @@ pub struct PeripheralInfoBuilder {
98124
display_name: Option<String>,
99125
version: Option<String>,
100126
description: Option<String>,
127+
alternate_peripheral: Option<String>,
101128
group_name: Option<String>,
129+
prepend_to_name: Option<String>,
130+
append_to_name: Option<String>,
131+
header_struct_name: Option<String>,
102132
base_address: Option<u64>,
103133
default_register_properties: RegisterProperties,
104134
address_block: Option<Vec<AddressBlock>>,
@@ -114,7 +144,11 @@ impl From<PeripheralInfo> for PeripheralInfoBuilder {
114144
display_name: p.display_name,
115145
version: p.version,
116146
description: p.description,
147+
alternate_peripheral: p.alternate_peripheral,
117148
group_name: p.group_name,
149+
prepend_to_name: p.prepend_to_name,
150+
append_to_name: p.append_to_name,
151+
header_struct_name: p.header_struct_name,
118152
base_address: Some(p.base_address),
119153
default_register_properties: p.default_register_properties,
120154
address_block: p.address_block,
@@ -146,11 +180,31 @@ impl PeripheralInfoBuilder {
146180
self.description = value;
147181
self
148182
}
183+
/// Set the alternate peripheral
184+
pub fn alternate_peripheral(mut self, value: Option<String>) -> Self {
185+
self.alternate_peripheral = value;
186+
self
187+
}
149188
/// Set the group name of the peripheral
150189
pub fn group_name(mut self, value: Option<String>) -> Self {
151190
self.group_name = value;
152191
self
153192
}
193+
/// Set the prefix for names of all registers of the peripheral
194+
pub fn prepend_to_name(mut self, value: Option<String>) -> Self {
195+
self.prepend_to_name = value;
196+
self
197+
}
198+
/// Set the suffix for names of all registers of the peripheral
199+
pub fn append_to_name(mut self, value: Option<String>) -> Self {
200+
self.append_to_name = value;
201+
self
202+
}
203+
/// Set the header struct name of the peripheral
204+
pub fn header_struct_name(mut self, value: Option<String>) -> Self {
205+
self.header_struct_name = value;
206+
self
207+
}
154208
/// Set the base address of the peripheral
155209
pub fn base_address(mut self, value: u64) -> Self {
156210
self.base_address = Some(value);
@@ -190,7 +244,11 @@ impl PeripheralInfoBuilder {
190244
display_name: self.display_name.empty_to_none(),
191245
version: self.version.empty_to_none(),
192246
description: self.description.empty_to_none(),
247+
alternate_peripheral: self.alternate_peripheral.empty_to_none(),
193248
group_name: self.group_name.empty_to_none(),
249+
prepend_to_name: self.prepend_to_name.empty_to_none(),
250+
append_to_name: self.append_to_name.empty_to_none(),
251+
header_struct_name: self.header_struct_name.empty_to_none(),
194252
base_address: self
195253
.base_address
196254
.ok_or_else(|| BuildError::Uninitialized("base_address".to_string()))?,
@@ -238,9 +296,21 @@ impl PeripheralInfo {
238296
if builder.description.is_some() {
239297
self.description = builder.description.empty_to_none();
240298
}
299+
if builder.alternate_peripheral.is_some() {
300+
self.alternate_peripheral = builder.alternate_peripheral.empty_to_none();
301+
}
241302
if builder.group_name.is_some() {
242303
self.group_name = builder.group_name.empty_to_none();
243304
}
305+
if builder.prepend_to_name.is_some() {
306+
self.prepend_to_name = builder.prepend_to_name.empty_to_none();
307+
}
308+
if builder.append_to_name.is_some() {
309+
self.append_to_name = builder.append_to_name.empty_to_none();
310+
}
311+
if builder.header_struct_name.is_some() {
312+
self.header_struct_name = builder.header_struct_name.empty_to_none();
313+
}
244314
if let Some(base_address) = builder.base_address {
245315
self.base_address = base_address;
246316
}

0 commit comments

Comments
 (0)