Harden the ToughC5 board detection: minimal pre-confirmation writes, safe reset ordering, ID retry - #243
Merged
Conversation
…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.
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hardens the ToughC5 board detection, following up on a review of the ToughC5 support.
Problems
use_resetpulse. Withuse_reset=falseafter 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.Changes (one commit each)
Testing