Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:78 Xiaozhi esp32 Power Management

From Leeroopedia
Knowledge Sources
Domains Power_Management, Embedded_Systems
Last Updated 2026-10-17 00:00 GMT

Overview

Principle of managing device power consumption through inactivity-based sleep transitions, PMU-controlled charging and voltage rails, and adaptive CPU frequency scaling to balance responsiveness with battery life.

Description

XiaoZhi devices implement a layered power management strategy:

  • Inactivity timers: PowerSaveTimer enters a low-power sleep mode after N seconds of inactivity and optionally requests shutdown. SleepTimer provides light/deep sleep staging. Both fire callbacks on state transitions so boards can turn off displays, reduce LED brightness, or disable peripherals.
  • PMU control: Boards with XPowers (AXP2101/AXP192/AXP202) or SY6970 PMU chips manage charging current, battery monitoring, rail voltages, and power-off via I2C. Board-specific PowerManager classes wrap the PMU API with device-specific thresholds and GPIO handling.
  • CPU frequency scaling: PowerSaveLevel (LOW_POWER, BALANCED, PERFORMANCE) adjusts CPU frequency and peripheral activity. The board translates these levels into PMU rail changes and esp_pm_lock acquisitions.
  • Adaptive behavior: During voice conversation, power save is set to PERFORMANCE; during idle, LOW_POWER is restored. Wake word detection runs in a reduced-power mode with the audio engine active but the display dimmed.

Usage

Use this principle when designing:

  • Battery-powered XiaoZhi devices with charging circuits
  • Inactivity-based sleep/wake transitions
  • PMU-based power rail management
  • Adaptive CPU frequency for different operating modes

Theoretical Basis

The power management strategy follows a hierarchical state machine:

PERFORMANCE (full CPU, all peripherals on)
    ↓ inactivity timer
BALANCED (reduced CPU, display dimmed)
    ↓ extended inactivity
LOW_POWER (minimal CPU, display off, wake word only)
    ↓ long inactivity
LIGHT_SLEEP (PMU maintains wake source)
    ↓ very long inactivity
DEEP_SLEEP / SHUTDOWN

Transitions are event-driven:

  • Wake events: wake word detected, button press, knob rotation, network activity, charging start
  • Sleep triggers: inactivity timer expiry, low battery threshold, manual power-off

Power consumption is minimized at each level by:

  • Disabling unused I2S channels (AudioCodec::EnableInput/EnableOutput)
  • Releasing esp_pm_lock to allow DFS (Dynamic Frequency Scaling)
  • Turning off display backlight and LED indicators
  • Switching PMU rails to lower voltage or disabling entirely

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment