Skip to content

Harden the ToughC5 board detection: minimal pre-confirmation writes, safe reset ordering, ID retry - #243

Merged
lovyan03 merged 2 commits into
m5stack:developfrom
ainyan03:toughc5_detect_hardening
Aug 10, 2026
Merged

Harden the ToughC5 board detection: minimal pre-confirmation writes, safe reset ordering, ID retry#243
lovyan03 merged 2 commits into
m5stack:developfrom
ainyan03:toughc5_detect_hardening

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Hardens the ToughC5 board detection, following up on a review of the ToughC5 support.

Problems

  1. The probe wrote a lot of state (PM1 power rails, watchdog, IO expander pin modes, both reset lines) after only the PM1/IOE address checks, before the panel ID had confirmed the board. A failed confirmation left all of that behind on whatever device had answered.
  2. The reset lines were switched to push-pull output before their output latch was written; the latch was only set high inside the use_reset pulse. With use_reset=false after a full power-down, the pin drives the power-on latch value — LCD_RST has no pull-up on the board, so the panel or touch controller could be held in reset.
  3. A single transient failure of the ID read left the board undetected for the rest of the run.

Changes (one commit each)

  1. Probe with minimal writes and restore them when not confirmed — pre-confirmation writes are reduced to what the ID read needs (LDO rail, LCD_EN / LCD_RST high), previous register values are recorded and written back when the panel does not answer. The reset latches are preloaded high before the pins become outputs. Everything else moves after confirmation.
  2. Retry the panel ID read once.

Testing

  • ToughC5 device: normal boot detection (slightly faster than before, since less is written before the ID read), display and touch working, and a cold start from full power removal (battery and USB disconnected) detects correctly — the case the latch preload addresses.
  • Built for ESP32 and ESP32-C5 targets.

…rmed

The ToughC5 probe configured the PM1 power rails, watchdog, IO expander
pins and both reset lines before the panel ID had confirmed the board,
and a failed confirmation left all of that behind on whatever device had
answered the address checks.

Restrict the pre-confirmation writes to what the panel ID read needs:
the LDO rail that powers the panel, and LCD_EN / LCD_RST driven high.
The previous register values are recorded first and written back when
the panel does not answer, so an unconfirmed candidate is left as it
was found. Everything else (watchdog, I2C sleep, charge and LED bits,
backlight pin, TP_RST, and the reset pulse itself) moves after the
board is confirmed.

The reset lines are also preloaded high in the output latch before the
pins are switched to push-pull output. LCD_RST has no pull-up on the
board, so with use_reset=false the pin used to drive whatever the
power-on latch value happened to be, which could hold the panel or the
touch controller in reset after a cold start.
A transient failure of the single ID read left the board undetected
for the rest of the run, with the C5 default fallback applied to
hardware it does not match.

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.

Pull request overview

This PR hardens ToughC5 (ESP32-C5) board autodetection by reducing and containing I2C side effects before the panel ID confirms the board, fixing reset-line ordering to avoid unintended reset assertion after cold power loss, and adding a single retry for transient panel-ID read failures.

Changes:

  • Reduce pre-confirmation I2C writes to only what’s required for panel ID read, and restore touched registers on non-confirmation.
  • Preload reset-line latches HIGH before configuring push-pull/output to avoid driving reset LOW unintentionally.
  • Retry the LCD panel ID read once if the first read does not match the expected ID.

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

@lovyan03
lovyan03 merged commit db7f0f4 into m5stack:develop Aug 10, 2026
23 checks passed
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.

3 participants