diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-23 15:13:47 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-23 15:13:47 +0200 |
| commit | 709df0dc1dfff577fb79bbc2f67ea84670072456 (patch) | |
| tree | 4a54aee47c0d3881b9e0bc809e075728cee8eeae /embassy-nrf/src/uarte.rs | |
| parent | 19d1ef0e29fdd0bf0407cbe37c388e8a87e7ddfe (diff) | |
nrf: replace PhantomData usages with PeripheralRef.
Diffstat (limited to 'embassy-nrf/src/uarte.rs')
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index e23525563..792b8ecca 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | //! memory may be used given that buffers are passed in directly to its read and write | 13 | //! memory may be used given that buffers are passed in directly to its read and write |
| 14 | //! methods. | 14 | //! methods. |
| 15 | 15 | ||
| 16 | use core::marker::PhantomData; | ||
| 17 | use core::sync::atomic::{compiler_fence, Ordering}; | 16 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 18 | use core::task::Poll; | 17 | use core::task::Poll; |
| 19 | 18 | ||
| @@ -63,7 +62,6 @@ pub enum Error { | |||
| 63 | /// | 62 | /// |
| 64 | /// For more details about EasyDMA, consult the module documentation. | 63 | /// For more details about EasyDMA, consult the module documentation. |
| 65 | pub struct Uarte<'d, T: Instance> { | 64 | pub struct Uarte<'d, T: Instance> { |
| 66 | phantom: PhantomData<&'d mut T>, | ||
| 67 | tx: UarteTx<'d, T>, | 65 | tx: UarteTx<'d, T>, |
| 68 | rx: UarteRx<'d, T>, | 66 | rx: UarteRx<'d, T>, |
| 69 | } | 67 | } |
| @@ -71,13 +69,13 @@ pub struct Uarte<'d, T: Instance> { | |||
| 71 | /// Transmitter interface to the UARTE peripheral obtained | 69 | /// Transmitter interface to the UARTE peripheral obtained |
| 72 | /// via [Uarte]::split. | 70 | /// via [Uarte]::split. |
| 73 | pub struct UarteTx<'d, T: Instance> { | 71 | pub struct UarteTx<'d, T: Instance> { |
| 74 | phantom: PhantomData<&'d mut T>, | 72 | _p: PeripheralRef<'d, T>, |
| 75 | } | 73 | } |
| 76 | 74 | ||
| 77 | /// Receiver interface to the UARTE peripheral obtained | 75 | /// Receiver interface to the UARTE peripheral obtained |
| 78 | /// via [Uarte]::split. | 76 | /// via [Uarte]::split. |
| 79 | pub struct UarteRx<'d, T: Instance> { | 77 | pub struct UarteRx<'d, T: Instance> { |
| 80 | phantom: PhantomData<&'d mut T>, | 78 | _p: PeripheralRef<'d, T>, |
| 81 | } | 79 | } |
| 82 | 80 | ||
| 83 | impl<'d, T: Instance> Uarte<'d, T> { | 81 | impl<'d, T: Instance> Uarte<'d, T> { |
| @@ -116,7 +114,7 @@ impl<'d, T: Instance> Uarte<'d, T> { | |||
| 116 | } | 114 | } |
| 117 | 115 | ||
| 118 | fn new_inner( | 116 | fn new_inner( |
| 119 | _uarte: impl Peripheral<P = T> + 'd, | 117 | uarte: impl Peripheral<P = T> + 'd, |
| 120 | irq: impl Peripheral<P = T::Interrupt> + 'd, | 118 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 121 | rxd: PeripheralRef<'d, AnyPin>, | 119 | rxd: PeripheralRef<'d, AnyPin>, |
| 122 | txd: PeripheralRef<'d, AnyPin>, | 120 | txd: PeripheralRef<'d, AnyPin>, |
| @@ -124,7 +122,7 @@ impl<'d, T: Instance> Uarte<'d, T> { | |||
| 124 | rts: Option<PeripheralRef<'d, AnyPin>>, | 122 | rts: Option<PeripheralRef<'d, AnyPin>>, |
| 125 | config: Config, | 123 | config: Config, |
| 126 | ) -> Self { | 124 | ) -> Self { |
| 127 | into_ref!(irq); | 125 | into_ref!(uarte, irq); |
| 128 | 126 | ||
| 129 | let r = T::regs(); | 127 | let r = T::regs(); |
| 130 | 128 | ||
| @@ -161,9 +159,10 @@ impl<'d, T: Instance> Uarte<'d, T> { | |||
| 161 | s.tx_rx_refcount.store(2, Ordering::Relaxed); | 159 | s.tx_rx_refcount.store(2, Ordering::Relaxed); |
| 162 | 160 | ||
| 163 | Self { | 161 | Self { |
| 164 | phantom: PhantomData, | 162 | tx: UarteTx { |
| 165 | tx: UarteTx { phantom: PhantomData }, | 163 | _p: unsafe { uarte.clone_unchecked() }, |
| 166 | rx: UarteRx { phantom: PhantomData }, | 164 | }, |
| 165 | rx: UarteRx { _p: uarte }, | ||
| 167 | } | 166 | } |
| 168 | } | 167 | } |
| 169 | 168 | ||
| @@ -267,13 +266,13 @@ impl<'d, T: Instance> UarteTx<'d, T> { | |||
| 267 | } | 266 | } |
| 268 | 267 | ||
| 269 | fn new_inner( | 268 | fn new_inner( |
| 270 | _uarte: impl Peripheral<P = T> + 'd, | 269 | uarte: impl Peripheral<P = T> + 'd, |
| 271 | irq: impl Peripheral<P = T::Interrupt> + 'd, | 270 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 272 | txd: PeripheralRef<'d, AnyPin>, | 271 | txd: PeripheralRef<'d, AnyPin>, |
| 273 | cts: Option<PeripheralRef<'d, AnyPin>>, | 272 | cts: Option<PeripheralRef<'d, AnyPin>>, |
| 274 | config: Config, | 273 | config: Config, |
| 275 | ) -> Self { | 274 | ) -> Self { |
| 276 | into_ref!(irq); | 275 | into_ref!(uarte, irq); |
| 277 | 276 | ||
| 278 | let r = T::regs(); | 277 | let r = T::regs(); |
| 279 | 278 | ||
| @@ -299,7 +298,7 @@ impl<'d, T: Instance> UarteTx<'d, T> { | |||
| 299 | let s = T::state(); | 298 | let s = T::state(); |
| 300 | s.tx_rx_refcount.store(1, Ordering::Relaxed); | 299 | s.tx_rx_refcount.store(1, Ordering::Relaxed); |
| 301 | 300 | ||
| 302 | Self { phantom: PhantomData } | 301 | Self { _p: uarte } |
| 303 | } | 302 | } |
| 304 | 303 | ||
| 305 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { | 304 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { |
| @@ -459,13 +458,13 @@ impl<'d, T: Instance> UarteRx<'d, T> { | |||
| 459 | } | 458 | } |
| 460 | 459 | ||
| 461 | fn new_inner( | 460 | fn new_inner( |
| 462 | _uarte: impl Peripheral<P = T> + 'd, | 461 | uarte: impl Peripheral<P = T> + 'd, |
| 463 | irq: impl Peripheral<P = T::Interrupt> + 'd, | 462 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 464 | rxd: PeripheralRef<'d, AnyPin>, | 463 | rxd: PeripheralRef<'d, AnyPin>, |
| 465 | rts: Option<PeripheralRef<'d, AnyPin>>, | 464 | rts: Option<PeripheralRef<'d, AnyPin>>, |
| 466 | config: Config, | 465 | config: Config, |
| 467 | ) -> Self { | 466 | ) -> Self { |
| 468 | into_ref!(irq); | 467 | into_ref!(uarte, irq); |
| 469 | 468 | ||
| 470 | let r = T::regs(); | 469 | let r = T::regs(); |
| 471 | 470 | ||
| @@ -491,7 +490,7 @@ impl<'d, T: Instance> UarteRx<'d, T> { | |||
| 491 | let s = T::state(); | 490 | let s = T::state(); |
| 492 | s.tx_rx_refcount.store(1, Ordering::Relaxed); | 491 | s.tx_rx_refcount.store(1, Ordering::Relaxed); |
| 493 | 492 | ||
| 494 | Self { phantom: PhantomData } | 493 | Self { _p: uarte } |
| 495 | } | 494 | } |
| 496 | 495 | ||
| 497 | pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { | 496 | pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { |
