aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/spim.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-03-21 22:09:06 +0100
committerDario Nieuwenhuis <[email protected]>2021-03-29 00:58:58 +0200
commit7b6086d19eca2d51c7cddf9dbbbc47eacf371472 (patch)
treef0b03ff19d89e2ba2cdb9e28b679d6a0953a2c56 /embassy-nrf/src/spim.rs
parenta134fce122d570cfcd3837944554fff6c35e4039 (diff)
nrf: add unborrow! macro
Diffstat (limited to 'embassy-nrf/src/spim.rs')
-rw-r--r--embassy-nrf/src/spim.rs11
1 files changed, 4 insertions, 7 deletions
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};
5use core::task::Poll; 5use core::task::Poll;
6use embassy::traits; 6use embassy::traits;
7use embassy::util::{wake_on_interrupt, PeripheralBorrow}; 7use embassy::util::{wake_on_interrupt, PeripheralBorrow};
8use embassy_extras::unborrow;
8use futures::future::poll_fn; 9use futures::future::poll_fn;
9use traits::spi::FullDuplex; 10use 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 {
220macro_rules! make_impl { 217macro_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 }