Skip to content

Commit

Permalink
Merge pull request #270 from rust-embedded/html-mwv
Browse files Browse the repository at this point in the history
html modifiedWriteValues
  • Loading branch information
burrbull authored Jan 21, 2025
2 parents 80dafbb + dfe9dd6 commit 5bfccba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 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
4 changes: 2 additions & 2 deletions src/html/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ <h3 id="{{ pname }}">
{%- for register in peripheral.registers %}
<tr>
<td>{{ register.offset }}{% if register.size != 32 %} ({{ register.size }}-bit){% endif %}</td>
<td>{{ register.name }}</td>
<td><a class="fieldlink" href="#{{ pname }}:{{ register.name }}">{{ register.name }}</a></td>
{%- for row in register.table %}
{%- if row %}
{%- for field in row.fields %}
Expand All @@ -139,7 +139,7 @@ <h3 id="{{ pname }}">
{%- endunless %}
{%- if field.name %}
<td colspan="{{ field.width }}" class="vertical{% if field.separated %} separated{% endif %}">
<div><a class="fieldlink" href="#{{ pname }}:{{ register.name }}:{{ field.name }}">{{ field.name }}</a></div>
<div><a class="fieldlink{% if field.doc %} text-success{% endif %}" href="#{{ pname }}:{{ register.name }}:{{ field.name }}">{{ field.name }}</a></div>
</td>
{%- endif %}
{%- endfor %}
Expand Down

0 comments on commit 5bfccba

Please sign in to comment.