Kleidos API Search

In development. It changes without notice.

Topic

Power Chip Drivers

The power chips: battery, power key, the supply of the parts, and switching the board off.

Chip Boards What the firmware uses it for
Axp192 Core2 v1.3, M5StickC Plus 1.1, M5StickC Plus SE Battery, power key, supplies, power-off
Axp2101 CoreS3 SE The same, with a fuel gauge
Py32Pmic (M5PM1) M5StickS3 Battery, power key, supplies, and the line that ends the deep sleep
Aw9523 (I/O expander) CoreS3 SE Resets and supplies of other parts

A driver for the IP5306 is here too; none of the nine boards has that chip.

Off. The AXP192 and the AXP2101 switch the board off. First they clear what their interrupts hold, and the AXP2101 masks them, because there a pending one would power the board on again. Only the chip's own power-on sources bring it back, as a cold start. Their power key's timing and interrupts are written at the start, since the chip keeps what any earlier firmware set.

Asleep. The M5PM1 does not switch the board off. Its driver lets a click of the power key pull one line low, which is what ends the ESP32-S3's deep sleep.

See also
Power, Battery & Parking, Audio Drivers

Files

file src/drivers/power/aw9523.h
AW9523B I/O expander driver for the CoreS3 SE's display rail/reset control.
file src/drivers/power/aw9523_regs.h
AW9523B I2C GPIO expander register map (CoreS3 SE display subset).
file src/drivers/power/axp192.h
X-Powers AXP192 PMIC driver (battery telemetry + display rails).
file src/drivers/power/axp192_regs.h
X-Powers AXP192 PMIC register map (Kleidos subset).
file src/drivers/power/axp2101.h
X-Powers AXP2101 PMIC driver (battery telemetry + display rails).
file src/drivers/power/axp2101_regs.h
X-Powers AXP2101 PMIC register map (Kleidos subset).
file src/drivers/power/axp_power_control.h
Power-key configuration, IRQ latch clearing and soft power-off of the X-Powers AXP192 and AXP2101.
file src/drivers/power/coulomb_raw.h
Raw coulomb-counter reading: the two hardware counters and the ADC rate.
file src/drivers/power/i_pmic.h
Abstract Power Management IC driver contract.
file src/drivers/power/ip5306.h
Injoinic IP5306 power-bank PMIC driver.
file src/drivers/power/ip5306_regs.h
Injoinic IP5306 power-bank PMIC register map (Kleidos subset).
file src/drivers/power/pmic_common.h
Shared pure helpers for the concrete PMIC drivers.
file src/drivers/power/pmic_factory.cpp
PMIC driver factory — probes the internal I2C bus for the chip.
file src/drivers/power/py32_pmic.h
PY32-based M5PM1 PMIC driver for the M5StickS3.
file src/drivers/power/py32_pmic_control.h
GPIO-function fields and the power-key IRQ line of the M5PM1 (PY32) PMIC on the M5StickS3.
file src/drivers/power/py32_pmic_regs.h
PY32-based M5PM1 PMIC register map (M5StickS3).

Classes

class kleidos::drivers::power::Aw9523
AW9523B I/O expander driver (CoreS3 SE LCD reset / display rail control). More about kleidos::drivers::power::Aw9523
class kleidos::drivers::power::Axp192
AXP192 power-chip driver (Core2 v1.3, M5StickC Plus 1.1, M5StickC Plus SE). More about kleidos::drivers::power::Axp192
struct kleidos::drivers::power::Axp192::BacklightConfig
Board-specific backlight wiring, supplied by the board so the driver itself carries no per-device branching. More about kleidos::drivers::power::Axp192::BacklightConfig
class kleidos::drivers::power::Axp2101
AXP2101 power-chip driver (CoreS3 SE). More about kleidos::drivers::power::Axp2101
struct kleidos::drivers::power::Axp2101::BacklightConfig
Board-specific backlight wiring, supplied by the board so the driver itself carries no per-device branching. More about kleidos::drivers::power::Axp2101::BacklightConfig
struct kleidos::drivers::power::axp192::UnusedOutputs
The AXP192 outputs a board never uses, each put in its off state at boot by parkUnusedOutputs. More about kleidos::drivers::power::axp192::UnusedOutputs
struct kleidos::drivers::power::CoulombRaw
One reading of a coulomb counter pair. More about kleidos::drivers::power::CoulombRaw
class kleidos::drivers::power::IPmic
The contract every power-management chip driver implements. More about kleidos::drivers::power::IPmic
class kleidos::drivers::power::Ip5306
IP5306 power-bank PMIC driver. More about kleidos::drivers::power::Ip5306
class kleidos::drivers::power::Py32Pmic
PY32-based M5PM1 PMIC driver (M5StickS3, I2C 0x6E). More about kleidos::drivers::power::Py32Pmic

Functions

