Skip to content

fix(pl18): add timeout to isChargerActive() to prevent hang when batt… - #7468

Merged
pfeerick merged 2 commits into
mainfrom
richardclli/fix-el18-nobatt-usb-blackscreen
Jun 18, 2026
Merged

pfeerick merged 2 commits into
mainfrom
richardclli/fix-el18-nobatt-usb-blackscreen

Conversation

@richardclli

@richardclli richardclli commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

…ery missing

Add 2-second timeout to the blocking charger detection loops in isChargerActive(). When no battery is installed and the radio is USB-powered, the TP5100 charger IC status pins can oscillate due to capacitive-load charge/discharge cycling. This causes the consecutive-sample debounce counter in chargerDetection() to perpetually reset, hanging the boot before LCD initialization results in a blank screen.

Fixes EL18 blank screen when powered via USB without batteries.

Summary by CodeRabbit

  • Bug Fixes
    • Improved charger detection stability by adding a bounded polling timeout, preventing potential indefinite waiting when charger detection readiness is not reached.

…ery missing

Add 2-second timeout to the blocking charger detection loops in
isChargerActive(). When no battery is installed and the radio is
USB-powered, the TP5100 charger IC status pins can oscillate due
to capacitive-load charge/discharge cycling. This causes the
consecutive-sample debounce counter in chargerDetection() to
perpetually reset, hanging the boot before LCD initialization
results in a blank screen.

Fixes EL18 blank screen when powered via USB without batteries.
@richardclli richardclli added this to the 2.11.7 milestone Jun 17, 2026
@richardclli richardclli self-assigned this Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 60625632-b85b-48fd-aa43-04ca2f442b1a

📥 Commits

Reviewing files that changed from the base of the PR and between a2e0052 and 7eeec56.

📒 Files selected for processing (1)
  • radio/src/targets/pl18/battery_driver.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • radio/src/targets/pl18/battery_driver.cpp

📝 Walkthrough

Walkthrough

isChargerActive() in the PL18 battery driver replaces unbounded while loops with a fixed 40-iteration timeout counter (10 ms between checks = ~400 ms max). Both the WIRELESS_CHARGER and USB-only code paths now terminate after the timeout expires regardless of whether charger detection flags become ready.

Changes

Charger Detection Timeout

Layer / File(s) Summary
Timeout constant and bounded polling in isChargerActive()
radio/src/targets/pl18/battery_driver.cpp
Introduces CHARGER_DETECTION_TIMEOUT (40 iterations) and replaces previously unbounded loops in both #ifdef WIRELESS_CHARGER and #else paths. Wireless mode waits until both USB and wireless charger flags are ready or timeout expires, then returns either charger's presence. USB-only mode waits for USB readiness or timeout and returns only uCharger.hasCharger.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

backport/2.11, backport/2.12

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a timeout to isChargerActive() to prevent hangs during battery detection.
Description check ✅ Passed The description explains the problem context, root cause, and solution, but does not explicitly reference the fixed issue number or follow the template structure completely.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch richardclli/fix-el18-nobatt-usb-blackscreen

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 and usage tips.

@BlueskyFR

Copy link
Copy Markdown

This PR fixes #7442, awesome job Richard!
As discussed together, the battery charging screen is still missing though (although less important :D)

@pfeerick pfeerick linked an issue Jun 17, 2026 that may be closed by this pull request
1 task done
@pfeerick pfeerick added backport/2.11 To be backported to a 2.11 release also. backport/2.12 To be backported to a 2.12 release also. labels Jun 18, 2026
@pfeerick
pfeerick merged commit 000e1d3 into main Jun 18, 2026
40 checks passed
@pfeerick
pfeerick deleted the richardclli/fix-el18-nobatt-usb-blackscreen branch June 18, 2026 00:05
richardclli added a commit to richardclli/edgetx that referenced this pull request Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.11 To be backported to a 2.11 release also. backport/2.12 To be backported to a 2.12 release also.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flysky EL18: cannot boot after flashing starting from 2.11.0 (2.10.6 works)

3 participants