Skip to content

Write and read the RX8130CE WEEK register as one-hot (iteration branch) - #16

Open
ptr727 wants to merge 2 commits into
devfrom
work/rx8130ce-week-onehot
Open

ptr727 wants to merge 2 commits into
devfrom
work/rx8130ce-week-onehot

Conversation

@ptr727

@ptr727 ptr727 commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Iteration branch for #15. Keep it open; never merge it. A clean single-commit branch for upstream is cut from it once it has baked. Upstream takes PRs on dev.

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.

Refs #15

🤖 Generated with Claude Code

ptr727 and others added 2 commits October 4, 2026 09:16
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings October 4, 2026 16:19
@coderabbitai

coderabbitai Bot commented Oct 4, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 054bca7c-5365-4329-a562-dd27acb7a4f4
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

No unresolved review comments remain, and the focused change is fully reviewed.

Review effort: Lite
Findings: None

What changed in this PR

Corrects RX8130CE WEEK register handling to use one-hot weekday encoding.

Changes:

  • Writes weekdays as 1 << tm_wday.
  • Decodes the lowest set weekday bit when reading.
File Description
src/​helpers/​RTC_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

ptr727 commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

Upstream: PR meshcore-dev#3550 (from fix/rx8130ce-week-onehot at 8c9c9772, byte-identical to this branch's 4cdd5d71) and issue meshcore-dev#3549.

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