From 0ef5991d3354d42c13b2943aba63a910d1b7b874 Mon Sep 17 00:00:00 2001 From: edisondeng Date: Fri, 31 Jul 2026 19:54:18 +0800 Subject: [PATCH] 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. --- App/app_home.c | 4 ++++ App/app_set_clock.c | 2 ++ App/config.h | 5 +++++ App/system.c | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/App/app_home.c b/App/app_home.c index c20da95..06a8874 100644 --- a/App/app_home.c +++ b/App/app_home.c @@ -44,6 +44,7 @@ static void HomeApp_OnStart(void) current_state = STATE_NORMAL; // 系统切入正常待机状态 RF_SetMode(1); // 开启天线并置为接收模式,监听无线探测器 +#if USE_PCF8563 // 尝试从 PCF8563 RTC 芯片中读取硬件时间与日期 (具备非阻塞防卡死保护) if (PCF8563_Init()) { PCF8563_ReadDateTime(¤t_hour, ¤t_min, ¤t_sec, ¤t_day, ¤t_month, ¤t_year); @@ -52,6 +53,9 @@ static void HomeApp_OnStart(void) } else { 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); diff --git a/App/app_set_clock.c b/App/app_set_clock.c index 24f9682..d3bc135 100644 --- a/App/app_set_clock.c +++ b/App/app_set_clock.c @@ -159,8 +159,10 @@ static EventResult SetClockApp_onEvent(SystemEvent *evt) // 短按 ■ 确认键保存最新时间与日期配置,退出到主菜单 (父 App) current_state = STATE_PAIR_MENU; +#if USE_PCF8563 // 同步将最新时间与日期 (含算好的星期) 一次性写入 PCF8563 芯片寄存器 PCF8563_WriteDateTime(current_hour, current_min, 0, current_day, current_month, current_year, current_weekday); +#endif // 退出短振反馈 MOTOR = 1; Delay_ms(50); MOTOR = 0; diff --git a/App/config.h b/App/config.h index cc37069..6c90225 100644 --- a/App/config.h +++ b/App/config.h @@ -174,4 +174,9 @@ extern volatile u16 comb_hold; // 组合键持续按下计时器 #define MAIN_Fosc 24000000UL // STC32G 主频工作频率定义 (24.0 MHz) #define CLONED_ADDR 0x37A86UL // 手环自身克隆发射的默认 24 位射频出厂 ID 地址 +// 硬件模块使能开关:某些 PCB 版本可能不焊接 PCF8563 RTC 芯片,置 0 后完全跳过 +// I2C 探测/读写与开机诊断扫描,只依赖软件时钟 (Timer1 驱动的 current_hour/min/sec 等), +// 不写入/不写回 RTC,断电后时间不保留,但整机功能不受影响。 +#define USE_PCF8563 1 + #endif // __CONFIG_H__ diff --git a/App/system.c b/App/system.c index 841b4de..f789e39 100644 --- a/App/system.c +++ b/App/system.c @@ -168,6 +168,7 @@ void Self_Test(void) Uart_SendString("\r\n========================================\r\n"); Uart_SendString("[SELF-TEST] System Power-On Self Test...\r\n"); +#if USE_PCF8563 // 执行 I2C 总线器件扫描,查找 RTC 是否物理响应 PCF8563_ScanDiagnostic(); @@ -198,6 +199,9 @@ void Self_Test(void) // 0.2 执行 RTC 底层单独试读测试 PCF8563_TryReadDiagnostic(); +#else + Uart_SendString("[SELF-TEST] USE_PCF8563=0, skipping RTC/I2C diagnostics.\r\n"); +#endif // 1. 验证 PWR_HOLD 锁存状态 if (PWR_HOLD == 1) {