added comment for Pinout

This commit is contained in:
Philipp_EndevourOS
2025-07-28 22:22:07 +02:00
parent 5a2beb1fb3
commit c1b54920ff
3 changed files with 43 additions and 31 deletions

View File

@@ -1 +1,28 @@
pub async fn rtc_config(i2c: I2c<'static, Async>) -> DS3231<I2c<'static, Async>> {
let mut rtc: DS3231<I2c<'static, Async>> = DS3231::new(i2c, RTC_ADDRESS);
let daily_alarm = Alarm1Config::AtTime {
hours: 0, // set alarm every day 00:00:00 to sync time
minutes: 0,
seconds: 0,
is_pm: None, // 24-hour mode
};
if let Err(e) = rtc.set_alarm1(&daily_alarm).await {
error!("Failed to configure RTC: {:?}", e);
panic!();
}
rtc
}
pub async fn read_rtc_time<'a>(rtc: &'a mut DS3231<I2c<'static, Async>>) -> Result<u64, DS3231Error<esp_hal::i2c::master::Error>> {
match rtc.datetime().await {
Ok(datetime) => {
let utc_time = datetime.and_utc().timestamp() as u64;
Ok(utc_time)
}
Err(e) => {
error!("Failed to read RTC datetime: {:?}", e);
Err(e)
}
}
}