Skip to content

Commit 3bc2008

Browse files
bors[bot]devsnek
andauthored
Merge #488
488: add debug trait r=therealprof a=devsnek This allows structs which hold peripherals to `#[derive(Debug)]` Co-authored-by: Gus Caplan <me@gus.host>
2 parents 4877d5c + db34f67 commit 3bc2008

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414

1515
- Provide an associated const ptr `PTR` per peripheral RegisterBlock
1616

17+
- Generated peripherals now implement `core::fmt::Debug`.
18+
1719
### Fixed
1820

1921
- Keyword sanitizing (`async`)

src/generate/peripheral.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ pub fn render(
4040
}
4141

4242
let span = Span::call_site();
43-
let name_pc = Ident::new(&p.name.to_sanitized_upper_case(), span);
43+
let name_str = p.name.to_sanitized_upper_case();
44+
let name_pc = Ident::new(&name_str, span);
4445
let address = util::hex(p.base_address as u64);
4546
let description = util::respace(p.description.as_ref().unwrap_or(&p.name));
4647

@@ -77,6 +78,12 @@ pub fn render(
7778
unsafe { &*Self::PTR }
7879
}
7980
}
81+
82+
impl core::fmt::Debug for #name_pc {
83+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
84+
f.debug_struct(#name_str).finish()
85+
}
86+
}
8087
});
8188

8289
// Derived peripherals may not require re-implementation, and will instead

0 commit comments

Comments
 (0)