11use core:: marker;
22
33/// Generic peripheral accessor
4- pub struct Periph < RB , const A : usize > {
5- _marker : marker:: PhantomData < RB > ,
4+ pub struct Periph < PER : PeripheralSpec > {
5+ _marker : marker:: PhantomData < PER > ,
66}
77
8- unsafe impl < RB , const A : usize > Send for Periph < RB , A > { }
8+ /// Peripheral data
9+ pub trait PeripheralSpec {
10+ /// RegisterBlock associated with peripheral
11+ type RB ;
12+ /// Address of the register block
13+ const ADDRESS : usize ;
14+ /// Debug name
15+ const NAME : & ' static str ;
16+ }
17+
18+ unsafe impl < PER : PeripheralSpec > Send for Periph < PER > { }
19+
20+ impl < PER : PeripheralSpec > core:: fmt:: Debug for Periph < PER > {
21+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
22+ f. debug_struct ( PER :: NAME ) . finish ( )
23+ }
24+ }
925
10- impl < RB , const A : usize > Periph < RB , A > {
26+ impl < PER : PeripheralSpec > Periph < PER > {
1127 ///Pointer to the register block
12- pub const PTR : * const RB = A as * const _ ;
28+ pub const PTR : * const PER :: RB = PER :: ADDRESS as * const _ ;
1329
1430 ///Return the pointer to the register block
1531 #[ inline( always) ]
16- pub const fn ptr ( ) -> * const RB {
32+ pub const fn ptr ( ) -> * const PER :: RB {
1733 Self :: PTR
1834 }
1935
@@ -37,8 +53,8 @@ impl<RB, const A: usize> Periph<RB, A> {
3753 }
3854}
3955
40- impl < RB , const A : usize > core:: ops:: Deref for Periph < RB , A > {
41- type Target = RB ;
56+ impl < PER : PeripheralSpec > core:: ops:: Deref for Periph < PER > {
57+ type Target = PER :: RB ;
4258
4359 #[ inline( always) ]
4460 fn deref ( & self ) -> & Self :: Target {
0 commit comments