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

[no changelog]
cepetr/display-if-refactor
cepetr 5 months ago
parent e93d46392d
commit a14ae705fb

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

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

@ -20,14 +20,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) }
}

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

@ -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,
@ -32,6 +29,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);
}

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

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

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

Loading…
Cancel
Save