mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
refactor(core): differentiate models by internal name in python
[no changelog]
This commit is contained in:
parent
a41a8c5f87
commit
5a86add884
@ -1,5 +1,5 @@
|
|||||||
#ifndef MODELS_MODEL_T2T1_H_
|
#ifndef MODELS_MODEL_D001_H_
|
||||||
#define MODELS_MODEL_T2T1_H_
|
#define MODELS_MODEL_D001_H_
|
||||||
|
|
||||||
#define MODEL_NAME "T"
|
#define MODEL_NAME "T"
|
||||||
#define MODEL_INTERNAL_NAME "D001"
|
#define MODEL_INTERNAL_NAME "D001"
|
||||||
|
@ -69,7 +69,7 @@ def get_features() -> Features:
|
|||||||
unit_btconly=utils.unit_btconly(),
|
unit_btconly=utils.unit_btconly(),
|
||||||
)
|
)
|
||||||
|
|
||||||
if utils.MODEL in ("1", "R"):
|
if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
|
||||||
f.homescreen_format = HomescreenFormat.ToiG
|
f.homescreen_format = HomescreenFormat.ToiG
|
||||||
else:
|
else:
|
||||||
f.homescreen_format = HomescreenFormat.Jpeg
|
f.homescreen_format = HomescreenFormat.Jpeg
|
||||||
|
@ -173,10 +173,10 @@ if __debug__:
|
|||||||
debug_events.last_event += 1
|
debug_events.last_event += 1
|
||||||
|
|
||||||
# TT click on specific coordinates, with possible hold
|
# TT click on specific coordinates, with possible hold
|
||||||
if x is not None and y is not None and utils.MODEL in ("T", "DISC1"):
|
if x is not None and y is not None and utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
click_chan.publish((debug_events.last_event, x, y, msg.hold_ms))
|
click_chan.publish((debug_events.last_event, x, y, msg.hold_ms))
|
||||||
# TR press specific button
|
# TR press specific button
|
||||||
elif msg.physical_button is not None and utils.MODEL in ("R",):
|
elif msg.physical_button is not None and utils.INTERNAL_MODEL in ("T2B1",):
|
||||||
button_chan.publish(
|
button_chan.publish(
|
||||||
(debug_events.last_event, msg.physical_button, msg.hold_ms)
|
(debug_events.last_event, msg.physical_button, msg.hold_ms)
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
BRT_PROTECT_CALL = ButtonRequestType.ProtectCall # CACHE
|
BRT_PROTECT_CALL = ButtonRequestType.ProtectCall # CACHE
|
||||||
|
|
||||||
if utils.MODEL in ("1", "R"):
|
if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
|
||||||
|
|
||||||
def _validate_homescreen_model_specific(homescreen: bytes) -> None:
|
def _validate_homescreen_model_specific(homescreen: bytes) -> None:
|
||||||
from trezor.ui import WIDTH, HEIGHT
|
from trezor.ui import WIDTH, HEIGHT
|
||||||
|
@ -65,7 +65,7 @@ async def _continue_recovery_process() -> Success:
|
|||||||
# If we are starting recovery, ask for word count first...
|
# If we are starting recovery, ask for word count first...
|
||||||
# _request_word_count
|
# _request_word_count
|
||||||
# For TT, just continuing straight to word count keyboard
|
# For TT, just continuing straight to word count keyboard
|
||||||
if utils.MODEL == "R":
|
if utils.INTERNAL_MODEL == "T2B1":
|
||||||
await layout.homescreen_dialog(
|
await layout.homescreen_dialog(
|
||||||
"Continue", "Select the number of words in your backup."
|
"Continue", "Select the number of words in your backup."
|
||||||
)
|
)
|
||||||
|
@ -52,7 +52,7 @@ def _find_message_handler_module(msg_type: int) -> str:
|
|||||||
if msg_type == MessageType.RebootToBootloader:
|
if msg_type == MessageType.RebootToBootloader:
|
||||||
return "apps.management.reboot_to_bootloader"
|
return "apps.management.reboot_to_bootloader"
|
||||||
|
|
||||||
if utils.MODEL in ("R",) and msg_type == MessageType.ShowDeviceTutorial:
|
if utils.INTERNAL_MODEL in ("T2B1",) and msg_type == MessageType.ShowDeviceTutorial:
|
||||||
return "apps.management.show_tutorial"
|
return "apps.management.show_tutorial"
|
||||||
|
|
||||||
if utils.USE_SD_CARD and msg_type == MessageType.SdProtect:
|
if utils.USE_SD_CARD and msg_type == MessageType.SdProtect:
|
||||||
|
@ -39,7 +39,7 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
# in both debug and production, emulator needs to draw the screen explicitly
|
# in both debug and production, emulator needs to draw the screen explicitly
|
||||||
if utils.EMULATOR or utils.MODEL in ("1", "R"):
|
if utils.EMULATOR or utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
|
||||||
loop.after_step_hook = refresh
|
loop.after_step_hook = refresh
|
||||||
|
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ class Component:
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.repaint = True
|
self.repaint = True
|
||||||
|
|
||||||
if utils.MODEL in ("T", "DISC1"):
|
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
|
|
||||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||||
if event is RENDER:
|
if event is RENDER:
|
||||||
@ -143,7 +143,7 @@ class Component:
|
|||||||
def on_touch_end(self, x: int, y: int) -> None:
|
def on_touch_end(self, x: int, y: int) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif utils.MODEL in ("1", "R"):
|
elif utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
|
||||||
|
|
||||||
def dispatch(self, event: int, x: int, y: int) -> None:
|
def dispatch(self, event: int, x: int, y: int) -> None:
|
||||||
if event is RENDER:
|
if event is RENDER:
|
||||||
@ -255,7 +255,7 @@ class Layout(Component):
|
|||||||
Usually overridden to add another tasks to the list."""
|
Usually overridden to add another tasks to the list."""
|
||||||
return self.handle_input(), self.handle_rendering()
|
return self.handle_input(), self.handle_rendering()
|
||||||
|
|
||||||
if utils.MODEL in ("T", "DISC1"):
|
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
|
|
||||||
def handle_input(self) -> Generator:
|
def handle_input(self) -> Generator:
|
||||||
"""Task that is waiting for the user input."""
|
"""Task that is waiting for the user input."""
|
||||||
@ -269,7 +269,7 @@ class Layout(Component):
|
|||||||
# way to get the lowest input-to-render latency.
|
# way to get the lowest input-to-render latency.
|
||||||
self.dispatch(RENDER, 0, 0)
|
self.dispatch(RENDER, 0, 0)
|
||||||
|
|
||||||
elif utils.MODEL in ("1", "R"):
|
elif utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
|
||||||
|
|
||||||
def handle_input(self) -> Generator:
|
def handle_input(self) -> Generator:
|
||||||
"""Task that is waiting for the user input."""
|
"""Task that is waiting for the user input."""
|
||||||
|
@ -4,9 +4,9 @@ from .common import * # noqa: F401,F403
|
|||||||
|
|
||||||
# NOTE: using any import magic probably causes mypy not to check equivalence of
|
# NOTE: using any import magic probably causes mypy not to check equivalence of
|
||||||
# layout type signatures across models
|
# layout type signatures across models
|
||||||
if utils.MODEL in ("1", "R"):
|
if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
|
||||||
from .tr import * # noqa: F401,F403
|
from .tr import * # noqa: F401,F403
|
||||||
elif utils.MODEL in ("T", "DISC1"):
|
elif utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
from .tt_v2 import * # noqa: F401,F403
|
from .tt_v2 import * # noqa: F401,F403
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unknown Trezor model")
|
raise ValueError("Unknown Trezor model")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from trezor import utils
|
from trezor import utils
|
||||||
|
|
||||||
if utils.MODEL in ("T", "DISC1"):
|
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
from .tt_v2.fido import * # noqa: F401,F403
|
from .tt_v2.fido import * # noqa: F401,F403
|
||||||
elif utils.MODEL in ("R",):
|
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||||
from .tr.fido import * # noqa: F401,F403
|
from .tr.fido import * # noqa: F401,F403
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from trezor import utils
|
from trezor import utils
|
||||||
|
|
||||||
if utils.MODEL in ("T", "DISC1"):
|
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
from .tt_v2.homescreen import * # noqa: F401,F403
|
from .tt_v2.homescreen import * # noqa: F401,F403
|
||||||
elif utils.MODEL in ("R",):
|
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||||
from .tr.homescreen import * # noqa: F401,F403
|
from .tr.homescreen import * # noqa: F401,F403
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from trezor import utils
|
from trezor import utils
|
||||||
|
|
||||||
if utils.MODEL in ("T", "DISC1"):
|
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
from .tt_v2.progress import * # noqa: F401,F403
|
from .tt_v2.progress import * # noqa: F401,F403
|
||||||
elif utils.MODEL in ("R",):
|
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||||
from .tr.progress import * # noqa: F401,F403
|
from .tr.progress import * # noqa: F401,F403
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from trezor import utils
|
from trezor import utils
|
||||||
|
|
||||||
if utils.MODEL in ("T", "DISC1"):
|
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
from .tt_v2.recovery import * # noqa: F401,F403
|
from .tt_v2.recovery import * # noqa: F401,F403
|
||||||
elif utils.MODEL in ("R",):
|
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||||
from .tr.recovery import * # noqa: F401,F403
|
from .tr.recovery import * # noqa: F401,F403
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from trezor import utils
|
from trezor import utils
|
||||||
|
|
||||||
if utils.MODEL in ("T", "DISC1"):
|
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||||
from .tt_v2.reset import * # noqa: F401,F403
|
from .tt_v2.reset import * # noqa: F401,F403
|
||||||
elif utils.MODEL in ("R",):
|
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||||
from .tr.reset import * # noqa: F401,F403
|
from .tr.reset import * # noqa: F401,F403
|
||||||
|
@ -266,6 +266,8 @@ class TrezorClient(Generic[UI]):
|
|||||||
|
|
||||||
if not self.model:
|
if not self.model:
|
||||||
# Trezor Model One bootloader 1.8.0 or older does not send model name
|
# Trezor Model One bootloader 1.8.0 or older does not send model name
|
||||||
|
self.model = models.by_internal_name(features.internal_model)
|
||||||
|
if self.model is None:
|
||||||
self.model = models.by_name(features.model or "1")
|
self.model = models.by_name(features.model or "1")
|
||||||
if self.model is None:
|
if self.model is None:
|
||||||
raise RuntimeError("Unsupported Trezor model")
|
raise RuntimeError("Unsupported Trezor model")
|
||||||
|
@ -27,6 +27,7 @@ VENDORS = ("bitcointrezor.com", "trezor.io")
|
|||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
class TrezorModel:
|
class TrezorModel:
|
||||||
name: str
|
name: str
|
||||||
|
internal_name: str
|
||||||
minimum_version: Tuple[int, int, int]
|
minimum_version: Tuple[int, int, int]
|
||||||
vendors: Collection[str]
|
vendors: Collection[str]
|
||||||
usb_ids: Collection[UsbId]
|
usb_ids: Collection[UsbId]
|
||||||
@ -35,6 +36,7 @@ class TrezorModel:
|
|||||||
|
|
||||||
TREZOR_ONE = TrezorModel(
|
TREZOR_ONE = TrezorModel(
|
||||||
name="1",
|
name="1",
|
||||||
|
internal_name="T1B1",
|
||||||
minimum_version=(1, 8, 0),
|
minimum_version=(1, 8, 0),
|
||||||
vendors=VENDORS,
|
vendors=VENDORS,
|
||||||
usb_ids=((0x534C, 0x0001),),
|
usb_ids=((0x534C, 0x0001),),
|
||||||
@ -43,6 +45,7 @@ TREZOR_ONE = TrezorModel(
|
|||||||
|
|
||||||
TREZOR_T = TrezorModel(
|
TREZOR_T = TrezorModel(
|
||||||
name="T",
|
name="T",
|
||||||
|
internal_name="T2T1",
|
||||||
minimum_version=(2, 1, 0),
|
minimum_version=(2, 1, 0),
|
||||||
vendors=VENDORS,
|
vendors=VENDORS,
|
||||||
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
||||||
@ -51,6 +54,7 @@ TREZOR_T = TrezorModel(
|
|||||||
|
|
||||||
TREZOR_R = TrezorModel(
|
TREZOR_R = TrezorModel(
|
||||||
name="R",
|
name="R",
|
||||||
|
internal_name="T2B1",
|
||||||
minimum_version=(2, 1, 0),
|
minimum_version=(2, 1, 0),
|
||||||
vendors=VENDORS,
|
vendors=VENDORS,
|
||||||
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
||||||
@ -59,6 +63,7 @@ TREZOR_R = TrezorModel(
|
|||||||
|
|
||||||
TREZOR_DISC1 = TrezorModel(
|
TREZOR_DISC1 = TrezorModel(
|
||||||
name="DISC1",
|
name="DISC1",
|
||||||
|
internal_name="D001",
|
||||||
minimum_version=(2, 1, 0),
|
minimum_version=(2, 1, 0),
|
||||||
vendors=VENDORS,
|
vendors=VENDORS,
|
||||||
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
||||||
@ -75,3 +80,12 @@ def by_name(name: Optional[str]) -> Optional[TrezorModel]:
|
|||||||
if model.name == name:
|
if model.name == name:
|
||||||
return model
|
return model
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def by_internal_name(name: Optional[str]) -> Optional[TrezorModel]:
|
||||||
|
if name is None:
|
||||||
|
return None
|
||||||
|
for model in TREZORS:
|
||||||
|
if model.internal_name == name:
|
||||||
|
return model
|
||||||
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user