From 6166295f9f484b543ed8bc277dae733a10f7c9e2 Mon Sep 17 00:00:00 2001 From: Justin latimer Date: Thu, 27 May 2021 07:31:40 +0000 Subject: [PATCH 1/2] Fix a doc comment. --- src/pack.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pack.rs b/src/pack.rs index a6dd2a5..534f10f 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -183,6 +183,7 @@ fn read_signal(signal: &Element) -> Signal { /// /// /// +/// ``` fn read_register_group(register_group: &Element) -> RegisterGroup { let (name, caption) = ( register_group.attributes.get("name").unwrap(), From 00f686f17cd62420e7a9ef2721f3ea6789735261 Mon Sep 17 00:00:00 2001 From: Justin latimer Date: Thu, 27 May 2021 07:38:25 +0000 Subject: [PATCH 2/2] Add support for a register group reference. --- src/model.rs | 18 ++++++++++++++++++ src/pack.rs | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/model.rs b/src/model.rs index 2de938d..7af4e25 100644 --- a/src/model.rs +++ b/src/model.rs @@ -123,10 +123,28 @@ pub struct Module { pub struct Instance { /// The name of the peripheral instance, for example, `PORTB`. pub name: String, + /// Reference to the register group that represents this instance. + pub register_group_ref: Option, /// What signals are used in the peripheral. pub signals: Vec, } +/// A refereance to a register group. +#[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] +pub struct RegisterGroupRef { + /// The name of the register group being referenced. + pub name: String, + /// The name of the register group being referenced in the module that + /// defines it. + pub name_in_module: String, + /// The offset of the register group. + pub offset: u32, + /// The address space. + pub address_space: String, + /// The caption describing the register group reference. + pub caption: Option, +} + /// A group of registers. #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] pub struct RegisterGroup { diff --git a/src/pack.rs b/src/pack.rs index 534f10f..aa24809 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -153,6 +153,8 @@ fn read_variant(variant: &Element) -> Variant { fn read_instance(instance: &Element) -> Instance { let instance_name = instance.attributes.get("name").unwrap().clone(); + let register_group_ref = instance.get_child("register-group").map(|e| read_register_group_ref(e)); + let signals = match instance.get_child("signals") { Some(signals) => signals .children @@ -163,7 +165,7 @@ fn read_instance(instance: &Element) -> Instance { None => Vec::new(), }; - Instance { name: instance_name, signals: signals } + Instance { name: instance_name, register_group_ref: register_group_ref, signals: signals } } fn read_signal(signal: &Element) -> Signal { @@ -174,6 +176,22 @@ fn read_signal(signal: &Element) -> Signal { } } +/// Reads a register group reference. +/// +/// This looks like so +/// ```xml +/// +/// ``` +fn read_register_group_ref(register_group_ref: &Element) -> RegisterGroupRef { + RegisterGroupRef { + name: register_group_ref.attributes.get("name").unwrap().clone(), + name_in_module: register_group_ref.attributes.get("name-in-module").unwrap().clone(), + offset: read_int(register_group_ref.attributes.get("offset")).clone(), + address_space: register_group_ref.attributes.get("address-space").unwrap().clone(), + caption: register_group_ref.attributes.get("caption").map(|p| p.clone()), + } +} + /// Reads a register group. /// /// This looks like so