Skip to content

add debug trait #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
9 changes: 8 additions & 1 deletion src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down