1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

refactor(core/embed): move TOIF format definition to rust

[no changelog]
This commit is contained in:
cepetr 2024-01-17 15:29:49 +01:00 committed by cepetr
parent 8eb1f9b309
commit 6331076444
16 changed files with 57 additions and 153 deletions

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "toif.h"
#include <stddef.h>
#include <string.h>
// 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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef LIB_TOIF_H
#define LIB_TOIF_H
#include <stdbool.h>
#include <stdint.h>
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

View File

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

View File

@ -1,14 +1,11 @@
use crate::{
trezorhal::display::ToifFormat,
ui::{
use crate::ui::{
component::{Component, Event, EventCtx, Never},
display,
display::{
toif::{image, Toif},
toif::{image, Toif, ToifFormat},
Color, Icon,
},
geometry::{Alignment2D, Offset, Point, Rect},
},
};
#[derive(PartialEq, Eq, Clone, Copy)]

View File

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

View File

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

View File

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

View File

@ -11,7 +11,6 @@
#include "rgb_led.h"
#include "secbool.h"
#include "storage.h"
#include "toif.h"
#include "touch.h"
#include "usb.h"