Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge register with registerinfo, same with other info #182

Merged
merged 1 commit into from
Dec 31, 2021
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
45 changes: 43 additions & 2 deletions svd-encoder/src/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Element, ElementMerge, Encode, EncodeError};
use super::{new_node, Element, ElementMerge, Encode, EncodeChildren, EncodeError, XMLNode};

use crate::svd::Cluster;
use crate::svd::{Cluster, ClusterInfo};

impl Encode for Cluster {
type Error = EncodeError;
Expand All @@ -17,3 +17,44 @@ impl Encode for Cluster {
}
}
}

impl Encode for ClusterInfo {
type Error = EncodeError;

fn encode(&self) -> Result<Element, EncodeError> {
let mut e = Element::new("cluster");

e.children.push(new_node("name", self.name.clone()));

if let Some(v) = &self.description {
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()));
}

e.children.push(new_node(
"addressOffset",
format!("{}", self.address_offset),
));

e.children
.extend(self.default_register_properties.encode()?);

for c in &self.children {
e.children.push(XMLNode::Element(c.encode()?));
}

if let Some(v) = &self.derived_from {
e.attributes
.insert(String::from("derivedFrom"), v.to_string());
}

Ok(e)
}
}
44 changes: 0 additions & 44 deletions svd-encoder/src/clusterinfo.rs

This file was deleted.

52 changes: 50 additions & 2 deletions svd-encoder/src/field.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Element, ElementMerge, Encode, EncodeError};
use super::{new_node, Element, ElementMerge, Encode, EncodeError, XMLNode};
use crate::bitrange::encode_bitrange;

use crate::svd::Field;
use crate::svd::{Field, FieldInfo};

impl Encode for Field {
type Error = EncodeError;
Expand All @@ -17,3 +18,50 @@ impl Encode for Field {
}
}
}

impl Encode for FieldInfo {
type Error = EncodeError;

fn encode(&self) -> Result<Element, EncodeError> {
let mut elem = Element::new("field");
elem.children.push(new_node("name", self.name.clone()));

if let Some(description) = &self.description {
elem.children
.push(new_node("description", description.clone()))
}

// Add bit range
elem.children.append(&mut encode_bitrange(&self.bit_range)?);

if let Some(v) = &self.access {
elem.children.push(v.encode_node()?);
}

if let Some(v) = &self.modified_write_values {
elem.children.push(v.encode_node()?);
}

if let Some(v) = &self.write_constraint {
elem.children.push(v.encode_node()?);
}

if let Some(v) = &self.read_action {
elem.children.push(v.encode_node()?);
}

let enumerated_values: Result<Vec<XMLNode>, EncodeError> = self
.enumerated_values
.iter()
.map(|v| v.encode_node())
.collect();
elem.children.append(&mut enumerated_values?);

if let Some(v) = &self.derived_from {
elem.attributes
.insert(String::from("derivedFrom"), v.to_string());
}

Ok(elem)
}
}
51 changes: 0 additions & 51 deletions svd-encoder/src/fieldinfo.rs

This file was deleted.

4 changes: 0 additions & 4 deletions svd-encoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,20 @@ mod access;
mod addressblock;
mod bitrange;
mod cluster;
mod clusterinfo;
mod cpu;
mod device;
mod dimelement;
mod endian;
mod enumeratedvalue;
mod enumeratedvalues;
mod field;
mod fieldinfo;
mod interrupt;
mod modifiedwritevalues;
mod peripheral;
mod peripheralinfo;
mod protection;
mod readaction;
mod register;
mod registercluster;
mod registerinfo;
mod registerproperties;
mod usage;
mod writeconstraint;
83 changes: 81 additions & 2 deletions svd-encoder/src/peripheral.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Element, ElementMerge, Encode, EncodeError};
use super::{new_node, Element, ElementMerge, Encode, EncodeChildren, EncodeError, XMLNode};

use crate::svd::Peripheral;
use crate::svd::{Interrupt, Peripheral, PeripheralInfo};

impl Encode for Peripheral {
type Error = EncodeError;
Expand All @@ -17,3 +17,82 @@ impl Encode for Peripheral {
}
}
}

impl Encode for PeripheralInfo {
type Error = EncodeError;

fn encode(&self) -> Result<Element, EncodeError> {
let mut elem = Element::new("peripheral");
elem.children.push(new_node("name", self.name.clone()));

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

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

if let Some(v) = &self.description {
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),
));

elem.children
.extend(self.default_register_properties.encode()?);

if let Some(v) = &self.address_block {
for ab in v {
elem.children.push(ab.encode_node()?);
}
}

let interrupts: Result<Vec<_>, _> =
self.interrupt.iter().map(Interrupt::encode_node).collect();

elem.children.append(&mut interrupts?);

if let Some(v) = &self.registers {
let children: Result<Vec<_>, _> = v.iter().map(|e| e.encode_node()).collect();

elem.children.push({
let mut e = Element::new("registers");
e.children = children?;
XMLNode::Element(e)
});
}

if let Some(v) = &self.derived_from {
elem.attributes
.insert(String::from("derivedFrom"), v.to_string());
}

Ok(elem)
}
}
Loading