diff --git a/CHANGELOG.md b/CHANGELOG.md index 30656bbc..4d9ca952 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`) diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 27ad8ee6..248572cb 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -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 } } @@ -71,7 +74,7 @@ pub fn render( #[inline(always)] fn deref(&self) -> &Self::Target { - unsafe { &*#name_pc::ptr() } + unsafe { &*Self::PTR } } } });