Kleidos API Search

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.

See also
Hardware Abstraction Layer, The boards, Power Chip Drivers, Power, Sleep & System Control

Files

file src/hal/power/battery_sampler.h
The one battery reading the firmware shows, taken every few seconds.
file src/hal/power/idle_park_logic.h
When the idle tick parks a peripheral that nothing is using.
file src/hal/power/ir_emitter.h
Parking of the unused IR transmitter LED.
file src/hal/power/peripheral_switch.h
Switch one named peripheral role off or on, on THIS board.
file src/hal/power/peripheral_switch_table.h
The per-board peripheral switch table: generic names, and the mechanism each one resolves to on a board with given capabilities.
file src/hal/power/pmic_power_off.h
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/hal/power/power_manager.h
Abstract power-management interface for the HAL.
file src/hal/power/power_manager_adc_battery.h
PowerManager backend that reads battery state from a raw ADC pin.
file src/hal/power/power_manager_axp2101.h
PowerManager backend for AXP-family PMICs (AXP192 and AXP2101).
file src/hal/power/power_manager_m5_pm1.h
PowerManager backend for the M5PM1 (PY32) PMIC.
file src/hal/power/wake_keys.h
The last two steps of an ESP deep sleep woken by keys.

Classes

struct kleidos::BatteryReading
One battery reading: the charge estimate, the terminal voltage and the charger state, read together. More about kleidos::BatteryReading
class kleidos::BatterySampler
When the battery is read, and the last reading taken. More about kleidos::BatterySampler
struct kleidos::hal::periph::idle_park::Inputs
What the idle tick knows about one role on this frame. More about kleidos::hal::periph::idle_park::Inputs
struct kleidos::hal::periph::Outcome
What one applied request did. More about kleidos::hal::periph::Outcome
struct kleidos::hal::periph::Reading
One read of a role's live state, where the hardware can tell us. More about kleidos::hal::periph::Reading
struct kleidos::hal::periph::Caps
Everything a board declares that the switch table is a function of. More about kleidos::hal::periph::Caps
struct kleidos::hal::periph::Spec
How one role is switched on one board, and at what honesty. More about kleidos::hal::periph::Spec
struct kleidos::hal::periph::ParseResult
What one parse of a whitespace-separated identifier list found. More about kleidos::hal::periph::ParseResult
class kleidos::hal::pmic_off::RtcDisarmPort
The BM8563 side of a supply cut, which disarmRtc drives. More about kleidos::hal::pmic_off::RtcDisarmPort
class kleidos::hal::pmic_off::PowerOffPort
The hardware switchOff drives: the board's BM8563 and its PMIC. More about kleidos::hal::pmic_off::PowerOffPort
struct kleidos::hal::pmic_off::RtcDisarmResult
What disarmRtc did. More about kleidos::hal::pmic_off::RtcDisarmResult
struct kleidos::hal::pmic_off::PowerOffResult
What switchOff did before it returned, which it does only while the board is still on. More about kleidos::hal::pmic_off::PowerOffResult
class kleidos::hal::pmic_off::PowerKeyBootFilter
Drops the power-key clicks that may be the press that powered the board on. More about kleidos::hal::pmic_off::PowerKeyBootFilter
class kleidos::PowerManager
Abstract power-management contract implemented by each variant backend. More about kleidos::PowerManager
class kleidos::PowerManagerAdcBattery
PowerManager implementation using a battery-divider ADC and GPIO wake. More about kleidos::PowerManagerAdcBattery
class kleidos::PowerManagerAXP2101
PowerManager implementation backed by an AXP192 or AXP2101 PMIC. More about kleidos::PowerManagerAXP2101
class kleidos::PowerManagerM5PM1
PowerManager implementation backed by the M5PM1 (PY32) PMIC. More about kleidos::PowerManagerM5PM1

Enumerations