boolkleidos::drivers::power::axp192::configurePowerKey (const bus::I2cDevice &dev)
Pin the AXP192 power-key timing and its IRQ enables.
boolkleidos::drivers::power::axp192::clearIrqStatus (const bus::I2cDevice &dev)
Clear every AXP192 IRQ status latch.
boolkleidos::drivers::power::axp192::powerOff (const bus::I2cDevice &dev)
Switch the board off at the AXP192.
boolkleidos::drivers::power::axp192::parkUnusedOutputs (const bus::I2cDevice &dev, const UnusedOutputs &outputs)
Put the AXP192 outputs a board never uses in their off state.
boolkleidos::drivers::power::axp2101::configurePowerKey (const bus::I2cDevice &dev)
Pin the AXP2101 power-key timing, its OFFLEVEL action and its IRQ enables.
boolkleidos::drivers::power::axp2101::clearIrqStatus (const bus::I2cDevice &dev)
Clear every AXP2101 IRQ status latch.
boolkleidos::drivers::power::axp2101::powerOff (const bus::I2cDevice &dev)
Switch the board off at the AXP2101.
IPmic *kleidos::drivers::power::createPmic (uint8_t address)
Probes the PMIC at address, returning a ready singleton driver for the detected chip, or nullptr if none is present/supported. The returned pointer is owned by the driver layer (static storage); callers must not delete it.
boolkleidos::drivers::power::py32::setGpioFunction (const bus::I2cDevice &dev, uint8_t pin, uint8_t function)
Set PYG pin's two-bit function field, preserving the other pins'.
boolkleidos::drivers::power::py32::setGpioLevel (const bus::I2cDevice &dev, uint8_t pin, bool high)
Drive PYG pin high or low, and nothing else: its bit of the output register, preserving the other pins'.
boolkleidos::drivers::power::py32::armKeyIrq (const bus::I2cDevice &dev, bool wakeFlag)
Route the power key's click to the PYG1 IRQ line, released.
boolkleidos::drivers::power::py32::armMotionIrq (const bus::I2cDevice &dev)
Route PYG4's level changes (the IMU's INT1) to the PYG1 IRQ line.
boolkleidos::drivers::power::py32::clearMotionIrq (const bus::I2cDevice &dev)
Clear the PYG level-change latch (IRQ_STATUS1), which releases the IRQ line while armMotionIrq has it routed.
boolkleidos::drivers::power::py32::clearIrqLatches (const bus::I2cDevice &dev)
Clear the three IRQ latches (0x40-0x42), releasing the IRQ line.
boolkleidos::drivers::power::py32::releaseKeyIrq (const bus::I2cDevice &dev)
Return PYG1 to the PMIC's reset state, a plain input.
constexpr uint8_tkleidos::drivers::power::py32::gpioFieldReg (uint8_t firstReg, uint8_t pin)
Register holding PYG pin's two-bit field, given the first of the pair.
constexpr uint8_tkleidos::drivers::power::py32::gpioFieldShift (uint8_t pin)
Bit position of PYG pin's two-bit field in its register.

Variables

