feat(rtc): add PCF8563 full date read/write (day/month/year/weekday)

PCF8563's second/minute/hour/day/weekday/month/year registers are
contiguous (0x02-0x08), so PCF8563_ReadDateTime() bursts all 7 bytes
in one transaction. PCF8563_ReadTime() becomes a thin wrapper that
discards the date fields. WriteTime() is kept as its own 3-byte-only
implementation (writing only sec/min/hour) rather than routed through
the new WriteDateTime(), since forcing it through a 7-byte write would
require synthesizing date values and risk corrupting the stored date;
WriteDateTime() is added as a separate full 7-byte write for callers
that actually have real date+weekday values to persist.
This commit is contained in:
edisondeng
2026-07-31 19:30:02 +08:00
parent 4a55c1f9eb
commit 1146bade70
2 changed files with 97 additions and 9 deletions

View File

@@ -42,6 +42,31 @@ bit PCF8563_ReadTime(u8 *hour, u8 *min, u8 *sec);
*/
bit PCF8563_WriteTime(u8 hour, u8 min, u8 sec);
/**
* @brief 从 PCF8563 芯片连续读取时间与日期 (时/分/秒/日/月/年)
* @param hour 小时指针 (0~23)
* @param min 分钟指针 (0~59)
* @param sec 秒钟指针 (0~59)
* @param day 日指针 (1~31)
* @param month 月指针 (1~12)
* @param year 年指针 (0~99代表 2000~2099不处理世纪位)
* @return bit 1: 读取成功, 0: 通讯失败
*/
bit PCF8563_ReadDateTime(u8 *hour, u8 *min, u8 *sec, u8 *day, u8 *month, u8 *year);
/**
* @brief 将指定的时间与日期一次性连续写入 PCF8563 芯片
* @param hour 小时 (0~23)
* @param min 分钟 (0~59)
* @param sec 秒钟 (0~59)
* @param day 日 (1~31)
* @param month 月 (1~12)
* @param year 年 (0~99代表 2000~2099)
* @param weekday 星期 (0~6需与软件侧约定的星期数值一致芯片本身不做校验)
* @return bit 1: 写入成功, 0: 通讯失败
*/
bit PCF8563_WriteDateTime(u8 hour, u8 min, u8 sec, u8 day, u8 month, u8 year, u8 weekday);
/**
* @brief I2C 总线器件扫描诊断函数
* @details 逐个发送 I2C 写地址,检测总线上是否有响应的器件,并在串口打印发现的设备地址