enum class kleidos::hal::periph::CardOnRestore : uint8_t { kleidos::hal::periph::CardOnRestore::Remount , kleidos::hal::periph::CardOnRestore::LeaveCold }
What a rail coming back does with the SD card on it. More about kleidos::hal::periph::CardOnRestore
enum class kleidos::hal::periph::Id : uint8_t { kleidos::hal::periph::Id::Sd, kleidos::hal::periph::Id::Kbd, kleidos::hal::periph::Id::Touch, kleidos::hal::periph::Id::Trackball, kleidos::hal::periph::Id::Imu, kleidos::hal::periph::Id::Gps, kleidos::hal::periph::Id::Lora, kleidos::hal::periph::Id::Backlight, kleidos::hal::periph::Id::Panel, kleidos::hal::periph::Id::Spk, kleidos::hal::periph::Id::Led, kleidos::hal::periph::Id::Ext5v, kleidos::hal::periph::Id::PeriphRail, kleidos::hal::periph::Id::Ble, kleidos::hal::periph::Id::Wifi, kleidos::hal::periph::Id::I2c, kleidos::hal::periph::Id::Rtc, kleidos::hal::periph::Id::Btn, kleidos::hal::periph::Id::Expander, kleidos::hal::periph::Id::Charger, kleidos::hal::periph::Id::Hold, kleidos::hal::periph::Id::KbdLight, kleidos::hal::periph::Id::Count }
enum class kleidos::hal::periph::Mech : uint8_t { kleidos::hal::periph::Mech::None, kleidos::hal::periph::Mech::Driver, kleidos::hal::periph::Mech::Field, kleidos::hal::periph::Mech::Gpio, kleidos::hal::periph::Mech::ChipCmd }
How a role is switched on a given board. More about kleidos::hal::periph::Mech
enum class kleidos::hal::periph::Scope : uint8_t { kleidos::hal::periph::Scope::Exact , kleidos::hal::periph::Scope::Wider }
Whether the switch that serves a name covers only that name's role. More about kleidos::hal::periph::Scope
enum class kleidos::hal::periph::Verdict : uint8_t { kleidos::hal::periph::Verdict::Ok , kleidos::hal::periph::Verdict::Coarse , kleidos::hal::periph::Verdict::Noop , kleidos::hal::periph::Verdict::Refused }
What a request did, as the reply prints it. More about kleidos::hal::periph::Verdict
enum class kleidos::hal::periph::Refusal : uint8_t { kleidos::hal::periph::Refusal::None, kleidos::hal::periph::Refusal::NotFitted, kleidos::hal::periph::Refusal::NotSwitchable, kleidos::hal::periph::Refusal::RailUnidentified, kleidos::hal::periph::Refusal::UseOtherCommand, kleidos::hal::periph::Refusal::NeedsBang, kleidos::hal::periph::Refusal::Unavailable, kleidos::hal::periph::Refusal::NotApplied, kleidos::hal::periph::Refusal::NothingToRestore }
Why a request was refused. More about kleidos::hal::periph::Refusal
enum class kleidos::hal::periph::SleepApportion : uint8_t { kleidos::hal::periph::SleepApportion::Yes , kleidos::hal::periph::SleepApportion::No , kleidos::hal::periph::SleepApportion::CableDependent }
Whether a peripheral off state can move this board's SLEEP current. More about kleidos::hal::periph::SleepApportion

Functions

