Skip to content

Commit ebf3fa6

Browse files
committedAug 30, 2020
Add RegisterBlock trait
1 parent 73d42ff commit ebf3fa6

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
/// Raw register type
413
pub trait RegisterSpec {
514
/// Raw register type (`u8`, `u16`, `u32`, ...).

‎src/generate/peripheral.rs

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

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

0 commit comments

Comments
 (0)
Failed to load comments.