Loading files
c44ec7454This file is pinned to the selected release. Download the original to open it in your design tool.
import { getAxp2101Power } from 'axp2101-power-capture'
// Mirrors the CoreS3 power-rail setup used by M5Stack/StackChan firmware
// (`firmware/main/hal/board/stackchan.cc` near the AXP2101 init path) and the
// X-Powers AXP2101 register map for DCDC/ALDO/BLDO/LDO and charge-control fields.
/** Apply Stack-chan rail and expander settings to the SDK-created power devices. */
function patchStackChanPower() {
const axp2101 = getAxp2101Power()
if (!axp2101) throw new Error('AXP2101 power instance is unavailable')
const data = axp2101.readUint8(0x90)
// Enable the LDO rails needed by the CoreS3 StackChan base.
axp2101.writeUint8(0x90, data | 0b10110100)
// Set DCDC/LDO voltage selector used by the reference firmware.
axp2101.writeUint8(0x97, 0b11110 - 2)
// Configure VBUS input current limit and power-path behavior.
axp2101.writeUint8(0x69, 0b00110101)
// Enable required DCDC outputs.
axp2101.writeUint8(0x30, 0b111111)
// Force the final LDO enable mask after the voltage selectors are set.
axp2101.writeUint8(0x90, 0xbf)
// Set ALDO/BLDO voltage setpoints.
axp2101.writeUint8(0x94, 33 - 5)
axp2101.writeUint8(0x95, 33 - 5)
// Disable one unused LDO path to match the reference board profile.
axp2101.writeUint8(0x27, 0x00)
const charge = axp2101.readUint8(0x62)
// Preserve charge-control upper bits and set the target charge-current field.
axp2101.writeUint8(0x62, (charge & 0xe0) | 13)
trace('[m5stackchan] patched CoreS3 AXP2101 power rails\n')
}
/** Apply board power settings after SDK setup and then release the startup continuation. */
export default function (done) {
// The inherited CoreS3 setup precedes this module and constructs the shared
// AXP2101 before this board-specific rail configuration runs.
try {
patchStackChanPower()
} catch (error) {
trace(`[m5stackchan] AXP2101 power patch failed: ${error}\n`)
}
done?.()
}