diff --git a/CHANGELOG-rust.md b/CHANGELOG-rust.md
index a7c6eb30..88829517 100644
--- a/CHANGELOG-rust.md
+++ b/CHANGELOG-rust.md
@@ -5,6 +5,10 @@ This changelog tracks the Rust `svdtools` project. See
## [Unreleased]
+## [v0.3.17] 2024-07-05
+
+* Support "isDefault" enum value in `svdtools html`
+
## [v0.3.16] 2024-07-03
* Add possibility to add field arrays
@@ -171,7 +175,8 @@ Other changes:
* Initial release with feature-parity with the Python project.
-[Unreleased]: https://github.com/rust-embedded/svdtools/compare/v0.3.16...HEAD
+[Unreleased]: https://github.com/rust-embedded/svdtools/compare/v0.3.17...HEAD
+[v0.3.17]: https://github.com/rust-embedded/svdtools/compare/v0.3.16...v0.3.17
[v0.3.16]: https://github.com/rust-embedded/svdtools/compare/v0.3.15...v0.3.16
[v0.3.15]: https://github.com/rust-embedded/svdtools/compare/v0.3.14...v0.3.15
[v0.3.14]: https://github.com/rust-embedded/svdtools/compare/v0.3.13...v0.3.14
diff --git a/Cargo.toml b/Cargo.toml
index 639534be..63372e43 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "svdtools"
-version = "0.3.16"
+version = "0.3.17"
repository = "https://github.com/rust-embedded/svdtools/"
description = "Tool for modifying bugs in CMSIS SVD"
authors = [
diff --git a/src/html/html_cli.rs b/src/html/html_cli.rs
index e35e5741..159b44aa 100644
--- a/src/html/html_cli.rs
+++ b/src/html/html_cli.rs
@@ -1,4 +1,5 @@
use std::borrow::Cow;
+use std::collections::BTreeMap;
use std::fs::File;
use std::io::{Read, Write};
#[cfg(target_os = "linux")]
@@ -23,6 +24,7 @@ use svd_parser::{
expand::{derive_peripheral, Index},
svd::{Access, Cluster, Register, RegisterInfo, WriteConstraint},
};
+use svd_rs::{EnumeratedValue, EnumeratedValues};
fn sanitize(input: &str) -> String {
use once_cell::sync::Lazy;
@@ -261,9 +263,19 @@ fn parse_register(
};
for value in &enums.values {
+ let val = if let Some(value) = value.value {
+ value.to_string()
+ } else {
+ let val = value
+ .is_default()
+ .then(|| enums_to_map(&enums))
+ .and_then(|map| minimal_hole(&map, fwidth))
+ .ok_or_else(|| anyhow!("Value is missing from {value:?}"))?;
+ format!("{val} (+)")
+ };
+
doc += &format!(
- "{}: {}: {}
",
- value.value.unwrap(),
+ "{val}: {}: {}
",
value.name,
sanitize(value.description.as_deref().unwrap_or(""))
);
@@ -272,7 +284,7 @@ fn parse_register(
} else if let Some(WriteConstraint::Range(wcrange)) = wc.as_ref() {
let mn = hex(wcrange.min);
let mx = hex(wcrange.max);
- fdoc = Some(format!("Allowed values: {mn}-{mx}"));
+ fdoc = Some(format!("Allowed values: {mn}-{mx}"));
}
}
fields.push(object!({
@@ -514,3 +526,17 @@ pub fn svd2html(htmldir: &Path, svdfiles: &[PathBuf]) -> anyhow::Result<()> {
generate_index_page(&devices, &mut file)?;
Ok(())
}
+
+fn enums_to_map(evs: &EnumeratedValues) -> BTreeMap {
+ let mut map = BTreeMap::new();
+ for ev in &evs.values {
+ if let Some(v) = ev.value {
+ map.insert(v, ev);
+ }
+ }
+ map
+}
+
+fn minimal_hole(map: &BTreeMap, width: u32) -> Option {
+ (0..(1u64 << width)).find(|&v| !map.contains_key(&v))
+}