Skip to content

Commit 0dafb0a

Browse files
committed
Add RegisterBlock trait
1 parent ee8a8a7 commit 0dafb0a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- RegisterBlock trait (like `Deref`, but don't require `self` instance,
13+
only for fixed in memory peripherals)
14+
1015
### Fixed
1116

1217
- Keyword sanitizing (`async`)

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
///This trait shows that register has `read` method
413
///
514
///Registers marked with `Writable` can be also `modify`'ed

src/generate/peripheral.rs

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ pub fn render(
7676
unsafe { &*#name_pc::ptr() }
7777
}
7878
}
79+
impl crate::RegisterBlock for #name_pc {
80+
type RB = #base::RegisterBlock;
81+
82+
#[inline(always)]
83+
fn rb() -> *const Self::RB {
84+
#name_pc::ptr()
85+
}
86+
}
7987
});
8088

8189
// Derived peripherals may not require re-implementation, and will instead

0 commit comments

Comments
 (0)