constexpr uint8_tkleidos::drivers::power::aw9523::kRegInputP0
Port 0 input state.
constexpr uint8_tkleidos::drivers::power::aw9523::kRegInputP1
Port 1 input state.
constexpr uint8_tkleidos::drivers::power::aw9523::kRegOutputP0
Port 0 output state.
constexpr uint8_tkleidos::drivers::power::aw9523::kRegOutputP1
Port 1 output state (LCD_RST = bit 1).
constexpr uint8_tkleidos::drivers::power::aw9523::kRegConfigP0
Port 0 direction (0 => output, 1 => input).
constexpr uint8_tkleidos::drivers::power::aw9523::kRegConfigP1
Port 1 direction.
constexpr uint8_tkleidos::drivers::power::aw9523::kRegChipId
Read-only chip ID.
constexpr uint8_tkleidos::drivers::power::aw9523::kRegGcr
Global control (bit4 => Port0 push-pull).
constexpr uint8_tkleidos::drivers::power::aw9523::kRegLedModeP0
1 => GPIO mode, 0 => LED dim mode.
constexpr uint8_tkleidos::drivers::power::aw9523::kRegLedModeP1
Port 1 LED/GPIO mode select.
constexpr uint8_tkleidos::drivers::power::aw9523::kChipId
Expected read-only chip ID value.
constexpr uint8_tkleidos::drivers::power::aw9523::kLcdResetBit
AW9523 P1.1 — panel reset line.
constexpr uint8_tkleidos::drivers::power::aw9523::kAmpGateBit
AW9523 P0.2 — speaker amplifier gate.
constexpr uint8_tkleidos::drivers::power::aw9523::kBusOutEnableBit
constexpr uint8_tkleidos::drivers::power::aw9523::kUsbOtgEnableBit
constexpr uint8_tkleidos::drivers::power::aw9523::kBoostEnableBit
AW9523 P1.7 BOOST_EN: the SY7088 5 V boost's enable.
constexpr uint8_tkleidos::drivers::power::aw9523::kOutputP0Init
constexpr uint8_tkleidos::drivers::power::aw9523::kOutputP0InitMask
constexpr uint8_tkleidos::drivers::power::aw9523::kOutputP1Init
constexpr uint8_tkleidos::drivers::power::aw9523::kOutputP1InitMask
Port 1 pins begin() writes: the ones it drives high and the boost enable.
constexpr uint8_tkleidos::drivers::power::aw9523::kConfigP0
Port 0 direction (1 => input).
constexpr uint8_tkleidos::drivers::power::aw9523::kConfigP1
Port 1 direction (1 => input).
constexpr uint8_tkleidos::drivers::power::aw9523::kGcrPushPull
GCR bit 4: Port 0 push-pull output mode.
constexpr uint8_tkleidos::drivers::power::aw9523::kLedModeGpio
Force GPIO mode on every port pin.
constexpr uint8_tkleidos::drivers::power::axp192::kRegStatus
Power-status register (charging bit).
constexpr uint8_tkleidos::drivers::power::axp192::kChargingMask
Charging flag bit in kRegStatus.
constexpr intkleidos::drivers::power::axp192::kBatteryVoltageScaleTenths
1.1 mV → (raw * 11 + 5) / 10
constexpr uint8_tkleidos::drivers::power::axp192::kRegBatteryChargeCurrent
constexpr uint8_tkleidos::drivers::power::axp192::kRegBatteryDischargeCurrent
constexpr intkleidos::drivers::power::axp192::kBatteryCurrentScaleHalfMa
0.5 mA/LSB → raw * 1 / 2
constexpr uint8_tkleidos::drivers::power::axp192::kRegVbusVoltage
constexpr uint8_tkleidos::drivers::power::axp192::kRegVbusCurrent
constexpr intkleidos::drivers::power::axp192::kVbusVoltageScaleTenths
1.7 mV/LSB → raw * 17 / 10
constexpr uint8_tkleidos::drivers::power::axp192::kRegAcinVoltage
constexpr uint8_tkleidos::drivers::power::axp192::kRegAcinCurrent
constexpr intkleidos::drivers::power::axp192::kAcinCurrentScaleNumerator
0.625 mA/LSB → raw * 625 / 1000
constexpr intkleidos::drivers::power::axp192::kAcinCurrentScaleDenominator
Denominator of the 0.625 mA/LSB scale.
constexpr uint8_tkleidos::drivers::power::axp192::kAdcEnableAcinVolt
0x82 bit5: ACIN-voltage ADC
constexpr uint8_tkleidos::drivers::power::axp192::kAdcEnableAcinCur
0x82 bit4: ACIN-current ADC
constexpr uint8_tkleidos::drivers::power::axp192::kRegInternalTemp
constexpr uint8_tkleidos::drivers::power::axp192::kRegChargeCoulomb
0xB0..0xB3 (MSB first)
constexpr uint8_tkleidos::drivers::power::axp192::kRegDischargeCoulomb
0xB4..0xB7 (MSB first)
constexpr uint8_tkleidos::drivers::power::axp192::kRegIrqStatus1
INTSTS1: ACIN / VBUS events.
constexpr uint8_tkleidos::drivers::power::axp192::kRegIrqStatus2
INTSTS2: battery / charger events.
constexpr uint8_tkleidos::drivers::power::axp192::kRegIrqStatus3
INTSTS3: power key, DCDC low-V, over-temp.
constexpr uint8_tkleidos::drivers::power::axp192::kRegIrqStatus4
INTSTS4: N_OE, VBUS session, APS low-V.
constexpr uint8_tkleidos::drivers::power::axp192::kRegIrqStatus5
constexpr std::array< uint8_t, 5 >kleidos::drivers::power::axp192::kIrqStatusRegs
Every IRQ status latch, in the order a full clear writes them.
constexpr uint8_tkleidos::drivers::power::axp192::kIrqStatusClearAll
Value written to a status latch to clear every bit of it (write-1-to-clear).
constexpr uint8_tkleidos::drivers::power::axp192::kRegPowerKeyIrq
Latch read by the click poll.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyIrqMask
Short + long press bits.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyIrqShift
Field offset of the key bits.
constexpr uint8_tkleidos::drivers::power::axp192::kRegIrqEnable3
INTEN3: power key, DCDC low-V, over-temp.
constexpr uint8_tkleidos::drivers::power::axp192::kIrqEnablePowerKeyShort
Short-press IRQ enable.
constexpr uint8_tkleidos::drivers::power::axp192::kIrqEnablePowerKeyLong
constexpr uint8_tkleidos::drivers::power::axp192::kIrqEnablePowerKeyMask
The key enables the driver owns in INTEN3 (both are set).
constexpr uint8_tkleidos::drivers::power::axp192::kRegPowerKeyTiming
POK_SET: power-key timing.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyOnLevel128Ms
ONLEVEL code 0: 128 ms press powers on.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyLongPress1s
Long-press IRQ after 1 s.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyAutoOff
Holding the key for OFFLEVEL powers off.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyPwrok64Ms
PWROK asserted 64 ms after power-up.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyOffLevel4s
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyTiming
The pinned POK_SET value: 128 ms on, 1 s long press, power off after a 4 s hold.
constexpr uint8_tkleidos::drivers::power::axp192::kPowerKeyTimingMask
POK_SET has no reserved bit.
constexpr uint8_tkleidos::drivers::power::axp192::kRegPowerOffControl
OFF_CTL: soft power-off, CHGLED, N_OE.
constexpr uint8_tkleidos::drivers::power::axp192::kSoftPowerOffBit
Soft power-off command bit.
constexpr uint8_tkleidos::drivers::power::axp192::kDc3EnableBit
constexpr uint8_tkleidos::drivers::power::axp192::kDc2EnableBit
constexpr uint8_tkleidos::drivers::power::axp192::kExtenEnableBit
constexpr uint8_tkleidos::drivers::power::axp192::kRegGpio34Control
GPIO3/4 function control.
constexpr uint8_tkleidos::drivers::power::axp192::kRegGpio34Signal
GPIO3/4 output level.
constexpr uint8_tkleidos::drivers::power::axp192::kGpio4OutputMode
bit7 enable, GPIO4 = output
constexpr uint8_tkleidos::drivers::power::axp192::kRegGpio0Control
GPIO0 function; 010 switches the LDOio0 rail on.
constexpr uint8_tkleidos::drivers::power::axp192::kRegGpio1Control
GPIO1 function.
constexpr uint8_tkleidos::drivers::power::axp192::kRegGpio2Control
GPIO2 function.
constexpr uint8_tkleidos::drivers::power::axp192::kGpioFunctionMask
The function field of a GPIO control register.
constexpr uint8_tkleidos::drivers::power::axp192::kGpioFunctionLow
constexpr uint8_tkleidos::drivers::power::axp192::kGpioFunctionFloating
Function 11x: the pin floats. 0x07, the power-on value, selects the same function.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegTdieAdc
constexpr uint8_tkleidos::drivers::power::axp2101::kRegVbusVoltage
constexpr uint8_tkleidos::drivers::power::axp2101::kRegIrqEnable1
INTEN1: SOC warnings, gauge, battery temperature.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegIrqEnable2
INTEN2: VBUS / battery insert-remove, power key.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegIrqEnable3
INTEN3: charger and protection events.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegIrqStatus1
INTSTS1: latches for INTEN1.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegIrqStatus2
INTSTS2: latches for INTEN2 (power key).
constexpr uint8_tkleidos::drivers::power::axp2101::kRegIrqStatus3
constexpr std::array< uint8_t, 3 >kleidos::drivers::power::axp2101::kIrqEnableRegs
Every IRQ enable register, in the order a power-off masks them.
constexpr std::array< uint8_t, 3 >kleidos::drivers::power::axp2101::kIrqStatusRegs
Every IRQ status latch, in the order a full clear writes them.
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqEnableNone
Masks every IRQ of one enable register.
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqStatusClearAll
Clears every bit of one status latch.
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqPowerKeyShort
Short press (released before IRQLEVEL).
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqPowerKeyLong
Long press (held for IRQLEVEL).
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqPowerKeyFalling
PWRON falling edge.
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqPowerKeyRising
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqEnablePowerKeyMask
Every power-key bit of INTEN2: the field the driver pins at begin().
constexpr uint8_tkleidos::drivers::power::axp2101::kIrqEnablePowerKeyPress
constexpr uint8_tkleidos::drivers::power::axp2101::kRegPowerKeyIrq
Latch read by the click poll.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerKeyIrqMask
Short + long press bits.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerKeyIrqShift
Field offset of the key bits.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegPowerKeyLevels
IRQ_OFF_ON_LEVEL_CTRL.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerKeyIrqLevel1s
IRQLEVEL code 0: long press after 1 s.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerKeyOffLevel4s
OFFLEVEL code 0: a 4 s hold powers off.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerKeyOnLevel128Ms
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerKeyLevels
The pinned timing: 1 s long press, power off after a 4 s hold, 128 ms on.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerKeyLevelsMask
The three timing fields (bits 5..0).
constexpr uint8_tkleidos::drivers::power::axp2101::kRegPowerOffEnable
PWROFF_EN.
constexpr uint8_tkleidos::drivers::power::axp2101::kLongPressOffEnable
An OFFLEVEL hold acts on the PMIC.
constexpr uint8_tkleidos::drivers::power::axp2101::kLongPressRestart
Set: restart; clear: power off.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerOffKeyMask
Key bits.
constexpr uint8_tkleidos::drivers::power::axp2101::kPowerOffKeyPowersOff
Hold to power off, no restart.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegCommonConfig
COMMON_CONFIG.
constexpr uint8_tkleidos::drivers::power::axp2101::kSoftPowerOffBit
Soft power-off command bit.
constexpr uint8_tkleidos::drivers::power::axp2101::kRegLdoEnable
LDO_ONOFF_CTRL0.
constexpr uint8_tkleidos::drivers::power::axp2101::kAldo1EnableBit
ALDO1 enable.
constexpr uint8_tkleidos::drivers::power::axp2101::kAldo2EnableBit
ALDO2 enable.
constexpr uint8_tkleidos::drivers::power::axp2101::kAldo4EnableBit
ALDO4 enable.
constexpr uint8_tkleidos::drivers::power::axp2101::kDldo1EnableBit
constexpr uint8_tkleidos::drivers::power::axp2101::kBoardRailsEnable
constexpr uint8_tkleidos::drivers::power::py32::kRegDeviceId
Device type (0x50 on the M5StickS3).
constexpr uint8_tkleidos::drivers::power::py32::kRegDeviceModel
Device model (0x20 on the M5StickS3).
constexpr uint8_tkleidos::drivers::power::py32::kRegWakeSource
Why the PMIC last powered on; 0 clears it.
constexpr uint8_tkleidos::drivers::power::py32::kRegPowerConfig
Charger, DC/DC, LDO, 5 V boost, LED level.
constexpr uint8_tkleidos::drivers::power::py32::kRegHoldConfig
Rails and PYG pins kept through a power-off.
constexpr uint8_tkleidos::drivers::power::py32::kRegI2cConfig
I2C speed and idle-sleep timeout.
constexpr uint8_tkleidos::drivers::power::py32::kRegSystemCommand
Write-only command port (key | opcode).
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioMode
bit=1 selects output direction
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioOutput
bit=1 drives the PYG pin high
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioInput
Live PYG input levels.
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioPushPull
bit=0 selects push-pull output
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioPull0
PYG0..PYG3 pulls, two bits per pin.
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioFunction0
PYG0..PYG3 function, two bits per pin.
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioWakeEnable
PYG pins that wake the PMIC from power-off.
constexpr uint8_tkleidos::drivers::power::py32::kRegGpioWakeConfig
Wake edge per PYG pin (0 = falling).
constexpr uint8_tkleidos::drivers::power::py32::kRegBatteryVoltageLow
Battery mV, low byte of a little-endian pair.
constexpr uint8_tkleidos::drivers::power::py32::kRegTimerCount0
Timer count in s, LSB of four bytes.
constexpr uint8_tkleidos::drivers::power::py32::kRegTimerConfig
Timer arm bit and action.
constexpr uint8_tkleidos::drivers::power::py32::kRegTimerKey
Write-only timer reload key port.
constexpr uint8_tkleidos::drivers::power::py32::kRegIrqStatus1
PYG level-change latches.
constexpr uint8_tkleidos::drivers::power::py32::kRegIrqStatus2
Power-source event latches.
constexpr uint8_tkleidos::drivers::power::py32::kRegIrqStatus3
Power-key event latches.
constexpr uint8_tkleidos::drivers::power::py32::kRegIrqMask1
bit=1 masks the matching IRQ_STATUS1 bit
constexpr uint8_tkleidos::drivers::power::py32::kRegIrqMask2
bit=1 masks the matching IRQ_STATUS2 bit
constexpr uint8_tkleidos::drivers::power::py32::kRegIrqMask3
bit=1 masks the matching IRQ_STATUS3 bit
constexpr uint8_tkleidos::drivers::power::py32::kRegButtonStatus
Power-key pressed state.
constexpr uint8_tkleidos::drivers::power::py32::kRegButtonConfig1
Key timings, single-click reset, download lock.
constexpr uint8_tkleidos::drivers::power::py32::kRegButtonConfig2
Double-click power-off disable.
constexpr uint8_tkleidos::drivers::power::py32::kPowerConfigChargeEnable
POWER_CONFIG: charger on.
constexpr uint8_tkleidos::drivers::power::py32::kPowerConfigDcdcEnable
POWER_CONFIG: 3.3 V DC/DC on.
constexpr uint8_tkleidos::drivers::power::py32::kPowerConfigLdoEnable
POWER_CONFIG: 3.3 V LDO on.
constexpr uint8_tkleidos::drivers::power::py32::kPowerConfigExternalOutputEnable
POWER_CONFIG: 5 V boost on.
constexpr uint8_tkleidos::drivers::power::py32::kPowerConfigLedEnableLevel
POWER_CONFIG: LED_EN level.
constexpr uint8_tkleidos::drivers::power::py32::kHoldConfigLdoPowerHold
HOLD_CONFIG: LDO kept on.
constexpr uint8_tkleidos::drivers::power::py32::kButtonConfigSingleResetDisable
BUTTON_CONFIG1: no click reset.
constexpr uint8_tkleidos::drivers::power::py32::kButtonConfigDownloadLock
BUTTON_CONFIG1: sticky DL lock.
constexpr uint8_tkleidos::drivers::power::py32::kButtonConfigDoubleOffDisable
BUTTON_CONFIG2: no 2-click off.
constexpr uint8_tkleidos::drivers::power::py32::kButtonStatusPressed
BUTTON_STATUS: key held down.
constexpr uint8_tkleidos::drivers::power::py32::kGpio0ChargingStatusMask
GPIO_INPUT: PYG0, 0 = charging.
constexpr uint8_tkleidos::drivers::power::py32::kPygIrq
PYG1: the IRQ output, to ESP32-S3 GPIO13.
constexpr uint8_tkleidos::drivers::power::py32::kPyg1Mask
PYG1's bit in a one-bit-per-pin register.
constexpr uint8_tkleidos::drivers::power::py32::kPygLcdRail
PYG2: enables the L3B rails (LCD, codec + microphone).
constexpr uint8_tkleidos::drivers::power::py32::kPyg2Mask
PYG2's bit in a one-bit-per-pin register.
constexpr uint8_tkleidos::drivers::power::py32::kPygSpeakerAmp
PYG3: SHDN line of the AW8737A speaker amplifier.
constexpr uint8_tkleidos::drivers::power::py32::kPyg3Mask
PYG3's bit in a one-bit-per-pin register.
constexpr uint8_tkleidos::drivers::power::py32::kPygImuInt
PYG4: the BMI270's INT1 output.
constexpr uint8_tkleidos::drivers::power::py32::kPyg4Mask
PYG4's bit in a one-bit-per-pin register.
constexpr uint8_tkleidos::drivers::power::py32::kMaxPygPin
Highest PM1 GPIO index (PYG4).
constexpr uint8_tkleidos::drivers::power::py32::kGpioFieldBits
Width of one pin's field.
constexpr uint8_tkleidos::drivers::power::py32::kGpioFieldMask
One pin's field, unshifted.
constexpr uint8_tkleidos::drivers::power::py32::kGpioPinsPerReg
Pins whose fields share one register.
constexpr uint8_tkleidos::drivers::power::py32::kGpioFunctionGpio
Function field: plain GPIO.
constexpr uint8_tkleidos::drivers::power::py32::kGpioFunctionIrq
Function field: the PMIC's IRQ output.
constexpr uint8_tkleidos::drivers::power::py32::kGpioPullNone
Pull field: no pull.
constexpr uint8_tkleidos::drivers::power::py32::kGpioPullUp
Pull field: pull-up.
constexpr uint8_tkleidos::drivers::power::py32::kIrqKeyClick
IRQ_STATUS3 / IRQ_MASK3: single click.
constexpr uint8_tkleidos::drivers::power::py32::kIrqKeyWakeFlag
IRQ_STATUS3 / IRQ_MASK3: wake-source flag.
constexpr uint8_tkleidos::drivers::power::py32::kIrqKeyDoubleClick
IRQ_STATUS3 / IRQ_MASK3: double click.
constexpr uint8_tkleidos::drivers::power::py32::kIrqMask1All
constexpr uint8_tkleidos::drivers::power::py32::kIrqMask1AllButImu
IRQ_MASK1 with PYG4 alone let through: the BMI270's INT1 edges, nothing else.
constexpr uint8_tkleidos::drivers::power::py32::kIrqMask3All
IRQ_MASK3: every power-key event.
constexpr uint8_tkleidos::drivers::power::py32::kIrqMask2All
IRQ_MASK2: every power-source event.
constexpr uint8_tkleidos::drivers::power::py32::kIrqLatchClear
An IRQ latch is cleared by writing 0.
constexpr uint8_tkleidos::drivers::power::py32::kWakeSourceClear
WAKE_SRC is cleared by writing 0.
constexpr uint8_tkleidos::drivers::power::py32::kSystemCommandKey
SYS_COMMAND key nibble.
constexpr uint8_tkleidos::drivers::power::py32::kSystemCommandShutdown
SYS_COMMAND opcode: power off.
constexpr uint8_tkleidos::drivers::power::py32::kTimerActionWakeFlag
TIMER_CONFIG action: set the wake flag.
constexpr uint8_tkleidos::drivers::power::py32::kTimerActionPowerOn
TIMER_CONFIG action: power on.
constexpr uint8_tkleidos::drivers::power::py32::kTimerArm
TIMER_CONFIG: start counting.
constexpr uint8_tkleidos::drivers::power::py32::kTimerReloadKey
TIMER_KEY value that commits the timer.

