From 1d0beb241e6d249b82818a91eeb063b070e40c6a Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Tue, 28 Jul 2020 02:28:57 +0200 Subject: [PATCH] Add associated const ptr `PTR` to each peripheral RegisterBlock cc https://github.com/rust-embedded/cortex-m/pull/235 Signed-off-by: Daniel Egger --- CHANGELOG.md | 2 ++ src/generate/peripheral.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) 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 } } } });