|
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<RB, PER> { |
| 5 | + _marker: marker::PhantomData<(RB, PER)>, |
6 | 6 | }
|
7 | 7 |
|
8 |
| -unsafe impl<RB, const A: usize> Send for Periph<RB, A> {} |
| 8 | +pub trait PeripheralSpec { |
| 9 | + ///Pointer to the register block |
| 10 | + const ADDRESS: usize; |
| 11 | + ///Debug name |
| 12 | + const NAME: &str; |
| 13 | +} |
| 14 | + |
| 15 | +unsafe impl<RB, PER> Send for Periph<RB, PER> {} |
| 16 | + |
| 17 | +impl<RB, PER: PeripheralSpec> core::fmt::Debug for Periph<RB, PER> { |
| 18 | + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 19 | + f.debug_struct(PER::NAME).finish() |
| 20 | + } |
| 21 | +} |
9 | 22 |
|
10 |
| -impl<RB, const A: usize> Periph<RB, A> { |
| 23 | +impl<RB, PER: PeripheralSpec> Periph<RB, PER> { |
11 | 24 | ///Pointer to the register block
|
12 |
| - pub const PTR: *const RB = A as *const _; |
| 25 | + pub const PTR: *const RB = PER::ADDRESS as *const _; |
13 | 26 |
|
14 | 27 | ///Return the pointer to the register block
|
15 | 28 | #[inline(always)]
|
@@ -37,7 +50,7 @@ impl<RB, const A: usize> Periph<RB, A> {
|
37 | 50 | }
|
38 | 51 | }
|
39 | 52 |
|
40 |
| -impl<RB, const A: usize> core::ops::Deref for Periph<RB, A> { |
| 53 | +impl<RB, PER: PeripheralSpec> core::ops::Deref for Periph<RB, PER> { |
41 | 54 | type Target = RB;
|
42 | 55 |
|
43 | 56 | #[inline(always)]
|
|
0 commit comments