mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-08-02 06:44:17 +00:00
added comment for Pinout
This commit is contained in:
parent
5a2beb1fb3
commit
c1b54920ff
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,19 @@ use log::error;
|
|||||||
use crate::init::wifi;
|
use crate::init::wifi;
|
||||||
use crate::init::network;
|
use crate::init::network;
|
||||||
|
|
||||||
|
/*************************************************
|
||||||
|
* GPIO Pinout Xiao Esp32c6
|
||||||
|
*
|
||||||
|
* D0 -> Level Shifter OE
|
||||||
|
* D1 -> Level Shifter A0 -> LED
|
||||||
|
* D3 -> SQW Interrupt RTC
|
||||||
|
* D4 -> SDA
|
||||||
|
* D5 -> SCL
|
||||||
|
* D7 -> Level Shifter A1 -> NFC Reader
|
||||||
|
* D8 -> Buzzer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
const RTC_ADDRESS: u8 = 0x57;
|
const RTC_ADDRESS: u8 = 0x57;
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
@ -110,34 +123,6 @@ pub async fn rtc_init_iterrupt(sqw_pin: GPIO21<'static>) -> Input<'static> {
|
|||||||
sqw_interrupt
|
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: 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn setup_spi_led() {
|
fn setup_spi_led() {
|
||||||
|
|
||||||
|
@ -74,17 +74,17 @@ async fn rtc_task(
|
|||||||
sqw_pin: peripherals::GPIO21<'static>,
|
sqw_pin: peripherals::GPIO21<'static>,
|
||||||
) {
|
) {
|
||||||
let mut rtc_interrupt = init::hardware::rtc_init_iterrupt(sqw_pin).await;
|
let mut rtc_interrupt = init::hardware::rtc_init_iterrupt(sqw_pin).await;
|
||||||
let mut rtc = init::hardware::rtc_config(i2c).await;
|
let mut rtc = drivers::rtc::rtc_config(i2c).await;
|
||||||
|
|
||||||
let mut utc_time = UTC_TIME.lock().await;
|
let mut utc_time = UTC_TIME.lock().await;
|
||||||
let timestamp_result = init::hardware::read_rtc_time(&mut rtc).await;
|
let timestamp_result = drivers::rtc::read_rtc_time(&mut rtc).await;
|
||||||
*utc_time = timestamp_result.unwrap_or(0);
|
*utc_time = timestamp_result.unwrap_or(0);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
rtc_interrupt.wait_for_falling_edge().await;
|
rtc_interrupt.wait_for_falling_edge().await;
|
||||||
debug!("RTC interrupt triggered");
|
debug!("RTC interrupt triggered");
|
||||||
utc_time = UTC_TIME.lock().await;
|
utc_time = UTC_TIME.lock().await;
|
||||||
let timestamp_result = init::hardware::read_rtc_time(&mut rtc).await;
|
let timestamp_result = drivers::rtc::read_rtc_time(&mut rtc).await;
|
||||||
*utc_time = timestamp_result.unwrap_or(0);
|
*utc_time = timestamp_result.unwrap_or(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user