Skip to content

Commit e953dfa

Browse files
committed
associated RegisterBlock
1 parent 56a10f3 commit e953dfa

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/generate/generic.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
use core::marker;
22

33
/// Generic peripheral accessor
4-
pub struct Periph<RB, PER> {
5-
_marker: marker::PhantomData<(RB, PER)>,
4+
pub struct Periph<PER: PeripheralSpec> {
5+
_marker: marker::PhantomData<PER>,
66
}
77

88
pub trait PeripheralSpec {
9+
type RB;
910
///Pointer to the register block
1011
const ADDRESS: usize;
1112
///Debug name
1213
const NAME: &str;
1314
}
1415

15-
unsafe impl<RB, PER> Send for Periph<RB, PER> {}
16+
unsafe impl<PER: PeripheralSpec> Send for Periph<PER> {}
1617

17-
impl<RB, PER: PeripheralSpec> core::fmt::Debug for Periph<RB, PER> {
18+
impl<PER: PeripheralSpec> core::fmt::Debug for Periph<PER> {
1819
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
1920
f.debug_struct(PER::NAME).finish()
2021
}
2122
}
2223

23-
impl<RB, PER: PeripheralSpec> Periph<RB, PER> {
24+
impl<PER: PeripheralSpec> Periph<PER> {
2425
///Pointer to the register block
25-
pub const PTR: *const RB = PER::ADDRESS as *const _;
26+
pub const PTR: *const PER::RB = PER::ADDRESS as *const _;
2627

2728
///Return the pointer to the register block
2829
#[inline(always)]
29-
pub const fn ptr() -> *const RB {
30+
pub const fn ptr() -> *const PER::RB {
3031
Self::PTR
3132
}
3233

@@ -50,8 +51,8 @@ impl<RB, PER: PeripheralSpec> Periph<RB, PER> {
5051
}
5152
}
5253

53-
impl<RB, PER: PeripheralSpec> core::ops::Deref for Periph<RB, PER> {
54-
type Target = RB;
54+
impl<PER: PeripheralSpec> core::ops::Deref for Periph<PER> {
55+
type Target = PER::RB;
5556

5657
#[inline(always)]
5758
fn deref(&self) -> &Self::Target {

src/generate/peripheral.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
8181
#phtml
8282
#doc_alias
8383
#feature_attribute
84-
pub type #p_ty = crate::Periph<#base::RegisterBlock, #pspec>;
84+
pub type #p_ty = crate::Periph<#pspec>;
8585

8686
#feature_attribute
8787
pub struct #pspec;
8888

8989
#feature_attribute
9090
impl PeripheralSpec for #pspec {
91+
type RB = #base::RegisterBlock;
9192
const ADDRESS: usize = #address;
9293
const NAME: &str = #name_str;
9394
}

0 commit comments

Comments
 (0)