From 6795980274c85a0684349619656f0e109638debb Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 5 Oct 2026 08:35:25 -0700 Subject: [PATCH 1/6] rtc: write the RX8130CE weekday one-hot zephcore_rtc_save() wrote the weekday as a binary 0-6 (Sunday 0) into whichever time-block byte the date does not use. The RX8130CE's WEEK register (13h) is one-hot: Epson ETM50E-10 14.1.2, Table 15, p. 27, gives Sunday 01h to Saturday 40h and says not to set more than one bit. So a Sunday was written as no day, a Monday as Sunday, and Wednesday, Friday and Saturday as two days at once, after every sync. ZephCore never reads the weekday back, so its time and date were unaffected; only the chip's week counter, and anything that reads it, was wrong. A new boolean weekday-one-hot descriptor property, set on the RX8130CE node in rtc-i2c.dtsi, makes the save write BIT(dow). The other chips keep the 0-6 encoding, as Zephyr's own DS3231, PCF8563 and RV3028 drivers write it. The same encoding as meshcore-dev/MeshCore#3550. Fixes fork issue ptr727/liquidraver-ZephCore#39. Co-Authored-By: Claude Opus 5.5 --- zephcore/adapters/clock/ZephyrRTCDiscover.c | 4 +++- zephcore/boards/common/rtc-i2c.dtsi | 2 ++ zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/zephcore/adapters/clock/ZephyrRTCDiscover.c b/zephcore/adapters/clock/ZephyrRTCDiscover.c index 3fb81843a..f68eef79a 100644 --- a/zephcore/adapters/clock/ZephyrRTCDiscover.c +++ b/zephcore/adapters/clock/ZephyrRTCDiscover.c @@ -36,6 +36,7 @@ struct rtc_desc { uint8_t status_reg; /* power-loss flag register, or RTC_STATUS_IN_SECONDS */ uint8_t status_mask; /* "time unreliable" bit within status_reg */ const uint8_t *zero; /* 7 bytes of bits the data sheet shows as 0, or NULL */ + bool week_one_hot; /* weekday as one bit per day, not 0-6 */ const char *name; }; @@ -61,6 +62,7 @@ DT_FOREACH_STATUS_OKAY(RTC_COMPAT, RTC_ZERO_ARRAY) .zero = COND_CODE_1( \ DT_NODE_HAS_PROP(node, zero_mask), \ (RTC_ZERO_NAME(node)), (NULL)), \ + .week_one_hot = DT_PROP(node, weekday_one_hot), \ .name = DT_NODE_FULL_NAME(node), \ }, @@ -313,7 +315,7 @@ void zephcore_rtc_save(uint32_t epoch) blk[2] = BIN2BCD(hour); /* weekday occupies whichever of index 3/4 the date doesn't. */ blk[d->date_index] = BIN2BCD(day); - blk[d->date_index == 4 ? 3 : 4] = (uint8_t)dow; + blk[d->date_index == 4 ? 3 : 4] = d->week_one_hot ? (uint8_t)BIT(dow) : (uint8_t)dow; blk[5] = BIN2BCD(m); blk[6] = BIN2BCD((unsigned)(y % 100)); diff --git a/zephcore/boards/common/rtc-i2c.dtsi b/zephcore/boards/common/rtc-i2c.dtsi index b4edf1cd8..2dabd133a 100644 --- a/zephcore/boards/common/rtc-i2c.dtsi +++ b/zephcore/boards/common/rtc-i2c.dtsi @@ -78,4 +78,6 @@ rtc_rx8130ce: rtc-rx8130ce@32 { status-mask = <0x02>; /* VLF — voltage low */ /* RX8130CE Application Manual ETM50E-10, 13.2.1 Table 12, p. 22 */ zero-mask = [80 80 c0 80 c0 e0 00]; + /* 14.1.2 Table 15, p. 27: Sunday 01h ... Saturday 40h */ + weekday-one-hot; }; diff --git a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml index 7e6643c25..bc60b0d47 100644 --- a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml +++ b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml @@ -51,3 +51,10 @@ properties: while the power-loss flag does not read as set, on two reads, is not this RTC and is never adopted. Leave it out for a chip whose unused bits are not documented as reading 0. + + weekday-one-hot: + type: boolean + description: > + The weekday register holds one bit per day (Sunday bit 0 to Saturday + bit 6) rather than a number 0-6. Set it for a chip whose data sheet + says so, such as the RX8130CE. From 5e2d541595d237208d431201d669091e64a196f2 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 5 Oct 2026 08:38:39 -0700 Subject: [PATCH 2/6] rtc: binding header names weekday-one-hot as a per-part field Local review: the header said only the day-of-month offset varies between parts, so someone adding a chip with a one-hot weekday (Zephyr's rv8803 driver writes one) would not look for the property. Co-Authored-By: Claude Opus 5.5 --- zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml index bc60b0d47..8e1613941 100644 --- a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml +++ b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml @@ -7,8 +7,9 @@ # (~2-3 KB total, "Path B") instead of pulling in the full RTC subsystem. # # All supported chips use a 7-byte BCD time block (sec, min, hour, then -# weekday/date, month, year) starting at "time-reg". Only the day-of-month -# byte offset varies between parts, captured by "date-index". +# weekday/date, month, year) starting at "time-reg". The day-of-month byte +# offset varies between parts, captured by "date-index", and so does the +# weekday encoding, captured by "weekday-one-hot". description: ZephCore data-only I2C RTC descriptor (raw-I2C, no Zephyr RTC driver) From 2abbd88c0ba85144b16320d77b0aab5bc6773b4f Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 5 Oct 2026 08:43:19 -0700 Subject: [PATCH 3/6] rtc: binding header no longer calls the weekday byte BCD Copilot on fork #45: the header described the whole 7-byte block as BCD, which a one-hot weekday is not. It now says every field but the weekday is BCD, and that the weekday is a number 0-6 or one bit per day. Co-Authored-By: Claude Opus 5.5 --- zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml index 8e1613941..8991277d1 100644 --- a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml +++ b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml @@ -6,10 +6,11 @@ # the properties below. This keeps the boot-time RTC restore compact # (~2-3 KB total, "Path B") instead of pulling in the full RTC subsystem. # -# All supported chips use a 7-byte BCD time block (sec, min, hour, then -# weekday/date, month, year) starting at "time-reg". The day-of-month byte -# offset varies between parts, captured by "date-index", and so does the -# weekday encoding, captured by "weekday-one-hot". +# All supported chips use a 7-byte time block (sec, min, hour, then +# weekday/date, month, year) starting at "time-reg", BCD in every field but +# the weekday. The day-of-month byte offset varies between parts, captured +# by "date-index", and so does the weekday encoding, a number 0-6 or one bit +# per day, captured by "weekday-one-hot". description: ZephCore data-only I2C RTC descriptor (raw-I2C, no Zephyr RTC driver) From 441088595ba0f4f0767ce5ae475d4868d510ff0f Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 5 Oct 2026 08:45:03 -0700 Subject: [PATCH 4/6] rtc: binding says what ZephCore writes to the weekday, not what chips define The DS3231 family defines its weekday register as 1-7, but ZephCore, like Zephyr's own rtc_ds3231.c, writes 0-6; the header now states the encoding ZephCore writes rather than claiming it for every chip. The time-reg description no longer calls the block BCD either. Co-Authored-By: Claude Opus 5.5 --- zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml index 8991277d1..64e86cb5b 100644 --- a/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml +++ b/zephcore/dts/bindings/rtc/zephcore,rtc-i2c.yaml @@ -9,8 +9,9 @@ # All supported chips use a 7-byte time block (sec, min, hour, then # weekday/date, month, year) starting at "time-reg", BCD in every field but # the weekday. The day-of-month byte offset varies between parts, captured -# by "date-index", and so does the weekday encoding, a number 0-6 or one bit -# per day, captured by "weekday-one-hot". +# by "date-index". The weekday is written as a number 0-6 (Sunday 0), as +# Zephyr's DS3231, PCF8563 and RV3028 drivers write it, or as one bit per +# day where "weekday-one-hot" is set. description: ZephCore data-only I2C RTC descriptor (raw-I2C, no Zephyr RTC driver) @@ -22,7 +23,7 @@ properties: time-reg: type: int required: true - description: Register address of the seconds byte (start of the 7-byte BCD block). + description: Register address of the seconds byte (start of the 7-byte time block). date-index: type: int From 23228baa53874fadbe40029a90161e8c1b728cd9 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 5 Oct 2026 12:18:05 -0700 Subject: [PATCH 5/6] rtc: file header no longer calls the whole time block BCD The RX8130CE weekday is now written one-hot, which is not BCD. Co-Authored-By: Claude Opus 5.5 --- zephcore/adapters/clock/ZephyrRTCDiscover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zephcore/adapters/clock/ZephyrRTCDiscover.c b/zephcore/adapters/clock/ZephyrRTCDiscover.c index 9cbb72fa1..7f0b6b561 100644 --- a/zephcore/adapters/clock/ZephyrRTCDiscover.c +++ b/zephcore/adapters/clock/ZephyrRTCDiscover.c @@ -3,7 +3,7 @@ * * Compact raw-I2C hardware-RTC auto-discovery. See ZephyrRTCDiscover.h. * - * Register layouts (sec/min/hour/.../month/year, all BCD) and the per-chip + * Register layouts (sec/min/hour/.../month/year) and the per-chip * power-loss flags are carried in devicetree via the "zephcore,rtc-i2c" * binding, so this reader is generic — adding a new chip is a DT node, not * code. Maps were taken from Zephyr's own drivers (rtc_pcf8563.c, From 44ed7e37f7198f3ceb26b59b42f32091319680c7 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 5 Oct 2026 12:33:22 -0700 Subject: [PATCH 6/6] rtc: write the meshtracker_x1 YSN8900 weekday one-hot The YSN8900 is an RX8900 second source, and the board already uses the RX8900 register map for it. The RX8900's WEEK register (03h) is one-hot: Epson RX8900 Application Manual ETM45E-11, 8.2.2, Table 15, p. 16, Sunday 01h to Saturday 40h. The YSN8900's own data sheet is a one-page brief with no register map, and its programming guide is not available. Co-Authored-By: Claude Opus 5.5 --- .../boards/nrf52840/meshtracker_x1/meshtracker_x1_nrf52840.dts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zephcore/boards/nrf52840/meshtracker_x1/meshtracker_x1_nrf52840.dts b/zephcore/boards/nrf52840/meshtracker_x1/meshtracker_x1_nrf52840.dts index 514578e07..f9e07a00f 100644 --- a/zephcore/boards/nrf52840/meshtracker_x1/meshtracker_x1_nrf52840.dts +++ b/zephcore/boards/nrf52840/meshtracker_x1/meshtracker_x1_nrf52840.dts @@ -354,6 +354,8 @@ date-index = <4>; status-reg = <0x0e>; status-mask = <0x02>; + /* RX8900 Application Manual ETM45E-11, 8.2.2 Table 15, p. 16 */ + weekday-one-hot; }; };