1
1
use core:: marker;
2
2
3
3
/// 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 > ,
6
6
}
7
7
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
+ }
9
25
10
- impl < RB , const A : usize > Periph < RB , A > {
26
+ impl < PER : PeripheralSpec > Periph < PER > {
11
27
///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 _ ;
13
29
14
30
///Return the pointer to the register block
15
31
#[ inline( always) ]
16
- pub const fn ptr ( ) -> * const RB {
32
+ pub const fn ptr ( ) -> * const PER :: RB {
17
33
Self :: PTR
18
34
}
19
35
@@ -37,8 +53,8 @@ impl<RB, const A: usize> Periph<RB, A> {
37
53
}
38
54
}
39
55
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 ;
42
58
43
59
#[ inline( always) ]
44
60
fn deref ( & self ) -> & Self :: Target {
0 commit comments