From 32abb12ccb1fe61a01186ea6710b4651f2b41bd8 Mon Sep 17 00:00:00 2001 From: grdddj Date: Thu, 9 Mar 2023 20:35:19 +0100 Subject: [PATCH] WIP - different colors for all display - Rust part --- .../extmod/modtrezorui/display_interface.h | 3 ++ core/embed/rust/build.rs | 1 + core/embed/rust/src/trezorhal/display.rs | 31 +++++++++++++++++-- core/embed/rust/src/ui/display/toif.rs | 13 +++++++- core/embed/rust/src/ui/model_tt/theme.rs | 15 +++++++++ core/embed/trezorhal/displays/st7789v.c | 4 +++ .../embed/trezorhal/displays/ug-2828tswig01.c | 4 +++ .../embed/trezorhal/displays/vg-2864ksweg01.c | 4 +++ core/embed/unix/display-unix.c | 4 +++ 9 files changed, 76 insertions(+), 3 deletions(-) diff --git a/core/embed/extmod/modtrezorui/display_interface.h b/core/embed/extmod/modtrezorui/display_interface.h index 5b9c3ca82..bd07a97c2 100644 --- a/core/embed/extmod/modtrezorui/display_interface.h +++ b/core/embed/extmod/modtrezorui/display_interface.h @@ -21,6 +21,7 @@ #define _DISPLAY_INTERFACE_H #include +#include "secbool.h" #include "common.h" #include TREZOR_BOARD @@ -36,6 +37,8 @@ void display_pixeldata(uint16_t c); void display_reset_state(); +secbool display_is_old(); + void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); int display_orientation(int degrees); int display_get_orientation(void); diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index fc8736626..e4dcad7a5 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -295,6 +295,7 @@ fn generate_trezorhal_bindings() { .allowlist_function("display_pixeldata_dirty") .allowlist_function("display_set_window") .allowlist_function("display_sync") + .allowlist_function("display_is_old") .allowlist_var("DISPLAY_CMD_ADDRESS") .allowlist_var("DISPLAY_DATA_ADDRESS") .allowlist_type("toif_format_t") diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index a90278ef2..3afb55dd2 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -3,6 +3,10 @@ use core::ptr; use cty::c_int; use crate::trezorhal::buffers::BufferText; +#[cfg(feature = "model_tt")] +use crate::ui::display::Color; +#[cfg(feature = "model_tt")] +use crate::ui::model_tt::theme::replace_colors_for_old_tt_display; #[derive(PartialEq, Debug, Eq, FromPrimitive, Clone, Copy)] pub enum ToifFormat { @@ -16,7 +20,25 @@ pub fn backlight(val: i32) -> i32 { unsafe { ffi::display_backlight(val) } } -pub fn text(baseline_x: i16, baseline_y: i16, text: &str, font: i32, fgcolor: u16, bgcolor: u16) { +#[cfg(feature = "model_tt")] +pub fn tt_old_display() -> bool { + ffi::sectrue == unsafe { ffi::display_is_old() } +} + +pub fn text( + baseline_x: i16, + baseline_y: i16, + text: &str, + font: i32, + mut fgcolor: u16, + mut bgcolor: u16, +) { + #[cfg(feature = "model_tt")] + if tt_old_display() { + fgcolor = replace_colors_for_old_tt_display(Color::from_u16(fgcolor)).to_u16(); + bgcolor = replace_colors_for_old_tt_display(Color::from_u16(bgcolor)).to_u16(); + } + unsafe { ffi::display_text( baseline_x.into(), @@ -72,7 +94,12 @@ pub fn text_baseline(font: i32) -> i16 { unsafe { ffi::font_baseline(font).try_into().unwrap_or(i16::MAX) } } -pub fn bar(x: i16, y: i16, w: i16, h: i16, fgcolor: u16) { +pub fn bar(x: i16, y: i16, w: i16, h: i16, mut fgcolor: u16) { + #[cfg(feature = "model_tt")] + if tt_old_display() { + fgcolor = replace_colors_for_old_tt_display(Color::from_u16(fgcolor)).to_u16(); + } + unsafe { ffi::display_bar(x.into(), y.into(), w.into(), h.into(), fgcolor) } } diff --git a/core/embed/rust/src/ui/display/toif.rs b/core/embed/rust/src/ui/display/toif.rs index 2da23f0b9..5d5d90f50 100644 --- a/core/embed/rust/src/ui/display/toif.rs +++ b/core/embed/rust/src/ui/display/toif.rs @@ -12,9 +12,20 @@ use crate::{ use super::Color; +#[cfg(feature = "model_tt")] +use crate::trezorhal::display::tt_old_display; +#[cfg(feature = "model_tt")] +use crate::ui::model_tt::theme::replace_colors_for_old_tt_display; + const TOIF_HEADER_LENGTH: usize = 12; -pub fn icon(icon: &Icon, center: Point, fg_color: Color, bg_color: Color) { +pub fn icon(icon: &Icon, center: Point, mut fg_color: Color, mut bg_color: Color) { + #[cfg(feature = "model_tt")] + if tt_old_display() { + fg_color = replace_colors_for_old_tt_display(fg_color); + bg_color = replace_colors_for_old_tt_display(bg_color); + } + let r = Rect::from_center_and_size(center, icon.toif.size()); let area = r.translate(get_offset()); let clamped = area.clamp(constant::screen()); diff --git a/core/embed/rust/src/ui/model_tt/theme.rs b/core/embed/rust/src/ui/model_tt/theme.rs index bb18afa82..24b313e8b 100644 --- a/core/embed/rust/src/ui/model_tt/theme.rs +++ b/core/embed/rust/src/ui/model_tt/theme.rs @@ -37,13 +37,28 @@ pub const GREEN_DARK: Color = Color::rgb(0x00, 0x55, 0x1D); // button pressed pub const BLUE: Color = Color::rgb(0x06, 0x1E, 0xAD); // button pub const BLUE_DARK: Color = Color::rgb(0x04, 0x10, 0x58); // button pressed pub const OFF_WHITE: Color = Color::rgb(0xDE, 0xDE, 0xDE); // very light grey +pub const OFF_WHITE_OLD_DISPLAY: Color = Color::rgb(0xF0, 0xF0, 0xF0); // very light grey pub const GREY_LIGHT: Color = Color::rgb(0x90, 0x90, 0x90); // secondary text +pub const GREY_LIGHT_OLD_DISPLAY: Color = Color::rgb(0xD0, 0xD0, 0xD0); // secondary text pub const GREY_MEDIUM: Color = Color::rgb(0x45, 0x45, 0x45); // button pressed +pub const GREY_MEDIUM_OLD_DISPLAY: Color = Color::rgb(0x85, 0x85, 0x85); // button pressed pub const GREY_DARK: Color = Color::rgb(0x1A, 0x1A, 0x1A); // button +pub const GREY_DARK_OLD_DISPLAY: Color = Color::rgb(0x5A, 0x5A, 0x5A); // button pub const VIOLET: Color = Color::rgb(0x95, 0x00, 0xCA); pub const FATAL_ERROR_COLOR: Color = Color::rgb(0xAD, 0x2B, 0x2B); +#[cfg(feature = "model_tt")] +pub fn replace_colors_for_old_tt_display(color: Color) -> Color { + match color { + OFF_WHITE => OFF_WHITE_OLD_DISPLAY, + GREY_LIGHT => GREY_LIGHT_OLD_DISPLAY, + GREY_DARK => GREY_DARK_OLD_DISPLAY, + GREY_MEDIUM => GREY_MEDIUM_OLD_DISPLAY, + _ => color, + } +} + // Commonly used corner radius (i.e. for buttons). pub const RADIUS: u8 = 2; diff --git a/core/embed/trezorhal/displays/st7789v.c b/core/embed/trezorhal/displays/st7789v.c index f84321c87..498251eae 100644 --- a/core/embed/trezorhal/displays/st7789v.c +++ b/core/embed/trezorhal/displays/st7789v.c @@ -227,6 +227,10 @@ int display_orientation(int degrees) { int display_get_orientation(void) { return DISPLAY_ORIENTATION; } +secbool display_is_old() { + return sectrue; +} + int display_backlight(int val) { if (DISPLAY_BACKLIGHT != val && val >= 0 && val <= 255) { DISPLAY_BACKLIGHT = val; diff --git a/core/embed/trezorhal/displays/ug-2828tswig01.c b/core/embed/trezorhal/displays/ug-2828tswig01.c index 0b750a904..b54bdb71a 100644 --- a/core/embed/trezorhal/displays/ug-2828tswig01.c +++ b/core/embed/trezorhal/displays/ug-2828tswig01.c @@ -166,6 +166,10 @@ int display_orientation(int degrees) { int display_get_orientation(void) { return DISPLAY_ORIENTATION; } +secbool display_is_old() { + return sectrue; +} + int display_backlight(int val) { if (DISPLAY_BACKLIGHT != val && val >= 0 && val <= 255) { DISPLAY_BACKLIGHT = val; diff --git a/core/embed/trezorhal/displays/vg-2864ksweg01.c b/core/embed/trezorhal/displays/vg-2864ksweg01.c index 15c0b82e6..d86745d6b 100644 --- a/core/embed/trezorhal/displays/vg-2864ksweg01.c +++ b/core/embed/trezorhal/displays/vg-2864ksweg01.c @@ -115,6 +115,10 @@ int display_orientation(int degrees) { int display_get_orientation(void) { return DISPLAY_ORIENTATION; } +secbool display_is_old() { + return sectrue; +} + int display_backlight(int val) { DISPLAY_BACKLIGHT = 255; return DISPLAY_BACKLIGHT; diff --git a/core/embed/unix/display-unix.c b/core/embed/unix/display-unix.c index ed6fcb87d..08b3684bf 100644 --- a/core/embed/unix/display-unix.c +++ b/core/embed/unix/display-unix.c @@ -280,6 +280,10 @@ int display_orientation(int degrees) { int display_get_orientation(void) { return DISPLAY_ORIENTATION; } +secbool display_is_old() { + return sectrue; +} + int display_backlight(int val) { #if defined TREZOR_MODEL_1 val = 255;