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