allow using AIN1 for VBAT on RAK19007 boards - #3328
Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes the RAK4631 variant’s VBAT sensing and NRF52 power-management LPCOMP configuration compile-time overrideable, enabling RAK19007 users to read VBAT via an alternate analog input (e.g., AIN1 on J11) without patching the core.
Changes:
- Wrapped
PIN_VBAT_READandADC_MULTIPLIERin#ifndefguards to allow-D/pre-include overrides. - Wrapped
PWRMGT_LPCOMP_AINandPWRMGT_LPCOMP_REFSELin#ifndefguards to allow alternative LPCOMP wake configuration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| variants/rak4631/variant.h | Allows overriding LPCOMP AIN/refsel defaults via preprocessor defines. |
| variants/rak4631/RAK4631Board.h | Allows overriding VBAT ADC pin and multiplier defaults via preprocessor defines. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // AIN3 = P0.05 = PIN_A0 / PIN_VBAT_READ | ||
| #define PWRMGT_LPCOMP_AIN 3 | ||
| #define PWRMGT_LPCOMP_REFSEL 4 // 5/8 VDD (~3.13-3.44V) | ||
| #ifndef PWRMGT_LPCOMP_AIN | ||
| #define PWRMGT_LPCOMP_AIN 3 | ||
| #endif |
|
HI Andy. Great minds think alike. I started working on this today after I got my V25 soldered up and connected directly to the 1W booster. I then found your PR and extended it to handle both the 4631 and the 3401. |
Wrap PIN_VBAT_READ / ADC_MULTIPLIER and the PWRMGT_* defines in #ifndef guards so build flags can redirect battery telemetry to another analog pin, e.g. a Voltaic V25/V50/V75 pack's USB-C SBU output (1/2 cell voltage) wired to the base board J11 AIN1 pin. Remove the unused Meshtastic-leftover battery defines from the rak3401 variant.h: nothing in the MeshCore, framework, or library compile closure references them, and the unconditional ADC_MULTIPLIER there would defeat both the new #ifndef default and any -D build flag (variant.h is included via Arduino.h before the board headers). Add a documented RAK_3401_repeater_voltaic example env that reports the pack's true cell voltage and keeps nRF52 power management active with LPCOMP wake rerouted to the SBU pin: sleep below 3.4V cell, wake once the pack recharges past ~3.7V. The rak4631 hunks are byte-identical to PR meshcore-dev#3328 by @andyshinn, which this change incorporates and extends. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Sounds good. If you open that one I can close this. |
Cool. Going to test on both boards so will probaly take a few days. I'll ping when they look good. |
This allows someone using the RAK19007 board to use AIN1 on the J11 header to get VBAT. Handy if using an external supply like a Voltaic pack.