What changed, and why it matters
This commit simply adds a new function that lets the device's Python-based software read the battery percentage from the power manager. It is a straightforward feature addition with no apparent security implications.
No security action required; review as normal feature code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change exposes pm_get_state().soc through a new MicroPython module function trezorio.pm.soc(). It returns an integer 0-100 or raises RuntimeError if the power manager call fails. No input is accepted, no memory is allocated in an unusual way, and no existing behavior is modified.
Changed components
core/embed/upymod/modtrezorio/modtrezorio-pm.hcore/mocks/generated/trezorio/pm.pyiInspect captured patch +25 / −0
diff --git a/core/embed/upymod/modtrezorio/modtrezorio-pm.h b/core/embed/upymod/modtrezorio/modtrezorio-pm.h
index 05aeee408..c2ac7a8e6 100644
--- a/core/embed/upymod/modtrezorio/modtrezorio-pm.h
+++ b/core/embed/upymod/modtrezorio/modtrezorio-pm.h
@@ -35,6 +35,22 @@
/// EVENT_WIRELESS_CONNECTED_CHANGED: int
/// EVENT_SOC_UPDATED: int
+/// def soc() -> int:
+/// """
+/// Returns the state of charge (SoC) in percent (0-100). Raises RuntimeError
+/// on failure.
+/// """
+STATIC mp_obj_t mod_trezorio_pm_soc() {
+ pm_state_t state = {0};
+ pm_status_t res = pm_get_state(&state);
+ if (res != PM_OK) {
+ mp_raise_msg(&mp_type_RuntimeError,
+ MP_ERROR_TEXT("Failed to get power manager state"));
+ }
+ return mp_obj_new_int(state.soc);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_soc_obj, mod_trezorio_pm_soc);
+
/// def suspend() -> int:
/// """
/// Suspends the device. Returns wakeup flag. Raises RuntimeError on
@@ -85,6 +101,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_pm_is_usb_connected_obj,
STATIC const mp_rom_map_elem_t mod_trezorio_pm_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pm)},
+ {MP_ROM_QSTR(MP_QSTR_soc), MP_ROM_PTR(&mod_trezorio_pm_soc_obj)},
{MP_ROM_QSTR(MP_QSTR_suspend), MP_ROM_PTR(&mod_trezorio_pm_suspend_obj)},
{MP_ROM_QSTR(MP_QSTR_hibernate),
MP_ROM_PTR(&mod_trezorio_pm_hibernate_obj)},
diff --git a/core/mocks/generated/trezorio/pm.pyi b/core/mocks/generated/trezorio/pm.pyi
index a1de4ab1b..3cc3309b9 100644
--- a/core/mocks/generated/trezorio/pm.pyi
+++ b/core/mocks/generated/trezorio/pm.pyi
@@ -14,6 +14,14 @@ EVENT_WIRELESS_CONNECTED_CHANGED: int
EVENT_SOC_UPDATED: int
+# upymod/modtrezorio/modtrezorio-pm.h
+def soc() -> int:
+ """
+ Returns the state of charge (SoC) in percent (0-100). Raises RuntimeError
+ on failure.
+ """
+
+
# upymod/modtrezorio/modtrezorio-pm.h
def suspend() -> int:
"""
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.