feat(config): add USE_PCF8563 build switch to run without the RTC chip
Some PCB variants may not populate the PCF8563. Guards RTC init/read in HomeApp_OnStart(), the WriteDateTime() save in SetClockApp, and the I2C/RTC diagnostic scans in Self_Test() behind #if USE_PCF8563. When disabled, the firmware runs entirely on the Timer1-driven software clock; date/time just won't survive a power cycle without the chip.
This commit is contained in:
@@ -44,6 +44,7 @@ static void HomeApp_OnStart(void)
|
|||||||
current_state = STATE_NORMAL; // 系统切入正常待机状态
|
current_state = STATE_NORMAL; // 系统切入正常待机状态
|
||||||
RF_SetMode(1); // 开启天线并置为接收模式,监听无线探测器
|
RF_SetMode(1); // 开启天线并置为接收模式,监听无线探测器
|
||||||
|
|
||||||
|
#if USE_PCF8563
|
||||||
// 尝试从 PCF8563 RTC 芯片中读取硬件时间与日期 (具备非阻塞防卡死保护)
|
// 尝试从 PCF8563 RTC 芯片中读取硬件时间与日期 (具备非阻塞防卡死保护)
|
||||||
if (PCF8563_Init()) {
|
if (PCF8563_Init()) {
|
||||||
PCF8563_ReadDateTime(¤t_hour, ¤t_min, ¤t_sec, ¤t_day, ¤t_month, ¤t_year);
|
PCF8563_ReadDateTime(¤t_hour, ¤t_min, ¤t_sec, ¤t_day, ¤t_month, ¤t_year);
|
||||||
@@ -52,6 +53,9 @@ static void HomeApp_OnStart(void)
|
|||||||
} else {
|
} else {
|
||||||
XTELL_LOG("[HomeApp] RTC Hardware Offline, using system clock.\r\n");
|
XTELL_LOG("[HomeApp] RTC Hardware Offline, using system clock.\r\n");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
XTELL_LOG("[HomeApp] USE_PCF8563=0, running on software clock only.\r\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
// 绘制并渲染待机时钟主页面画面
|
// 绘制并渲染待机时钟主页面画面
|
||||||
UI_ShowClockPage(current_state, current_hour, current_min, current_weekday, current_day, current_month);
|
UI_ShowClockPage(current_state, current_hour, current_min, current_weekday, current_day, current_month);
|
||||||
|
|||||||
@@ -159,8 +159,10 @@ static EventResult SetClockApp_onEvent(SystemEvent *evt)
|
|||||||
// 短按 ■ 确认键保存最新时间与日期配置,退出到主菜单 (父 App)
|
// 短按 ■ 确认键保存最新时间与日期配置,退出到主菜单 (父 App)
|
||||||
current_state = STATE_PAIR_MENU;
|
current_state = STATE_PAIR_MENU;
|
||||||
|
|
||||||
|
#if USE_PCF8563
|
||||||
// 同步将最新时间与日期 (含算好的星期) 一次性写入 PCF8563 芯片寄存器
|
// 同步将最新时间与日期 (含算好的星期) 一次性写入 PCF8563 芯片寄存器
|
||||||
PCF8563_WriteDateTime(current_hour, current_min, 0, current_day, current_month, current_year, current_weekday);
|
PCF8563_WriteDateTime(current_hour, current_min, 0, current_day, current_month, current_year, current_weekday);
|
||||||
|
#endif
|
||||||
|
|
||||||
// 退出短振反馈
|
// 退出短振反馈
|
||||||
MOTOR = 1; Delay_ms(50); MOTOR = 0;
|
MOTOR = 1; Delay_ms(50); MOTOR = 0;
|
||||||
|
|||||||
@@ -174,4 +174,9 @@ extern volatile u16 comb_hold; // 组合键持续按下计时器
|
|||||||
#define MAIN_Fosc 24000000UL // STC32G 主频工作频率定义 (24.0 MHz)
|
#define MAIN_Fosc 24000000UL // STC32G 主频工作频率定义 (24.0 MHz)
|
||||||
#define CLONED_ADDR 0x37A86UL // 手环自身克隆发射的默认 24 位射频出厂 ID 地址
|
#define CLONED_ADDR 0x37A86UL // 手环自身克隆发射的默认 24 位射频出厂 ID 地址
|
||||||
|
|
||||||
|
// 硬件模块使能开关:某些 PCB 版本可能不焊接 PCF8563 RTC 芯片,置 0 后完全跳过
|
||||||
|
// I2C 探测/读写与开机诊断扫描,只依赖软件时钟 (Timer1 驱动的 current_hour/min/sec 等),
|
||||||
|
// 不写入/不写回 RTC,断电后时间不保留,但整机功能不受影响。
|
||||||
|
#define USE_PCF8563 1
|
||||||
|
|
||||||
#endif // __CONFIG_H__
|
#endif // __CONFIG_H__
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ void Self_Test(void)
|
|||||||
Uart_SendString("\r\n========================================\r\n");
|
Uart_SendString("\r\n========================================\r\n");
|
||||||
Uart_SendString("[SELF-TEST] System Power-On Self Test...\r\n");
|
Uart_SendString("[SELF-TEST] System Power-On Self Test...\r\n");
|
||||||
|
|
||||||
|
#if USE_PCF8563
|
||||||
// 执行 I2C 总线器件扫描,查找 RTC 是否物理响应
|
// 执行 I2C 总线器件扫描,查找 RTC 是否物理响应
|
||||||
PCF8563_ScanDiagnostic();
|
PCF8563_ScanDiagnostic();
|
||||||
|
|
||||||
@@ -198,6 +199,9 @@ void Self_Test(void)
|
|||||||
|
|
||||||
// 0.2 执行 RTC 底层单独试读测试
|
// 0.2 执行 RTC 底层单独试读测试
|
||||||
PCF8563_TryReadDiagnostic();
|
PCF8563_TryReadDiagnostic();
|
||||||
|
#else
|
||||||
|
Uart_SendString("[SELF-TEST] USE_PCF8563=0, skipping RTC/I2C diagnostics.\r\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
// 1. 验证 PWR_HOLD 锁存状态
|
// 1. 验证 PWR_HOLD 锁存状态
|
||||||
if (PWR_HOLD == 1) {
|
if (PWR_HOLD == 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user