Skip to content

Commit

Permalink
Merge pull request #192 from rust-embedded/bit-range
Browse files Browse the repository at this point in the history
bitRange support
  • Loading branch information
burrbull authored Dec 19, 2023
2 parents 94de5e3 + a9ac8a3 commit 9537e0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This changelog tracks the Rust `svdtools` project. See

## [Unreleased]

* Support `bitRange` and `msb+lsb` in field `_modify`
* Support `_include` in peripherals in `device.yaml`
* Add `--enum_derive` flag
* Strip `alternateRegister` too
Expand Down
32 changes: 19 additions & 13 deletions src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use svd_parser::svd::{
WriteConstraintRange,
};
use svd_parser::SVDError::DimIndexParse;
use svd_rs::{DimElement, DimElementBuilder, MaybeArray};
use svd_rs::{BitRange, DimElement, DimElementBuilder, MaybeArray};
use yaml_rust::{yaml::Hash, Yaml, YamlLoader};

use anyhow::{anyhow, Context, Result};
Expand Down Expand Up @@ -422,22 +422,28 @@ fn make_field(fadd: &Hash) -> Result<FieldInfoBuilder> {
let mut fnew = FieldInfo::builder()
.description(fadd.get_string("description")?)
.derived_from(fadd.get_string("derivedFrom")?)
.access(fadd.get_str("access")?.and_then(Access::parse_str));
.access(fadd.get_str("access")?.and_then(Access::parse_str))
.modified_write_values(
fadd.get_str("modifiedWriteValues")?
.and_then(ModifiedWriteValues::parse_str),
)
.read_action(fadd.get_str("readAction")?.and_then(ReadAction::parse_str));

if let Some(name) = fadd.get_str("name")? {
fnew = fnew.name(name.into());
}
if let Some(offset) = fadd.get_i64("bitOffset")? {
fnew = fnew.bit_offset(offset as u32)
}
if let Some(width) = fadd.get_i64("bitWidth")? {
fnew = fnew.bit_width(width as u32)
}
if let Some(modified_write_values) = fadd.get_str("modifiedWriteValues")? {
fnew = fnew.modified_write_values(ModifiedWriteValues::parse_str(modified_write_values))
}
if let Some(read_action) = fadd.get_str("readAction")? {
fnew = fnew.read_action(ReadAction::parse_str(read_action))
// NOTE: support only both `msb` and `lsb` passed together
if let (Some(msb), Some(lsb)) = (fadd.get_i64("msb")?, fadd.get_i64("lsb")?) {
fnew = fnew.bit_range(BitRange::from_msb_lsb(msb as _, lsb as _));
} else if let Some(bit_range) = fadd.get_str("bitRange")?.and_then(BitRange::from_bit_range) {
fnew = fnew.bit_range(bit_range);
} else {
if let Some(offset) = fadd.get_i64("bitOffset")? {
fnew = fnew.bit_offset(offset as u32)
}
if let Some(width) = fadd.get_i64("bitWidth")? {
fnew = fnew.bit_width(width as u32)
}
}

Ok(fnew)
Expand Down

0 comments on commit 9537e0f

Please sign in to comment.