aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xci.sh1
-rw-r--r--embassy-nrf/src/gpiote.rs58
-rw-r--r--examples/nrf51/Cargo.toml2
-rw-r--r--tests/nrf51422/Cargo.toml3
-rw-r--r--tests/nrf51422/src/bin/gpiote.rs47
5 files changed, 96 insertions, 15 deletions
diff --git a/ci.sh b/ci.sh
index 6a5e6e3f5..ba250fa67 100755
--- a/ci.sh
+++ b/ci.sh
@@ -47,6 +47,7 @@ cargo batch \
47 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip \ 47 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip \
48 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip,medium-ethernet \ 48 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip,medium-ethernet \
49 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip,medium-ethernet,medium-ieee802154 \ 49 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip,medium-ethernet,medium-ieee802154 \
50 --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,gpiote,time,time-driver-rtc1 \
50 --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time,time-driver-rtc1 \ 51 --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time,time-driver-rtc1 \
51 --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time,time-driver-rtc1 \ 52 --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time,time-driver-rtc1 \
52 --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time,time-driver-rtc1 \ 53 --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time,time-driver-rtc1 \
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index a459446a2..12f4ed0a0 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -13,6 +13,10 @@ use crate::interrupt::InterruptExt;
13use crate::ppi::{Event, Task}; 13use crate::ppi::{Event, Task};
14use crate::{interrupt, pac, peripherals}; 14use crate::{interrupt, pac, peripherals};
15 15
16#[cfg(feature = "nrf51")]
17/// Amount of GPIOTE channels in the chip.
18const CHANNEL_COUNT: usize = 4;
19#[cfg(not(feature = "_nrf51"))]
16/// Amount of GPIOTE channels in the chip. 20/// Amount of GPIOTE channels in the chip.
17const CHANNEL_COUNT: usize = 8; 21const CHANNEL_COUNT: usize = 8;
18 22
@@ -61,16 +65,20 @@ fn regs() -> &'static pac::gpiote::RegisterBlock {
61} 65}
62 66
63pub(crate) fn init(irq_prio: crate::interrupt::Priority) { 67pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
64 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 68 // no latched GPIO detect in nrf51.
65 let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] }; 69 #[cfg(not(feature = "_nrf51"))]
66 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 70 {
67 let ports = unsafe { &[&*pac::P0::ptr()] }; 71 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
68 72 let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] };
69 for &p in ports { 73 #[cfg(not(any(feature = "_nrf51", feature = "nrf52833", feature = "nrf52840")))]
70 // Enable latched detection 74 let ports = unsafe { &[&*pac::P0::ptr()] };
71 p.detectmode.write(|w| w.detectmode().ldetect()); 75
72 // Clear latch 76 for &p in ports {
73 p.latch.write(|w| unsafe { w.bits(0xFFFFFFFF) }) 77 // Enable latched detection
78 p.detectmode.write(|w| w.detectmode().ldetect());
79 // Clear latch
80 p.latch.write(|w| unsafe { w.bits(0xFFFFFFFF) })
81 }
74 } 82 }
75 83
76 // Enable interrupts 84 // Enable interrupts
@@ -78,7 +86,7 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
78 let irq = interrupt::GPIOTE0; 86 let irq = interrupt::GPIOTE0;
79 #[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))] 87 #[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))]
80 let irq = interrupt::GPIOTE1; 88 let irq = interrupt::GPIOTE1;
81 #[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))] 89 #[cfg(any(feature = "_nrf51", feature = "_nrf52", feature = "nrf5340-net"))]
82 let irq = interrupt::GPIOTE; 90 let irq = interrupt::GPIOTE;
83 91
84 irq.unpend(); 92 irq.unpend();
@@ -103,7 +111,7 @@ fn GPIOTE1() {
103 unsafe { handle_gpiote_interrupt() }; 111 unsafe { handle_gpiote_interrupt() };
104} 112}
105 113
106#[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))] 114#[cfg(any(feature = "_nrf51", feature = "_nrf52", feature = "nrf5340-net"))]
107#[cfg(feature = "rt")] 115#[cfg(feature = "rt")]
108#[interrupt] 116#[interrupt]
109fn GPIOTE() { 117fn GPIOTE() {
@@ -125,9 +133,29 @@ unsafe fn handle_gpiote_interrupt() {
125 133
126 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 134 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
127 let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()]; 135 let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()];
128 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 136 #[cfg(not(any(feature = "_nrf51", feature = "nrf52833", feature = "nrf52840")))]
129 let ports = &[&*pac::P0::ptr()]; 137 let ports = &[&*pac::P0::ptr()];
138 #[cfg(feature = "_nrf51")]
139 let ports = unsafe { &[&*pac::GPIO::ptr()] };
140
141 #[cfg(feature = "_nrf51")]
142 for (port, &p) in ports.iter().enumerate() {
143 let inp = p.in_.read().bits();
144 for pin in 0..32 {
145 let fired = match p.pin_cnf[pin as usize].read().sense().variant() {
146 Some(pac::gpio::pin_cnf::SENSE_A::HIGH) => inp & (1 << pin) != 0,
147 Some(pac::gpio::pin_cnf::SENSE_A::LOW) => inp & (1 << pin) == 0,
148 _ => false,
149 };
150
151 if fired {
152 PORT_WAKERS[port * 32 + pin as usize].wake();
153 p.pin_cnf[pin as usize].modify(|_, w| w.sense().disabled());
154 }
155 }
156 }
130 157
158 #[cfg(not(feature = "_nrf51"))]
131 for (port, &p) in ports.iter().enumerate() { 159 for (port, &p) in ports.iter().enumerate() {
132 let bits = p.latch.read().bits(); 160 let bits = p.latch.read().bits();
133 for pin in BitIter(bits) { 161 for pin in BitIter(bits) {
@@ -476,9 +504,13 @@ impl_channel!(GPIOTE_CH0, 0);
476impl_channel!(GPIOTE_CH1, 1); 504impl_channel!(GPIOTE_CH1, 1);
477impl_channel!(GPIOTE_CH2, 2); 505impl_channel!(GPIOTE_CH2, 2);
478impl_channel!(GPIOTE_CH3, 3); 506impl_channel!(GPIOTE_CH3, 3);
507#[cfg(not(feature = "nrf51"))]
479impl_channel!(GPIOTE_CH4, 4); 508impl_channel!(GPIOTE_CH4, 4);
509#[cfg(not(feature = "nrf51"))]
480impl_channel!(GPIOTE_CH5, 5); 510impl_channel!(GPIOTE_CH5, 5);
511#[cfg(not(feature = "nrf51"))]
481impl_channel!(GPIOTE_CH6, 6); 512impl_channel!(GPIOTE_CH6, 6);
513#[cfg(not(feature = "nrf51"))]
482impl_channel!(GPIOTE_CH7, 7); 514impl_channel!(GPIOTE_CH7, 7);
483 515
484// ==================== 516// ====================
diff --git a/examples/nrf51/Cargo.toml b/examples/nrf51/Cargo.toml
index d1e919a33..06c3d20cb 100644
--- a/examples/nrf51/Cargo.toml
+++ b/examples/nrf51/Cargo.toml
@@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
7[dependencies] 7[dependencies]
8embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-4096", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 8embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-4096", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
9embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 9embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
10embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time", "rt"] } 10embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "gpiote", "time-driver-rtc1", "unstable-pac", "time", "rt"] }
11 11
12defmt = "0.3" 12defmt = "0.3"
13defmt-rtt = "0.4" 13defmt-rtt = "0.4"
diff --git a/tests/nrf51422/Cargo.toml b/tests/nrf51422/Cargo.toml
index 2cab20ac0..07236987b 100644
--- a/tests/nrf51422/Cargo.toml
+++ b/tests/nrf51422/Cargo.toml
@@ -7,10 +7,11 @@ license = "MIT OR Apache-2.0"
7[dependencies] 7[dependencies]
8teleprobe-meta = "1" 8teleprobe-meta = "1"
9 9
10embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
10embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] } 11embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] }
11embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-128", "integrated-timers"] } 12embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-128", "integrated-timers"] }
12embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 13embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
13embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time"] } 14embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time", "gpiote"] }
14embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } 15embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
15embedded-hal-async = { version = "1.0" } 16embedded-hal-async = { version = "1.0" }
16 17
diff --git a/tests/nrf51422/src/bin/gpiote.rs b/tests/nrf51422/src/bin/gpiote.rs
new file mode 100644
index 000000000..330fe993e
--- /dev/null
+++ b/tests/nrf51422/src/bin/gpiote.rs
@@ -0,0 +1,47 @@
1#![no_std]
2#![no_main]
3teleprobe_meta::target!(b"nrf51-dk");
4
5use defmt::{assert, info};
6use embassy_executor::Spawner;
7use embassy_futures::join::join;
8use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
9use embassy_time::{Duration, Instant, Timer};
10use {defmt_rtt as _, panic_probe as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let p = embassy_nrf::init(Default::default());
15
16 let mut input = Input::new(p.P0_13, Pull::Up);
17 let mut output = Output::new(p.P0_14, Level::Low, OutputDrive::Standard);
18
19 let fut1 = async {
20 Timer::after_millis(100).await;
21 output.set_high();
22 };
23 let fut2 = async {
24 let start = Instant::now();
25 input.wait_for_high().await;
26 let dur = Instant::now() - start;
27 assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur));
28 };
29
30 join(fut1, fut2).await;
31
32 let fut1 = async {
33 Timer::after_millis(100).await;
34 output.set_low();
35 };
36 let fut2 = async {
37 let start = Instant::now();
38 input.wait_for_low().await;
39 let dur = Instant::now() - start;
40 assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur));
41 };
42
43 join(fut1, fut2).await;
44
45 info!("Test OK");
46 cortex_m::asm::bkpt();
47}