WIP - different colors for all display - Rust part

grdddj/different_colors_for_old_display
grdddj 1 year ago
parent d8603dcc23
commit 32abb12ccb

@ -21,6 +21,7 @@
#define _DISPLAY_INTERFACE_H
#include <stdint.h>
#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);

@ -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")

@ -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) }
}

@ -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());

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

Loading…
Cancel
Save