Skip to content

Commit

Permalink
Merge #190
Browse files Browse the repository at this point in the history
190: offsets r=Emilgardis a=burrbull



Co-authored-by: Andrey Zgarbul <[email protected]>
  • Loading branch information
bors[bot] and burrbull authored Jan 2, 2022
2 parents 08c8fe8 + 440990a commit 02d51d4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion svd-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased

- skip serializing `values` in `EnumeratedValues` if empty
- add `names` function for arrays
- add `names` function for arrays, `base_addresses` for `Peripheral`,
`address_offsets` for `Register` and `Cluster`, `bit_offsets` for `Field` arrays
- add missing fields in `Device`, require `version`, `description`, `address_unit_bits` and `width`,
also `schema_version` is required, but skipped during (de)serialization
- merge `register` with `registerinfo` modules same as other `info`s
Expand Down
8 changes: 8 additions & 0 deletions svd-rs/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ pub struct ClusterInfo {
pub derived_from: Option<String>,
}

/// Return iterator over address offsets of each cluster in array
pub fn address_offsets<'a>(
info: &'a ClusterInfo,
dim: &'a DimElement,
) -> impl Iterator<Item = u32> + 'a {
(0..dim.dim).map(move |i| info.address_offset + i * dim.dim_increment)
}

/// Builder for [`ClusterInfo`]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ClusterInfoBuilder {
Expand Down
5 changes: 5 additions & 0 deletions svd-rs/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ pub struct FieldInfo {
pub derived_from: Option<String>,
}

/// Return iterator over bit offsets of each field in array
pub fn bit_offsets<'a>(info: &'a FieldInfo, dim: &'a DimElement) -> impl Iterator<Item = u32> + 'a {
(0..dim.dim).map(move |i| info.bit_offset() + i * dim.dim_increment)
}

/// Builder for [`FieldInfo`]
#[derive(Clone, Debug, Default, PartialEq)]
Expand Down
8 changes: 8 additions & 0 deletions svd-rs/src/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ pub struct PeripheralInfo {
pub derived_from: Option<String>,
}

/// Return iterator over base addresses of each peripheral in array
pub fn base_addresses<'a>(
info: &'a PeripheralInfo,
dim: &'a DimElement,
) -> impl Iterator<Item = u64> + 'a {
(0..dim.dim as u64).map(move |i| info.base_address + i * dim.dim_increment as u64)
}

/// Builder for [`Peripheral`]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PeripheralInfoBuilder {
Expand Down
8 changes: 8 additions & 0 deletions svd-rs/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ pub struct RegisterInfo {
pub derived_from: Option<String>,
}

/// Return iterator over address offsets of each register in array
pub fn address_offsets<'a>(
info: &'a RegisterInfo,
dim: &'a DimElement,
) -> impl Iterator<Item = u32> + 'a {
(0..dim.dim).map(move |i| info.address_offset + i * dim.dim_increment)
}

/// Builder for [`RegisterInfo`]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RegisterInfoBuilder {
Expand Down

0 comments on commit 02d51d4

Please sign in to comment.