RP: Add RTC example to rp2040.
This commit is contained in:
parent
d8c7c3fc4b
commit
55a5e9b3a5
33
examples/rp/src/bin/rtc.rs
Normal file
33
examples/rp/src/bin/rtc.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
use defmt::*;
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_rp::rtc::{DateTime, DayOfWeek, RealTimeClock};
|
||||||
|
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());
|
||||||
|
info!("Hello World!");
|
||||||
|
|
||||||
|
let now = DateTime {
|
||||||
|
year: 2020,
|
||||||
|
month: 5,
|
||||||
|
day: 15,
|
||||||
|
day_of_week: DayOfWeek::Monday,
|
||||||
|
hour: 10,
|
||||||
|
minute: 30,
|
||||||
|
second: 50,
|
||||||
|
};
|
||||||
|
|
||||||
|
let rtc_result = RealTimeClock::new(p.RTC, now);
|
||||||
|
if let Ok(rtc) = rtc_result {
|
||||||
|
// In reality the delay would be much longer
|
||||||
|
Timer::after(Duration::from_millis(20000)).await;
|
||||||
|
|
||||||
|
let _then: DateTime = rtc.now().unwrap();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user