Skip to content

Write and read the RX8130CE WEEK register as one-hot 馃馃 - #3550

Open
ptr727 wants to merge 1 commit into
meshcore-dev:devfrom
ptr727:fix/rx8130ce-week-onehot
Open

ptr727 wants to merge 1 commit into
meshcore-dev:devfrom
ptr727:fix/rx8130ce-week-onehot

Conversation

@ptr727

@ptr727 ptr727 commented Oct 4, 2026

Copy link
Copy Markdown

References:

The defect

The RX8130CE's WEEK register (13h) is one-hot: Sunday = 01h through Saturday = 40h (搂14.1.2 "Week counter", Table 15, p. 27). The manual says "Do not set '1' to more than one day at the same time".

  • setTime() L98 wrote bin2bcd(t->tm_wday) & 0x07, so no day was stored correctly:
    • Sunday wrote 00h, no day at all.
    • Wednesday, Friday and Saturday each wrote two days.
    • Monday, Tuesday and Thursday each wrote another day's bit.
  • getTime() L144 decoded it the same wrong way.

The fix

  • L98 writes 1 << t->tm_wday. Its only caller, adjust(), passes gmtime() output, which is 0-6.
  • L144-L150 read back the position of the lowest set bit among bits 0-6. A chip still holding the old zero value reads as Sunday until the next adjust() rewrites the register.

Impact and notes

  • Low impact. now() and unixtime() go through mktime(), which ignores tm_wday, so the date and time MeshCore uses never depended on this. Only the chip's own week counter was wrong. That affects a weekday alarm, which MeshCore doesn't use, or any other firmware reading the chip.
  • No other users. tm_wday and register 13h are used nowhere else in src/, examples/ or variants/.
  • Out of scope, pre-existing in this driver, found by review:
    • begin() neither checks VLF nor initialises the time registers after power-up, which the manual requires.
    • stop() rewrites all of 1Eh, not just the STOP bit.
    • bin2bcd(tm_year - 100) is wrong outside 2000-2099.

Testing

  • Build: R1Neo_repeater builds, the only board using this driver (Muzi R1 Neo), as do RAK_4631_repeater, heltec_v4_repeater and RAK_11310_repeater.
  • Hardware: not tested. No RX8130CE is available here.

The same defect was found independently in ZephCore: ptr727/liquidraver-ZephCore#39.

Fixes #3549

Iteration history and review: ptr727/meshcore-dev-MeshCore#16.

馃 Generated with Claude Code

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 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

馃煝 Approval recommended

The reviewed weekday encoding and decoding changes are complete.

Review effort: Lite
Findings: None

What changed in this PR

Fixes RX8130CE weekday handling to match the chip鈥檚 one-hot WEEK register format.

Changes:

  • Writes weekdays as 1 << tm_wday.
  • Decodes the lowest set weekday bit when reading.
File Description
src/鈥媓elpers/鈥婻TC_RX8130CE.cpp Corrects WEEK register encoding and decoding.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

ptr727 added a commit to ptr727/liquidraver-ZephCore that referenced this pull request Oct 5, 2026
rtc_time_block() wrote the weekday as a number 0-6 (Sunday 0) for every
RTC. The RX8130CE's WEEK register (13h) is one-hot: Epson ETM50E-10
14.1.2, Table 15, p. 27, Sunday 01h to Saturday 40h, with no more than
one bit set. So each sync wrote Sunday as no day, Monday as Sunday, and
Wednesday, Friday and Saturday as two days at once. ZephCore never
reads the weekday back, so its time and date were unaffected.

A new boolean descriptor property, weekday-one-hot, is set on the
RX8130CE node in rtc-i2c.dtsi, and rtc_time_block() writes BIT(dow)
where it is set. That is the encoding of Zephyr's rtc_rx8130ce.c. The
DS3231, PCF8563 and RV3028 keep 0-6, as Zephyr's drivers for them
write it. The binding and comments no longer call the whole block BCD.

meshtracker_x1's YSN8900 sets it too. The board already uses the RX8900
register map for it, and the RX8900's WEEK register (03h) is one-hot:
Epson ETM45E-11 8.2.2, Table 15, p. 16. The YSN8900's own data sheet
has no register map, and its programming guide is not available.

The same defect and fix as meshcore-dev/MeshCore#3550.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants