2020-09-24 17:59:20 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
2021-03-17 01:48:16 +00:00
|
|
|
#![feature(min_type_alias_impl_trait)]
|
|
|
|
#![feature(impl_trait_in_bindings)]
|
2020-09-24 17:59:20 +00:00
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
use example_common::*;
|
|
|
|
|
|
|
|
use core::mem::MaybeUninit;
|
|
|
|
use cortex_m_rt::entry;
|
2020-12-29 00:05:28 +00:00
|
|
|
use defmt::panic;
|
2020-09-25 21:38:42 +00:00
|
|
|
use embassy::time::{Alarm, Clock};
|
2020-12-29 00:05:28 +00:00
|
|
|
use embassy_nrf::{interrupt, rtc};
|
2020-09-24 17:59:20 +00:00
|
|
|
use nrf52840_hal::clocks;
|
|
|
|
|
|
|
|
static mut RTC: MaybeUninit<rtc::RTC<embassy_nrf::pac::RTC1>> = MaybeUninit::uninit();
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
2020-11-01 16:17:24 +00:00
|
|
|
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
|
2020-09-24 17:59:20 +00:00
|
|
|
|
|
|
|
clocks::Clocks::new(p.CLOCK)
|
|
|
|
.enable_ext_hfosc()
|
|
|
|
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
|
|
|
|
.start_lfclk();
|
|
|
|
|
2020-12-29 00:05:28 +00:00
|
|
|
let irq = interrupt::take!(RTC1);
|
|
|
|
|
2020-09-24 17:59:20 +00:00
|
|
|
let rtc: &'static _ = unsafe {
|
|
|
|
let ptr = RTC.as_mut_ptr();
|
2020-12-29 00:05:28 +00:00
|
|
|
ptr.write(rtc::RTC::new(p.RTC1, irq));
|
2020-09-24 17:59:20 +00:00
|
|
|
&*ptr
|
|
|
|
};
|
|
|
|
|
2020-09-25 01:25:06 +00:00
|
|
|
let alarm = rtc.alarm0();
|
|
|
|
|
2020-09-24 17:59:20 +00:00
|
|
|
rtc.start();
|
2020-09-25 01:25:06 +00:00
|
|
|
|
2021-02-02 04:14:52 +00:00
|
|
|
alarm.set_callback(|_| info!("ALARM TRIGGERED"), core::ptr::null_mut());
|
2020-09-25 21:25:49 +00:00
|
|
|
alarm.set(53719);
|
2020-09-24 17:59:20 +00:00
|
|
|
|
|
|
|
info!("initialized!");
|
|
|
|
|
|
|
|
let mut val = 0;
|
|
|
|
let mut printval = 0;
|
|
|
|
loop {
|
|
|
|
let val2 = rtc.now();
|
|
|
|
if val2 < val {
|
2021-02-24 07:57:06 +00:00
|
|
|
info!("timer ran backwards! {} -> {}", val as u32, val2 as u32);
|
2020-09-24 17:59:20 +00:00
|
|
|
}
|
|
|
|
val = val2;
|
|
|
|
|
|
|
|
if val > printval + 32768 {
|
2021-02-24 07:57:06 +00:00
|
|
|
info!("tick {}", val as u32);
|
2020-09-24 17:59:20 +00:00
|
|
|
printval = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|