nrf/rtc: update to new api

This commit is contained in:
Dario Nieuwenhuis
2021-03-27 03:12:58 +01:00
parent 3eccddc44d
commit 5646926cca
14 changed files with 197 additions and 236 deletions

View File

@ -3,6 +3,7 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;

View File

@ -3,18 +3,20 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use example_common::*;
use core::mem;
use core::task::Poll;
use cortex_m_rt::entry;
use defmt::panic;
use embassy::executor::{task, Executor};
use embassy::time::{Duration, Instant, Timer};
use embassy::util::Forever;
use embassy_nrf::pac;
use embassy_nrf::peripherals;
use embassy_nrf::{interrupt, rtc};
use nrf52840_hal::clocks;
@ -42,17 +44,17 @@ async fn run3() {
.await;
}
static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
let p = unwrap!(embassy_nrf::Peripherals::take());
clocks::Clocks::new(p.CLOCK)
clocks::Clocks::new(unsafe { mem::transmute(()) })
.enable_ext_hfosc()
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
.start_lfclk();

View File

@ -3,6 +3,7 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;

View File

@ -3,6 +3,7 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
@ -32,23 +33,23 @@ async fn button(n: usize, mut pin: PortInput<'static, AnyPin>) {
async fn run() {
let p = Peripherals::take().unwrap();
let g = gpiote::initialize(p.gpiote, interrupt::take!(GPIOTE));
let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
let button1 = button(
1,
PortInput::new(g, Input::new(p.p0_11.degrade(), Pull::Up)),
PortInput::new(g, Input::new(p.P0_11.degrade(), Pull::Up)),
);
let button2 = button(
2,
PortInput::new(g, Input::new(p.p0_12.degrade(), Pull::Up)),
PortInput::new(g, Input::new(p.P0_12.degrade(), Pull::Up)),
);
let button3 = button(
3,
PortInput::new(g, Input::new(p.p0_24.degrade(), Pull::Up)),
PortInput::new(g, Input::new(p.P0_24.degrade(), Pull::Up)),
);
let button4 = button(
4,
PortInput::new(g, Input::new(p.p0_25.degrade(), Pull::Up)),
PortInput::new(g, Input::new(p.P0_25.degrade(), Pull::Up)),
);
futures::join!(button1, button2, button3, button4);
}

View File

@ -58,9 +58,12 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use core::mem;
use example_common::*;
use cortex_m_rt::entry;
@ -71,7 +74,7 @@ use embassy::executor::{task, Executor, InterruptExecutor};
use embassy::interrupt::InterruptExt;
use embassy::time::{Duration, Instant, Timer};
use embassy::util::Forever;
use embassy_nrf::{interrupt, pac, rtc};
use embassy_nrf::{interrupt, peripherals, rtc};
#[task]
async fn run_high() {
@ -115,21 +118,21 @@ async fn run_low() {
}
}
static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
static ALARM_HIGH: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
static ALARM_HIGH: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new();
static ALARM_MED: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static ALARM_MED: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new();
static ALARM_LOW: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static ALARM_LOW: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR_LOW: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
let p = unwrap!(embassy_nrf::Peripherals::take());
clocks::Clocks::new(p.CLOCK)
clocks::Clocks::new(unsafe { mem::transmute(()) })
.enable_ext_hfosc()
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
.start_lfclk();

View File

@ -3,6 +3,7 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
@ -28,12 +29,12 @@ struct AlignedBuf([u8; 4096]);
async fn run() {
let p = Peripherals::take().unwrap();
let csn = p.p0_17;
let sck = p.p0_19;
let io0 = p.p0_20;
let io1 = p.p0_21;
let io2 = p.p0_22;
let io3 = p.p0_23;
let csn = p.P0_17;
let sck = p.P0_19;
let io0 = p.P0_20;
let io1 = p.P0_21;
let io2 = p.P0_22;
let io3 = p.P0_23;
let config = qspi::Config {
read_opcode: qspi::ReadOpcode::READ4IO,
@ -44,7 +45,7 @@ async fn run() {
};
let irq = interrupt::take!(QSPI);
let q = qspi::Qspi::new(p.qspi, irq, sck, csn, io0, io1, io2, io3, config);
let q = qspi::Qspi::new(p.QSPI, irq, sck, csn, io0, io1, io2, io3, config);
pin_mut!(q);
let mut id = [1; 3];

View File

@ -13,7 +13,7 @@ use defmt::panic;
use embassy::executor::Executor;
use embassy::time::{Duration, Timer};
use embassy::util::Forever;
use embassy_nrf::pac;
use embassy_nrf::peripherals;
use embassy_nrf::{interrupt, rtc};
use nrf52840_hal::clocks;
@ -31,17 +31,17 @@ async fn run2() {
}
}
static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
let p = unwrap!(embassy_nrf::Peripherals::take());
clocks::Clocks::new(p.CLOCK)
clocks::Clocks::new(unsafe { mem::transmute(()) })
.enable_ext_hfosc()
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
.start_lfclk();

View File

@ -1,62 +0,0 @@
#![no_std]
#![no_main]
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#[path = "../example_common.rs"]
mod example_common;
use example_common::*;
use core::mem::MaybeUninit;
use cortex_m_rt::entry;
use defmt::panic;
use embassy::time::{Alarm, Clock};
use embassy_nrf::{interrupt, rtc};
use nrf52840_hal::clocks;
static mut RTC: MaybeUninit<rtc::RTC<embassy_nrf::pac::RTC1>> = MaybeUninit::uninit();
#[entry]
fn main() -> ! {
info!("Hello World!");
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
clocks::Clocks::new(p.CLOCK)
.enable_ext_hfosc()
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
.start_lfclk();
let irq = interrupt::take!(RTC1);
let rtc: &'static _ = unsafe {
let ptr = RTC.as_mut_ptr();
ptr.write(rtc::RTC::new(p.RTC1, irq));
&*ptr
};
let alarm = rtc.alarm0();
rtc.start();
alarm.set_callback(|_| info!("ALARM TRIGGERED"), core::ptr::null_mut());
alarm.set(53719);
info!("initialized!");
let mut val = 0;
let mut printval = 0;
loop {
let val2 = rtc.now();
if val2 < val {
info!("timer ran backwards! {} -> {}", val as u32, val2 as u32);
}
val = val2;
if val > printval + 32768 {
info!("tick {}", val as u32);
printval = val;
}
}
}

View File

@ -3,17 +3,21 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use core::mem;
use cortex_m_rt::entry;
use defmt::panic;
use embassy::executor::{task, Executor};
use embassy::util::Forever;
use embassy::util::Steal;
use embassy_nrf::gpio::{Level, Output, OutputDrive};
use embassy_nrf::Peripherals;
use embassy_nrf::{interrupt, pac, rtc, spim};
use embassy_nrf::{interrupt, rtc, spim};
use embassy_nrf::{peripherals, Peripherals};
use embassy_traits::spi::FullDuplex;
use embedded_hal::digital::v2::*;
use example_common::*;
@ -24,7 +28,7 @@ use nrf52840_hal::clocks;
async fn run() {
info!("running!");
let p = Peripherals::take().unwrap();
let p = unsafe { Peripherals::steal() };
let config = spim::Config {
frequency: spim::Frequency::M16,
@ -33,10 +37,10 @@ async fn run() {
};
let irq = interrupt::take!(SPIM3);
let spim = spim::Spim::new(p.spim3, irq, p.p0_29, p.p0_28, p.p0_30, config);
let spim = spim::Spim::new(p.SPIM3, irq, p.P0_29, p.P0_28, p.P0_30, config);
pin_mut!(spim);
let mut ncs = Output::new(p.p0_31, Level::High, OutputDrive::Standard);
let mut ncs = Output::new(p.P0_31, Level::High, OutputDrive::Standard);
// Example on how to talk to an ENC28J60 chip
@ -84,17 +88,17 @@ async fn run() {
info!("erevid: {=[?]}", rx);
}
static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
let p = unwrap!(embassy_nrf::Peripherals::take());
clocks::Clocks::new(p.CLOCK)
clocks::Clocks::new(unsafe { mem::transmute(()) })
.enable_ext_hfosc()
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
.start_lfclk();

View File

@ -3,9 +3,12 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use core::mem;
use example_common::*;
use cortex_m_rt::entry;
@ -13,7 +16,7 @@ use defmt::panic;
use embassy::executor::{task, Executor};
use embassy::time::{Duration, Timer};
use embassy::util::Forever;
use embassy_nrf::pac;
use embassy_nrf::peripherals;
use embassy_nrf::{interrupt, rtc};
use nrf52840_hal::clocks;
@ -33,21 +36,21 @@ async fn run2() {
}
}
static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
clocks::Clocks::new(p.CLOCK)
clocks::Clocks::new(unsafe { mem::transmute(()) })
.enable_ext_hfosc()
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
.start_lfclk();
let p = unwrap!(embassy_nrf::Peripherals::take());
let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
rtc.start();

View File

@ -3,34 +3,34 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use core::mem;
use embassy_nrf::gpio::NoPin;
use example_common::*;
use cortex_m_rt::entry;
use defmt::panic;
use embassy::executor::{task, Executor};
use embassy::time::{Duration, Timer};
use embassy::traits::uart::{Read, Write};
use embassy::util::Forever;
use embassy_nrf::{interrupt, pac, rtc, uarte, Peripherals};
use futures::future::{select, Either};
use embassy::util::{Forever, Steal};
use embassy_nrf::{interrupt, peripherals, rtc, uarte, Peripherals};
use futures::pin_mut;
use nrf52840_hal::clocks;
use nrf52840_hal::gpio;
#[task]
async fn run() {
let p = Peripherals::take().unwrap();
let p = unsafe { Peripherals::steal() };
let mut config = uarte::Config::default();
config.parity = uarte::Parity::EXCLUDED;
config.baudrate = uarte::Baudrate::BAUD115200;
let irq = interrupt::take!(UARTE0_UART0);
let uart = unsafe { uarte::Uarte::new(p.uarte0, irq, p.p0_08, p.p0_06, NoPin, NoPin, config) };
let uart = unsafe { uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, NoPin, NoPin, config) };
pin_mut!(uart);
info!("uarte initialized!");
@ -78,17 +78,17 @@ async fn run() {
}
}
static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
let p = unwrap!(embassy_nrf::Peripherals::take());
clocks::Clocks::new(p.CLOCK)
clocks::Clocks::new(unsafe { mem::transmute(()) })
.enable_ext_hfosc()
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
.start_lfclk();