2023-06-22 22:37:24 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::*;
|
|
|
|
use embassy_executor::Spawner;
|
2023-07-11 18:41:45 +02:00
|
|
|
use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc};
|
2023-06-22 22:37:24 +02:00
|
|
|
use embassy_time::{Duration, Timer};
|
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
2023-07-12 14:13:19 +02:00
|
|
|
info!("Wait for 20s");
|
2023-06-22 22:37:24 +02:00
|
|
|
|
2023-07-11 18:41:45 +02:00
|
|
|
let mut rtc = Rtc::new(p.RTC);
|
2023-06-22 22:37:24 +02:00
|
|
|
|
2023-07-12 15:16:56 +02:00
|
|
|
if !rtc.is_running() {
|
|
|
|
info!("Start RTC");
|
2023-07-12 14:13:19 +02:00
|
|
|
let now = DateTime {
|
2023-07-12 15:16:56 +02:00
|
|
|
year: 2000,
|
|
|
|
month: 1,
|
|
|
|
day: 1,
|
|
|
|
day_of_week: DayOfWeek::Saturday,
|
|
|
|
hour: 0,
|
|
|
|
minute: 0,
|
|
|
|
second: 0,
|
2023-07-12 14:13:19 +02:00
|
|
|
};
|
|
|
|
rtc.set_datetime(now).unwrap();
|
2023-06-22 22:37:24 +02:00
|
|
|
}
|
2023-07-12 14:13:19 +02:00
|
|
|
|
|
|
|
Timer::after(Duration::from_millis(20000)).await;
|
|
|
|
|
|
|
|
if let Ok(dt) = rtc.now() {
|
|
|
|
info!(
|
|
|
|
"Now: {}-{:02}-{:02} {}:{:02}:{:02}",
|
|
|
|
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("Reboot.");
|
|
|
|
Timer::after(Duration::from_millis(200)).await;
|
|
|
|
cortex_m::peripheral::SCB::sys_reset();
|
2023-06-22 22:37:24 +02:00
|
|
|
}
|