Skip to content

Commit

Permalink
html modifiedWriteValues
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jan 19, 2025
1 parent 666ee0d commit fab6f58
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This changelog tracks the Rust `svdtools` project. See

## [Unreleased]

* `html`: field `readAction` and `modifiedWriteValues` in `access`

## [v0.4.0] 2025-01-06

* **breaking** Support "?~" in field `_modify` & `_derive`
Expand Down
41 changes: 39 additions & 2 deletions src/html/html_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use svd_parser::{
expand::{derive_peripheral, Index},
svd::{Access, Cluster, Register, RegisterInfo, WriteConstraint},
};
use svd_rs::{EnumeratedValue, EnumeratedValues};
use svd_rs::{EnumeratedValue, EnumeratedValues, ModifiedWriteValues, ReadAction};

fn sanitize(input: &str) -> String {
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -95,6 +95,31 @@ fn short_access(accs: &str) -> &str {
}
}

fn short_mwv(mwv: ModifiedWriteValues) -> &'static str {
use ModifiedWriteValues::*;
match mwv {
OneToClear => "w1c",
OneToSet => "w1s",
OneToToggle => "w1t",
ZeroToClear => "w0c",
ZeroToSet => "w0s",
ZeroToToggle => "w0t",
Clear => "wc",
Set => "ws",
Modify => "w",
}
}

fn short_ra(ra: Option<ReadAction>) -> &'static str {
match ra {
None => "r",
Some(ReadAction::Clear) => "rc",
Some(ReadAction::Set) => "rs",
Some(ReadAction::Modify) => "rm",
Some(ReadAction::ModifyExternal) => "re",
}
}

trait GetI64 {
fn get_i64(&self, key: &str) -> Option<i64>;
fn get_str(&self, key: &str) -> Option<Cow<str>>;
Expand Down Expand Up @@ -328,7 +353,19 @@ fn parse_register(
for (ftag, _) in flds.iter().rev() {
let foffset = ftag.bit_offset();
let faccs = ftag.access.map(Access::as_str).unwrap_or(raccs);
let access = short_access(faccs);
let mut access = short_access(faccs).to_string();
let mwv = ftag
.modified_write_values
.unwrap_or(ModifiedWriteValues::Modify);
let ra = ftag.read_action;
if access != "N/A" {
match (faccs, mwv, ra) {
(_, ModifiedWriteValues::Modify, None) => {}
("read-only", _, ra) => access = short_ra(ra).to_string(),
("write-only", mwv, _) => access = short_mwv(mwv).to_string(),
(_, mwv, ra) => access = format!("{}/{}", short_ra(ra), short_mwv(mwv)),
};
}
let fwidth = ftag.bit_width();
if foffset + fwidth > rsize {
return Err(anyhow!("Wrong field offset/width"));
Expand Down

0 comments on commit fab6f58

Please sign in to comment.