aboutsummaryrefslogtreecommitdiff
path: root/embassy-hal-common
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 15:13:47 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 15:13:47 +0200
commit709df0dc1dfff577fb79bbc2f67ea84670072456 (patch)
tree4a54aee47c0d3881b9e0bc809e075728cee8eeae /embassy-hal-common
parent19d1ef0e29fdd0bf0407cbe37c388e8a87e7ddfe (diff)
nrf: replace PhantomData usages with PeripheralRef.
Diffstat (limited to 'embassy-hal-common')
-rw-r--r--embassy-hal-common/src/peripheral.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-hal-common/src/peripheral.rs
index 99df4b894..038cebb5e 100644
--- a/embassy-hal-common/src/peripheral.rs
+++ b/embassy-hal-common/src/peripheral.rs
@@ -27,6 +27,36 @@ impl<'a, T> PeripheralRef<'a, T> {
27 } 27 }
28 } 28 }
29 29
30 /// Unsafely clone (duplicate) a peripheral singleton.
31 ///
32 /// # Safety
33 ///
34 /// This returns an owned clone of the peripheral. You must manually ensure
35 /// only one copy of the peripheral is in use at a time. For example, don't
36 /// create two SPI drivers on `SPI1`, because they will "fight" each other.
37 ///
38 /// You should strongly prefer using `reborrow()` instead. It returns a
39 /// `PeripheralRef` that borrows `self`, which allows the borrow checker
40 /// to enforce this at compile time.
41 pub unsafe fn clone_unchecked(&mut self) -> PeripheralRef<'a, T>
42 where
43 T: Peripheral<P = T>,
44 {
45 PeripheralRef::new(self.inner.clone_unchecked())
46 }
47
48 /// Reborrow into a "child" PeripheralRef.
49 ///
50 /// `self` will stay borrowed until the child PeripheralRef is dropped.
51 pub fn reborrow(&mut self) -> PeripheralRef<'_, T>
52 where
53 T: Peripheral<P = T>,
54 {
55 // safety: we're returning the clone inside a new PeripheralRef that borrows
56 // self, so user code can't use both at the same time.
57 PeripheralRef::new(unsafe { self.inner.clone_unchecked() })
58 }
59
30 /// Map the inner peripheral using `Into`. 60 /// Map the inner peripheral using `Into`.
31 /// 61 ///
32 /// This converts from `PeripheralRef<'a, T>` to `PeripheralRef<'a, U>`, using an 62 /// This converts from `PeripheralRef<'a, T>` to `PeripheralRef<'a, U>`, using an