Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions svd-encoder/src/clusterinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ impl Encode for ClusterInfo {
e.children.push(new_node("description", v.clone()));
}

if let Some(v) = &self.alternate_cluster {
e.children.push(new_node("alternateCluster", v.clone()));
}

if let Some(v) = &self.header_struct_name {
e.children.push(new_node("headerStructName", v.clone()));
}
Expand Down
19 changes: 19 additions & 0 deletions svd-encoder/src/peripheralinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,28 @@ impl Encode for PeripheralInfo {
elem.children.push(new_node("description", v.to_string()));
}

if let Some(v) = &self.alternate_peripheral {
elem.children
.push(new_node("alternatePeripheral", v.to_string()));
}

if let Some(v) = &self.group_name {
elem.children.push(new_node("groupName", v.to_string()));
}

if let Some(v) = &self.prepend_to_name {
elem.children.push(new_node("prependToName", v.to_string()));
}

if let Some(v) = &self.append_to_name {
elem.children.push(new_node("appendToName", v.to_string()));
}

if let Some(v) = &self.header_struct_name {
elem.children
.push(new_node("headerStructName", v.to_string()));
}

elem.children.push(new_node(
"baseAddress",
format!("0x{:.08X}", self.base_address),
Expand Down
1 change: 1 addition & 0 deletions svd-parser/src/clusterinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl Parse for ClusterInfo {
ClusterInfo::builder()
.name(tree.get_child_text("name")?)
.description(tree.get_child_text_opt("description")?)
.alternate_cluster(tree.get_child_text_opt("alternateCluster")?)
.header_struct_name(tree.get_child_text_opt("headerStructName")?)
.address_offset(tree.get_child_u32("addressOffset")?)
.default_register_properties(RegisterProperties::parse(tree, config)?)
Expand Down
4 changes: 4 additions & 0 deletions svd-parser/src/peripheralinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl Parse for PeripheralInfo {
.display_name(tree.get_child_text_opt("displayName")?)
.version(tree.get_child_text_opt("version")?)
.description(tree.get_child_text_opt("description")?)
.alternate_peripheral(tree.get_child_text_opt("alternatePeripheral")?)
.group_name(tree.get_child_text_opt("groupName")?)
.prepend_to_name(tree.get_child_text_opt("prependToName")?)
.append_to_name(tree.get_child_text_opt("appendToName")?)
.header_struct_name(tree.get_child_text_opt("headerStructName")?)
.base_address(tree.get_child_u64("baseAddress")?)
.default_register_properties(RegisterProperties::parse(tree, config)?)
.address_block({
Expand Down
2 changes: 2 additions & 0 deletions svd-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- Add `alternate_peripheral`, `prepend_to_name`, `append_to_name`,
`header_struct_name` to `PeripheralInfo`, `alternate_cluster` to `ClusterInfo`
- Add `protection` to `RegisterProperties` and `AddressBlock`
- Add `readAction` to `RegisterInfo` and `FieldInfo`
- Add `single` and `array` for `Info` types,
Expand Down
19 changes: 18 additions & 1 deletion svd-rs/src/clusterinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ pub struct ClusterInfo {
)]
pub description: Option<String>,

// alternateCluster
/// Specify the name of the original cluster if this cluster provides an alternative description
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub alternate_cluster: Option<String>,

/// Specify the struct type name created in the device header file
#[cfg_attr(
feature = "serde",
Expand Down Expand Up @@ -64,6 +70,7 @@ pub struct ClusterInfo {
pub struct ClusterInfoBuilder {
name: Option<String>,
description: Option<String>,
alternate_cluster: Option<String>,
header_struct_name: Option<String>,
address_offset: Option<u32>,
default_register_properties: RegisterProperties,
Expand All @@ -76,6 +83,7 @@ impl From<ClusterInfo> for ClusterInfoBuilder {
Self {
name: Some(c.name),
description: c.description,
alternate_cluster: c.alternate_cluster,
header_struct_name: c.header_struct_name,
address_offset: Some(c.address_offset),
default_register_properties: c.default_register_properties,
Expand All @@ -96,6 +104,11 @@ impl ClusterInfoBuilder {
self.description = value;
self
}
/// Set the alternate cluster.
pub fn alternate_cluster(mut self, value: Option<String>) -> Self {
self.alternate_cluster = value;
self
}
/// Set the struct type name of the cluster. If not specified, the name of the cluster should be used.
pub fn header_struct_name(mut self, value: Option<String>) -> Self {
self.header_struct_name = value;
Expand Down Expand Up @@ -128,6 +141,7 @@ impl ClusterInfoBuilder {
.name
.ok_or_else(|| BuildError::Uninitialized("name".to_string()))?,
description: self.description.empty_to_none(),
alternate_cluster: self.alternate_cluster.empty_to_none(),
header_struct_name: self.header_struct_name.empty_to_none(),
address_offset: self
.address_offset
Expand Down Expand Up @@ -170,6 +184,9 @@ impl ClusterInfo {
if builder.description.is_some() {
self.description = builder.description.empty_to_none();
}
if builder.alternate_cluster.is_some() {
self.alternate_cluster = builder.alternate_cluster.empty_to_none();
}
if builder.header_struct_name.is_some() {
self.header_struct_name = builder.header_struct_name.empty_to_none();
}
Expand Down
15 changes: 13 additions & 2 deletions svd-rs/src/derive_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ impl DeriveFrom for EnumeratedValues {
impl DeriveFrom for PeripheralInfo {
fn derive_from(&self, other: &Self) -> Self {
let mut derived = self.clone();
derived.group_name = derived.group_name.or_else(|| other.group_name.clone());
derived.version = derived.version.or_else(|| other.version.clone());
derived.description = derived.description.or_else(|| other.description.clone());
derived.group_name = derived.group_name.or_else(|| other.group_name.clone());
derived.prepend_to_name = derived
.prepend_to_name
.or_else(|| other.prepend_to_name.clone());
derived.append_to_name = derived
.append_to_name
.or_else(|| other.append_to_name.clone());
derived.header_struct_name = derived
.header_struct_name
.or_else(|| other.header_struct_name.clone());
derived.default_register_properties = derived
.default_register_properties
.derive_from(&other.default_register_properties);
Expand Down Expand Up @@ -72,9 +82,10 @@ impl DeriveFrom for RegisterProperties {
fn derive_from(&self, other: &Self) -> Self {
let mut derived = self.clone();
derived.size = derived.size.or(other.size);
derived.access = derived.access.or(other.access);
derived.protection = derived.protection.or(other.protection);
derived.reset_value = derived.reset_value.or(other.reset_value);
derived.reset_mask = derived.reset_mask.or(other.reset_mask);
derived.access = derived.access.or(other.access);
derived
}
}
Expand Down
74 changes: 72 additions & 2 deletions svd-rs/src/peripheralinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,41 @@ pub struct PeripheralInfo {
)]
pub description: Option<String>,

// alternatePeripheral
/// Specifies peripheral assigned to the same address blocks
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub alternate_peripheral: Option<String>,

/// Assigns this peripheral to a group of peripherals. This is only used bye the System View
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub group_name: Option<String>,

// headerStructName
/// Define a string as prefix. All register names of this peripheral get this prefix
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub prepend_to_name: Option<String>,

/// Define a string as suffix. All register names of this peripheral get this suffix
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub append_to_name: Option<String>,

/// Specify the struct type name created in the device header file
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub header_struct_name: Option<String>,

/// Lowest address reserved or used by the peripheral
pub base_address: u64,

Expand Down Expand Up @@ -98,7 +124,11 @@ pub struct PeripheralInfoBuilder {
display_name: Option<String>,
version: Option<String>,
description: Option<String>,
alternate_peripheral: Option<String>,
group_name: Option<String>,
prepend_to_name: Option<String>,
append_to_name: Option<String>,
header_struct_name: Option<String>,
base_address: Option<u64>,
default_register_properties: RegisterProperties,
address_block: Option<Vec<AddressBlock>>,
Expand All @@ -114,7 +144,11 @@ impl From<PeripheralInfo> for PeripheralInfoBuilder {
display_name: p.display_name,
version: p.version,
description: p.description,
alternate_peripheral: p.alternate_peripheral,
group_name: p.group_name,
prepend_to_name: p.prepend_to_name,
append_to_name: p.append_to_name,
header_struct_name: p.header_struct_name,
base_address: Some(p.base_address),
default_register_properties: p.default_register_properties,
address_block: p.address_block,
Expand Down Expand Up @@ -146,11 +180,31 @@ impl PeripheralInfoBuilder {
self.description = value;
self
}
/// Set the alternate peripheral
pub fn alternate_peripheral(mut self, value: Option<String>) -> Self {
self.alternate_peripheral = value;
self
}
/// Set the group name of the peripheral
pub fn group_name(mut self, value: Option<String>) -> Self {
self.group_name = value;
self
}
/// Set the prefix for names of all registers of the peripheral
pub fn prepend_to_name(mut self, value: Option<String>) -> Self {
self.prepend_to_name = value;
self
}
/// Set the suffix for names of all registers of the peripheral
pub fn append_to_name(mut self, value: Option<String>) -> Self {
self.append_to_name = value;
self
}
/// Set the header struct name of the peripheral
pub fn header_struct_name(mut self, value: Option<String>) -> Self {
self.header_struct_name = value;
self
}
/// Set the base address of the peripheral
pub fn base_address(mut self, value: u64) -> Self {
self.base_address = Some(value);
Expand Down Expand Up @@ -190,7 +244,11 @@ impl PeripheralInfoBuilder {
display_name: self.display_name.empty_to_none(),
version: self.version.empty_to_none(),
description: self.description.empty_to_none(),
alternate_peripheral: self.alternate_peripheral.empty_to_none(),
group_name: self.group_name.empty_to_none(),
prepend_to_name: self.prepend_to_name.empty_to_none(),
append_to_name: self.append_to_name.empty_to_none(),
header_struct_name: self.header_struct_name.empty_to_none(),
base_address: self
.base_address
.ok_or_else(|| BuildError::Uninitialized("base_address".to_string()))?,
Expand Down Expand Up @@ -238,9 +296,21 @@ impl PeripheralInfo {
if builder.description.is_some() {
self.description = builder.description.empty_to_none();
}
if builder.alternate_peripheral.is_some() {
self.alternate_peripheral = builder.alternate_peripheral.empty_to_none();
}
if builder.group_name.is_some() {
self.group_name = builder.group_name.empty_to_none();
}
if builder.prepend_to_name.is_some() {
self.prepend_to_name = builder.prepend_to_name.empty_to_none();
}
if builder.append_to_name.is_some() {
self.append_to_name = builder.append_to_name.empty_to_none();
}
if builder.header_struct_name.is_some() {
self.header_struct_name = builder.header_struct_name.empty_to_none();
}
if let Some(base_address) = builder.base_address {
self.base_address = base_address;
}
Expand Down