Skip to content

Commit 440990a

Browse files
committed
offsets
1 parent 08c8fe8 commit 440990a

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

svd-rs/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## Unreleased
99

1010
- skip serializing `values` in `EnumeratedValues` if empty
11-
- add `names` function for arrays
11+
- add `names` function for arrays, `base_addresses` for `Peripheral`,
12+
`address_offsets` for `Register` and `Cluster`, `bit_offsets` for `Field` arrays
1213
- add missing fields in `Device`, require `version`, `description`, `address_unit_bits` and `width`,
1314
also `schema_version` is required, but skipped during (de)serialization
1415
- merge `register` with `registerinfo` modules same as other `info`s

svd-rs/src/cluster.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ pub struct ClusterInfo {
7171
pub derived_from: Option<String>,
7272
}
7373

74+
/// Return iterator over address offsets of each cluster in array
75+
pub fn address_offsets<'a>(
76+
info: &'a ClusterInfo,
77+
dim: &'a DimElement,
78+
) -> impl Iterator<Item = u32> + 'a {
79+
(0..dim.dim).map(move |i| info.address_offset + i * dim.dim_increment)
80+
}
81+
7482
/// Builder for [`ClusterInfo`]
7583
#[derive(Clone, Debug, Default, PartialEq)]
7684
pub struct ClusterInfoBuilder {

svd-rs/src/field.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ pub struct FieldInfo {
8181
pub derived_from: Option<String>,
8282
}
8383

84+
/// Return iterator over bit offsets of each field in array
85+
pub fn bit_offsets<'a>(info: &'a FieldInfo, dim: &'a DimElement) -> impl Iterator<Item = u32> + 'a {
86+
(0..dim.dim).map(move |i| info.bit_offset() + i * dim.dim_increment)
87+
}
88+
8489
/// Builder for [`FieldInfo`]
8590
8691
#[derive(Clone, Debug, Default, PartialEq)]

svd-rs/src/peripheral.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ pub struct PeripheralInfo {
123123
pub derived_from: Option<String>,
124124
}
125125

126+
/// Return iterator over base addresses of each peripheral in array
127+
pub fn base_addresses<'a>(
128+
info: &'a PeripheralInfo,
129+
dim: &'a DimElement,
130+
) -> impl Iterator<Item = u64> + 'a {
131+
(0..dim.dim as u64).map(move |i| info.base_address + i * dim.dim_increment as u64)
132+
}
133+
126134
/// Builder for [`Peripheral`]
127135
#[derive(Clone, Debug, Default, PartialEq)]
128136
pub struct PeripheralInfoBuilder {

svd-rs/src/register.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ pub struct RegisterInfo {
101101
pub derived_from: Option<String>,
102102
}
103103

104+
/// Return iterator over address offsets of each register in array
105+
pub fn address_offsets<'a>(
106+
info: &'a RegisterInfo,
107+
dim: &'a DimElement,
108+
) -> impl Iterator<Item = u32> + 'a {
109+
(0..dim.dim).map(move |i| info.address_offset + i * dim.dim_increment)
110+
}
111+
104112
/// Builder for [`RegisterInfo`]
105113
#[derive(Clone, Debug, Default, PartialEq)]
106114
pub struct RegisterInfoBuilder {

0 commit comments

Comments
 (0)