constexpr boolkleidos::hal::periph::idle_park::shouldPark (const Inputs &in)
Whether this frame should park the role.
voidkleidos::hal::ir_emitter::park (bool hold)
Drive the IR LED pin to its inactive level.
const Caps &kleidos::hal::periph::boardCaps ()
What this board declares, as the switch table reads it.
Speckleidos::hal::periph::specOf (Id id)
How id is switched on this board.
Readingkleidos::hal::periph::readState (Id id)
Read a role's current state.
Readingkleidos::hal::periph::requestedState (Id id)
The last state this command asked for, in this session.
Outcomekleidos::hal::periph::apply (Id id, bool on, bool forced, CardOnRestore card=CardOnRestore::Remount)
Apply one request: switch id off or on.
voidkleidos::hal::periph::idleTick (uint32_t nowMs)
Park every peripheral nothing is using right now.
voidkleidos::hal::periph::parkRailLoads (bool hold)
Park everything the peripheral rail orphans, before its supply drops.
voidkleidos::hal::periph::releaseRailLoadHolds ()
Release the deep-sleep holds parkRailLoads latched.
boolkleidos::hal::periph::dropRailSelects ()
Drive low the chip-selects the cut peripheral rail would be fed through.
SleepApportionkleidos::hal::periph::sleepApportionHere ()
Whether a peripheral off state can move THIS board's SLEEP current.
size_tkleidos::hal::periph::safeRoles (Id *out, size_t cap)
Every role that has a mechanism here and does not need the bang.
voidkleidos::hal::periph::formatMech (Id id, const Spec &spec, char *out, size_t outLen)
Write a Spec's mechanism detail as the reply prints it.
const char *kleidos::hal::periph::nameOf (Id id)
The name of a role, as the console spells it (e.g. "SD", "PERIPHRAIL").
const char *kleidos::hal::periph::mechKindText (Mech mech)
One word for a mechanism kind, as the reply prints it before its detail.
const char *kleidos::hal::periph::verdictText (Verdict verdict)
The reply's word for a verdict.
SleepApportionkleidos::hal::periph::sleepApportion (const Caps &caps)
Whether an off state can move this board's sleep current.
const char *kleidos::hal::periph::sleepApportionText (SleepApportion apportion)
The reply's token for a SleepApportion.
const char *kleidos::hal::periph::refusalText (Refusal refusal)
The reply's token for a refusal reason, e.g. "not_fitted".
boolkleidos::hal::periph::idFromName (const char *token, Id &out)
Resolve a console token to a role, case-insensitively.
ParseResultkleidos::hal::periph::parseNames (const char *text, Id *out, size_t cap)
Parse one or more identifiers from a command tail.
Speckleidos::hal::periph::specFor (Id id, const Caps &caps)
How a role is switched on a board with these capabilities.
const Id *kleidos::hal::periph::railLoads (size_t &count)
The loads of the one peripheral rail, for a COARSE line's also= list.
RtcDisarmResultkleidos::hal::pmic_off::disarmRtc (RtcDisarmPort &port)
Disarm both BM8563 interrupt sources before a supply cut.
PowerOffResultkleidos::hal::pmic_off::switchOff (PowerOffPort &port, uint8_t rtcPowerOnSeconds)
Switch the board off at its PMIC, the BM8563 disarmed first.
boolkleidos::hal::wake_keys::awaitReleased (std::span< const int > pins, uint32_t timeoutMs)
Wait, bounded, until every wake key reads released (high).
boolkleidos::hal::wake_keys::arm (std::span< const int > pins)
Arm active-low wake keys for an ESP deep sleep.

Variables

constexpr size_tkleidos::hal::periph::kMechTextBytes
Longest mechanism detail formatMech writes, including the terminator.
constexpr size_tkleidos::hal::periph::kMaxRequestedNames
Maximum identifiers one request may carry.
constexpr size_tkleidos::hal::periph::kMaxTokenBytes
Longest identifier the parser echoes back when it does not recognize one.
constexpr uint8_tkleidos::hal::pmic_off::kStepAttempts
constexpr uint32_tkleidos::hal::pmic_off::kRetryDelayMs
Wait between two tries of a step that failed on the bus, in ms.
constexpr uint32_tkleidos::hal::pmic_off::kPowerOffSettleMs
Wait after a power-off command was written, in ms.
constexpr uint32_tkleidos::hal::pmic_off::kPowerKeyBootWindowMs
Uptime within which a latched power-key click may still be the press that powered the board on, in ms.
constexpr uint32_tkleidos::hal::wake_keys::kReleaseWaitMs
Longest wait for a wake key that is still down when its sleep starts.

Back to the top

Enumeration Type Documentation

CardOnRestore #

enum class kleidos::hal::periph::CardOnRestore : uint8_t

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 (SdCard::slotKnownEmpty) is left alone: the mount could only fail.

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 #

enum class kleidos::hal::periph::Id : uint8_t

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.

Enumerator
Sd 

The micro-SD slot: the card, its SPI host and the FATFS mount.

Kbd 

The board's own physical key matrix.

Touch 

The capacitive touch panel.

Trackball 

Trackball directions (the center click is never switchable).

Imu 

Accelerometer / gyroscope.

Gps 

GNSS receiver.

Lora 

Sub-GHz LoRa transceiver.

Backlight 

The light behind the glass, and nothing else.

Panel 

The display controller itself.

Spk 

The speaker output path's amplifier gate.

Led 

The board's status LED.

Ext5v 

The 5 V boost / external header output.

PeriphRail 

A whole firmware-switched peripheral supply rail.

Ble 

Refused: a radio with an owner, stopped through its owner.

Wifi 

Refused: a radio with an owner, stopped through its owner.

I2c 

Refused: parking the bus can strand the board.

Rtc 

Refused: not switchable on any board.

Btn 

Refused: a passive switch has no off state.

Expander 

Refused: its pins already belong to PANEL and SPK.

Charger 

Refused: an off state that outlives the session.

Hold 

Refused: the board's own power hold, not a peripheral.

KbdLight 

Refused: another command drives the keyboard light.

Count 

Number of names (not a name).

Mech #

enum class kleidos::hal::periph::Mech : uint8_t

