worted on rtc task, still not tested

This commit is contained in:
Philipp_EndevourOS
2025-07-28 17:53:26 +02:00
parent 49027fed99
commit d5c20bf348
2 changed files with 26 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
use core::slice::RChunks;
use ds3231::{DS3231, Alarm1Config};
use ds3231::{Alarm1Config, DS3231Error, DS3231};
use embassy_executor::Spawner;
use embassy_net::{driver, Stack};
use embassy_sync::mutex::Mutex;
@@ -105,16 +105,16 @@ fn setup_i2c(
}
pub async fn rtc_init_iterrupt(sqw_pin: GPIO21<'static>) -> Input<'static> {
let config = esp_hal::gpio::InputConfig::default().with_pull(Pull::Up);
let mut sqw_interrupt = Input::new(sqw_pin, config);
let config = esp_hal::gpio::InputConfig::default().with_pull(Pull::Up); //Active low interrupt in rtc
let sqw_interrupt = Input::new(sqw_pin, config);
sqw_interrupt
}
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: 9,
minutes: 30,
hours: 0, // set alarm every day 00:00:00 to sync time
minutes: 0,
seconds: 0,
is_pm: None, // 24-hour mode
};
@@ -125,6 +125,19 @@ pub async fn rtc_config(i2c: I2c<'static, Async>) -> DS3231<I2c<'static, Async>>
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)
}
}
}
fn setup_spi_led() {