Skip to content

Commit e10defc

Browse files
committed
Add RegisterBlock trait
1 parent d894fd1 commit e10defc

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ 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 fixed in memory peripherals)
1214
- Generated crates now contain the git commit hash and date of svd2rust
1315
compilation.
1416

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
/// Trait implemented by readable registers to enable the `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
@@ -74,6 +74,14 @@ pub fn render(
7474
unsafe { &*#name_pc::ptr() }
7575
}
7676
}
77+
impl crate::RegisterBlock for #name_pc {
78+
type RB = #base::RegisterBlock;
79+
80+
#[inline(always)]
81+
fn rb() -> *const Self::RB {
82+
#name_pc::ptr()
83+
}
84+
}
7785
});
7886

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

0 commit comments

Comments
 (0)