How a role is switched on a given board.

Enumerator
None 

Nothing to switch: no rail, no pin, no chip command.

Driver 

A driver/facade call owns the teardown and the restore.

Field 

A named bit-field of a chip register (regmap read-modify-write).

Gpio 

A board GPIO level, optionally latched through deep sleep.

ChipCmd 

A command putting the part into its own lowest-power mode.

Refusal #

enum class kleidos::hal::periph::Refusal : uint8_t

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 #

enum class kleidos::hal::periph::Scope : uint8_t

Whether the switch that serves a name covers only that name's role.

Enumerator
Exact 

The switch covers this role and nothing else.

Wider 

A wider switch serves it; other roles go down with it.

SleepApportion #

enum class kleidos::hal::periph::SleepApportion : uint8_t

Whether a peripheral off state can move this board's SLEEP current.

Enumerator
Yes 

The sleep leaves peripherals powered (an ESP deep sleep).

No 

The sleep cuts the board's own supply: only AWAKE moves.

CableDependent 

A dropped power hold: the supply goes on battery, not on USB.

Verdict #

enum class kleidos::hal::periph::Verdict : uint8_t

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.

Back to the top

Function Documentation

apply() #

Outcome kleidos::hal::periph::apply(Id id, bool on, bool forced, CardOnRestore card = CardOnRestore::Remount)

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
NameMeaning
idRole to switch.
onTrue to restore it, false to switch it off.
forcedTrue when the operator used the bang form, which is required for a role whose OFF can leave the board with no input.
cardFor 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() #

bool kleidos::hal::wake_keys::arm(std::span< const int > pins)

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
NameDirectionMeaning
pinsinActive-low wake GPIOs, each an RTC GPIO of the SoC.
Return values
ValueMeaning
trueThe wake source is armed.
falsepins is empty, or the SoC refused the wake configuration.

awaitReleased() #

bool kleidos::hal::wake_keys::awaitReleased(std::span< const int > pins, uint32_t timeoutMs)

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
NameDirectionMeaning
pinsinActive-low wake GPIOs, still configured as digital inputs (call before arm).
timeoutMsinLongest wait in milliseconds.
Return values
ValueMeaning
trueEvery key read released.
falseA key was still down when the wait ran out; a sleep armed on it ends as soon as it starts.

boardCaps() #

const Caps & kleidos::hal::periph::boardCaps()

What this board declares, as the switch table reads it.

Returns
A reference to the one immutable record, built on first use.

disarmRtc() #

RtcDisarmResult kleidos::hal::pmic_off::disarmRtc(RtcDisarmPort & port)

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
NameDirectionMeaning
portin, outThe board's BM8563.
Returns
Which of the two steps succeeded.

dropRailSelects() #

bool kleidos::hal::periph::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
ValueMeaning
trueThe rail is cut and the selects were driven low.
falseThe rail is not cut by this module, or a card is mounted: nothing changed.

formatMech() #

void kleidos::hal::periph::formatMech(Id id, const Spec & spec, char * out, size_t outLen)

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
NameDirectionMeaning
idinRole the spec belongs to (names the driver call).
specinSpec to describe.
outoutDestination buffer; always NUL-terminated.
outLeninCapacity of out (use ::kMechTextBytes).

idFromName() #

bool kleidos::hal::periph::idFromName(const char * token, Id & out)

Resolve a console token to a role, case-insensitively.

Parameters
NameDirectionMeaning
tokeninIdentifier as typed (not a command keyword).
outoutThe role, on a match.
Return values
ValueMeaning
truetoken named a role and out was written.
falsetoken named nothing.

idleTick() #

void kleidos::hal::periph::idleTick(uint32_t nowMs)

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_park::shouldPark, 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
NameMeaning
nowMsclock::millis32() at this frame, for the back-off.

mechKindText() #

const char * kleidos::hal::periph::mechKindText(Mech mech)

One word for a mechanism kind, as the reply prints it before its detail.

Parameters
NameMeaning
mechMechanism kind.
Returns
"none", "driver", "field", "gpio" or "chipcmd".

nameOf() #

const char * kleidos::hal::periph::nameOf(Id id)

The name of a role, as the console spells it (e.g. "SD", "PERIPHRAIL").

Parameters
NameMeaning
idRole to name.
Returns
The role's name, or "?" for Id::Count.

park() #

void kleidos::hal::ir_emitter::park(bool hold)

Drive the IR LED pin to its inactive level.

