diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-03-21 22:09:06 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-03-29 00:58:58 +0200 |
| commit | 7b6086d19eca2d51c7cddf9dbbbc47eacf371472 (patch) | |
| tree | f0b03ff19d89e2ba2cdb9e28b679d6a0953a2c56 /embassy-nrf/src | |
| parent | a134fce122d570cfcd3837944554fff6c35e4039 (diff) | |
nrf: add unborrow! macro
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/qspi.rs | 14 | ||||
| -rw-r--r-- | embassy-nrf/src/spim.rs | 11 |
2 files changed, 8 insertions, 17 deletions
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 39cefa0a3..10564ba59 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -5,6 +5,7 @@ use core::task::Poll; | |||
| 5 | 5 | ||
| 6 | use embassy::interrupt::Interrupt; | 6 | use embassy::interrupt::Interrupt; |
| 7 | use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; | 7 | use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; |
| 8 | use embassy_extras::unborrow; | ||
| 8 | 9 | ||
| 9 | use crate::fmt::{assert, assert_eq, *}; | 10 | use crate::fmt::{assert, assert_eq, *}; |
| 10 | use crate::gpio::Pin as GpioPin; | 11 | use crate::gpio::Pin as GpioPin; |
| @@ -61,14 +62,7 @@ impl<'d, T: Instance> Qspi<'d, T> { | |||
| 61 | io3: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | 62 | io3: impl PeripheralBorrow<Target = impl GpioPin> + 'd, |
| 62 | config: Config, | 63 | config: Config, |
| 63 | ) -> Self { | 64 | ) -> Self { |
| 64 | let mut qspi = unsafe { qspi.unborrow() }; | 65 | unborrow!(qspi, irq, sck, csn, io0, io1, io2, io3); |
| 65 | let irq = unsafe { irq.unborrow() }; | ||
| 66 | let sck = unsafe { sck.unborrow() }; | ||
| 67 | let csn = unsafe { csn.unborrow() }; | ||
| 68 | let io0 = unsafe { io0.unborrow() }; | ||
| 69 | let io1 = unsafe { io1.unborrow() }; | ||
| 70 | let io2 = unsafe { io2.unborrow() }; | ||
| 71 | let io3 = unsafe { io3.unborrow() }; | ||
| 72 | 66 | ||
| 73 | let r = qspi.regs(); | 67 | let r = qspi.regs(); |
| 74 | 68 | ||
| @@ -361,7 +355,7 @@ mod sealed { | |||
| 361 | use super::*; | 355 | use super::*; |
| 362 | 356 | ||
| 363 | pub trait Instance { | 357 | pub trait Instance { |
| 364 | fn regs(&mut self) -> &pac::qspi::RegisterBlock; | 358 | fn regs(&self) -> &pac::qspi::RegisterBlock; |
| 365 | } | 359 | } |
| 366 | } | 360 | } |
| 367 | 361 | ||
| @@ -372,7 +366,7 @@ pub trait Instance: sealed::Instance + 'static { | |||
| 372 | macro_rules! make_impl { | 366 | macro_rules! make_impl { |
| 373 | ($type:ident, $irq:ident) => { | 367 | ($type:ident, $irq:ident) => { |
| 374 | impl sealed::Instance for peripherals::$type { | 368 | impl sealed::Instance for peripherals::$type { |
| 375 | fn regs(&mut self) -> &pac::qspi::RegisterBlock { | 369 | fn regs(&self) -> &pac::qspi::RegisterBlock { |
| 376 | unsafe { &*pac::$type::ptr() } | 370 | unsafe { &*pac::$type::ptr() } |
| 377 | } | 371 | } |
| 378 | } | 372 | } |
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 214868b6f..c84861f30 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -5,6 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | use embassy::traits; | 6 | use embassy::traits; |
| 7 | use embassy::util::{wake_on_interrupt, PeripheralBorrow}; | 7 | use embassy::util::{wake_on_interrupt, PeripheralBorrow}; |
| 8 | use embassy_extras::unborrow; | ||
| 8 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 9 | use traits::spi::FullDuplex; | 10 | use traits::spi::FullDuplex; |
| 10 | 11 | ||
| @@ -46,11 +47,7 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 46 | mosi: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | 47 | mosi: impl PeripheralBorrow<Target = impl GpioPin> + 'd, |
| 47 | config: Config, | 48 | config: Config, |
| 48 | ) -> Self { | 49 | ) -> Self { |
| 49 | let mut spim = unsafe { spim.unborrow() }; | 50 | unborrow!(spim, irq, sck, miso, mosi); |
| 50 | let irq = unsafe { irq.unborrow() }; | ||
| 51 | let sck = unsafe { sck.unborrow() }; | ||
| 52 | let miso = unsafe { miso.unborrow() }; | ||
| 53 | let mosi = unsafe { mosi.unborrow() }; | ||
| 54 | 51 | ||
| 55 | let r = spim.regs(); | 52 | let r = spim.regs(); |
| 56 | 53 | ||
| @@ -209,7 +206,7 @@ mod sealed { | |||
| 209 | use super::*; | 206 | use super::*; |
| 210 | 207 | ||
| 211 | pub trait Instance { | 208 | pub trait Instance { |
| 212 | fn regs(&mut self) -> &pac::spim0::RegisterBlock; | 209 | fn regs(&self) -> &pac::spim0::RegisterBlock; |
| 213 | } | 210 | } |
| 214 | } | 211 | } |
| 215 | 212 | ||
| @@ -220,7 +217,7 @@ pub trait Instance: sealed::Instance + 'static { | |||
| 220 | macro_rules! make_impl { | 217 | macro_rules! make_impl { |
| 221 | ($type:ident, $irq:ident) => { | 218 | ($type:ident, $irq:ident) => { |
| 222 | impl sealed::Instance for peripherals::$type { | 219 | impl sealed::Instance for peripherals::$type { |
| 223 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | 220 | fn regs(&self) -> &pac::spim0::RegisterBlock { |
| 224 | unsafe { &*pac::$type::ptr() } | 221 | unsafe { &*pac::$type::ptr() } |
| 225 | } | 222 | } |
| 226 | } | 223 | } |
