diff --git a/core/SConscript.boardloader b/core/SConscript.boardloader index 9fcc16a63..1efe8e105 100644 --- a/core/SConscript.boardloader +++ b/core/SConscript.boardloader @@ -57,11 +57,11 @@ CPPPATH_MOD += [ 'vendor/micropython/lib/uzlib', ] SOURCE_MOD += [ - 'embed/lib/display.c', - 'embed/lib/display_utils.c', 'embed/lib/colors.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display_utils.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', 'embed/lib/mini_printf.c', 'embed/lib/terminal.c', diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index d1845e0cb..94a322261 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -79,17 +79,17 @@ CPPPATH_MOD += [ ] SOURCE_MOD += [ - 'embed/lib/mini_printf.c', - 'embed/lib/unit_variant.c', + 'embed/extmod/modtrezorcrypto/rand.c', 'embed/lib/buffers.c', 'embed/lib/colors.c', - 'embed/lib/display.c', 'embed/lib/display_utils.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', + 'embed/lib/mini_printf.c', 'embed/lib/terminal.c', - 'embed/extmod/modtrezorcrypto/rand.c', + 'embed/lib/unit_variant.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', diff --git a/core/SConscript.bootloader_ci b/core/SConscript.bootloader_ci index 6041a998c..d730e8349 100644 --- a/core/SConscript.bootloader_ci +++ b/core/SConscript.bootloader_ci @@ -74,15 +74,15 @@ CPPPATH_MOD += [ 'vendor/micropython/lib/uzlib', ] SOURCE_MOD += [ - 'embed/lib/display.c', - 'embed/lib/display_utils.c', - 'embed/lib/terminal.c', + 'embed/extmod/modtrezorcrypto/rand.c', 'embed/lib/colors.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display_utils.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', 'embed/lib/mini_printf.c', - 'embed/extmod/modtrezorcrypto/rand.c', + 'embed/lib/terminal.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu index ee5e4b844..fe5ae12c9 100644 --- a/core/SConscript.bootloader_emu +++ b/core/SConscript.bootloader_emu @@ -77,17 +77,17 @@ CPPPATH_MOD += [ ] SOURCE_MOD += [ - 'embed/lib/unit_variant.c', + 'embed/extmod/modtrezorcrypto/rand.c', 'embed/lib/buffers.c', 'embed/lib/colors.c', - 'embed/lib/display.c', 'embed/lib/display_utils.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', 'embed/lib/terminal.c', 'embed/lib/touch.c', - 'embed/extmod/modtrezorcrypto/rand.c', + 'embed/lib/unit_variant.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 93c82945e..85cd7f6c3 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -186,17 +186,17 @@ CPPPATH_MOD += [ 'vendor/micropython/lib/uzlib', ] SOURCE_MOD += [ - 'embed/lib/mini_printf.c', - 'embed/lib/unit_variant.c', + 'embed/extmod/modtrezorui/modtrezorui.c', 'embed/lib/buffers.c', 'embed/lib/colors.c', - 'embed/lib/display.c', 'embed/lib/display_utils.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', + 'embed/lib/mini_printf.c', 'embed/lib/terminal.c', - 'embed/extmod/modtrezorui/modtrezorui.c', + 'embed/lib/unit_variant.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index 54a079da3..c2f9b9d10 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -79,15 +79,15 @@ CPPPATH_MOD += [ ] SOURCE_MOD += [ - 'embed/lib/display.c', - 'embed/lib/display_utils.c', 'embed/lib/colors.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display_utils.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', 'embed/lib/mini_printf.c', - 'embed/lib/terminal.c', 'embed/lib/qr-code-generator/qrcodegen.c', + 'embed/lib/terminal.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', diff --git a/core/SConscript.reflash b/core/SConscript.reflash index e274113f4..026e82689 100644 --- a/core/SConscript.reflash +++ b/core/SConscript.reflash @@ -54,11 +54,11 @@ CPPPATH_MOD += [ 'vendor/micropython/lib/uzlib', ] SOURCE_MOD += [ - 'embed/lib/display.c', - 'embed/lib/display_utils.c', 'embed/lib/colors.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display_utils.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', 'embed/lib/mini_printf.c', 'embed/lib/terminal.c', diff --git a/core/SConscript.unix b/core/SConscript.unix index 8d8ff4e58..94617ef1a 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -187,16 +187,16 @@ CPPPATH_MOD += [ 'vendor/micropython/lib/uzlib', ] SOURCE_MOD += [ - 'embed/lib/unit_variant.c', + 'embed/extmod/modtrezorui/modtrezorui.c', 'embed/lib/buffers.c', 'embed/lib/colors.c', - 'embed/lib/display.c', 'embed/lib/display_utils.c', - 'embed/lib/fonts/fonts.c', + 'embed/lib/display.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/fonts/fonts.c', 'embed/lib/image.c', 'embed/lib/terminal.c', - 'embed/extmod/modtrezorui/modtrezorui.c', + 'embed/lib/unit_variant.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', diff --git a/core/embed/lib/toif.c b/core/embed/lib/toif.c deleted file mode 100644 index 8221f45f2..000000000 --- a/core/embed/lib/toif.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "toif.h" -#include -#include - -// see docs/misc/toif.md for definition of the TOIF format -bool toif_header_parse(const uint8_t *data, uint32_t len, uint16_t *out_w, - uint16_t *out_h, toif_format_t *out_format) { - if (len < 12 || memcmp(data, "TOI", 3) != 0) { - return false; - } - toif_format_t format = false; - if (data[3] == 'f') { - format = TOIF_FULL_COLOR_BE; - } else if (data[3] == 'g') { - format = TOIF_GRAYSCALE_OH; - } else if (data[3] == 'F') { - format = TOIF_FULL_COLOR_LE; - } else if (data[3] == 'G') { - format = TOIF_GRAYSCALE_EH; - } else { - return false; - } - - uint16_t w = *(uint16_t *)(data + 4); - uint16_t h = *(uint16_t *)(data + 6); - - uint32_t datalen = *(uint32_t *)(data + 8); - if (datalen != len - 12) { - return false; - } - - if (out_w != NULL && out_h != NULL && out_format != NULL) { - *out_w = w; - *out_h = h; - *out_format = format; - } - return true; -} diff --git a/core/embed/lib/toif.h b/core/embed/lib/toif.h deleted file mode 100644 index ccea6125c..000000000 --- a/core/embed/lib/toif.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIB_TOIF_H -#define LIB_TOIF_H - -#include -#include - -typedef enum { - TOIF_FULL_COLOR_BE = 0, // big endian - TOIF_GRAYSCALE_OH = 1, // odd hi - TOIF_FULL_COLOR_LE = 2, // little endian - TOIF_GRAYSCALE_EH = 3, // even hi -} toif_format_t; - -bool toif_header_parse(const uint8_t *buf, uint32_t len, uint16_t *out_w, - uint16_t *out_h, toif_format_t *out_format); - -#endif // LIB_TOIF_H diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index 5f30e7af7..95a76ad2f 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -19,14 +19,6 @@ pub struct FrameBuffer(*mut u16); #[derive(Copy, Clone)] pub struct FrameBuffer(*mut u32); -#[derive(PartialEq, Debug, Eq, FromPrimitive, Clone, Copy)] -pub enum ToifFormat { - FullColorBE = ffi::toif_format_t_TOIF_FULL_COLOR_BE as _, - GrayScaleOH = ffi::toif_format_t_TOIF_GRAYSCALE_OH as _, - FullColorLE = ffi::toif_format_t_TOIF_FULL_COLOR_LE as _, - GrayScaleEH = ffi::toif_format_t_TOIF_GRAYSCALE_EH as _, -} - pub fn backlight(val: i32) -> i32 { unsafe { ffi::display_backlight(val) } } diff --git a/core/embed/rust/src/ui/component/image.rs b/core/embed/rust/src/ui/component/image.rs index 7a5b9d46f..41c1a6883 100644 --- a/core/embed/rust/src/ui/component/image.rs +++ b/core/embed/rust/src/ui/component/image.rs @@ -1,14 +1,11 @@ -use crate::{ - trezorhal::display::ToifFormat, - ui::{ - component::{Component, Event, EventCtx, Never}, - display, - display::{ - toif::{image, Toif}, - Color, Icon, - }, - geometry::{Alignment2D, Offset, Point, Rect}, +use crate::ui::{ + component::{Component, Event, EventCtx, Never}, + display, + display::{ + toif::{image, Toif, ToifFormat}, + Color, Icon, }, + geometry::{Alignment2D, Offset, Point, Rect}, }; #[derive(PartialEq, Eq, Clone, Copy)] diff --git a/core/embed/rust/src/ui/display/toif.rs b/core/embed/rust/src/ui/display/toif.rs index 1a605e18a..b39dd94ee 100644 --- a/core/embed/rust/src/ui/display/toif.rs +++ b/core/embed/rust/src/ui/display/toif.rs @@ -1,9 +1,6 @@ use crate::{ error::Error, - trezorhal::{ - display::ToifFormat, - uzlib::{UzlibContext, UZLIB_WINDOW_SIZE}, - }, + trezorhal::uzlib::{UzlibContext, UZLIB_WINDOW_SIZE}, ui::{ component::image::Image, constant, @@ -33,6 +30,14 @@ use super::Color; const TOIF_HEADER_LENGTH: usize = 12; +#[derive(PartialEq, Debug, Eq, FromPrimitive, Clone, Copy)] +pub enum ToifFormat { + FullColorBE = 0, // big endian + GrayScaleOH = 1, // odd hi + FullColorLE = 2, // little endian + GrayScaleEH = 3, // even hi +} + pub fn render_icon(icon: &Icon, center: Point, fg_color: Color, bg_color: Color) { render_toif(&icon.toif, center, fg_color, bg_color); } diff --git a/core/embed/rust/src/ui/model_tr/component/homescreen.rs b/core/embed/rust/src/ui/model_tr/component/homescreen.rs index bac39440e..dfa46da8a 100644 --- a/core/embed/rust/src/ui/model_tr/component/homescreen.rs +++ b/core/embed/rust/src/ui/model_tr/component/homescreen.rs @@ -1,10 +1,14 @@ use crate::{ strutil::StringType, - trezorhal::{display::ToifFormat, usb::usb_configured}, + trezorhal::usb::usb_configured, ui::{ component::{Child, Component, Event, EventCtx, Label}, constant::{HEIGHT, WIDTH}, - display::{rect_fill, toif::Toif, Font, Icon}, + display::{ + rect_fill, + toif::{Toif, ToifFormat}, + Font, Icon, + }, event::USBEvent, geometry::{Alignment2D, Insets, Offset, Point, Rect}, layout::util::get_user_custom_image, diff --git a/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs b/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs index dad943255..a89345fef 100644 --- a/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs +++ b/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs @@ -14,12 +14,12 @@ use crate::{ }; use crate::{ - trezorhal::{buffers::BufferJpegWork, display::ToifFormat, uzlib::UZLIB_WINDOW_SIZE}, + trezorhal::{buffers::BufferJpegWork, uzlib::UZLIB_WINDOW_SIZE}, ui::{ constant::HEIGHT, display::{ tjpgd::{jpeg_test, BufferInput}, - toif::Toif, + toif::{Toif, ToifFormat}, }, model_tt::component::homescreen::render::{ HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE, diff --git a/core/embed/rust/trezorhal.h b/core/embed/rust/trezorhal.h index aa12b3763..e34711d70 100644 --- a/core/embed/rust/trezorhal.h +++ b/core/embed/rust/trezorhal.h @@ -11,7 +11,6 @@ #include "rgb_led.h" #include "secbool.h" #include "storage.h" -#include "toif.h" #include "touch.h" #include "usb.h"