Skip to content

Commit 3d1d618

Browse files
Merge #457
457: Add associated const ptr `PTR` to each peripheral RegisterBlock r=adamgreig a=therealprof cc rust-embedded/cortex-m#235 Signed-off-by: Daniel Egger <[email protected]> Co-authored-by: Daniel Egger <[email protected]>
2 parents 2cd3630 + 1d0beb2 commit 3d1d618

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Generated crates now contain the git commit hash and date of svd2rust
1313
compilation.
1414

15+
- Provide an associated const ptr `PTR` per peripheral RegisterBlock
16+
1517
### Fixed
1618

1719
- Keyword sanitizing (`async`)

src/generate/peripheral.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ pub fn render(
5959
unsafe impl Send for #name_pc {}
6060

6161
impl #name_pc {
62-
///Returns a pointer to the register block
62+
///Pointer to the register block
63+
pub const PTR: *const #base::RegisterBlock = #address as *const _;
64+
65+
///Return the pointer to the register block
6366
#[inline(always)]
6467
pub const fn ptr() -> *const #base::RegisterBlock {
65-
#address as *const _
68+
Self::PTR
6669
}
6770
}
6871

@@ -71,7 +74,7 @@ pub fn render(
7174

7275
#[inline(always)]
7376
fn deref(&self) -> &Self::Target {
74-
unsafe { &*#name_pc::ptr() }
77+
unsafe { &*Self::PTR }
7578
}
7679
}
7780
});

0 commit comments

Comments
 (0)