diff --git a/CHANGELOG.md b/CHANGELOG.md index c8a6d22b..698dd87f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Provide an associated const ptr `PTR` per peripheral RegisterBlock +- Generated peripherals now implement `core::fmt::Debug`. + ### Fixed - Keyword sanitizing (`async`) diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 4517ac3a..17f67793 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -40,7 +40,8 @@ pub fn render( } let span = Span::call_site(); - let name_pc = Ident::new(&p.name.to_sanitized_upper_case(), span); + let name_str = p.name.to_sanitized_upper_case(); + let name_pc = Ident::new(&name_str, span); let address = util::hex(p.base_address as u64); let description = util::respace(p.description.as_ref().unwrap_or(&p.name)); @@ -77,6 +78,12 @@ pub fn render( unsafe { &*Self::PTR } } } + + impl core::fmt::Debug for #name_pc { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + f.debug_struct(#name_str).finish() + } + } }); // Derived peripherals may not require re-implementation, and will instead