Skip to content

Power: keep per-board capabilities in one table per kind - #423

Merged
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:power_caps_table
Oct 27, 2026
Merged

lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:power_caps_table

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Summary

The charge state, charge control and power output capabilities were spread across the three capability getters and the switch statements of seven setters, some keyed by PMIC first and others by board first. Each kind now has one table function that the getter returns, and each setter refuses a request whose capability bit is clear, right after the PMIC identity check. The board conditions the setters repeated are removed.

Capability results and setter results do not change for any board that begin() initializes. One table entry is narrowed: on ESP32 Core2 the vibration bit is cleared when the PMIC is neither AXP192 nor AXP2101 (the motor rail is AXP192 LDO3 or AXP2101 DLDO1). begin() never produces that pair.

Also:

  • the two PMIC identity flags become a three-state enum (not_probed, settled, unconfirmed) with the same transitions
  • comments that named IP2316 are corrected to IP2315, and a comment that described the capability table as the source of getChargeState() is fixed (the table is only used for the debug cross check)

Testing

  • every (PMIC, board) pair that begin() produces was checked against the seven setters (setBatteryCharge, setChargeCurrent, setChargeVoltage, setExtOutput, setUsbOutput, setVibration, setExtPortBusConfig) in both directions: no setter path without its capability bit, and no capability bit without a setter path
  • On hardware: 39 boards report the same getChargeStateCaps() / getChargeControlCaps() / getPowerOutputCaps() and charge state as develop; external output control checked on Core2 (AXP192 and AXP2101), Tough and ToughC5, vibration on both Core2
  • Builds: ESP-IDF 5.1 to 6.1 and Arduino-ESP32 2.x / 3.x (ESP32, S2, S3, C3, C5, C6, C61, H2, P4), SDL, fork CI passed

The charge state, charge control and power output capabilities were
spread across the getters and the switch statements of seven setters,
some keyed by PMIC first and others by board first. Each kind now has
one static table function (_charge_state_caps, _charge_control_caps,
_power_output_caps) that the getter returns directly, and every setter
rejects a request whose capability bit is clear right after the identity
check. The board conditions that the setters used to repeat are gone.

On ESP32 Core2, the vibration bit is now cleared when the PMIC is not
AXP192 or AXP2101, matching the only motor rails (AXP192 LDO3, AXP2101
DLDO1). begin() never produces such a pair, so the results for an
initialized board are unchanged.

The two PMIC identity flags become a three-state enum (not_probed,
settled, unconfirmed); the transitions are the same as before.

Also correct comments that named IP2316 instead of IP2315, and a comment
that described the capability table as the source of getChargeState().
@lovyan03
lovyan03 merged commit cff0082 into m5stack:develop Oct 27, 2026
30 checks passed
@ainyan03
ainyan03 deleted the power_caps_table branch October 28, 2026 00:49
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.

2 participants