Back to the top

Function Documentation

armKeyIrq() #

bool kleidos::drivers::power::py32::armKeyIrq(const bus::I2cDevice & dev, bool wakeFlag)

Route the power key's click to the PYG1 IRQ line, released.

Masks every PYG level change and power-source event, unmasks the key's click and double click (and the wake-source flag when wakeFlag is set), clears WAKE_SRC, configures PYG1 as a push-pull output driven high with its pull-up and gives it the IRQ function, then clears the three latches. Stops at the first step that fails.

Parameters
NameDirectionMeaning
devinThe M5PM1 on the internal I2C bus.
wakeFlaginAlso raise the line on the wake-source flag, which the PMIC timer's "set wake flag" action sets (a self-test of the wake path).
Return values
ValueMeaning
trueEvery step landed: the next key click pulls GPIO13 low.
falseA step failed; the line's state is unknown, so the caller reads it before arming it as a wake source.
See also
releaseKeyIrq, clearIrqLatches

armMotionIrq() #

bool kleidos::drivers::power::py32::armMotionIrq(const bus::I2cDevice & dev)

Route PYG4's level changes (the IMU's INT1) to the PYG1 IRQ line.

Masks every PYG level change but PYG4's, every power-source event and every key event, gives PYG1 the pad setup and the IRQ function of armKeyIrq, then clears the three latches. Stops at the first step that fails.

