Skip to content

Commit 5bfccba

Browse files
authored
Merge pull request #270 from rust-embedded/html-mwv
html modifiedWriteValues
2 parents 80dafbb + dfe9dd6 commit 5bfccba

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

CHANGELOG-rust.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This changelog tracks the Rust `svdtools` project. See
55

66
## [Unreleased]
77

8+
* `html`: field `readAction` and `modifiedWriteValues` in `access`
9+
810
## [v0.4.0] 2025-01-06
911

1012
* **breaking** Support "?~" in field `_modify` & `_derive`

src/html/html_cli.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use svd_parser::{
2525
expand::{derive_peripheral, Index},
2626
svd::{Access, Cluster, Register, RegisterInfo, WriteConstraint},
2727
};
28-
use svd_rs::{EnumeratedValue, EnumeratedValues};
28+
use svd_rs::{EnumeratedValue, EnumeratedValues, ModifiedWriteValues, ReadAction};
2929

3030
fn sanitize(input: &str) -> String {
3131
use once_cell::sync::Lazy;
@@ -95,6 +95,31 @@ fn short_access(accs: &str) -> &str {
9595
}
9696
}
9797

98+
fn short_mwv(mwv: ModifiedWriteValues) -> &'static str {
99+
use ModifiedWriteValues::*;
100+
match mwv {
101+
OneToClear => "w1c",
102+
OneToSet => "w1s",
103+
OneToToggle => "w1t",
104+
ZeroToClear => "w0c",
105+
ZeroToSet => "w0s",
106+
ZeroToToggle => "w0t",
107+
Clear => "wc",
108+
Set => "ws",
109+
Modify => "w",
110+
}
111+
}
112+
113+
fn short_ra(ra: Option<ReadAction>) -> &'static str {
114+
match ra {
115+
None => "r",
116+
Some(ReadAction::Clear) => "rc",
117+
Some(ReadAction::Set) => "rs",
118+
Some(ReadAction::Modify) => "rm",
119+
Some(ReadAction::ModifyExternal) => "re",
120+
}
121+
}
122+
98123
trait GetI64 {
99124
fn get_i64(&self, key: &str) -> Option<i64>;
100125
fn get_str(&self, key: &str) -> Option<Cow<str>>;
@@ -328,7 +353,19 @@ fn parse_register(
328353
for (ftag, _) in flds.iter().rev() {
329354
let foffset = ftag.bit_offset();
330355
let faccs = ftag.access.map(Access::as_str).unwrap_or(raccs);
331-
let access = short_access(faccs);
356+
let mut access = short_access(faccs).to_string();
357+
let mwv = ftag
358+
.modified_write_values
359+
.unwrap_or(ModifiedWriteValues::Modify);
360+
let ra = ftag.read_action;
361+
if access != "N/A" {
362+
match (faccs, mwv, ra) {
363+
(_, ModifiedWriteValues::Modify, None) => {}
364+
("read-only", _, ra) => access = short_ra(ra).to_string(),
365+
("write-only", mwv, _) => access = short_mwv(mwv).to_string(),
366+
(_, mwv, ra) => access = format!("{}/{}", short_ra(ra), short_mwv(mwv)),
367+
};
368+
}
332369
let fwidth = ftag.bit_width();
333370
if foffset + fwidth > rsize {
334371
return Err(anyhow!("Wrong field offset/width"));

src/html/template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ <h3 id="{{ pname }}">
128128
{%- for register in peripheral.registers %}
129129
<tr>
130130
<td>{{ register.offset }}{% if register.size != 32 %} ({{ register.size }}-bit){% endif %}</td>
131-
<td>{{ register.name }}</td>
131+
<td><a class="fieldlink" href="#{{ pname }}:{{ register.name }}">{{ register.name }}</a></td>
132132
{%- for row in register.table %}
133133
{%- if row %}
134134
{%- for field in row.fields %}
@@ -139,7 +139,7 @@ <h3 id="{{ pname }}">
139139
{%- endunless %}
140140
{%- if field.name %}
141141
<td colspan="{{ field.width }}" class="vertical{% if field.separated %} separated{% endif %}">
142-
<div><a class="fieldlink" href="#{{ pname }}:{{ register.name }}:{{ field.name }}">{{ field.name }}</a></div>
142+
<div><a class="fieldlink{% if field.doc %} text-success{% endif %}" href="#{{ pname }}:{{ register.name }}:{{ field.name }}">{{ field.name }}</a></div>
143143
</td>
144144
{%- endif %}
145145
{%- endfor %}

0 commit comments

Comments
 (0)