|
1 | 1 | use core::marker;
|
2 | 2 |
|
| 3 | +/// Generic peripheral accessor |
| 4 | +pub struct Periph<RB, const A: usize> { |
| 5 | + _marker: marker::PhantomData<RB>, |
| 6 | +} |
| 7 | + |
| 8 | +unsafe impl<RB, const A: usize> Send for Periph<RB, A> {} |
| 9 | + |
| 10 | +impl<RB, const A: usize> Periph<RB, A> { |
| 11 | + ///Pointer to the register block |
| 12 | + pub const PTR: *const RB = A as *const _; |
| 13 | + |
| 14 | + ///Return the pointer to the register block |
| 15 | + #[inline(always)] |
| 16 | + pub const fn ptr() -> *const RB { |
| 17 | + Self::PTR |
| 18 | + } |
| 19 | + |
| 20 | + /// Steal an instance of this peripheral |
| 21 | + /// |
| 22 | + /// # Safety |
| 23 | + /// |
| 24 | + /// Ensure that the new instance of the peripheral cannot be used in a way |
| 25 | + /// that may race with any existing instances, for example by only |
| 26 | + /// accessing read-only or write-only registers, or by consuming the |
| 27 | + /// original peripheral and using critical sections to coordinate |
| 28 | + /// access between multiple new instances. |
| 29 | + /// |
| 30 | + /// Additionally, other software such as HALs may rely on only one |
| 31 | + /// peripheral instance existing to ensure memory safety; ensure |
| 32 | + /// no stolen instances are passed to such software. |
| 33 | + pub unsafe fn steal() -> Self { |
| 34 | + Self { |
| 35 | + _marker: marker::PhantomData, |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +impl<RB, const A: usize> core::ops::Deref for Periph<RB, A> { |
| 41 | + type Target = RB; |
| 42 | + |
| 43 | + #[inline(always)] |
| 44 | + fn deref(&self) -> &Self::Target { |
| 45 | + unsafe { &*Self::PTR } |
| 46 | + } |
| 47 | +} |
| 48 | + |
3 | 49 | /// Raw register type (`u8`, `u16`, `u32`, ...)
|
4 | 50 | pub trait RawReg:
|
5 | 51 | Copy
|
@@ -247,7 +293,10 @@ impl<REG: Writable> W<REG> {
|
247 | 293 | self
|
248 | 294 | }
|
249 | 295 | }
|
250 |
| -impl<REG> W<REG> where REG: Writable<Safety = Safe> { |
| 296 | +impl<REG> W<REG> |
| 297 | +where |
| 298 | + REG: Writable<Safety = Safe>, |
| 299 | +{ |
251 | 300 | /// Writes raw bits to the register.
|
252 | 301 | #[inline(always)]
|
253 | 302 | pub fn set(&mut self, bits: REG::Ux) -> &mut Self {
|
@@ -335,7 +384,8 @@ pub struct RangeFrom<const MIN: u64>;
|
335 | 384 | pub struct RangeTo<const MAX: u64>;
|
336 | 385 |
|
337 | 386 | /// Write field Proxy
|
338 |
| -pub type FieldWriter<'a, REG, const WI: u8, FI = u8, Safety = Unsafe> = raw::FieldWriter<'a, REG, WI, FI, Safety>; |
| 387 | +pub type FieldWriter<'a, REG, const WI: u8, FI = u8, Safety = Unsafe> = |
| 388 | + raw::FieldWriter<'a, REG, WI, FI, Safety>; |
339 | 389 |
|
340 | 390 | impl<REG, const WI: u8, FI, Safety> FieldWriter<'_, REG, WI, FI, Safety>
|
341 | 391 | where
|
@@ -390,7 +440,8 @@ where
|
390 | 440 | }
|
391 | 441 | }
|
392 | 442 |
|
393 |
| -impl<'a, REG, const WI: u8, FI, const MIN: u64, const MAX: u64> FieldWriter<'a, REG, WI, FI, Range<MIN, MAX>> |
| 443 | +impl<'a, REG, const WI: u8, FI, const MIN: u64, const MAX: u64> |
| 444 | + FieldWriter<'a, REG, WI, FI, Range<MIN, MAX>> |
394 | 445 | where
|
395 | 446 | REG: Writable + RegisterSpec,
|
396 | 447 | FI: FieldSpec,
|
@@ -478,7 +529,7 @@ macro_rules! bit_proxy {
|
478 | 529 | pub const fn width(&self) -> u8 {
|
479 | 530 | Self::WIDTH
|
480 | 531 | }
|
481 |
| - |
| 532 | + |
482 | 533 | /// Field offset
|
483 | 534 | #[inline(always)]
|
484 | 535 | pub const fn offset(&self) -> u8 {
|
|
0 commit comments