Skip to content

Commit 6c20f37

Browse files
committedApr 17, 2021
Add RegisterBlock trait
1 parent cbb1ade commit 6c20f37

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
- RegisterBlock trait (like `Deref`, but don't require `self` instance,
13+
only for memory fixed peripherals)
14+
1215
- New `-m` switch generates a `mod.rs` file instead of `lib.rs`, which can
1316
be used as a module inside a crate without further modification.
1417

‎src/generate/generic.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
use core::marker;
22

3+
///This trait allows to get raw pointer on derived peripheral
4+
///as block of registers of base peripheral (like unsafe `Deref`)
5+
pub trait RegisterBlock {
6+
///Type of RegisterBlock of base peripheral
7+
type RB;
8+
///Take peripheral address as raw pointer
9+
fn rb() -> *const Self::RB;
10+
}
11+
312
/// Raw register type
413
pub trait RegisterSpec {
514
/// Raw register type (`u8`, `u16`, `u32`, ...).

‎src/generate/peripheral.rs

+9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ pub fn render(
7979
}
8080
}
8181

82+
impl crate::RegisterBlock for #name_pc {
83+
type RB = #base::RegisterBlock;
84+
85+
#[inline(always)]
86+
fn rb() -> *const Self::RB {
87+
#name_pc::ptr()
88+
}
89+
}
90+
8291
impl core::fmt::Debug for #name_pc {
8392
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
8493
f.debug_struct(#name_str).finish()

0 commit comments

Comments
 (0)
Failed to load comments.