From 8c9c9772c92c209b64b16bbd9db9c1e35dd12b29 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 4 Oct 2026 10:11:49 -0700 Subject: [PATCH] Write and read the RX8130CE WEEK register as one-hot The RX8130CE encodes the day of the week one-hot, Sunday = 01h through Saturday = 40h (Epson ETM50E-10, 14.1.2, Table 15, p. 27), and "do not set '1' to more than one day at the same time". setTime() wrote bin2bcd(tm_wday), so no day was stored correctly: Sunday wrote no day, and Wednesday, Friday and Saturday wrote two. getTime() decoded it the same way. The date and time are unaffected, as mktime() ignores tm_wday. Write 1 << tm_wday (gmtime() gives 0-6), and read back the position of the lowest set bit. Co-Authored-By: Claude Opus 5.5 --- src/helpers/RTC_RX8130CE.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/helpers/RTC_RX8130CE.cpp b/src/helpers/RTC_RX8130CE.cpp index 8aa2b1ff3a..7cf4646360 100644 --- a/src/helpers/RTC_RX8130CE.cpp +++ b/src/helpers/RTC_RX8130CE.cpp @@ -95,7 +95,7 @@ bool RTC_RX8130CE::setTime(struct tm *t) { buf[1] = bin2bcd(t->tm_sec) & 0x7F; buf[2] = bin2bcd(t->tm_min) & 0x7F; buf[3] = bin2bcd(t->tm_hour) & 0x3F; - buf[4] = bin2bcd(t->tm_wday) & 0x07; + buf[4] = 1 << t->tm_wday; // one-hot, Sunday = 01h ... Saturday = 40h; gmtime() gives 0-6 buf[5] = bin2bcd(t->tm_mday) & 0x3F; buf[6] = bin2bcd(t->tm_mon + 1) & 0x1F; buf[7] = bin2bcd((t->tm_year - 100)); @@ -141,7 +141,13 @@ bool RTC_RX8130CE::getTime(struct tm *t) { t->tm_sec = bcd2bin(buff[0] & 0x7F); t->tm_min = bcd2bin(buff[1] & 0x7F); t->tm_hour = bcd2bin(buff[2] & 0x3F); - t->tm_wday = bcd2bin(buff[3] & 0x07); + t->tm_wday = 0; // the lowest set bit of the one-hot WEEK register; none reads as Sunday + for (int i = 0; i < 7; i++) { + if (buff[3] & (1 << i)) { + t->tm_wday = i; + break; + } + } t->tm_mday = bcd2bin(buff[4] & 0x3F); t->tm_mon = bcd2bin(buff[5] & 0x1F) - 1; t->tm_year = bcd2bin(buff[6]) + 100;