summaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2022-07-23 14:27:45 +0200
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2022-07-23 14:27:45 +0200
commitf02ba35482790a54067978cde923867de3dc52a2 (patch)
tree3260a5ffd1e65e21f019b8ee367fe290b2aeee7d /embassy-nrf
parenta158295782b75bce5f83f5d1c2c476b841493979 (diff)
downloadembassy-f02ba35482790a54067978cde923867de3dc52a2.zip
Remove PeripheralRef::into_inner()
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs9
-rw-r--r--embassy-nrf/src/gpio.rs22
-rw-r--r--embassy-nrf/src/ppi/mod.rs16
-rw-r--r--embassy-nrf/src/pwm.rs60
-rw-r--r--embassy-nrf/src/qdec.rs8
-rw-r--r--embassy-nrf/src/qspi.rs19
-rw-r--r--embassy-nrf/src/spim.rs19
-rw-r--r--embassy-nrf/src/uarte.rs61
8 files changed, 136 insertions, 78 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index 48ffe5c2..036af380 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -147,8 +147,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> {
timer.cc(0).short_compare_stop();
let mut ppi_ch1 = Ppi::new_one_to_two(
- //TODO: Avoid into_inner?
- unsafe { ppi_ch1.into_inner() }.degrade(),
+ ppi_ch1.map_into(),
Event::from_reg(&r.events_rxdrdy),
timer.task_clear(),
timer.task_start(),
@@ -156,16 +155,14 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> {
ppi_ch1.enable();
let mut ppi_ch2 = Ppi::new_one_to_one(
- //TODO: Avoid into_inner?
- unsafe { ppi_ch2.into_inner() }.degrade(),
+ ppi_ch2.map_into(),
timer.cc(0).event_compare(),
Task::from_reg(&r.tasks_stoprx),
);
ppi_ch2.enable();
Self {
- //TODO: Avoid into_inner?
- inner: PeripheralMutex::new(unsafe { irq.into_inner() }, &mut state.0, move || StateInner {
+ inner: PeripheralMutex::new(irq, &mut state.0, move || StateInner {
phantom: PhantomData,
timer,
_ppi_ch1: ppi_ch1,
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index ae08d859..a61ff6aa 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -374,7 +374,7 @@ pub(crate) mod sealed {
}
}
-pub trait Pin: Peripheral<P = Self> + sealed::Pin + Sized + 'static {
+pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static {
/// Number of the pin within the port (0..31)
#[inline]
fn pin(&self) -> u8 {
@@ -416,20 +416,6 @@ impl AnyPin {
pub unsafe fn steal(pin_port: u8) -> Self {
Self { pin_port }
}
-
- pub(crate) fn into_degraded_ref<'a>(pin: impl Peripheral<P = impl Pin + 'a> + 'a) -> PeripheralRef<'a, Self> {
- PeripheralRef::new(AnyPin {
- pin_port: pin.into_ref().pin_port(),
- })
- }
-}
-
-macro_rules! into_degraded_ref {
- ($($name:ident),*) => {
- $(
- let $name = $crate::gpio::AnyPin::into_degraded_ref($name);
- )*
- };
}
impl_peripheral!(AnyPin);
@@ -475,6 +461,12 @@ macro_rules! impl_pin {
$port_num * 32 + $pin_num
}
}
+
+ impl From<peripherals::$type> for crate::gpio::AnyPin {
+ fn from(val: peripherals::$type) -> Self {
+ crate::gpio::Pin::degrade(val)
+ }
+ }
};
}
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index 796de217..23ab011b 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -92,11 +92,11 @@ pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized {
fn number(&self) -> usize;
}
-pub trait ConfigurableChannel: Channel {
+pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> {
fn degrade(self) -> AnyConfigurableChannel;
}
-pub trait StaticChannel: Channel {
+pub trait StaticChannel: Channel + Into<AnyStaticChannel> {
fn degrade(self) -> AnyStaticChannel;
}
@@ -167,6 +167,12 @@ macro_rules! impl_ppi_channel {
}
}
}
+
+ impl From<peripherals::$type> for crate::ppi::AnyStaticChannel {
+ fn from(val: peripherals::$type) -> Self {
+ crate::ppi::StaticChannel::degrade(val)
+ }
+ }
};
($type:ident, $number:expr => configurable) => {
impl_ppi_channel!($type, $number);
@@ -178,6 +184,12 @@ macro_rules! impl_ppi_channel {
}
}
}
+
+ impl From<peripherals::$type> for crate::ppi::AnyConfigurableChannel {
+ fn from(val: peripherals::$type) -> Self {
+ crate::ppi::ConfigurableChannel::degrade(val)
+ }
+ }
};
}
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 603fd8ef..ecc674ce 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -3,7 +3,7 @@
use core::marker::PhantomData;
use core::sync::atomic::{compiler_fence, Ordering};
-use embassy_hal_common::PeripheralRef;
+use embassy_hal_common::{into_ref, PeripheralRef};
use crate::gpio::sealed::Pin as _;
use crate::gpio::{AnyPin, Pin as GpioPin, PselBits};
@@ -55,8 +55,8 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
ch0: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
- into_degraded_ref!(ch0);
- Self::new_inner(pwm, Some(ch0), None, None, None, config)
+ into_ref!(ch0);
+ Self::new_inner(pwm, Some(ch0.map_into()), None, None, None, config)
}
/// Create a new 2-channel PWM
@@ -67,8 +67,8 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
ch1: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
- into_degraded_ref!(ch0, ch1);
- Self::new_inner(pwm, Some(ch0), Some(ch1), None, None, config)
+ into_ref!(ch0, ch1);
+ Self::new_inner(pwm, Some(ch0.map_into()), Some(ch1.map_into()), None, None, config)
}
/// Create a new 3-channel PWM
@@ -80,8 +80,15 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
ch2: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
- into_degraded_ref!(ch0, ch1, ch2);
- Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None, config)
+ into_ref!(ch0, ch1, ch2);
+ Self::new_inner(
+ pwm,
+ Some(ch0.map_into()),
+ Some(ch1.map_into()),
+ Some(ch2.map_into()),
+ None,
+ config,
+ )
}
/// Create a new 4-channel PWM
@@ -94,8 +101,15 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
ch3: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
- into_degraded_ref!(ch0, ch1, ch2, ch3);
- Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3), config)
+ into_ref!(ch0, ch1, ch2, ch3);
+ Self::new_inner(
+ pwm,
+ Some(ch0.map_into()),
+ Some(ch1.map_into()),
+ Some(ch2.map_into()),
+ Some(ch3.map_into()),
+ config,
+ )
}
fn new_inner(
@@ -561,8 +575,8 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
#[allow(unused_unsafe)]
pub fn new_1ch(pwm: impl Peripheral<P = T> + 'd, ch0: impl Peripheral<P = impl GpioPin> + 'd) -> Self {
unsafe {
- into_degraded_ref!(ch0);
- Self::new_inner(pwm, Some(ch0), None, None, None)
+ into_ref!(ch0);
+ Self::new_inner(pwm, Some(ch0.map_into()), None, None, None)
}
}
@@ -573,8 +587,8 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
ch0: impl Peripheral<P = impl GpioPin> + 'd,
ch1: impl Peripheral<P = impl GpioPin> + 'd,
) -> Self {
- into_degraded_ref!(ch0, ch1);
- Self::new_inner(pwm, Some(ch0), Some(ch1), None, None)
+ into_ref!(ch0, ch1);
+ Self::new_inner(pwm, Some(ch0.map_into()), Some(ch1.map_into()), None, None)
}
/// Create a new 3-channel PWM
@@ -586,8 +600,14 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
ch2: impl Peripheral<P = impl GpioPin> + 'd,
) -> Self {
unsafe {
- into_degraded_ref!(ch0, ch1, ch2);
- Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None)
+ into_ref!(ch0, ch1, ch2);
+ Self::new_inner(
+ pwm,
+ Some(ch0.map_into()),
+ Some(ch1.map_into()),
+ Some(ch2.map_into()),
+ None,
+ )
}
}
@@ -601,8 +621,14 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
ch3: impl Peripheral<P = impl GpioPin> + 'd,
) -> Self {
unsafe {
- into_degraded_ref!(ch0, ch1, ch2, ch3);
- Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3))
+ into_ref!(ch0, ch1, ch2, ch3);
+ Self::new_inner(
+ pwm,
+ Some(ch0.map_into()),
+ Some(ch1.map_into()),
+ Some(ch2.map_into()),
+ Some(ch3.map_into()),
+ )
}
}
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs
index 2fb31fc2..d5dc1446 100644
--- a/embassy-nrf/src/qdec.rs
+++ b/embassy-nrf/src/qdec.rs
@@ -49,8 +49,8 @@ impl<'d> Qdec<'d> {
b: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(a, b);
- Self::new_inner(qdec, irq, a, b, None, config)
+ into_ref!(a, b);
+ Self::new_inner(qdec, irq, a.map_into(), b.map_into(), None, config)
}
pub fn new_with_led(
@@ -61,8 +61,8 @@ impl<'d> Qdec<'d> {
led: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(a, b, led);
- Self::new_inner(qdec, irq, a, b, Some(led), config)
+ into_ref!(a, b, led);
+ Self::new_inner(qdec, irq, a.map_into(), b.map_into(), Some(led.map_into()), config)
}
fn new_inner(
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index 51d9446a..67634b5b 100644
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -7,7 +7,6 @@ use embassy_hal_common::drop::DropBomb;
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
-use crate::gpio::sealed::Pin as _;
use crate::gpio::{self, Pin as GpioPin};
use crate::interrupt::{Interrupt, InterruptExt};
pub use crate::pac::qspi::ifconfig0::{
@@ -82,12 +81,18 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
let r = T::regs();
- into_degraded_ref!(sck, csn, io0, io1, io2, io3);
-
- for pin in [&sck, &csn, &io0, &io1, &io2, &io3] {
- pin.set_high();
- pin.conf().write(|w| w.dir().output().drive().h0h1());
- }
+ sck.set_high();
+ csn.set_high();
+ io0.set_high();
+ io1.set_high();
+ io2.set_high();
+ io3.set_high();
+ sck.conf().write(|w| w.dir().output().drive().h0h1());
+ csn.conf().write(|w| w.dir().output().drive().h0h1());
+ io0.conf().write(|w| w.dir().output().drive().h0h1());
+ io1.conf().write(|w| w.dir().output().drive().h0h1());
+ io2.conf().write(|w| w.dir().output().drive().h0h1());
+ io3.conf().write(|w| w.dir().output().drive().h0h1());
r.psel.sck.write(|w| unsafe { w.bits(sck.psel_bits()) });
r.psel.csn.write(|w| unsafe { w.bits(csn.psel_bits()) });
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index 4bb0f445..a6b0be07 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -60,8 +60,15 @@ impl<'d, T: Instance> Spim<'d, T> {
mosi: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(sck, miso, mosi);
- Self::new_inner(spim, irq, sck, Some(miso), Some(mosi), config)
+ into_ref!(sck, miso, mosi);
+ Self::new_inner(
+ spim,
+ irq,
+ sck.map_into(),
+ Some(miso.map_into()),
+ Some(mosi.map_into()),
+ config,
+ )
}
pub fn new_txonly(
@@ -71,8 +78,8 @@ impl<'d, T: Instance> Spim<'d, T> {
mosi: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(sck, mosi);
- Self::new_inner(spim, irq, sck, None, Some(mosi), config)
+ into_ref!(sck, mosi);
+ Self::new_inner(spim, irq, sck.map_into(), None, Some(mosi.map_into()), config)
}
pub fn new_rxonly(
@@ -82,8 +89,8 @@ impl<'d, T: Instance> Spim<'d, T> {
miso: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(sck, miso);
- Self::new_inner(spim, irq, sck, Some(miso), None, config)
+ into_ref!(sck, miso);
+ Self::new_inner(spim, irq, sck.map_into(), Some(miso.map_into()), None, config)
}
fn new_inner(
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index a556d6b9..e2352556 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -89,8 +89,8 @@ impl<'d, T: Instance> Uarte<'d, T> {
txd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(rxd, txd);
- Self::new_inner(uarte, irq, rxd, txd, None, None, config)
+ into_ref!(rxd, txd);
+ Self::new_inner(uarte, irq, rxd.map_into(), txd.map_into(), None, None, config)
}
/// Create a new UARTE with hardware flow control (RTS/CTS)
@@ -103,8 +103,16 @@ impl<'d, T: Instance> Uarte<'d, T> {
rts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(rxd, txd, cts, rts);
- Self::new_inner(uarte, irq, rxd, txd, Some(cts), Some(rts), config)
+ into_ref!(rxd, txd, cts, rts);
+ Self::new_inner(
+ uarte,
+ irq,
+ rxd.map_into(),
+ txd.map_into(),
+ Some(cts.map_into()),
+ Some(rts.map_into()),
+ config,
+ )
}
fn new_inner(
@@ -242,8 +250,8 @@ impl<'d, T: Instance> UarteTx<'d, T> {
txd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(txd);
- Self::new_inner(uarte, irq, txd, None, config)
+ into_ref!(txd);
+ Self::new_inner(uarte, irq, txd.map_into(), None, config)
}
/// Create a new tx-only UARTE with hardware flow control (RTS/CTS)
@@ -254,8 +262,8 @@ impl<'d, T: Instance> UarteTx<'d, T> {
cts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(txd, cts);
- Self::new_inner(uarte, irq, txd, Some(cts), config)
+ into_ref!(txd, cts);
+ Self::new_inner(uarte, irq, txd.map_into(), Some(cts.map_into()), config)
}
fn new_inner(
@@ -434,8 +442,8 @@ impl<'d, T: Instance> UarteRx<'d, T> {
rxd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(rxd);
- Self::new_inner(uarte, irq, rxd, None, config)
+ into_ref!(rxd);
+ Self::new_inner(uarte, irq, rxd.map_into(), None, config)
}
/// Create a new rx-only UARTE with hardware flow control (RTS/CTS)
@@ -446,8 +454,8 @@ impl<'d, T: Instance> UarteRx<'d, T> {
rts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(rxd, rts);
- Self::new_inner(uarte, irq, rxd, Some(rts), config)
+ into_ref!(rxd, rts);
+ Self::new_inner(uarte, irq, rxd.map_into(), Some(rts.map_into()), config)
}
fn new_inner(
@@ -677,8 +685,19 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
txd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(rxd, txd);
- Self::new_inner(uarte, timer, ppi_ch1, ppi_ch2, irq, rxd, txd, None, None, config)
+ into_ref!(rxd, txd);
+ Self::new_inner(
+ uarte,
+ timer,
+ ppi_ch1,
+ ppi_ch2,
+ irq,
+ rxd.map_into(),
+ txd.map_into(),
+ None,
+ None,
+ config,
+ )
}
/// Create a new UARTE with hardware flow control (RTS/CTS)
@@ -694,17 +713,17 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
rts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
- into_degraded_ref!(rxd, txd, cts, rts);
+ into_ref!(rxd, txd, cts, rts);
Self::new_inner(
uarte,
timer,
ppi_ch1,
ppi_ch2,
irq,
- rxd,
- txd,
- Some(cts),
- Some(rts),
+ rxd.map_into(),
+ txd.map_into(),
+ Some(cts.map_into()),
+ Some(rts.map_into()),
config,
)
}
@@ -744,7 +763,7 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
timer.cc(0).short_compare_stop();
let mut ppi_ch1 = Ppi::new_one_to_two(
- unsafe { ppi_ch1.into_inner() }.degrade(),
+ ppi_ch1.map_into(),
Event::from_reg(&r.events_rxdrdy),
timer.task_clear(),
timer.task_start(),
@@ -752,7 +771,7 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
ppi_ch1.enable();
let mut ppi_ch2 = Ppi::new_one_to_one(
- unsafe { ppi_ch2.into_inner() }.degrade(),
+ ppi_ch2.map_into(),
timer.cc(0).event_compare(),
Task::from_reg(&r.tasks_stoprx),
);