Parameters
NameDirectionMeaning
devinThe M5PM1 on the internal I2C bus.
Return values
ValueMeaning
trueEvery step landed: the next edge on PYG4 pulls GPIO13 low.
falseA step failed; the caller releases the line.
See also
clearMotionIrq, releaseKeyIrq

clearIrqLatches() #

bool kleidos::drivers::power::py32::clearIrqLatches(const bus::I2cDevice & dev)

Clear the three IRQ latches (0x40-0x42), releasing the IRQ line.

Every latch is attempted even after a failed write.

Parameters
NameDirectionMeaning
devinThe M5PM1 on the internal I2C bus.
Return values
ValueMeaning
trueAll three latches were written.
falseAt least one write failed.

clearIrqStatus() [1/2] #

bool kleidos::drivers::power::axp192::clearIrqStatus(const bus::I2cDevice & dev)

Clear every AXP192 IRQ status latch.

Writes 0xFF to the five write-1-to-clear latches (0x44-0x47, 0x4D). The enable registers are left as they are. Every latch is attempted even after a failed write.

Parameters
NameDirectionMeaning
devinThe AXP192 on the internal I2C bus.
Return values
ValueMeaning
trueAll five latches were written.
falseAt least one write failed.
See also
powerOff

clearIrqStatus() [2/2] #

