From 1d69ca4929a581e1b3f0a8e62a2b07c056029e2b Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Wed, 31 Aug 2022 15:49:46 +0200 Subject: [PATCH] display logo on firmware boot --- core/embed/firmware/main.c | 3 +++ core/embed/rust/rust_ui.h | 3 +++ core/embed/rust/src/boot/mod.rs | 14 ++++++++++++++ core/embed/rust/src/lib.rs | 1 + .../rust/src/ui/model_tt/res/trezor_empty.toif | Bin 0 -> 647 bytes core/embed/rust/src/ui/model_tt/theme.rs | 1 + python/src/trezorlib/toif.py | 13 +++++++++++++ 7 files changed, 35 insertions(+) create mode 100644 core/embed/rust/rust_ui.h create mode 100644 core/embed/rust/src/boot/mod.rs create mode 100644 core/embed/rust/src/ui/model_tt/res/trezor_empty.toif diff --git a/core/embed/firmware/main.c b/core/embed/firmware/main.c index 147441c0b9..b69af45c47 100644 --- a/core/embed/firmware/main.c +++ b/core/embed/firmware/main.c @@ -50,6 +50,7 @@ #if defined TREZOR_MODEL_R || defined TREZOR_MODEL_1 #include "button.h" #endif +#include "rust_ui.h" #ifdef SYSTEM_VIEW #include "systemview.h" @@ -125,6 +126,8 @@ int main(void) { ensure(sectrue * (zkp_context_init() == 0), NULL); #endif + boot_firmware(0); + printf("CORE: Preparing stack\n"); // Stack limit should be less than real stack size, so we have a chance // to recover from limit hit. diff --git a/core/embed/rust/rust_ui.h b/core/embed/rust/rust_ui.h new file mode 100644 index 0000000000..d3807cd4fe --- /dev/null +++ b/core/embed/rust/rust_ui.h @@ -0,0 +1,3 @@ +#include "common.h" + +void boot_firmware(uint16_t stage); diff --git a/core/embed/rust/src/boot/mod.rs b/core/embed/rust/src/boot/mod.rs new file mode 100644 index 0000000000..1750f4de09 --- /dev/null +++ b/core/embed/rust/src/boot/mod.rs @@ -0,0 +1,14 @@ + + +use crate::ui::display::icon; +use crate::ui::model_tt::theme::{ICON_TREZOR_EMPTY, BLUE, BLACK, WHITE}; +use crate::ui::constant; + + +#[no_mangle] +pub extern "C" fn boot_firmware( + stage: cty::uint16_t +) { + + icon(constant::screen().center(), ICON_TREZOR_EMPTY, WHITE, BLACK); +} diff --git a/core/embed/rust/src/lib.rs b/core/embed/rust/src/lib.rs index 2f63df12b4..bbd87b6a71 100644 --- a/core/embed/rust/src/lib.rs +++ b/core/embed/rust/src/lib.rs @@ -20,6 +20,7 @@ mod trace; #[cfg(feature = "ui")] #[macro_use] pub mod ui; +pub mod boot; #[cfg(feature = "debug")] #[panic_handler] diff --git a/core/embed/rust/src/ui/model_tt/res/trezor_empty.toif b/core/embed/rust/src/ui/model_tt/res/trezor_empty.toif new file mode 100644 index 0000000000000000000000000000000000000000..8ac9aae44359e065f97eda9ca163bd7b7767b01f GIT binary patch literal 647 zcmV;20(kvYPf2G~0C@m=0ssK*l0A3YFcgL*8##E)*_Ms3k%B%OYkiZaMx z?Y$V(lh4bM3EJqV|LmuamN((EeEy3@=fM#9vB%%_(dl^w8hM81+o({;TC!p^CXLy{ zR;rV>vN{pX`gUJq4A}-uP3K1DI0Vneq2{;LVm`*&%Ow@`MafcmF zOveE$#BJ75#7+3+toy@}+^B~9Xwv;rt1%|~r&_HQGW}MgP$k!O{q-BNAsezG8?qtI z6$;m`oK_-4hl#U?a# z6Tk+8KIEgKHJG7rkx&O&FXz_qhoJ_FUZ{rRcAhRxQ>`!Dj5M7-tNdxHR7j1e6=Lu_ z1*8K5DB13U8vJRg%dY&XpspEIO~?LEYZhXoPi~TpYL{$BFqN9|>d(PUQ10R?$WV6K hA#AUM%r6_KF!I(R@9AuU`7L0f!k bytes: data += struct.pack(">B", c) return bytes(data) +def _from_pil_grayscale_alpha(pixels: Sequence[int]) -> bytes: + data = bytearray() + for i in range(0, len(pixels), 2): + left, right = pixels[i], pixels[i + 1] + c = (left[1] & 0xF0) | ((right[1] & 0xF0) >> 4) + data += struct.pack(">B", c) + return bytes(data) + def _to_grayscale(data: bytes) -> bytes: res = bytearray() @@ -161,6 +169,11 @@ def from_image( if image.size[0] % 2 != 0: raise ValueError("Only even-width grayscale images are supported") toif_data = _from_pil_grayscale(image.getdata()) + elif image.mode == "LA": + toif_mode = firmware.ToifMode.grayscale + if image.size[0] % 2 != 0: + raise ValueError("Only even-width grayscale images are supported") + toif_data = _from_pil_grayscale_alpha(image.getdata()) elif image.mode == "RGB": toif_mode = firmware.ToifMode.full_color toif_data = _from_pil_rgb(image.getdata())