Skip to content

Commit 9a5e301

Browse files
authored
Merge pull request #138 from stm32-rs/clusters
cluster add/modify (rust)
2 parents ce6ff66 + 55ba085 commit 9a5e301

File tree

6 files changed

+890
-275
lines changed

6 files changed

+890
-275
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
pip install .
2727
- name: Check
2828
run: |
29-
black --check svdtools
29+
black --check --diff svdtools
3030
isort --check-only svdtools
3131
- name: Test
3232
run: pytest svdtools

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+
* cluster add/modify
9+
810
## [v0.2.8] 2022-01-28
911

1012
* patch: added possibility to modify dim elements (arrays)

src/patch/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::HashSet;
66
use std::{fs::File, io::Read, path::Path};
77

88
use super::iterators::{MatchIter, Matched};
9-
use super::peripheral::PeripheralExt;
9+
use super::peripheral::{PeripheralExt, RegisterBlockExt};
1010
use super::yaml_ext::{AsType, GetVal};
1111
use super::{abspath, matchname, PatchResult, VAL_LVL};
1212
use super::{make_address_block, make_address_blocks, make_cpu, make_interrupt, make_peripheral};
@@ -302,7 +302,7 @@ impl DeviceExt for Device {
302302
make_peripheral(hash, true)?.derived_from(Some(pderive.into())),
303303
)
304304
} else {
305-
return Err(anyhow!("derive: incorrect syntax for {}", pname));
305+
return Err(anyhow!("derive: incorrect syntax for {pname}"));
306306
};
307307

308308
if !pderive.contains('.') {

src/patch/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,22 @@ fn make_register(radd: &Hash) -> Result<RegisterInfoBuilder> {
408408
fn make_cluster(cadd: &Hash) -> Result<ClusterInfoBuilder> {
409409
let mut cnew = ClusterInfo::builder()
410410
.description(cadd.get_string("description")?)
411-
.default_register_properties(get_register_properties(cadd)?);
411+
.default_register_properties(get_register_properties(cadd)?)
412+
.children(match cadd.get_hash("registers")? {
413+
Some(h) => {
414+
let mut ch = Vec::new();
415+
for (rname, val) in h {
416+
ch.push(RegisterCluster::Register(
417+
make_register(val.hash()?)?
418+
.name(rname.str()?.into())
419+
.build(VAL_LVL)?
420+
.single(),
421+
));
422+
}
423+
ch
424+
}
425+
_ => Vec::new(),
426+
});
412427

413428
if let Some(name) = cadd.get_str("name")? {
414429
cnew = cnew.name(name.into());

0 commit comments

Comments
 (0)