Skip to content

feat(Power): support EXT_PWR_DETECT_MODE & EXT_PWR_DETECT_VAL, simplify EXT_PWR_DETECT#10140

Merged
jp-bennett merged 1 commit intomeshtastic:developfrom
mesh-malaysia:ext-pwr-detect
Apr 23, 2026
Merged

feat(Power): support EXT_PWR_DETECT_MODE & EXT_PWR_DETECT_VAL, simplify EXT_PWR_DETECT#10140
jp-bennett merged 1 commit intomeshtastic:developfrom
mesh-malaysia:ext-pwr-detect

Conversation

@ndoo
Copy link
Copy Markdown
Contributor

@ndoo ndoo commented Apr 12, 2026

Motivation: Simplify future variants by allowing to use internal pull-up/pull-down resistors, thus eliminating a physical resistor on the PCB.

  • Also adds feature parity to EXT_CHG_DETECT which supports custom modes and high/low state already.
  • Support the use of custom GPIO mode for EXT_PWR_DETECT GPIO pin, which allows the use of INPUT_PULLDOWN and INPUT_PULLUP on MCUs which have internal pull-up or pull-down resistors supported in Arduino.
  • Migrate heltec_capsule_sensor_v3 and heltec_sensor_hub from inline ifdef hacks to EXT_PWR_DETECT_MODE.
  • Support the use of EXT_PWR_DETECT_VAL which allows both internal or external pull-down resistors to be used for EXT_PWR_DETECT. Automatically set the appropriate EXT_PWR_DETECT_VAL if internal pull resistors are used.
  • Simplified EXT_PWR_DETECT by comparing with EXT_PWR_DETECT_VAL directly and remove heltec_capsule_sensor_v3 and heltec_sensor_hub #ifdef hacks now that EXT_PWR_DETECT_VAL is used.

Clean up the comments for isVbusIn() while I am here.

Build tested on:

  • heltec_capsule_sensor_v3
  • heltec_sensor_hub
  • heltec-v3 (as a regression test)
  • russell (not in this PR, working on a bunch of enhancements seperately)

Functionality tested on:

  • russell (not in this PR, working on a bunch of enhancements seperately)

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)
    • Testers needed, especially heltec_capsule_sensor_v3 & heltec_sensor_hub, I don’t have these devices but they are using hacks that this PR removes in favor of proper implementation

@github-actions github-actions Bot added needs-review Needs human review enhancement New feature or request labels Apr 12, 2026
@ndoo
Copy link
Copy Markdown
Contributor Author

ndoo commented Apr 12, 2026

That being said, EXT_CHRG_DETECT is out of scope of this PR but I think needs a cleanup too, as it currently stores its defines in a runtime uint8_t variable unnecessarily - because it never changes in runtime, it should just be handled by preprocessor directives.

@ndoo ndoo force-pushed the ext-pwr-detect branch 2 times, most recently from 37c121a to 4df6172 Compare April 12, 2026 19:19
@Stary2001 Stary2001 self-requested a review April 16, 2026 11:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds configurable external power detection behavior to the Power subsystem so board variants can use internal GPIO pull-ups/pull-downs (and configurable active level) instead of hardcoded per-board hacks.

Changes:

  • Introduces EXT_PWR_DETECT_MODE (and inferred/defaulted EXT_PWR_DETECT_VAL) handling in src/Power.cpp.
  • Simplifies isVbusIn() to compare digitalRead(EXT_PWR_DETECT) directly against EXT_PWR_DETECT_VAL.
  • Updates Heltec ESP32-S3 variants to use EXT_PWR_DETECT_MODE INPUT_PULLUP instead of special-case #ifdef logic.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Power.cpp Adds EXT_PWR_DETECT_MODE/EXT_PWR_DETECT_VAL handling, removes Heltec-specific conditionals, simplifies external power detection and pin setup.
variants/esp32s3/heltec_capsule_sensor_v3/variant.h Sets EXT_PWR_DETECT_MODE to INPUT_PULLUP for this variant.
variants/esp32s3/heltec_sensor_hub/variant.h Sets EXT_PWR_DETECT_MODE to INPUT_PULLUP for this variant.

Comment thread src/Power.cpp Outdated
…lify EXT_PWR_DETECT

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Andrew Yong <me@ndoo.sg>
@ndoo
Copy link
Copy Markdown
Contributor Author

ndoo commented Apr 20, 2026

Renamed EXT_PWR_DETECT_VAL → EXT_PWR_DETECT_VALUE for consistency with ext-chrg-detect.

Rebased on develop HEAD (as of now) to keep fresh.

@jp-bennett jp-bennett merged commit b2d980f into meshtastic:develop Apr 23, 2026
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants