In development. It changes without notice.
Topic
Power, Battery & Parking
How each board sleeps, why it woke, what its battery says, and how hardware that nothing is using is switched off.
| Power manager | Boards | What it reads and commands |
|---|---|---|
| PowerManagerAXP2101 | Core2 v1.3, CoreS3 SE, M5StickC Plus 1.1, M5StickC Plus SE | The AXP192 or AXP2101 power chip, which switches the board off |
| PowerManagerM5PM1 | M5StickS3 | The M5PM1 power chip, through which the power key ends the sleep |
| PowerManagerAdcBattery | M5StickC Plus2 | The battery's voltage, and the pin that holds the supply on |
| PowerManagerCoreInk | CoreInk | The same, with the clock chip's alarm |
| PowerManagerCardputerAdv | M5Cardputer ADV | The battery's voltage, and the ESP's deep sleep |
| PowerManagerTDeck | LILYGO T-Deck | The battery's voltage, and the rail that feeds its parts |
The battery is read every few seconds on the loop's own ticks, and at once when the panel wakes; every screen and the portal show that one sample. Before a deep sleep that a key ends, the manager waits for the key to be released, since a key still down would end the sleep at once.
The idle tick switches off, or holds still, each part that nothing is using, through a named switch of the board.
Files | |
| file | src/ |
| The one battery reading the firmware shows, taken every few seconds. | |
| file | src/ |
| When the idle tick parks a peripheral that nothing is using. | |
| file | src/ |
| Parking of the unused IR transmitter LED. | |
| file | src/ |
| Switch one named peripheral role off or on, on THIS board. | |
| file | src/ |
| The per-board peripheral switch table: generic names, and the mechanism each one resolves to on a board with given capabilities. | |
| file | src/ |
| The PMIC power-off sleep: the order of its steps, its BM8563 disarm (shared with the power-hold release), and the filter that keeps the power-key press that switched the board on from locking it. | |
| file | src/ |
| Abstract power-management interface for the HAL. | |
| file | src/ |
| PowerManager backend that reads battery state from a raw ADC pin. | |
| file | src/ |
| PowerManager backend for AXP-family PMICs (AXP192 and AXP2101). | |
| file | src/ |
| PowerManager backend for the M5PM1 (PY32) PMIC. | |
| file | src/ |
| The last two steps of an ESP deep sleep woken by keys. | |
Functions | |
| constexpr bool | kleidos:: |
| Whether this frame should park the role. | |
| void | kleidos:: |
| Drive the IR LED pin to its inactive level. | |
| const Caps & | kleidos:: |
| What this board declares, as the switch table reads it. | |
| Spec | kleidos:: |
How id is switched on this board. | |
| Reading | kleidos:: |
| Read a role's current state. | |
| Reading | kleidos:: |
| The last state this command asked for, in this session. | |
| Outcome | kleidos:: |
Apply one request: switch id off or on. | |
| void | kleidos:: |
| Park every peripheral nothing is using right now. | |
| void | kleidos:: |
| Park everything the peripheral rail orphans, before its supply drops. | |
| void | kleidos:: |
| Release the deep-sleep holds parkRailLoads latched. | |
| bool | kleidos:: |
| Drive low the chip-selects the cut peripheral rail would be fed through. | |
| SleepApportion | kleidos:: |
| Whether a peripheral off state can move THIS board's SLEEP current. | |
| size_t | kleidos:: |
| Every role that has a mechanism here and does not need the bang. | |
| void | kleidos:: |
| Write a Spec's mechanism detail as the reply prints it. | |
| const char * | kleidos:: |
| The name of a role, as the console spells it (e.g. "SD", "PERIPHRAIL"). | |
| const char * | kleidos:: |
| One word for a mechanism kind, as the reply prints it before its detail. | |
| const char * | kleidos:: |
| The reply's word for a verdict. | |
| SleepApportion | kleidos:: |
| Whether an off state can move this board's sleep current. | |
| const char * | kleidos:: |
| The reply's token for a SleepApportion. | |
| const char * | kleidos:: |
| The reply's token for a refusal reason, e.g. "not_fitted". | |
| bool | kleidos:: |
| Resolve a console token to a role, case-insensitively. | |
| ParseResult | kleidos:: |
| Parse one or more identifiers from a command tail. | |
| Spec | kleidos:: |
| How a role is switched on a board with these capabilities. | |
| const Id * | kleidos:: |
The loads of the one peripheral rail, for a COARSE line's also= list. | |
| RtcDisarmResult | kleidos:: |
| Disarm both BM8563 interrupt sources before a supply cut. | |
| PowerOffResult | kleidos:: |
| Switch the board off at its PMIC, the BM8563 disarmed first. | |
| bool | kleidos:: |
| Wait, bounded, until every wake key reads released (high). | |
| bool | kleidos:: |
| Arm active-low wake keys for an ESP deep sleep. | |
Variables | |
| constexpr size_t | kleidos:: |
| Longest mechanism detail formatMech writes, including the terminator. | |
| constexpr size_t | kleidos:: |
| Maximum identifiers one request may carry. | |
| constexpr size_t | kleidos:: |
| Longest identifier the parser echoes back when it does not recognize one. | |
| constexpr uint8_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| Wait between two tries of a step that failed on the bus, in ms. | |
| constexpr uint32_t | kleidos:: |
| Wait after a power-off command was written, in ms. | |
| constexpr uint32_t | kleidos:: |
| Uptime within which a latched power-key click may still be the press that powered the board on, in ms. | |
| constexpr uint32_t | kleidos:: |
| Longest wait for a wake key that is still down when its sleep starts. | |
Enumeration Type Documentation
CardOnRestore #
What a rail coming back does with the SD card on it.
| Enumerator | |
|---|---|
| Remount | Mount it again, as switching the card on does: a full mount, the card identified and its volume mounted. A slot known empty ( |
| LeaveCold | Send it no command: it stays as its supply left it, uninitialized, until something mounts it. How a measurement of the cold card leaves it. |
Id #
Every peripheral role the command knows a name for, switchable or not.
The order is the order the debug console lists them in: the roles that can be switched on some board first, then the names that exist only to be refused for a stated reason.
Mech #
How a role is switched on a given board.
Refusal #
Why a request was refused.
| Enumerator | |
|---|---|
| None | Not refused. |
| NotFitted | The part is not on this board. |
| NotSwitchable | Fitted, but this board exposes no way to switch it. |
| RailUnidentified | A rail exists but no file here says which one it is. |
| UseOtherCommand | Another console command owns it; Spec::pointer names it. |
| NeedsBang | It can strand the board: the bang form is required. |
| Unavailable | Fitted and switchable, but the driver did not answer its probe. |
| NotApplied | The mechanism was attempted and the bus/driver refused it. |
| NothingToRestore | An ON with no state this session saved to restore. |
Scope #
SleepApportion #
Verdict #
What a request did, as the reply prints it.
| Enumerator | |
|---|---|
| Ok | Applied, and the switch's scope equals the name's role. |
| Coarse | Applied by a wider switch; other roles went down with it. |
| Noop | Nothing to do: the part is already in the state asked for. |
| Refused | Not done, for the Refusal the line names. |
Function Documentation
apply() #
Apply one request: switch id off or on.
Order is fixed by the mechanism, not by the command line: a mounted card is unmounted through the facade that owns it before any rail drops, and a rail comes back with its settle and its drivers re-initialized rather than as a bare pin level.
A rail's ON blocks the calling task for the rail's settle and the drivers' re-initialization (a few hundred ms on the T-Deck).
- Parameters
-
Name Meaning id Role to switch. on True to restore it, false to switch it off. forced True when the operator used the bang form, which is required for a role whose OFF can leave the board with no input. card For a role switched by the peripheral rail, what its ON does with the SD card on the rail; ignored by every other role.
- Returns
- What was done, and the read-back where there is one.
arm() #
Arm active-low wake keys for an ESP deep sleep.
Sets each key's RTC pull-up first: a pad that wakes the sleep runs in its RTC function, where only the RTC pull applies. Then arms one key on EXT0, or several as one EXT1 any-low set (the ESP32-S3's; the classic ESP32 has no any-low EXT1 and refuses the set).
- Parameters
-
Name Direction Meaning pins in Active-low wake GPIOs, each an RTC GPIO of the SoC.
- Return values
-
Value Meaning true The wake source is armed. false pinsis empty, or the SoC refused the wake configuration.
awaitReleased() #
Wait, bounded, until every wake key reads released (high).
A lock started by a press of the wake key itself (the Cardputer's side key) can reach the sleep while the key is still down. Polls the keys, feeding the calling task's watchdog between reads, until all read high or timeoutMs has passed.
- Parameters
-
Name Direction Meaning pins in Active-low wake GPIOs, still configured as digital inputs (call before arm). timeoutMs in Longest wait in milliseconds.
- Return values
-
Value Meaning true Every key read released. false A key was still down when the wait ran out; a sleep armed on it ends as soon as it starts.
boardCaps() #
What this board declares, as the switch table reads it.
- Returns
- A reference to the one immutable record, built on first use.
disarmRtc() #
Disarm both BM8563 interrupt sources before a supply cut.
In order: disarm the RTC alarm, then the RTC countdown, each tried up to kStepAttempts times with kRetryDelayMs between two tries. A step that keeps failing does not stop the other one, and the caller goes on with its cut: the worst a live interrupt causes is a power-on straight after.
- Parameters
-
Name Direction Meaning port in, out The board's BM8563.
- Returns
- Which of the two steps succeeded.
dropRailSelects() #
Drive low the chip-selects the cut peripheral rail would be fed through.
The awake rail cut parks the radio with its select high and leaves the card's select high from its unmount: deselected is right while a chip is powered, but once its supply is gone a select held high is 3.3 V into a dead chip, which its input protection carries into the rail the cut just dropped (the back-feed the deep-sleep park avoids for the radio). Low is safe for both: the radio is held in reset beside it, and the card is unmounted. The rail's restore raises both again before any chip on it is addressed, as the boot does. For a measurement that needs the rail's chips to lose their supply, not only to be deselected, such as a measurement of the cold SD card.
Does nothing unless the last switch of the peripheral rail was an OFF this module made and no card is mounted, so it never selects the card on a live bus. The panel's select and the clock and data lines it shares with the card belong to the SPI peripheral and are not touched.
- Return values
-
Value Meaning true The rail is cut and the selects were driven low. false The rail is not cut by this module, or a card is mounted: nothing changed.
formatMech() #
Write a Spec's mechanism detail as the reply prints it.
none, driver:<call>, field:<chip>.<REG>.<field>, gpio:<pin>[+hold] or chipcmd:<what> — the mechanism kind plus enough detail to check it against the hardware.
- Parameters
-
Name Direction Meaning id in Role the spec belongs to (names the driver call). spec in Spec to describe. out out Destination buffer; always NUL-terminated. outLen in Capacity of out(use ::kMechTextBytes).
idFromName() #
Resolve a console token to a role, case-insensitively.
- Parameters
-
Name Direction Meaning token in Identifier as typed (not a command keyword). out out The role, on a match.
- Return values
-
Value Meaning true tokennamed a role andoutwas written.false tokennamed nothing.
idleTick() #
Park every peripheral nothing is using right now.
The production entry point into this module's parks, called once per main-loop frame from the loop task. It is what makes "parked" a peripheral's default state instead of a state some caller has to remember: a part whose owner never ran, or died with the surface that opened it, is parked on the next frame.
Today it carries one role — the GPS receiver, which sits on a supply no sleep cuts and free-runs in acquisition from power-on until a standby frame stops it. The rule that decides each role is idle_, and a park that does not take is retried after a back-off rather than on every frame.
Cheap by construction: a role that is not fitted, is in use, or is already parked costs two reads of this module's own state and no bus traffic.
- Parameters
-
Name Meaning nowMs clock::at this frame, for the back-off.millis32()
mechKindText() #
One word for a mechanism kind, as the reply prints it before its detail.
- Parameters
-
Name Meaning mech Mechanism kind.
- Returns
- "none", "driver", "field", "gpio" or "chipcmd".
nameOf() #
The name of a role, as the console spells it (e.g. "SD", "PERIPHRAIL").
- Parameters
-
Name Meaning id Role to name.
- Returns
- The role's name, or "?" for
Id::Count.
park() #
Drive the IR LED pin to its inactive level.
Releases any hold left from the last deep sleep, drives device:: to the opposite of device:: and, with hold, latches it so the level survives deep sleep (the sleep facade arms the deep-sleep hold on entry).
- Parameters
-
Name Direction Meaning hold in True to latch the level through deep sleep.
parkRailLoads() #
Park everything the peripheral rail orphans, before its supply drops.
One code path for the rail switch and for the board's own deep sleep, so the two park the same radio lines and the same input pads; the levels differ, because what is right while the chip is awake is a leak through a sleep:
- Awake (
holdfalse, the rail switch): the radio's select high and reset low, and the input pads the rail orphans (the trackball's directions, the keyboard INT) driven low, so the running edge ISRs are not fed a pad floating across the input buffer's threshold. The touch controller is not parked: it keeps its supply and drives its own INT line. - Asleep (
holdtrue, the production deep sleep): in this order, while the rail is still on and the I2C bus still up, the touch controller's own Sleep command where it takes one (INT driven low first; skipped for one sleep in a debug image), then the radio's select and reset both latched low, the orphaned input pads latched hi-Z with no pull, the touch INT latched low (or hi-Z under the knob), and akTouchIntKickSettleMswait after that latch, because on the T-Deck a falling INT edge may switch the rail on for about 10 ms. The caller ends the bus and cuts the rail after this returns, never before.
- Parameters
-
Name Meaning hold True to latch every level so it survives a deep sleep. A latched pad no longer follows its driver, so the next boot must call releaseRailLoadHolds before anything configures it (the touch INT excepted: its driver's begin releases that one).
parseNames() #
Parse one or more identifiers from a command tail.
Whitespace-separated, case-insensitive, order preserved, a repeat of a role already in the list dropped (so one rail is never cut twice). Keywords such as ALL are the caller's business: this function only knows role names.
- Parameters
-
Name Direction Meaning text in Argument tail; nullptr or empty yields a zeroed result. out out Receives the roles, in order. cap in Capacity of out.
- Returns
- What was found, including the counts of what was not.
railLoads() #
The loads of the one peripheral rail, for a COARSE line's also= list.
- Parameters
-
Name Direction Meaning count out Number of roles written.
- Returns
- Pointer to a static list of the roles that rail feeds.
readState() #
Read a role's current state.
Two mechanisms read back: a Mech::Field one through the regmap, and the keypad controller's scan stop, whose keypad-select registers are read/write. For the rest — a panel command with no status register, a PWM duty that does not prove the light is out, a fire-and-forget standby frame, a mount flag that is software, a GPIO whose own output latch proves nothing about the pad — this returns known=false, and the query says so up front, because those are the ones a careless measurement misattributes.
- Parameters
-
Name Meaning id Role to read.
- Returns
- What the hardware says, or
known=false.
refusalText() #
The reply's token for a refusal reason, e.g. "not_fitted".
- Parameters
-
Name Meaning refusal Refusal to name.
- Returns
- The reason's token, or "none" for
Refusal::None.
releaseRailLoadHolds() #
Release the deep-sleep holds parkRailLoads latched.
Call once at boot, before the rail is raised and before any driver configures its pads: a hold survives deep sleep by design, so without this the radio's select and reset would stay latched low into a powered radio, and the trackball directions and the keyboard INT would keep their latched hi-Z whatever their drivers configure. The touch INT is left latched: the touch driver's begin releases it straight into the level it wants (low for a controller it put to sleep, an input otherwise), so the line never floats in between. No-op on a board with none of those pads.
requestedState() #
The last state this command asked for, in this session.
A different claim from readState, and reported as such: it says what was requested, not what the hardware confirms. For the roles whose off state cannot be read back it is all there is, which is exactly why the two are never printed under one name.
- Parameters
-
Name Meaning id Role to look up.
- Returns
known=falseuntil this session switchedid.
safeRoles() #
Every role that has a mechanism here and does not need the bang.
What switching every role off expands to: a safe floor measurement that skips every role whose OFF could strand the board, so on the T-Deck it does not cut the rail and on a touch-only board it does not remove the only input.
- Parameters
-
Name Direction Meaning out out Receives the roles, in table order. cap in Capacity of out.
- Returns
- How many roles were written.
shouldPark() #
Whether this frame should park the role.
- Parameters
-
Name Direction Meaning in in What the caller knows about the role.
- Return values
-
Value Meaning true Park it now. false Leave it alone (not fitted, in use, already parked, or still inside the back-off of a failed attempt).
sleepApportion() #
Whether an off state can move this board's sleep current.
- Parameters
-
Name Meaning caps What the board declares.
- Returns
- Yes, No, or CableDependent (see ::
SleepApportion).
sleepApportionHere() #
Whether a peripheral off state can move THIS board's SLEEP current.
No where the production sleep removes the board's own supply (a PMIC power-off): nothing is left powered for a per-peripheral off to change, so the command is an instrument for the awake budget there and the reply must not imply a sleep saving. CableDependent where the sleep drops a power hold, which cuts the supply on battery but leaves an ESP deep sleep with the peripherals powered on USB — and USB is the cable the console is on, so a sleep step does exist there and the reply must not deny it either.
A role can still be awake-only on a board that answers Yes: Spec awakeOnly says the sleep path already does that role's own parking.
- Returns
- What a sleep measurement on this board can attribute.
sleepApportionText() #
The reply's token for a SleepApportion.
- Parameters
-
Name Meaning apportion Value to name.
- Returns
- "yes", "none" or "cable_
dependent".
specFor() #
How a role is switched on a board with these capabilities.
The one place per-board switch knowledge lives. Pure: the same caps always yields the same Spec, which is what lets the host tests assert every board's switches without a board.
- Parameters
-
Name Meaning id Role to resolve. caps What the board declares.
- Returns
- The mechanism, its scope, and any refusal.
specOf() #
How id is switched on this board.
- Parameters
-
Name Meaning id Role to resolve.
- Returns
- The table's answer for boardCaps.
switchOff() #
Switch the board off at its PMIC, the BM8563 disarmed first.
In order: disarm the RTC alarm, then the RTC countdown (disarmRtc); start the countdown rtcPowerOnSeconds asks for, if any; then write the power-off command up to kStepAttempts times, waiting kPowerOffSettleMs after each one written. A failed RTC disarm does not stop the power-off: the worst it causes is a power-on straight after, a cold boot to the unlock screen. A requested countdown that could not be started does: without it nothing would switch the board back on, so the caller's fallback keeps it reachable.
- Parameters
-
Name Direction Meaning port in, out The hardware to drive. rtcPowerOnSeconds in RTC countdown that switches the board back on, in s; 0 starts none (the production sleep, which only the power key ends).
- Returns
- What was done. The call returns only when the board is still on.
verdictText() #
The reply's word for a verdict.
- Parameters
-
Name Meaning verdict Verdict to name.
- Returns
- "OK", "COARSE", "NOOP" or "REFUSED".
Variable Documentation
kPowerKeyBootWindowMs #
Uptime within which a latched power-key click may still be the press that powered the board on, in ms.
Uptime starts after the PMIC raised the rails and the bootloader ran, and the key timing every AXP board pins at boot makes a press held for 1 s a long press, which is never a click (drivers/
kPowerOffSettleMs #
Wait after a power-off command was written, in ms.
The rails drop within a few milliseconds of the command; a board still running after this wait did not switch off, and the next try reissues it.