From c30f1231d56d1cee3cdfe6cf6e12ba840e8cfd17 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Tue, 25 Apr 2023 22:44:59 +0200 Subject: [PATCH] refactor(core): expose USE_TOUCH and USE_BUTTON to uPy [no changelog] --- core/SConscript.firmware | 2 ++ core/SConscript.unix | 26 ++++++------------- .../extmod/modtrezorutils/modtrezorutils.c | 14 ++++++++++ core/mocks/generated/trezorutils.pyi | 4 +++ .../site_tools/micropython/__init__.py | 4 +++ core/src/trezor/utils.py | 2 ++ 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 9cd97ee35..070ceaf74 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -760,6 +760,8 @@ if FROZEN: bitcoin_only=BITCOIN_ONLY, backlight='backlight' in FEATURES_AVAILABLE, optiga='optiga' in FEATURES_AVAILABLE, + use_button='button' in FEATURES_AVAILABLE, + use_touch='touch' in FEATURES_AVAILABLE, ui_layout=UI_LAYOUT, thp=THP, ) diff --git a/core/SConscript.unix b/core/SConscript.unix index 8dad6103b..b30d09c0c 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -485,18 +485,6 @@ elif TREZOR_MODEL in ('T3T1',): else: raise ValueError('Unknown Trezor model') - -if 'sd_card' in FEATURES_AVAILABLE: - SDCARD = True -else: - SDCARD = False - -if 'optiga' in FEATURES_AVAILABLE: - OPTIGA = True -else: - OPTIGA = False - - env.Tool('micropython') env.Replace( @@ -664,7 +652,7 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py', exclude=[ SOURCE_PY_DIR + 'trezor/sdcard.py', - ] if not SDCARD else [] + ] if 'sd_card' not in FEATURES_AVAILABLE else [] )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py')) @@ -701,7 +689,7 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py', exclude=[ SOURCE_PY_DIR + 'storage/sd_salt.py', - ] if not SDCARD else [] + ] if 'sd_card' not in FEATURES_AVAILABLE else [] )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py')) @@ -726,16 +714,16 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/common/*.py', exclude=[ SOURCE_PY_DIR + 'apps/common/sdcard.py', - ] if not SDCARD else [] + ] if "sd_card" not in FEATURES_AVAILABLE else [] )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/debug/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/homescreen/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*.py', exclude=[ SOURCE_PY_DIR + 'apps/management/sd_protect.py', - ] if not SDCARD else [] + [ + ] if "sd_card" not in FEATURES_AVAILABLE else [] + [ SOURCE_PY_DIR + 'apps/management/authenticate_device.py', - ] if not OPTIGA else []) + ] if "optiga" not in FEATURES_AVAILABLE else []) ) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py')) @@ -804,7 +792,9 @@ if FROZEN: source_dir=SOURCE_PY_DIR, bitcoin_only=BITCOIN_ONLY, backlight='backlight' in FEATURES_AVAILABLE, - optiga=OPTIGA, + optiga='optiga' in FEATURES_AVAILABLE, + use_button='button' in FEATURES_AVAILABLE, + use_touch='touch' in FEATURES_AVAILABLE, ui_layout=UI_LAYOUT, thp=THP, ) diff --git a/core/embed/extmod/modtrezorutils/modtrezorutils.c b/core/embed/extmod/modtrezorutils/modtrezorutils.c index d00e35d11..f948004c1 100644 --- a/core/embed/extmod/modtrezorutils/modtrezorutils.c +++ b/core/embed/extmod/modtrezorutils/modtrezorutils.c @@ -420,6 +420,10 @@ STATIC mp_obj_tuple_t mod_trezorutils_version_obj = { /// """Whether the hardware supports haptic feedback.""" /// USE_OPTIGA: bool /// """Whether the hardware supports Optiga secure element.""" +/// USE_TOUCH: bool +/// """Whether the hardware supports touch screen.""" +/// USE_BUTTON: bool +/// """Whether the hardware supports two-button input.""" /// MODEL: str /// """Model name.""" /// MODEL_FULL_NAME: str @@ -485,6 +489,16 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_USE_OPTIGA), mp_const_true}, #else {MP_ROM_QSTR(MP_QSTR_USE_OPTIGA), mp_const_false}, +#endif +#ifdef USE_TOUCH + {MP_ROM_QSTR(MP_QSTR_USE_TOUCH), mp_const_true}, +#else + {MP_ROM_QSTR(MP_QSTR_USE_TOUCH), mp_const_false}, +#endif +#ifdef USE_BUTTON + {MP_ROM_QSTR(MP_QSTR_USE_BUTTON), mp_const_true}, +#else + {MP_ROM_QSTR(MP_QSTR_USE_BUTTON), mp_const_false}, #endif {MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_PTR(&mod_trezorutils_model_name_obj)}, {MP_ROM_QSTR(MP_QSTR_MODEL_FULL_NAME), diff --git a/core/mocks/generated/trezorutils.pyi b/core/mocks/generated/trezorutils.pyi index 5c497046b..0607b5c91 100644 --- a/core/mocks/generated/trezorutils.pyi +++ b/core/mocks/generated/trezorutils.pyi @@ -130,6 +130,10 @@ USE_HAPTIC: bool """Whether the hardware supports haptic feedback.""" USE_OPTIGA: bool """Whether the hardware supports Optiga secure element.""" +USE_TOUCH: bool +"""Whether the hardware supports touch screen.""" +USE_BUTTON: bool +"""Whether the hardware supports two-button input.""" MODEL: str """Model name.""" MODEL_FULL_NAME: str diff --git a/core/site_scons/site_tools/micropython/__init__.py b/core/site_scons/site_tools/micropython/__init__.py index 22e9feac9..ee5a0c80a 100644 --- a/core/site_scons/site_tools/micropython/__init__.py +++ b/core/site_scons/site_tools/micropython/__init__.py @@ -46,6 +46,8 @@ def generate(env): optiga = env["optiga"] layout_tt = env["ui_layout"] == "UI_LAYOUT_TT" layout_tr = env["ui_layout"] == "UI_LAYOUT_TR" + touch = env["use_touch"] + button = env["use_button"] layout_mercury = env["ui_layout"] == "UI_LAYOUT_MERCURY" thp = env["thp"] interim = f"{target[:-4]}.i" # replace .mpy with .i @@ -56,6 +58,8 @@ def generate(env): rf"-e 's/utils\.UI_LAYOUT == \"TT\"/{layout_tt}/g'", rf"-e 's/utils\.UI_LAYOUT == \"TR\"/{layout_tr}/g'", rf"-e 's/utils\.UI_LAYOUT == \"MERCURY\"/{layout_mercury}/g'", + rf"-e 's/utils\.USE_BUTTON/{button}/g'", + rf"-e 's/utils\.USE_TOUCH/{touch}/g'", rf"-e 's/utils\.USE_THP/{thp}/g'", r"-e 's/if TYPE_CHECKING/if False/'", r"-e 's/import typing/# \0/'", diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 134274db6..7021759ba 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -11,10 +11,12 @@ from trezorutils import ( # noqa: F401 SCM_REVISION, UI_LAYOUT, USE_BACKLIGHT, + USE_BUTTON, USE_HAPTIC, USE_OPTIGA, USE_SD_CARD, USE_THP, + USE_TOUCH, VERSION, bootloader_locked, check_firmware_header,