Merge branch 'main' of https://github.com/aidant/embassy into rtc

This commit is contained in:
xoviat 2023-08-27 15:23:25 -05:00
commit f77a7fe4bf
2 changed files with 15 additions and 6 deletions

View File

@ -89,7 +89,7 @@ pub enum DayOfWeek {
#[cfg(feature = "chrono")] #[cfg(feature = "chrono")]
impl From<chrono::Weekday> for DayOfWeek { impl From<chrono::Weekday> for DayOfWeek {
fn from(weekday: Weekday) -> Self { fn from(weekday: Weekday) -> Self {
day_of_week_from_u8(weekday.number_from_monday() as u8).unwrap() day_of_week_from_u8(weekday.num_days_from_monday() as u8).unwrap()
} }
} }

View File

@ -5,13 +5,19 @@
use chrono::{NaiveDate, NaiveDateTime}; use chrono::{NaiveDate, NaiveDateTime};
use defmt::*; use defmt::*;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::rtc::{Rtc, RtcConfig}; use embassy_stm32::{
rtc::{Rtc, RtcClockSource, RtcConfig},
Config,
};
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default()); let mut config = Config::default();
config.rcc.rtc = Option::Some(RtcClockSource::LSI);
let p = embassy_stm32::init(config);
info!("Hello World!"); info!("Hello World!");
let now = NaiveDate::from_ymd_opt(2020, 5, 15) let now = NaiveDate::from_ymd_opt(2020, 5, 15)
@ -23,8 +29,11 @@ async fn main(_spawner: Spawner) {
rtc.set_datetime(now.into()).expect("datetime not set"); rtc.set_datetime(now.into()).expect("datetime not set");
// In reality the delay would be much longer loop {
Timer::after(Duration::from_millis(20000)).await; let now: NaiveDateTime = rtc.now().unwrap().into();
let _then: NaiveDateTime = rtc.now().unwrap().into(); info!("{}", now.timestamp());
Timer::after(Duration::from_millis(1000)).await;
}
} }