Skip to content

Add associated const ptr PTR to each peripheral RegisterBlock #457

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
Jul 28, 2020
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 @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Generated crates now contain the git commit hash and date of svd2rust
compilation.

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

### Fixed

- Keyword sanitizing (`async`)
Expand Down
9 changes: 6 additions & 3 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ pub fn render(
unsafe impl Send for #name_pc {}

impl #name_pc {
///Returns a pointer to the register block
///Pointer to the register block
pub const PTR: *const #base::RegisterBlock = #address as *const _;

///Return the pointer to the register block
#[inline(always)]
pub const fn ptr() -> *const #base::RegisterBlock {
#address as *const _
Self::PTR
}
}

Expand All @@ -71,7 +74,7 @@ pub fn render(

#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*#name_pc::ptr() }
unsafe { &*Self::PTR }
}
}
});
Expand Down