bool kleidos::drivers::power::axp2101::clearIrqStatus(const bus::I2cDevice & dev)

Clear every AXP2101 IRQ status latch.

Writes 0xFF to the three write-1-to-clear latches (0x48-0x4A). The enable registers are left as they are. Every latch is attempted even after a failed write.

Parameters
NameDirectionMeaning
devinThe AXP2101 on the internal I2C bus.
Return values
ValueMeaning
trueAll three latches were written.
falseAt least one write failed.
See also
powerOff

clearMotionIrq() #

bool kleidos::drivers::power::py32::clearMotionIrq(const bus::I2cDevice & dev)

Clear the PYG level-change latch (IRQ_STATUS1), which releases the IRQ line while armMotionIrq has it routed.

Parameters
NameDirectionMeaning
devinThe M5PM1 on the internal I2C bus.
Return values
ValueMeaning
trueThe latch was written.
falseThe write failed.

configurePowerKey() [1/2] #

bool kleidos::drivers::power::axp192::configurePowerKey(const bus::I2cDevice & dev)

Pin the AXP192 power-key timing and its IRQ enables.

Sets POK_SET (0x36) to kPowerKeyTiming and the short- and long-press enables of INTEN3 (0x42), leaving its other enables untouched. A register that already holds the value is not rewritten. Both registers are attempted even when the first one fails.

Parameters
NameDirectionMeaning
devinThe AXP192 on the internal I2C bus.
Return values
ValueMeaning
trueBoth registers hold the pinned values.
falseAn I2C transaction failed; that register keeps its old value.
See also
clearIrqStatus, powerOff

configurePowerKey() [2/2] #

bool kleidos::drivers::power::axp2101::configurePowerKey(const bus::I2cDevice & dev)

Pin the AXP2101 power-key timing, its OFFLEVEL action and its IRQ enables.

Sets the timing fields of IRQ_OFF_ON_LEVEL_CTRL (0x27, reserved bits 7..6 preserved), makes an OFFLEVEL hold a power-off rather than a restart in PWROFF_EN (0x22, bit2 preserved), and sets the power-key field of INTEN2 (0x41) to short and long press only, leaving its VBUS and battery enables untouched. A register that already holds the value is not rewritten. All three registers are attempted even when one fails.

Parameters
NameDirectionMeaning
devinThe AXP2101 on the internal I2C bus.
Return values
ValueMeaning
trueAll three registers hold the pinned values.
falseAn I2C transaction failed; that register keeps its old value.
See also
clearIrqStatus, powerOff

createPmic() #

IPmic * kleidos::drivers::power::createPmic(uint8_t address)

Probes the PMIC at address, returning a ready singleton driver for the detected chip, or nullptr if none is present/supported. The returned pointer is owned by the driver layer (static storage); callers must not delete it.

The AXP192 and AXP2101 share I2C address 0x34 — the factory probes kRegChipId to disambiguate. The IP5306 sits on 0x75. The PY32/M5PM1 PMIC is not exposed through this interface; it has its own Py32Pmic driver because its register layout and lifecycle are fundamentally different.

Parameters
NameDirectionMeaning
addressinI2C address to probe.
Returns
Pointer to the singleton PMIC driver, or nullptr.
See also
Axp192, Axp2101, Ip5306

gpioFieldReg() #

uint8_t kleidos::drivers::power::py32::gpioFieldReg(uint8_t firstReg, uint8_t pin)
constexpr

Register holding PYG pin's two-bit field, given the first of the pair.

Parameters
NameDirectionMeaning
firstReginGPIO_FUNC0 (0x16) or GPIO_PU_PD0 (0x14).
pininPM1 GPIO index (0..4).
Returns
firstReg for PYG0..PYG3, the next register for PYG4.

