summaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2021-05-12 01:01:08 +0200
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2021-05-17 00:57:20 +0200
commit97b01f1c4799a66bc2af596bfc5138ccf919a6de (patch)
treea2d705f32bf9e5abea5cdb0239ec2b2b31092c4d /embassy-nrf
parent92be72e0e3917782aade44e5b4cdbebb2dbab46e (diff)
downloadembassy-97b01f1c4799a66bc2af596bfc5138ccf919a6de.zip
nrf/gpiote: initialize automatically
Diffstat (limited to 'embassy-nrf')
-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
9 files changed, 15 insertions, 36 deletions
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();
}