feat(core): expose touch_wakeup_set/get_enabled to MicroPython via trezorio.touch
What changed, and why it matters
This commit simply adds a way for the device's Python code to ask whether the hardware supports waking from sleep by touch, and to turn that feature on or off. It is a normal feature-exposure change with no security bug visible in the diff.
No security action required. Review as part of normal feature development if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces a new MicroPython module trezorio.touch exposing two functions guarded by USE_TOUCH_WAKEUP: touch_wakeup_set_enabled(bool) and touch_wakeup_get_enabled() -> bool. These are thin wrappers around existing C functions touch_wakeup_set_enabled() and touch_wakeup_get_enabled() from <io/touch.h>. It also exports a USE_TOUCH_WAKEUP boolean constant via trezorutils. The commit is purely an API surface addition; no logic changes to authentication, cryptography, memory handling, or privileged operations are present.
Changed components
core/embed/upymod/modtrezorio/modtrezorio-touch.hcore/embed/upymod/modtrezorio/modtrezorio.ccore/embed/upymod/modtrezorutils/modtrezorutils.ccore/mocks/generated/trezorio/__init__.pyicore/mocks/generated/trezorio/touch.pyicore/mocks/generated/trezorutils.pyicore/src/trezor/utils.pyInspect captured patch +96 / −2
diff --git a/core/embed/upymod/modtrezorio/modtrezorio-touch.h b/core/embed/upymod/modtrezorio/modtrezorio-touch.h
new file mode 100644
index 00000000..7c45012a
--- /dev/null
+++ b/core/embed/upymod/modtrezorio/modtrezorio-touch.h
@@ -0,0 +1,64 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <io/touch.h>
+
+/// package: trezorio.touch
+
+#ifdef USE_TOUCH_WAKEUP
+
+/// def touch_wakeup_set_enabled(enable: bool) -> None:
+/// """
+/// Enable/disable touch wakeup during suspend.
+/// """
+STATIC mp_obj_t mod_trezorio_touch_wakeup_set_enabled(mp_obj_t enable) {
+ touch_wakeup_set_enabled(mp_obj_is_true(enable));
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_touch_wakeup_set_enabled_obj,
+ mod_trezorio_touch_wakeup_set_enabled);
+
+/// def touch_wakeup_get_enabled() -> bool:
+/// """
+/// Return whether touch wakeup during suspend is enabled.
+/// """
+STATIC mp_obj_t mod_trezorio_touch_wakeup_get_enabled(void) {
+ return mp_obj_new_bool(touch_wakeup_get_enabled());
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_touch_wakeup_get_enabled_obj,
+ mod_trezorio_touch_wakeup_get_enabled);
+
+#endif // USE_TOUCH_WAKEUP
+
+STATIC const mp_rom_map_elem_t mod_trezorio_touch_globals_table[] = {
+ {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_touch)},
+#ifdef USE_TOUCH_WAKEUP
+ {MP_ROM_QSTR(MP_QSTR_touch_wakeup_set_enabled),
+ MP_ROM_PTR(&mod_trezorio_touch_wakeup_set_enabled_obj)},
+ {MP_ROM_QSTR(MP_QSTR_touch_wakeup_get_enabled),
+ MP_ROM_PTR(&mod_trezorio_touch_wakeup_get_enabled_obj)},
+#endif // USE_TOUCH_WAKEUP
+};
+STATIC MP_DEFINE_CONST_DICT(mod_trezorio_touch_globals,
+ mod_trezorio_touch_globals_table);
+
+STATIC const mp_obj_module_t mod_trezorio_touch_module = {
+ .base = {&mp_type_module},
+ .globals = (mp_obj_dict_t *)&mod_trezorio_touch_globals,
+};
diff --git a/core/embed/upymod/modtrezorio/modtrezorio.c b/core/embed/upymod/modtrezorio/modtrezorio.c
index f34fe64d..8136d388 100644
--- a/core/embed/upymod/modtrezorio/modtrezorio.c
+++ b/core/embed/upymod/modtrezorio/modtrezorio.c
@@ -58,6 +58,9 @@ uint32_t last_touch_sample_time = 0;
#ifdef USE_HAPTIC
#include "modtrezorio-haptic.h"
#endif
+#ifdef USE_TOUCH
+#include "modtrezorio-touch.h"
+#endif
#ifdef USE_RGB_LED
#include "modtrezorio-rgb_led.h"
#endif
@@ -70,7 +73,7 @@ uint32_t last_touch_sample_time = 0;
#include "modtrezorio-poll.h"
/// package: trezorio.__init__
-/// from . import fatfs, haptic, sdcard, ble, pm, rgb_led, ipc, app_cache
+/// from . import fatfs, haptic, sdcard, ble, pm, rgb_led, ipc, app_cache, touch
/// POLL_READ: int # wait until interface is readable and return read data
/// POLL_WRITE: int # wait until interface is writable
@@ -124,6 +127,7 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_ROM_INT((TOUCH_START >> 24) & 0xFFU)},
{MP_ROM_QSTR(MP_QSTR_TOUCH_MOVE), MP_ROM_INT((TOUCH_MOVE >> 24) & 0xFFU)},
{MP_ROM_QSTR(MP_QSTR_TOUCH_END), MP_ROM_INT((TOUCH_END >> 24) & 0xFFU)},
+ {MP_ROM_QSTR(MP_QSTR_touch), MP_ROM_PTR(&mod_trezorio_touch_module)},
#endif
#ifdef USE_BUTTON
{MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_INT(SYSHANDLE_BUTTON)},
diff --git a/core/embed/upymod/modtrezorutils/modtrezorutils.c b/core/embed/upymod/modtrezorutils/modtrezorutils.c
index 452cafa4..b6ecd830 100644
--- a/core/embed/upymod/modtrezorutils/modtrezorutils.c
+++ b/core/embed/upymod/modtrezorutils/modtrezorutils.c
@@ -828,6 +828,8 @@ STATIC const mp_obj_tuple_t mod_trezorutils_version_obj = {
/// """Whether the hardware supports MCU attestation signing and certificate."""
/// USE_TOUCH: bool
/// """Whether the hardware supports touch screen."""
+/// USE_TOUCH_WAKEUP: bool
+/// """Whether the hardware supports touch-based wakeup."""
/// USE_BUTTON: bool
/// """Whether the hardware supports two-button input."""
/// USE_POWER_MANAGER: bool
@@ -1015,6 +1017,11 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
#else
{MP_ROM_QSTR(MP_QSTR_USE_HAPTIC), mp_const_false},
#endif
+#ifdef USE_TOUCH_WAKEUP
+ {MP_ROM_QSTR(MP_QSTR_USE_TOUCH_WAKEUP), mp_const_true},
+#else
+ {MP_ROM_QSTR(MP_QSTR_USE_TOUCH_WAKEUP), mp_const_false},
+#endif
#ifdef USE_RGB_LED
{MP_ROM_QSTR(MP_QSTR_USE_RGB_LED), mp_const_true},
#else
diff --git a/core/mocks/generated/trezorio/__init__.pyi b/core/mocks/generated/trezorio/__init__.pyi
index e09e8b4d..097edf19 100644
--- a/core/mocks/generated/trezorio/__init__.pyi
+++ b/core/mocks/generated/trezorio/__init__.pyi
@@ -113,7 +113,7 @@ class USB:
"""
Cleans up the USB stack.
"""
-from . import fatfs, haptic, sdcard, ble, pm, rgb_led, ipc, app_cache
+from . import fatfs, haptic, sdcard, ble, pm, rgb_led, ipc, app_cache, touch
POLL_READ: int # wait until interface is readable and return read data
POLL_WRITE: int # wait until interface is writable
diff --git a/core/mocks/generated/trezorio/touch.pyi b/core/mocks/generated/trezorio/touch.pyi
new file mode 100644
index 00000000..5c628ef5
--- /dev/null
+++ b/core/mocks/generated/trezorio/touch.pyi
@@ -0,0 +1,16 @@
+from typing import *
+from buffer_types import *
+
+
+# upymod/modtrezorio/modtrezorio-touch.h
+def touch_wakeup_set_enabled(enable: bool) -> None:
+ """
+ Enable/disable touch wakeup during suspend.
+ """
+
+
+# upymod/modtrezorio/modtrezorio-touch.h
+def touch_wakeup_get_enabled() -> bool:
+ """
+ Return whether touch wakeup during suspend is enabled.
+ """
diff --git a/core/mocks/generated/trezorutils.pyi b/core/mocks/generated/trezorutils.pyi
index 32bab40b..e90020a8 100644
--- a/core/mocks/generated/trezorutils.pyi
+++ b/core/mocks/generated/trezorutils.pyi
@@ -275,6 +275,8 @@ USE_MCU_ATTESTATION: bool
"""Whether the hardware supports MCU attestation signing and certificate."""
USE_TOUCH: bool
"""Whether the hardware supports touch screen."""
+USE_TOUCH_WAKEUP: bool
+"""Whether the hardware supports touch-based wakeup."""
USE_BUTTON: bool
"""Whether the hardware supports two-button input."""
USE_POWER_MANAGER: bool
diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py
index 83a09343..0e49c436 100644
--- a/core/src/trezor/utils.py
+++ b/core/src/trezor/utils.py
@@ -38,6 +38,7 @@ from trezorutils import ( # noqa: F401
USE_TELEMETRY,
USE_THP,
USE_TOUCH,
+ USE_TOUCH_WAKEUP,
USE_TROPIC,
VERSION,
bootloader_locked,
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.