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

html modifiedWriteValues #270

Merged
merged 2 commits into from
Jan 21, 2025
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
@@ -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`
41 changes: 39 additions & 2 deletions src/html/html_cli.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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>>;
@@ -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"));
4 changes: 2 additions & 2 deletions src/html/template.html
Original file line number Diff line number Diff line change
@@ -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 %}
@@ -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 %}