Skip to content

Commit a1e6374

Browse files
authored
Merge pull request #142 from stm32-rs/all-regs
iter registers always 1-depth
2 parents b8a2ed9 + df1fa26 commit a1e6374

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/patch/peripheral.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use super::{
1414
};
1515
use super::{make_cluster, make_interrupt, make_register};
1616

17-
use svd::registercluster::{AllRegistersIterMut, ClusterIterMut};
17+
use svd::registercluster::{ClusterIterMut, RegisterIterMut};
1818
pub type ClusterMatchIterMut<'a, 'b> = MatchIter<'b, ClusterIterMut<'a>>;
19-
pub type RegMatchIterMut<'a, 'b> = MatchIter<'b, AllRegistersIterMut<'a>>;
19+
pub type RegMatchIterMut<'a, 'b> = MatchIter<'b, RegisterIterMut<'a>>;
2020

2121
/// Collecting methods for processing peripheral contents
2222
pub trait PeripheralExt: InterruptExt + RegisterBlockExt {
@@ -332,15 +332,6 @@ impl PeripheralExt for Peripheral {
332332
}
333333
}
334334

335-
// Handle clusters
336-
for (cspec, cluster) in pmod.hash_iter("_clusters") {
337-
let cspec = cspec.str()?;
338-
if !cspec.starts_with('_') {
339-
self.process_cluster(cspec, cluster.hash()?, update_fields)
340-
.with_context(|| format!("According to `{cspec}`"))?;
341-
}
342-
}
343-
344335
// Handle registers
345336
for (rspec, register) in pmod {
346337
let rspec = rspec.str()?;
@@ -364,6 +355,15 @@ impl PeripheralExt for Peripheral {
364355
.with_context(|| format!("Collecting registers in cluster `{cname}`"))?;
365356
}
366357

358+
// Handle clusters
359+
for (cspec, cluster) in pmod.hash_iter("_clusters") {
360+
let cspec = cspec.str()?;
361+
if !cspec.starts_with('_') {
362+
self.process_cluster(cspec, cluster.hash()?, update_fields)
363+
.with_context(|| format!("According to `{cspec}`"))?;
364+
}
365+
}
366+
367367
Ok(())
368368
}
369369
}
@@ -403,7 +403,7 @@ impl InterruptExt for Peripheral {
403403

404404
impl RegisterBlockExt for Peripheral {
405405
fn iter_registers<'a, 'b>(&'a mut self, spec: &'b str) -> RegMatchIterMut<'a, 'b> {
406-
self.all_registers_mut().matched(spec)
406+
self.registers_mut().matched(spec)
407407
}
408408

409409
fn iter_clusters<'a, 'b>(&'a mut self, spec: &'b str) -> ClusterMatchIterMut<'a, 'b> {
@@ -447,9 +447,9 @@ impl RegisterBlockExt for Peripheral {
447447
}
448448

449449
fn add_cluster(&mut self, cname: &str, cadd: &Hash) -> PatchResult {
450-
if self.all_registers().any(|c| c.name == cname) {
450+
if self.clusters().any(|c| c.name == cname) {
451451
return Err(anyhow!(
452-
"peripheral {} already has a register {cname}",
452+
"peripheral {} already has a cluster {cname}",
453453
self.name
454454
));
455455
}
@@ -515,7 +515,7 @@ impl RegisterBlockExt for Peripheral {
515515
})?;
516516

517517
let mut source = self
518-
.all_registers()
518+
.registers()
519519
.find(|r| r.name == srcname)
520520
.ok_or_else(|| anyhow!("peripheral {} does not have register {srcname}", self.name))?
521521
.clone();
@@ -524,7 +524,7 @@ impl RegisterBlockExt for Peripheral {
524524
.display_name(Some("".into()));
525525
// Modifying fields in derived register not implemented
526526
source.modify_from(fixes, VAL_LVL)?;
527-
if let Some(ptag) = self.all_registers_mut().find(|r| r.name == rname) {
527+
if let Some(ptag) = self.registers_mut().find(|r| r.name == rname) {
528528
source.address_offset = ptag.address_offset;
529529
*ptag = source;
530530
} else {
@@ -574,7 +574,7 @@ impl RegisterBlockExt for Peripheral {
574574
fn strip_start(&mut self, prefix: &str) -> PatchResult {
575575
let len = prefix.len();
576576
let glob = globset::Glob::new(&(prefix.to_string() + "*"))?.compile_matcher();
577-
for rtag in self.all_registers_mut() {
577+
for rtag in self.registers_mut() {
578578
if glob.is_match(&rtag.name) {
579579
rtag.name.drain(..len);
580580
}
@@ -592,7 +592,7 @@ impl RegisterBlockExt for Peripheral {
592592
let glob = globset::Glob::new(&("*".to_string() + suffix))
593593
.unwrap()
594594
.compile_matcher();
595-
for rtag in self.all_registers_mut() {
595+
for rtag in self.registers_mut() {
596596
if glob.is_match(&rtag.name) {
597597
let nlen = rtag.name.len();
598598
rtag.name.truncate(nlen - len);
@@ -867,7 +867,7 @@ impl ClusterExt for Cluster {
867867

868868
impl RegisterBlockExt for Cluster {
869869
fn iter_registers<'a, 'b>(&'a mut self, spec: &'b str) -> RegMatchIterMut<'a, 'b> {
870-
self.all_registers_mut().matched(spec)
870+
self.registers_mut().matched(spec)
871871
}
872872

873873
fn iter_clusters<'a, 'b>(&'a mut self, spec: &'b str) -> ClusterMatchIterMut<'a, 'b> {
@@ -973,7 +973,7 @@ impl RegisterBlockExt for Cluster {
973973
})?;
974974

975975
let mut source = self
976-
.all_registers()
976+
.registers()
977977
.find(|r| r.name == srcname)
978978
.ok_or_else(|| anyhow!("peripheral {} does not have register {srcname}", self.name,))?
979979
.clone();
@@ -982,7 +982,7 @@ impl RegisterBlockExt for Cluster {
982982
.display_name(Some("".into()));
983983
// Modifying fields in derived register not implemented
984984
source.modify_from(fixes, VAL_LVL)?;
985-
if let Some(ptag) = self.all_registers_mut().find(|r| r.name == rname) {
985+
if let Some(ptag) = self.registers_mut().find(|r| r.name == rname) {
986986
source.address_offset = ptag.address_offset;
987987
*ptag = source;
988988
} else {
@@ -1023,7 +1023,7 @@ impl RegisterBlockExt for Cluster {
10231023
fn strip_start(&mut self, prefix: &str) -> PatchResult {
10241024
let len = prefix.len();
10251025
let glob = globset::Glob::new(&(prefix.to_string() + "*"))?.compile_matcher();
1026-
for rtag in self.all_registers_mut() {
1026+
for rtag in self.registers_mut() {
10271027
if glob.is_match(&rtag.name) {
10281028
rtag.name.drain(..len);
10291029
}
@@ -1041,7 +1041,7 @@ impl RegisterBlockExt for Cluster {
10411041
let glob = globset::Glob::new(&("*".to_string() + suffix))
10421042
.unwrap()
10431043
.compile_matcher();
1044-
for rtag in self.all_registers_mut() {
1044+
for rtag in self.registers_mut() {
10451045
if glob.is_match(&rtag.name) {
10461046
let nlen = rtag.name.len();
10471047
rtag.name.truncate(nlen - len);

0 commit comments

Comments
 (0)