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

offsets #190

Merged
merged 1 commit into from
Jan 2, 2022
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
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