summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf-examples/src/bin/gpiote_channel.rs5
-rw-r--r--embassy-nrf-examples/src/bin/gpiote_port.rs13
-rw-r--r--embassy-nrf-examples/src/bin/ppi.rs7
-rw-r--r--embassy-nrf/src/chips/nrf52805.rs1
-rw-r--r--embassy-nrf/src/chips/nrf52810.rs1
-rw-r--r--embassy-nrf/src/chips/nrf52811.rs1
-rw-r--r--embassy-nrf/src/chips/nrf52820.rs1
-rw-r--r--embassy-nrf/src/chips/nrf52832.rs1
-rw-r--r--embassy-nrf/src/chips/nrf52833.rs1
-rw-r--r--embassy-nrf/src/chips/nrf52840.rs1
-rw-r--r--embassy-nrf/src/gpiote.rs41
-rw-r--r--embassy-nrf/src/system.rs3
12 files changed, 21 insertions, 55 deletions
diff --git a/embassy-nrf-examples/src/bin/gpiote_channel.rs b/embassy-nrf-examples/src/bin/gpiote_channel.rs
index 9e653192..ee670acd 100644
--- a/embassy-nrf-examples/src/bin/gpiote_channel.rs
+++ b/embassy-nrf-examples/src/bin/gpiote_channel.rs
@@ -18,30 +18,25 @@ use embassy_nrf::{interrupt, Peripherals};
#[embassy::main]
async fn main(spawner: Spawner) {
let p = Peripherals::take().unwrap();
- let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
info!("Starting!");
let ch1 = InputChannel::new(
- g,
p.GPIOTE_CH0,
Input::new(p.P0_11, Pull::Up),
InputChannelPolarity::HiToLo,
);
let ch2 = InputChannel::new(
- g,
p.GPIOTE_CH1,
Input::new(p.P0_12, Pull::Up),
InputChannelPolarity::LoToHi,
);
let ch3 = InputChannel::new(
- g,
p.GPIOTE_CH2,
Input::new(p.P0_24, Pull::Up),
InputChannelPolarity::Toggle,
);
let ch4 = InputChannel::new(
- g,
p.GPIOTE_CH3,
Input::new(p.P0_25, Pull::Up),
InputChannelPolarity::Toggle,
diff --git a/embassy-nrf-examples/src/bin/gpiote_port.rs b/embassy-nrf-examples/src/bin/gpiote_port.rs
index 386806df..717d3398 100644
--- a/embassy-nrf-examples/src/bin/gpiote_port.rs
+++ b/embassy-nrf-examples/src/bin/gpiote_port.rs
@@ -8,12 +8,11 @@
#[path = "../example_common.rs"]
mod example_common;
-use core::pin::Pin;
use defmt::panic;
use embassy::executor::Spawner;
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
-use embassy_nrf::gpiote::{self, PortInput};
+use embassy_nrf::gpiote::PortInput;
use embassy_nrf::interrupt;
use embassy_nrf::Peripherals;
use example_common::*;
@@ -32,12 +31,12 @@ async fn button_task(n: usize, mut pin: PortInput<'static, AnyPin>) {
async fn main(spawner: Spawner) {
let p = Peripherals::take().unwrap();
- let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
+ info!("Starting!");
- let btn1 = PortInput::new(g, Input::new(p.P0_11.degrade(), Pull::Up));
- let btn2 = PortInput::new(g, Input::new(p.P0_12.degrade(), Pull::Up));
- let btn3 = PortInput::new(g, Input::new(p.P0_24.degrade(), Pull::Up));
- let btn4 = PortInput::new(g, Input::new(p.P0_25.degrade(), Pull::Up));
+ let btn1 = PortInput::new(Input::new(p.P0_11.degrade(), Pull::Up));
+ let btn2 = PortInput::new(Input::new(p.P0_12.degrade(), Pull::Up));
+ let btn3 = PortInput::new(Input::new(p.P0_24.degrade(), Pull::Up));
+ let btn4 = PortInput::new(Input::new(p.P0_25.degrade(), Pull::Up));
spawner.spawn(button_task(1, btn1)).unwrap();
spawner.spawn(button_task(2, btn2)).unwrap();
diff --git a/embassy-nrf-examples/src/bin/ppi.rs b/embassy-nrf-examples/src/bin/ppi.rs
index aeda76f2..3c39e032 100644
--- a/embassy-nrf-examples/src/bin/ppi.rs
+++ b/embassy-nrf-examples/src/bin/ppi.rs
@@ -21,44 +21,37 @@ use gpiote::{OutputChannel, OutputChannelPolarity};
#[embassy::main]
async fn main(spawner: Spawner) {
let p = Peripherals::take().unwrap();
- let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
info!("Starting!");
let button1 = InputChannel::new(
- g,
p.GPIOTE_CH0,
Input::new(p.P0_11, Pull::Up),
InputChannelPolarity::HiToLo,
);
let button2 = InputChannel::new(
- g,
p.GPIOTE_CH1,
Input::new(p.P0_12, Pull::Up),
InputChannelPolarity::HiToLo,
);
let button3 = InputChannel::new(
- g,
p.GPIOTE_CH2,
Input::new(p.P0_24, Pull::Up),
InputChannelPolarity::HiToLo,
);
let button4 = InputChannel::new(
- g,
p.GPIOTE_CH3,
Input::new(p.P0_25, Pull::Up),
InputChannelPolarity::HiToLo,
);
let led1 = OutputChannel::new(
- g,
p.GPIOTE_CH4,
Output::new(p.P0_13, Level::Low, OutputDrive::Standard),
OutputChannelPolarity::Toggle,
);
let led2 = OutputChannel::new(
- g,
p.GPIOTE_CH5,
Output::new(p.P0_14, Level::Low, OutputDrive::Standard),
OutputChannelPolarity::Toggle,
diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs
index 8b2ba7c0..272cabc0 100644
--- a/embassy-nrf/src/chips/nrf52805.rs
+++ b/embassy-nrf/src/chips/nrf52805.rs
@@ -24,7 +24,6 @@ embassy_extras::peripherals! {
TIMER2,
// GPIOTE
- GPIOTE,
GPIOTE_CH0,
GPIOTE_CH1,
GPIOTE_CH2,
diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs
index 9f3ed9cf..2e77a2fa 100644
--- a/embassy-nrf/src/chips/nrf52810.rs
+++ b/embassy-nrf/src/chips/nrf52810.rs
@@ -24,7 +24,6 @@ embassy_extras::peripherals! {
TIMER2,
// GPIOTE
- GPIOTE,
GPIOTE_CH0,
GPIOTE_CH1,
GPIOTE_CH2,
diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs
index 6728f6a4..b3ad5817 100644
--- a/embassy-nrf/src/chips/nrf52811.rs
+++ b/embassy-nrf/src/chips/nrf52811.rs
@@ -24,7 +24,6 @@ embassy_extras::peripherals! {
TIMER2,
// GPIOTE
- GPIOTE,
GPIOTE_CH0,
GPIOTE_CH1,
GPIOTE_CH2,
diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs
index 2f9eb5f5..d0a8b9e9 100644
--- a/embassy-nrf/src/chips/nrf52820.rs
+++ b/embassy-nrf/src/chips/nrf52820.rs
@@ -25,7 +25,6 @@ embassy_extras::peripherals! {
TIMER3,
// GPIOTE
- GPIOTE,
GPIOTE_CH0,
GPIOTE_CH1,
GPIOTE_CH2,
diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs
index 015bc51f..ed94430e 100644
--- a/embassy-nrf/src/chips/nrf52832.rs
+++ b/embassy-nrf/src/chips/nrf52832.rs
@@ -29,7 +29,6 @@ embassy_extras::peripherals! {
TIMER4,
// GPIOTE
- GPIOTE,
GPIOTE_CH0,
GPIOTE_CH1,
GPIOTE_CH2,
diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs
index 40488393..080157d6 100644
--- a/embassy-nrf/src/chips/nrf52833.rs
+++ b/embassy-nrf/src/chips/nrf52833.rs
@@ -30,7 +30,6 @@ embassy_extras::peripherals! {
TIMER4,
// GPIOTE
- GPIOTE,
GPIOTE_CH0,
GPIOTE_CH1,
GPIOTE_CH2,
diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs
index 26dfc7e8..06b508d8 100644
--- a/embassy-nrf/src/chips/nrf52840.rs
+++ b/embassy-nrf/src/chips/nrf52840.rs
@@ -33,7 +33,6 @@ embassy_extras::peripherals! {
TIMER4,
// GPIOTE
- GPIOTE,
GPIOTE_CH0,
GPIOTE_CH1,
GPIOTE_CH2,
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index bfa5ba68..f322c169 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -2,7 +2,7 @@ use core::convert::Infallible;
use core::future::Future;
use core::marker::PhantomData;
use core::task::{Context, Poll};
-use embassy::interrupt::InterruptExt;
+use embassy::interrupt::{Interrupt, InterruptExt};
use embassy::traits::gpio::{WaitForAnyEdge, WaitForHigh, WaitForLow};
use embassy::util::AtomicWaker;
use embassy_extras::impl_unborrow;
@@ -40,15 +40,7 @@ pub enum OutputChannelPolarity {
Toggle,
}
-/// Token indicating GPIOTE has been correctly initialized.
-///
-/// This is not an owned singleton, it is Copy. Drivers that make use of GPIOTE require it.
-#[derive(Clone, Copy)]
-pub struct Initialized {
- _private: (),
-}
-
-pub fn initialize(_gpiote: peripherals::GPIOTE, irq: interrupt::GPIOTE) -> Initialized {
+pub(crate) fn init() {
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] };
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
@@ -62,17 +54,18 @@ pub fn initialize(_gpiote: peripherals::GPIOTE, irq: interrupt::GPIOTE) -> Initi
}
// Enable interrupts
- let g = unsafe { &*pac::GPIOTE::ptr() };
- g.events_port.write(|w| w);
- g.intenset.write(|w| w.port().set());
- irq.set_handler(on_irq);
+
+ let irq = unsafe { interrupt::GPIOTE::steal() };
irq.unpend();
irq.enable();
- Initialized { _private: () }
+ let g = unsafe { &*pac::GPIOTE::ptr() };
+ g.events_port.write(|w| w);
+ g.intenset.write(|w| w.port().set());
}
-unsafe fn on_irq(_ctx: *mut ()) {
+#[interrupt]
+unsafe fn GPIOTE() {
let g = &*pac::GPIOTE::ptr();
for i in 0..CHANNEL_COUNT {
@@ -133,12 +126,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
}
impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
- pub fn new(
- _init: Initialized,
- ch: C,
- pin: Input<'d, T>,
- polarity: InputChannelPolarity,
- ) -> Self {
+ pub fn new(ch: C, pin: Input<'d, T>, polarity: InputChannelPolarity) -> Self {
let g = unsafe { &*pac::GPIOTE::ptr() };
let num = ch.number();
@@ -217,12 +205,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
}
impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
- pub fn new(
- _init: Initialized,
- ch: C,
- pin: Output<'d, T>,
- polarity: OutputChannelPolarity,
- ) -> Self {
+ pub fn new(ch: C, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
let g = unsafe { &*pac::GPIOTE::ptr() };
let num = ch.number();
@@ -297,7 +280,7 @@ pub struct PortInput<'d, T: GpioPin> {
impl<'d, T: GpioPin> Unpin for PortInput<'d, T> {}
impl<'d, T: GpioPin> PortInput<'d, T> {
- pub fn new(_init: Initialized, pin: Input<'d, T>) -> Self {
+ pub fn new(pin: Input<'d, T>) -> Self {
Self { pin }
}
}
diff --git a/embassy-nrf/src/system.rs b/embassy-nrf/src/system.rs
index 5d36e66f..e358d2c3 100644
--- a/embassy-nrf/src/system.rs
+++ b/embassy-nrf/src/system.rs
@@ -73,4 +73,7 @@ pub unsafe fn configure(config: Config) {
r.events_lfclkstarted.write(|w| unsafe { w.bits(0) });
r.tasks_lfclkstart.write(|w| unsafe { w.bits(1) });
while r.events_lfclkstarted.read().bits() == 0 {}
+
+ // Init GPIOTE
+ crate::gpiote::init();
}