diff options
| author | huntc <[email protected]> | 2021-12-01 09:14:24 +1100 |
|---|---|---|
| committer | huntc <[email protected]> | 2021-12-01 09:14:24 +1100 |
| commit | 469852c667cd7105d5eba7b197e1e2b5b9528d15 (patch) | |
| tree | c3a7b3e1d294ae129b38d11127dd88229fa0ed6e /embassy-nrf/src | |
| parent | e36e36dab6b19ae90c6f78b1cdd2233e295bd171 (diff) | |
Removed unsafe from uarte
The constructors themselves are not strictly unsafe. Interactions with DMA can be generally unsafe if a future is dropped, but that's a separate issue. It is important that we use the `unsafe` keyword diligently as it can lead to confusion otherwise.
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/buffered_uarte.rs | 33 | ||||
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 9 |
2 files changed, 18 insertions, 24 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 717ada78d..9763774de 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -65,8 +65,7 @@ pub struct BufferedUarte<'d, U: UarteInstance, T: TimerInstance> { | |||
| 65 | impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {} | 65 | impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {} |
| 66 | 66 | ||
| 67 | impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | 67 | impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { |
| 68 | /// unsafe: may not leak self or futures | 68 | pub fn new( |
| 69 | pub unsafe fn new( | ||
| 70 | state: &'d mut State<'d, U, T>, | 69 | state: &'d mut State<'d, U, T>, |
| 71 | _uarte: impl Unborrow<Target = U> + 'd, | 70 | _uarte: impl Unborrow<Target = U> + 'd, |
| 72 | timer: impl Unborrow<Target = T> + 'd, | 71 | timer: impl Unborrow<Target = T> + 'd, |
| @@ -160,20 +159,22 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | |||
| 160 | ppi_ch2.enable(); | 159 | ppi_ch2.enable(); |
| 161 | 160 | ||
| 162 | Self { | 161 | Self { |
| 163 | inner: PeripheralMutex::new_unchecked(irq, &mut state.0, move || StateInner { | 162 | inner: unsafe { |
| 164 | phantom: PhantomData, | 163 | PeripheralMutex::new_unchecked(irq, &mut state.0, move || StateInner { |
| 165 | timer, | 164 | phantom: PhantomData, |
| 166 | _ppi_ch1: ppi_ch1, | 165 | timer, |
| 167 | _ppi_ch2: ppi_ch2, | 166 | _ppi_ch1: ppi_ch1, |
| 168 | 167 | _ppi_ch2: ppi_ch2, | |
| 169 | rx: RingBuffer::new(rx_buffer), | 168 | |
| 170 | rx_state: RxState::Idle, | 169 | rx: RingBuffer::new(rx_buffer), |
| 171 | rx_waker: WakerRegistration::new(), | 170 | rx_state: RxState::Idle, |
| 172 | 171 | rx_waker: WakerRegistration::new(), | |
| 173 | tx: RingBuffer::new(tx_buffer), | 172 | |
| 174 | tx_state: TxState::Idle, | 173 | tx: RingBuffer::new(tx_buffer), |
| 175 | tx_waker: WakerRegistration::new(), | 174 | tx_state: TxState::Idle, |
| 176 | }), | 175 | tx_waker: WakerRegistration::new(), |
| 176 | }) | ||
| 177 | }, | ||
| 177 | } | 178 | } |
| 178 | } | 179 | } |
| 179 | 180 | ||
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 459bc8436..543f7fb73 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -48,14 +48,7 @@ pub struct Uarte<'d, T: Instance> { | |||
| 48 | impl<'d, T: Instance> Uarte<'d, T> { | 48 | impl<'d, T: Instance> Uarte<'d, T> { |
| 49 | /// Creates the interface to a UARTE instance. | 49 | /// Creates the interface to a UARTE instance. |
| 50 | /// Sets the baud rate, parity and assigns the pins to the UARTE peripheral. | 50 | /// Sets the baud rate, parity and assigns the pins to the UARTE peripheral. |
| 51 | /// | 51 | pub fn new( |
| 52 | /// # Safety | ||
| 53 | /// | ||
| 54 | /// The returned API is safe unless you use `mem::forget` (or similar safe mechanisms) | ||
| 55 | /// on stack allocated buffers which which have been passed to [`send()`](Uarte::send) | ||
| 56 | /// or [`receive`](Uarte::receive). | ||
| 57 | #[allow(unused_unsafe)] | ||
| 58 | pub unsafe fn new( | ||
| 59 | _uarte: impl Unborrow<Target = T> + 'd, | 52 | _uarte: impl Unborrow<Target = T> + 'd, |
| 60 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 53 | irq: impl Unborrow<Target = T::Interrupt> + 'd, |
| 61 | rxd: impl Unborrow<Target = impl GpioPin> + 'd, | 54 | rxd: impl Unborrow<Target = impl GpioPin> + 'd, |
