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/buffered_uarte.rs | |
| 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/buffered_uarte.rs')
| -rw-r--r-- | embassy-nrf/src/buffered_uarte.rs | 33 |
1 files changed, 17 insertions, 16 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 | ||
