From 16869139aab1e5f9839ea83327f7d73ff7124e0b Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 4 Oct 2026 09:16:12 -0700 Subject: [PATCH 1/2] 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, 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..c571e62a62 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 % 7); // WEEK is one-hot: Sunday = 01h ... Saturday = 40h 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; From 4cdd5d71def537b317f302a38ed79038a5372ed8 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 4 Oct 2026 09:17:58 -0700 Subject: [PATCH 2/2] Drop the RX8130CE weekday modulo, which guarded nothing tm_wday comes from gmtime() and is 0-6; a negative value would stay negative under %, so the modulo implied a guard it was not. From review. Co-Authored-By: Claude Opus 5.5 --- src/helpers/RTC_RX8130CE.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/RTC_RX8130CE.cpp b/src/helpers/RTC_RX8130CE.cpp index c571e62a62..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] = 1 << (t->tm_wday % 7); // WEEK is one-hot: Sunday = 01h ... Saturday = 40h + 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));