Releases any hold left from the last deep sleep, drives device::kPinIrTx to the opposite of device::kIrTxActiveHigh and, with hold, latches it so the level survives deep sleep (the sleep facade arms the deep-sleep hold on entry).

Parameters
NameDirectionMeaning
holdinTrue to latch the level through deep sleep.

parkRailLoads() #

void kleidos::hal::periph::parkRailLoads(bool hold)

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 (hold false, 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 (hold true, 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 a kTouchIntKickSettleMs wait 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
NameMeaning
holdTrue 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() #

ParseResult kleidos::hal::periph::parseNames(const char * text, Id * out, size_t cap)

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
NameDirectionMeaning
textinArgument tail; nullptr or empty yields a zeroed result.
outoutReceives the roles, in order.
capinCapacity of out.
Returns
What was found, including the counts of what was not.

railLoads() #

const Id * kleidos::hal::periph::railLoads(size_t & count)

The loads of the one peripheral rail, for a COARSE line's also= list.

Parameters
NameDirectionMeaning
countoutNumber of roles written.
Returns
Pointer to a static list of the roles that rail feeds.

readState() #

Reading kleidos::hal::periph::readState(Id id)

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
NameMeaning
idRole to read.
Returns
What the hardware says, or known=false.

refusalText() #

const char * kleidos::hal::periph::refusalText(Refusal refusal)

The reply's token for a refusal reason, e.g. "not_fitted".

Parameters
NameMeaning
refusalRefusal to name.
Returns
The reason's token, or "none" for Refusal::None.

releaseRailLoadHolds() #

void kleidos::hal::periph::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() #

Reading kleidos::hal::periph::requestedState(Id id)

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
NameMeaning
idRole to look up.
Returns
known=false until this session switched id.

safeRoles() #

size_t kleidos::hal::periph::safeRoles(Id * out, size_t cap)

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
NameDirectionMeaning
outoutReceives the roles, in table order.
capinCapacity of out.
Returns
How many roles were written.

shouldPark() #

bool kleidos::hal::periph::idle_park::shouldPark(const Inputs & in)
constexpr

Whether this frame should park the role.

Parameters
NameDirectionMeaning
ininWhat the caller knows about the role.
Return values
ValueMeaning
truePark it now.
falseLeave it alone (not fitted, in use, already parked, or still inside the back-off of a failed attempt).

sleepApportion() #

SleepApportion kleidos::hal::periph::sleepApportion(const Caps & caps)

Whether an off state can move this board's sleep current.

Parameters
NameMeaning
capsWhat the board declares.
Returns
Yes, No, or CableDependent (see ::SleepApportion).

sleepApportionHere() #

SleepApportion kleidos::hal::periph::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() #

const char * kleidos::hal::periph::sleepApportionText(SleepApportion apportion)

The reply's token for a SleepApportion.

Parameters
NameMeaning
apportionValue to name.
Returns
"yes", "none" or "cable_dependent".

specFor() #

Spec kleidos::hal::periph::specFor(Id id, const Caps & caps)

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
NameMeaning
idRole to resolve.
capsWhat the board declares.
Returns
The mechanism, its scope, and any refusal.

specOf() #

Spec kleidos::hal::periph::specOf(Id id)

How id is switched on this board.

Parameters
NameMeaning
idRole to resolve.
Returns
The table's answer for boardCaps.

switchOff() #

PowerOffResult kleidos::hal::pmic_off::switchOff(PowerOffPort & port, uint8_t rtcPowerOnSeconds)

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
NameDirectionMeaning
portin, outThe hardware to drive.
rtcPowerOnSecondsinRTC 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() #

const char * kleidos::hal::periph::verdictText(Verdict verdict)

The reply's word for a verdict.

Parameters
NameMeaning
verdictVerdict to name.
Returns
"OK", "COARSE", "NOOP" or "REFUSED".

Back to the top

Variable Documentation

kPowerKeyBootWindowMs #

uint32_t kleidos::hal::pmic_off::kPowerKeyBootWindowMs
inlineconstexpr

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/power/axp_power_control.h). A short press that powered the board on is therefore released within the first second of uptime; the extra half second is margin.

kPowerOffSettleMs #

uint32_t kleidos::hal::pmic_off::kPowerOffSettleMs
inlineconstexpr

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.

kStepAttempts #

uint8_t kleidos::hal::pmic_off::kStepAttempts
inlineconstexpr

Tries of each step of disarmRtc and switchOff before it gives that step up.

Back to the top