gpioFieldShift() #

uint8_t kleidos::drivers::power::py32::gpioFieldShift(uint8_t pin)
constexpr

Bit position of PYG pin's two-bit field in its register.

Parameters
NameDirectionMeaning
pininPM1 GPIO index (0..4).
Returns
0, 2, 4 or 6.

parkUnusedOutputs() #

bool kleidos::drivers::power::axp192::parkUnusedOutputs(const bus::I2cDevice & dev, const UnusedOutputs & outputs)

Put the AXP192 outputs a board never uses in their off state.

The chip keeps its registers across an ESP32 reset or a reflash, so an output the firmware never writes holds whatever the last firmware on the board left there. This writes each output named in outputs:

Output Register Written
EXTEN OUTPUT_ENABLE (0x12) bit6 0
DC-DC2 OUTPUT_ENABLE (0x12) bit4 0
DC-DC3 OUTPUT_ENABLE (0x12) bit1 0
LDO3 OUTPUT_ENABLE (0x12) bit3 0
GPIO0 GPIO0_CTL (0x90) bits2..0 11x, floating
GPIO1 GPIO1_CTL (0x92) bits2..0 11x, floating
GPIO2 GPIO2_CTL (0x93) bits2..0 101, held low

The other bits of each register are preserved, a register that already holds the value is not rewritten, and every register is attempted even after one fails. Nothing is written unless the chip at dev identifies itself as an AXP192.

Parameters
NameDirectionMeaning
devinThe AXP192 on the internal I2C bus.
outputsinWhich outputs the board leaves unused.
Return values
ValueMeaning
trueEvery named output holds its off state (also when none is named).
falseThe chip is not an AXP192, or an I2C transaction failed.

powerOff() [1/2] #

bool kleidos::drivers::power::axp192::powerOff(const bus::I2cDevice & dev)

Switch the board off at the AXP192.

Clears every IRQ latch, then sets OFF_CTL (0x32) bit7, preserving the register's other bits. Every output except LDO1 (the RTC supply) drops, and the board returns only through a power-on source of the chip (its power key), as a cold boot. The power-off bit is not written when a latch could not be cleared.

Parameters
NameDirectionMeaning
devinThe AXP192 on the internal I2C bus.
Return values
ValueMeaning
trueThe power-off command was written. If execution continues afterwards, the board did not switch off.
falseA step failed and the power-off command was not written.
See also
clearIrqStatus

powerOff() [2/2] #

bool kleidos::drivers::power::axp2101::powerOff(const bus::I2cDevice & dev)

Switch the board off at the AXP2101.

Masks every IRQ enable (0x40-0x42), clears every IRQ latch, then sets COMMON_CONFIG (0x10) bit0, preserving the register's other bits. Every output except the RTC LDO drops, and the board returns only through a power-on source of the chip (its power key, or its IRQ pin pulled low), as a cold boot. The power-off bit is not written when an enable could not be masked or a latch could not be cleared. A power-off that lands does not keep the masks: the chip's next power-on restores INTEN1..3 to their power-on values (read back on the CoreS3 SE). One that does not land leaves them masked: the next configurePowerKey() (every begin()) re-enables only the short- and long-press bits of INTEN2, and every other enable of INTEN1..3 stays at 0 until the next PMIC power cycle.

Parameters
NameDirectionMeaning
devinThe AXP2101 on the internal I2C bus.
Return values
ValueMeaning
trueThe power-off command was written. If execution continues afterwards, the board did not switch off.
falseA step failed and the power-off command was not written.
See also
clearIrqStatus, configurePowerKey

releaseKeyIrq() #

bool kleidos::drivers::power::py32::releaseKeyIrq(const bus::I2cDevice & dev)

Return PYG1 to the PMIC's reset state, a plain input.

Gives PYG1 the GPIO function first, which leaves no IRQ pin, so the PMIC clears its latches; then input direction, open-drain, no pull, output latch low. Every step is attempted even after a failed one.

Parameters
NameDirectionMeaning
devinThe M5PM1 on the internal I2C bus.
Return values
ValueMeaning
trueEvery step landed.
falseAt least one I2C transaction failed.
See also
armKeyIrq

setGpioFunction() #

bool kleidos::drivers::power::py32::setGpioFunction(const bus::I2cDevice & dev, uint8_t pin, uint8_t function)

Set PYG pin's two-bit function field, preserving the other pins'.

Parameters
NameDirectionMeaning
devinThe M5PM1 on the internal I2C bus.
pininPM1 GPIO index (0..4).
functioninkGpioFunctionGpio or kGpioFunctionIrq.
Return values
ValueMeaning
trueThe field holds function.
falsepin or function is out of range, or an I2C transaction failed.

setGpioLevel() #

bool kleidos::drivers::power::py32::setGpioLevel(const bus::I2cDevice & dev, uint8_t pin, bool high)

Drive PYG pin high or low, and nothing else: its bit of the output register, preserving the other pins'.

For a pin already configured as a push-pull output with the GPIO function, which is how a line that toggles often is switched (the speaker amplifier's gate, raised and lowered around every sound): one read and one write, where the whole pad sequence is four of each.

Parameters
NameDirectionMeaning
devinThe M5PM1 on the internal I2C bus.
pininPM1 GPIO index (0..4).
highinTrue to drive the pin high.
Return values
ValueMeaning
trueThe pin's output bit holds high.
falsepin is out of range, or an I2C transaction failed.

Back to the top

Variable Documentation

kBoardRailsEnable #

uint8_t kleidos::drivers::power::axp2101::kBoardRailsEnable
constexpr

The CoreS3 SE's LDO rails, written in one go before the panel's first init: ALDO1 (VDD_1V8, the AW88298's DVDD), ALDO2 (VDDA_3V3, the ES7210's supplies), ALDO4 (VDD_3V3_SD, the microSD socket) and DLDO1 (VCC_BL, the backlight). The panel's own logic is on DC-DC1. ALDO3 (VDDCAM_3V3), BLDO1 (AVDD) and BLDO2 (DVDD) reach only the camera footprint the SE leaves empty, and CPUSLDO no pin of the board: the write switches all four off (M5Stack's schematic, boards repo cores3-se netlist). Their power-on state left ALDO3 on, and M5Stack's CoreS3 bring-up, which this value replaced, wrote 0xBF.

