Merge pull request #2532 from embassy-rs/nrf51-gpiote
nrf/gpiote: add support for nrf51.
This commit is contained in:
commit
e782c8f463
5 changed files with 95 additions and 14 deletions
1
ci.sh
1
ci.sh
|
@ -47,6 +47,7 @@ cargo batch \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ip \
|
||||||
--- 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 \
|
--- 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 \
|
||||||
--- 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 \
|
--- 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 \
|
||||||
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv6m-none-eabi --features nrf51,gpiote,time,time-driver-rtc1 \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time,time-driver-rtc1 \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time,time-driver-rtc1 \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time,time-driver-rtc1 \
|
||||||
|
|
|
@ -13,6 +13,10 @@ use crate::interrupt::InterruptExt;
|
||||||
use crate::ppi::{Event, Task};
|
use crate::ppi::{Event, Task};
|
||||||
use crate::{interrupt, pac, peripherals};
|
use crate::{interrupt, pac, peripherals};
|
||||||
|
|
||||||
|
#[cfg(feature = "nrf51")]
|
||||||
|
/// Amount of GPIOTE channels in the chip.
|
||||||
|
const CHANNEL_COUNT: usize = 4;
|
||||||
|
#[cfg(not(feature = "_nrf51"))]
|
||||||
/// Amount of GPIOTE channels in the chip.
|
/// Amount of GPIOTE channels in the chip.
|
||||||
const CHANNEL_COUNT: usize = 8;
|
const CHANNEL_COUNT: usize = 8;
|
||||||
|
|
||||||
|
@ -61,9 +65,12 @@ fn regs() -> &'static pac::gpiote::RegisterBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
|
pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
|
||||||
|
// no latched GPIO detect in nrf51.
|
||||||
|
#[cfg(not(feature = "_nrf51"))]
|
||||||
|
{
|
||||||
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
|
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
|
||||||
let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] };
|
let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] };
|
||||||
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
|
#[cfg(not(any(feature = "_nrf51", feature = "nrf52833", feature = "nrf52840")))]
|
||||||
let ports = unsafe { &[&*pac::P0::ptr()] };
|
let ports = unsafe { &[&*pac::P0::ptr()] };
|
||||||
|
|
||||||
for &p in ports {
|
for &p in ports {
|
||||||
|
@ -72,13 +79,14 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
|
||||||
// Clear latch
|
// Clear latch
|
||||||
p.latch.write(|w| unsafe { w.bits(0xFFFFFFFF) })
|
p.latch.write(|w| unsafe { w.bits(0xFFFFFFFF) })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Enable interrupts
|
// Enable interrupts
|
||||||
#[cfg(any(feature = "nrf5340-app-s", feature = "nrf9160-s"))]
|
#[cfg(any(feature = "nrf5340-app-s", feature = "nrf9160-s"))]
|
||||||
let irq = interrupt::GPIOTE0;
|
let irq = interrupt::GPIOTE0;
|
||||||
#[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))]
|
#[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))]
|
||||||
let irq = interrupt::GPIOTE1;
|
let irq = interrupt::GPIOTE1;
|
||||||
#[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))]
|
#[cfg(any(feature = "_nrf51", feature = "_nrf52", feature = "nrf5340-net"))]
|
||||||
let irq = interrupt::GPIOTE;
|
let irq = interrupt::GPIOTE;
|
||||||
|
|
||||||
irq.unpend();
|
irq.unpend();
|
||||||
|
@ -103,7 +111,7 @@ fn GPIOTE1() {
|
||||||
unsafe { handle_gpiote_interrupt() };
|
unsafe { handle_gpiote_interrupt() };
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))]
|
#[cfg(any(feature = "_nrf51", feature = "_nrf52", feature = "nrf5340-net"))]
|
||||||
#[cfg(feature = "rt")]
|
#[cfg(feature = "rt")]
|
||||||
#[interrupt]
|
#[interrupt]
|
||||||
fn GPIOTE() {
|
fn GPIOTE() {
|
||||||
|
@ -125,9 +133,29 @@ unsafe fn handle_gpiote_interrupt() {
|
||||||
|
|
||||||
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
|
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
|
||||||
let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()];
|
let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()];
|
||||||
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
|
#[cfg(not(any(feature = "_nrf51", feature = "nrf52833", feature = "nrf52840")))]
|
||||||
let ports = &[&*pac::P0::ptr()];
|
let ports = &[&*pac::P0::ptr()];
|
||||||
|
#[cfg(feature = "_nrf51")]
|
||||||
|
let ports = unsafe { &[&*pac::GPIO::ptr()] };
|
||||||
|
|
||||||
|
#[cfg(feature = "_nrf51")]
|
||||||
|
for (port, &p) in ports.iter().enumerate() {
|
||||||
|
let inp = p.in_.read().bits();
|
||||||
|
for pin in 0..32 {
|
||||||
|
let fired = match p.pin_cnf[pin as usize].read().sense().variant() {
|
||||||
|
Some(pac::gpio::pin_cnf::SENSE_A::HIGH) => inp & (1 << pin) != 0,
|
||||||
|
Some(pac::gpio::pin_cnf::SENSE_A::LOW) => inp & (1 << pin) == 0,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if fired {
|
||||||
|
PORT_WAKERS[port * 32 + pin as usize].wake();
|
||||||
|
p.pin_cnf[pin as usize].modify(|_, w| w.sense().disabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "_nrf51"))]
|
||||||
for (port, &p) in ports.iter().enumerate() {
|
for (port, &p) in ports.iter().enumerate() {
|
||||||
let bits = p.latch.read().bits();
|
let bits = p.latch.read().bits();
|
||||||
for pin in BitIter(bits) {
|
for pin in BitIter(bits) {
|
||||||
|
@ -476,9 +504,13 @@ impl_channel!(GPIOTE_CH0, 0);
|
||||||
impl_channel!(GPIOTE_CH1, 1);
|
impl_channel!(GPIOTE_CH1, 1);
|
||||||
impl_channel!(GPIOTE_CH2, 2);
|
impl_channel!(GPIOTE_CH2, 2);
|
||||||
impl_channel!(GPIOTE_CH3, 3);
|
impl_channel!(GPIOTE_CH3, 3);
|
||||||
|
#[cfg(not(feature = "nrf51"))]
|
||||||
impl_channel!(GPIOTE_CH4, 4);
|
impl_channel!(GPIOTE_CH4, 4);
|
||||||
|
#[cfg(not(feature = "nrf51"))]
|
||||||
impl_channel!(GPIOTE_CH5, 5);
|
impl_channel!(GPIOTE_CH5, 5);
|
||||||
|
#[cfg(not(feature = "nrf51"))]
|
||||||
impl_channel!(GPIOTE_CH6, 6);
|
impl_channel!(GPIOTE_CH6, 6);
|
||||||
|
#[cfg(not(feature = "nrf51"))]
|
||||||
impl_channel!(GPIOTE_CH7, 7);
|
impl_channel!(GPIOTE_CH7, 7);
|
||||||
|
|
||||||
// ====================
|
// ====================
|
||||||
|
|
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-4096", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-4096", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||||
embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time", "rt"] }
|
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "gpiote", "time-driver-rtc1", "unstable-pac", "time", "rt"] }
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.4"
|
defmt-rtt = "0.4"
|
||||||
|
|
|
@ -7,10 +7,11 @@ license = "MIT OR Apache-2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
teleprobe-meta = "1"
|
teleprobe-meta = "1"
|
||||||
|
|
||||||
|
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||||
embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] }
|
embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] }
|
||||||
embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-128", "integrated-timers"] }
|
embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-128", "integrated-timers"] }
|
||||||
embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time"] }
|
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time", "gpiote"] }
|
||||||
embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
|
embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
|
||||||
embedded-hal-async = { version = "1.0" }
|
embedded-hal-async = { version = "1.0" }
|
||||||
|
|
||||||
|
|
47
tests/nrf51422/src/bin/gpiote.rs
Normal file
47
tests/nrf51422/src/bin/gpiote.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
teleprobe_meta::target!(b"nrf51-dk");
|
||||||
|
|
||||||
|
use defmt::{assert, info};
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_futures::join::join;
|
||||||
|
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
|
||||||
|
use embassy_time::{Duration, Instant, Timer};
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) {
|
||||||
|
let p = embassy_nrf::init(Default::default());
|
||||||
|
|
||||||
|
let mut input = Input::new(p.P0_13, Pull::Up);
|
||||||
|
let mut output = Output::new(p.P0_14, Level::Low, OutputDrive::Standard);
|
||||||
|
|
||||||
|
let fut1 = async {
|
||||||
|
Timer::after_millis(100).await;
|
||||||
|
output.set_high();
|
||||||
|
};
|
||||||
|
let fut2 = async {
|
||||||
|
let start = Instant::now();
|
||||||
|
input.wait_for_high().await;
|
||||||
|
let dur = Instant::now() - start;
|
||||||
|
assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur));
|
||||||
|
};
|
||||||
|
|
||||||
|
join(fut1, fut2).await;
|
||||||
|
|
||||||
|
let fut1 = async {
|
||||||
|
Timer::after_millis(100).await;
|
||||||
|
output.set_low();
|
||||||
|
};
|
||||||
|
let fut2 = async {
|
||||||
|
let start = Instant::now();
|
||||||
|
input.wait_for_low().await;
|
||||||
|
let dur = Instant::now() - start;
|
||||||
|
assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur));
|
||||||
|
};
|
||||||
|
|
||||||
|
join(fut1, fut2).await;
|
||||||
|
|
||||||
|
info!("Test OK");
|
||||||
|
cortex_m::asm::bkpt();
|
||||||
|
}
|
Loading…
Reference in a new issue