kBusOutEnableBit #

uint8_t kleidos::drivers::power::aw9523::kBusOutEnableBit
constexpr

AW9523 P0.1 BUS_OUT_EN: high closes U14 (the boost's 5 V out to the bus) and opens U19 (the bus's 5 V in).

kDc2EnableBit #

uint8_t kleidos::drivers::power::axp192::kDc2EnableBit
constexpr

DC-DC2 enable. On the StickC Plus boards and the Core2 v1.3 no part takes DC-DC2's output: the schematics leave its pins unconnected.

kDc3EnableBit #

uint8_t kleidos::drivers::power::axp192::kDc3EnableBit
constexpr

0x02

kDldo1EnableBit #

uint8_t kleidos::drivers::power::axp2101::kDldo1EnableBit
constexpr

DLDO1 enable (the CoreS3 SE's backlight).

kExtenEnableBit #

uint8_t kleidos::drivers::power::axp192::kExtenEnableBit
constexpr

EXTEN pin: the board's 5 V boost enable. The datasheet (rev 1.1, p. 36) documents the switch at REG10H bit 2; REG12H bit 6 is the same switch: on the M5StickC Plus SE and the Core2 v1.3, writing either bit sets the other on read-back, and clearing either clears both; on the Core2 v1.3 either bit brings the boost's BUS_5V up on the AXP192's own VBUS input, read at 5.0-5.2 V. The datasheet pairs DC-DC2 the same way (REG10H bit 0, REG12H bit 4).

kGpioFunctionLow #

uint8_t kleidos::drivers::power::axp192::kGpioFunctionLow
constexpr

Function 101: the pin is driven low.

kIrqEnablePowerKeyLong #

uint8_t kleidos::drivers::power::axp192::kIrqEnablePowerKeyLong
constexpr

Long-press IRQ enable.

kIrqEnablePowerKeyPress #

uint8_t kleidos::drivers::power::axp2101::kIrqEnablePowerKeyPress
constexpr

The pinned key enables: short and long press latch, the raw edges do not (nothing reads or clears them, so an enabled edge would keep the IRQ output asserted).

kIrqMask1All #

uint8_t kleidos::drivers::power::py32::kIrqMask1All
constexpr

IRQ_MASK1: every PYG0..PYG4 level change

kIrqPowerKeyRising #

uint8_t kleidos::drivers::power::axp2101::kIrqPowerKeyRising
constexpr

PWRON rising edge.

kOutputP0Init #

uint8_t kleidos::drivers::power::aw9523::kOutputP0Init
constexpr

Port 0 pins begin() drives high.

kOutputP0InitMask #

uint8_t kleidos::drivers::power::aw9523::kOutputP0InitMask
constexpr

Port 0 pins begin() writes: the ones it drives high, the amplifier gate and the two power-path switch enables.

kOutputP1Init #

uint8_t kleidos::drivers::power::aw9523::kOutputP1Init
constexpr

Port 1 pins begin() drives high.

kPowerKeyOffLevel4s #

uint8_t kleidos::drivers::power::axp192::kPowerKeyOffLevel4s
constexpr

OFFLEVEL code 0: a 4 s hold powers off.

kPowerKeyOnLevel128Ms #

uint8_t kleidos::drivers::power::axp2101::kPowerKeyOnLevel128Ms
constexpr

ONLEVEL code 0: 128 ms press powers on.

kRegAcinCurrent #

uint8_t kleidos::drivers::power::axp192::kRegAcinCurrent
constexpr
  • 0x59[3:0]

kRegAcinVoltage #

uint8_t kleidos::drivers::power::axp192::kRegAcinVoltage
constexpr
  • 0x57[3:0]

kRegBatteryChargeCurrent #

uint8_t kleidos::drivers::power::axp192::kRegBatteryChargeCurrent
constexpr
  • 0x7B[3:0]

kRegBatteryDischargeCurrent #

uint8_t kleidos::drivers::power::axp192::kRegBatteryDischargeCurrent
constexpr
  • 0x7D[4:0]

kRegInternalTemp #

uint8_t kleidos::drivers::power::axp192::kRegInternalTemp
constexpr
  • 0x5F[3:0]

kRegIrqStatus3 #

uint8_t kleidos::drivers::power::axp2101::kRegIrqStatus3
constexpr

INTSTS3: latches for INTEN3.

kRegIrqStatus5 #

uint8_t kleidos::drivers::power::axp192::kRegIrqStatus5
constexpr

INTSTS5: GPIO edges, timer timeout.

kRegTdieAdc #

uint8_t kleidos::drivers::power::axp2101::kRegTdieAdc
constexpr
  • 0x3D

kRegVbusCurrent #

uint8_t kleidos::drivers::power::axp192::kRegVbusCurrent
constexpr
  • 0x5D[3:0]

kRegVbusVoltage [1/2] #

uint8_t kleidos::drivers::power::axp192::kRegVbusVoltage
constexpr
  • 0x5B[3:0]

kRegVbusVoltage [2/2] #

uint8_t kleidos::drivers::power::axp2101::kRegVbusVoltage
constexpr
  • 0x39

kUsbOtgEnableBit #

uint8_t kleidos::drivers::power::aw9523::kUsbOtgEnableBit
constexpr

AW9523 P0.5 USB_OTG_EN: high closes U17 (5 V out to the USB-C port) and opens U18 (the port's VBUS into the PMIC), so a high level cuts the USB supply.

Back to the top