mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 20:38:10 +00:00
refactor(core): remove unused functions
[no changelog]
This commit is contained in:
parent
6ea68baf34
commit
eb72fb4241
@ -30,10 +30,6 @@
|
||||
/// FONT_NORMAL: int # id of normal-width font
|
||||
/// FONT_BOLD: int # id of bold-width font
|
||||
/// FONT_DEMIBOLD: int # id of demibold font
|
||||
/// TOIF_FULL_COLOR_BE: int # full color big endian TOI image
|
||||
/// TOIF_FULL_COLOR_LE: int # full color little endian TOI image
|
||||
/// TOIF_GRAYSCALE_EH: int # grayscale even high TOI image
|
||||
/// TOIF_FULL_COLOR_BE: int # grayscale odd high TOI image
|
||||
///
|
||||
typedef struct _mp_obj_Display_t {
|
||||
mp_obj_base_t base;
|
||||
@ -91,395 +87,6 @@ STATIC mp_obj_t mod_trezorui_Display_bar(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_bar_obj, 6, 6,
|
||||
mod_trezorui_Display_bar);
|
||||
|
||||
/// def bar_radius(
|
||||
/// self,
|
||||
/// x: int,
|
||||
/// y: int,
|
||||
/// w: int,
|
||||
/// h: int,
|
||||
/// fgcolor: int,
|
||||
/// bgcolor: int | None = None,
|
||||
/// radius: int | None = None,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// Renders a rounded bar at position (x,y = upper left corner) with width w
|
||||
/// and height h of color fgcolor. Background is set to bgcolor and corners
|
||||
/// are drawn with radius radius.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_bar_radius(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_int_t w = mp_obj_get_int(args[3]);
|
||||
mp_int_t h = mp_obj_get_int(args[4]);
|
||||
uint16_t c = mp_obj_get_int(args[5]);
|
||||
uint16_t b = mp_obj_get_int(args[6]);
|
||||
uint8_t r = mp_obj_get_int(args[7]);
|
||||
display_bar_radius(x, y, w, h, c, b, r);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_bar_radius_obj,
|
||||
8, 8,
|
||||
mod_trezorui_Display_bar_radius);
|
||||
|
||||
/// def toif_info(self, image: bytes) -> tuple[int, int, int]:
|
||||
/// """
|
||||
/// Returns tuple containing TOIF image dimensions: width, height, and
|
||||
/// format Raises an exception for corrupted images.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_toif_info(mp_obj_t self, mp_obj_t image) {
|
||||
mp_buffer_info_t buffer = {0};
|
||||
mp_get_buffer_raise(image, &buffer, MP_BUFFER_READ);
|
||||
|
||||
uint16_t w = 0;
|
||||
uint16_t h = 0;
|
||||
toif_format_t format = TOIF_FULL_COLOR_BE;
|
||||
bool valid = display_toif_info(buffer.buf, buffer.len, &w, &h, &format);
|
||||
|
||||
if (!valid) {
|
||||
mp_raise_ValueError("Invalid image format");
|
||||
}
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(w);
|
||||
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(h);
|
||||
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(format);
|
||||
return MP_OBJ_FROM_PTR(tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_toif_info_obj,
|
||||
mod_trezorui_Display_toif_info);
|
||||
|
||||
/// def image(self, x: int, y: int, image: bytes) -> None:
|
||||
/// """
|
||||
/// Renders an image at position (x,y).
|
||||
/// The image needs to be in Trezor Optimized Image Format (TOIF) -
|
||||
/// full-color mode.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_image(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t image = {0};
|
||||
mp_get_buffer_raise(args[3], &image, MP_BUFFER_READ);
|
||||
const uint8_t *data = image.buf;
|
||||
|
||||
uint16_t w = 0;
|
||||
uint16_t h = 0;
|
||||
toif_format_t format = TOIF_FULL_COLOR_BE;
|
||||
bool valid = display_toif_info(data, image.len, &w, &h, &format);
|
||||
if (!valid || format != TOIF_FULL_COLOR_LE) {
|
||||
mp_raise_ValueError("Invalid image format");
|
||||
}
|
||||
display_image(x, y, w, h, data + 12, image.len - 12);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_image_obj, 4, 4,
|
||||
mod_trezorui_Display_image);
|
||||
|
||||
/// def avatar(
|
||||
/// self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// Renders an avatar at position (x,y).
|
||||
/// The image needs to be in Trezor Optimized Image Format (TOIF) -
|
||||
/// full-color mode. Image needs to be of exactly AVATAR_IMAGE_SIZE x
|
||||
/// AVATAR_IMAGE_SIZE pixels size.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_avatar(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t image = {0};
|
||||
mp_get_buffer_raise(args[3], &image, MP_BUFFER_READ);
|
||||
const uint8_t *data = image.buf;
|
||||
|
||||
uint16_t w = 0;
|
||||
uint16_t h = 0;
|
||||
toif_format_t format = TOIF_FULL_COLOR_BE;
|
||||
bool valid = display_toif_info(data, image.len, &w, &h, &format);
|
||||
if (!valid || format != TOIF_FULL_COLOR_BE) {
|
||||
mp_raise_ValueError("Invalid image format");
|
||||
}
|
||||
if (w != AVATAR_IMAGE_SIZE || h != AVATAR_IMAGE_SIZE) {
|
||||
mp_raise_ValueError("Invalid image size");
|
||||
}
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[4]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[5]);
|
||||
display_avatar(x, y, data + 12, image.len - 12, fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_avatar_obj, 6,
|
||||
6, mod_trezorui_Display_avatar);
|
||||
|
||||
/// def icon(
|
||||
/// self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// Renders an icon at position (x,y), fgcolor is used as foreground color,
|
||||
/// bgcolor as background. The icon needs to be in Trezor Optimized Image
|
||||
/// Format (TOIF) - gray-scale mode.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_icon(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t icon = {0};
|
||||
mp_get_buffer_raise(args[3], &icon, MP_BUFFER_READ);
|
||||
const uint8_t *data = icon.buf;
|
||||
|
||||
uint16_t w = 0;
|
||||
uint16_t h = 0;
|
||||
toif_format_t format = TOIF_FULL_COLOR_BE;
|
||||
bool valid = display_toif_info(data, icon.len, &w, &h, &format);
|
||||
if (!valid || format != TOIF_GRAYSCALE_EH) {
|
||||
mp_raise_ValueError("Invalid icon format");
|
||||
}
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[4]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[5]);
|
||||
display_icon(x, y, w, h, data + 12, icon.len - 12, fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_icon_obj, 6, 6,
|
||||
mod_trezorui_Display_icon);
|
||||
/// def loader(
|
||||
/// self,
|
||||
/// progress: int,
|
||||
/// indeterminate: bool,
|
||||
/// yoffset: int,
|
||||
/// fgcolor: int,
|
||||
/// bgcolor: int,
|
||||
/// icon: bytes | None = None,
|
||||
/// iconfgcolor: int | None = None,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// Renders a rotating loader graphic.
|
||||
/// Progress determines its position (0-1000), fgcolor is used as foreground
|
||||
/// color, bgcolor as background. When icon and iconfgcolor are provided, an
|
||||
/// icon is drawn in the middle using the color specified in iconfgcolor.
|
||||
/// Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels
|
||||
/// size.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_loader(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t progress = mp_obj_get_int(args[1]);
|
||||
bool indeterminate = args[2] == mp_const_true;
|
||||
mp_int_t yoffset = mp_obj_get_int(args[3]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[4]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[5]);
|
||||
if (n_args > 6) { // icon provided
|
||||
mp_buffer_info_t icon = {0};
|
||||
mp_get_buffer_raise(args[6], &icon, MP_BUFFER_READ);
|
||||
const uint8_t *data = icon.buf;
|
||||
if (icon.len < 8 || memcmp(data, "TOIG", 4) != 0) {
|
||||
mp_raise_ValueError("Invalid image format");
|
||||
}
|
||||
mp_int_t w = *(uint16_t *)(data + 4);
|
||||
mp_int_t h = *(uint16_t *)(data + 6);
|
||||
uint32_t datalen = *(uint32_t *)(data + 8);
|
||||
if (w != LOADER_ICON_SIZE || h != LOADER_ICON_SIZE) {
|
||||
mp_raise_ValueError("Invalid icon size");
|
||||
}
|
||||
if (datalen != icon.len - 12) {
|
||||
mp_raise_ValueError("Invalid size of data");
|
||||
}
|
||||
uint16_t iconfgcolor = 0;
|
||||
if (n_args > 7) { // icon color provided
|
||||
iconfgcolor = mp_obj_get_int(args[7]);
|
||||
} else {
|
||||
iconfgcolor = ~bgcolor; // invert
|
||||
}
|
||||
display_loader(progress, indeterminate, yoffset, fgcolor, bgcolor, icon.buf,
|
||||
icon.len, iconfgcolor);
|
||||
} else {
|
||||
display_loader(progress, indeterminate, yoffset, fgcolor, bgcolor, NULL, 0,
|
||||
0);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_loader_obj, 6,
|
||||
8, mod_trezorui_Display_loader);
|
||||
|
||||
/// def print(self, text: str) -> None:
|
||||
/// """
|
||||
/// Renders text using 5x8 bitmap font (using special text mode).
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_print(mp_obj_t self, mp_obj_t text) {
|
||||
mp_buffer_info_t buf = {0};
|
||||
mp_get_buffer_raise(text, &buf, MP_BUFFER_READ);
|
||||
if (buf.len > 0) {
|
||||
display_print(buf.buf, buf.len);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_print_obj,
|
||||
mod_trezorui_Display_print);
|
||||
|
||||
/// def text(
|
||||
/// self,
|
||||
/// x: int,
|
||||
/// y: int,
|
||||
/// text: str,
|
||||
/// font: int,
|
||||
/// fgcolor: int,
|
||||
/// bgcolor: int,
|
||||
/// text_offset: int | None = None,
|
||||
/// text_len: int | None = None,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// Renders left-aligned text at position (x,y) where x is left position and
|
||||
/// y is baseline. Font font is used for rendering, fgcolor is used as
|
||||
/// foreground color, bgcolor as background.
|
||||
///
|
||||
/// Arguments text_offset and text_len can be used to render a substring of
|
||||
/// the text.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
||||
|
||||
const char *buf_start = text.buf;
|
||||
int buf_len = text.len;
|
||||
if (n_args > 7) {
|
||||
mp_int_t off = mp_obj_get_int(args[7]);
|
||||
mp_int_t len = n_args > 8 ? mp_obj_get_int(args[8]) : text.len - off;
|
||||
if (off < 0 || off > text.len) {
|
||||
mp_raise_ValueError("Invalid text_offset");
|
||||
}
|
||||
if (len < 0 || len + off > text.len) {
|
||||
mp_raise_ValueError("Invalid text_len");
|
||||
}
|
||||
display_utf8_substr(text.buf, text.len, off, len, &buf_start, &buf_len);
|
||||
}
|
||||
|
||||
display_text(x, y, buf_start, buf_len, font, fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 9,
|
||||
mod_trezorui_Display_text);
|
||||
|
||||
/// def text_center(
|
||||
/// self,
|
||||
/// x: int,
|
||||
/// y: int,
|
||||
/// text: str,
|
||||
/// font: int,
|
||||
/// fgcolor: int,
|
||||
/// bgcolor: int,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// Renders text centered at position (x,y) where x is text center and y is
|
||||
/// baseline. Font font is used for rendering, fgcolor is used as foreground
|
||||
/// color, bgcolor as background.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
||||
display_text_center(x, y, text.buf, text.len, font, fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_center_obj,
|
||||
7, 7,
|
||||
mod_trezorui_Display_text_center);
|
||||
|
||||
/// def text_right(
|
||||
/// self,
|
||||
/// x: int,
|
||||
/// y: int,
|
||||
/// text: str,
|
||||
/// font: int,
|
||||
/// fgcolor: int,
|
||||
/// bgcolor: int,
|
||||
/// ) -> None:
|
||||
/// """
|
||||
/// Renders right-aligned text at position (x,y) where x is right position
|
||||
/// and y is baseline. Font font is used for rendering, fgcolor is used as
|
||||
/// foreground color, bgcolor as background.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
||||
display_text_right(x, y, text.buf, text.len, font, fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj,
|
||||
7, 7,
|
||||
mod_trezorui_Display_text_right);
|
||||
|
||||
/// def text_width(
|
||||
/// self,
|
||||
/// text: str,
|
||||
/// font: int,
|
||||
/// text_offset: int | None = None,
|
||||
/// text_len: int | None = None,
|
||||
/// ) -> int:
|
||||
/// """
|
||||
/// Returns a width of text in pixels. Font font is used for rendering.
|
||||
///
|
||||
/// Arguments text_offset and text_len can be used to render a substring of
|
||||
/// the text.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text_width(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t txt = {0};
|
||||
mp_get_buffer_raise(args[1], &txt, MP_BUFFER_READ);
|
||||
mp_int_t f = mp_obj_get_int(args[2]);
|
||||
|
||||
const char *buf_start = txt.buf;
|
||||
int buf_len = txt.len;
|
||||
if (n_args > 3) {
|
||||
mp_int_t off = mp_obj_get_int(args[3]);
|
||||
mp_int_t len = n_args > 4 ? mp_obj_get_int(args[4]) : txt.len - off;
|
||||
if (off < 0 || off > txt.len) {
|
||||
mp_raise_ValueError("Invalid text_offset");
|
||||
}
|
||||
if (len < 0 || len + off > txt.len) {
|
||||
mp_raise_ValueError("Invalid text_len");
|
||||
}
|
||||
display_utf8_substr(txt.buf, txt.len, off, len, &buf_start, &buf_len);
|
||||
}
|
||||
|
||||
int w = display_text_width(buf_start, buf_len, f);
|
||||
return mp_obj_new_int(w);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_width_obj,
|
||||
3, 5,
|
||||
mod_trezorui_Display_text_width);
|
||||
|
||||
/// def text_split(self, text: str, font: int, requested_width: int) -> int:
|
||||
/// """
|
||||
/// Returns how many characters of the string can be used before exceeding
|
||||
/// the requested width. Tries to avoid breaking words if possible. Font
|
||||
/// font is used for rendering.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_text_split(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
mp_buffer_info_t text = {0};
|
||||
mp_get_buffer_raise(args[1], &text, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[2]);
|
||||
mp_int_t requested_width = mp_obj_get_int(args[3]);
|
||||
int chars = display_text_split(text.buf, text.len, font, requested_width);
|
||||
return mp_obj_new_int(chars);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_split_obj,
|
||||
4, 4,
|
||||
mod_trezorui_Display_text_split);
|
||||
|
||||
/// def orientation(self, degrees: int | None = None) -> int:
|
||||
/// """
|
||||
/// Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
@ -528,39 +135,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_backlight_obj,
|
||||
1, 2,
|
||||
mod_trezorui_Display_backlight);
|
||||
|
||||
/// def offset(self, xy: tuple[int, int] | None = None) -> tuple[int, int]:
|
||||
/// """
|
||||
/// Sets offset (x, y) for all subsequent drawing calls.
|
||||
/// Call without the xy parameter to just perform the read of the value.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorui_Display_offset(size_t n_args,
|
||||
const mp_obj_t *args) {
|
||||
int xy[2] = {0}, x = 0, y = 0;
|
||||
if (n_args > 1) {
|
||||
size_t xy_cnt = 0;
|
||||
mp_obj_t *xy_obj = NULL;
|
||||
if (MP_OBJ_IS_TYPE(args[1], &mp_type_tuple)) {
|
||||
mp_obj_tuple_get(args[1], &xy_cnt, &xy_obj);
|
||||
} else {
|
||||
mp_raise_TypeError("Tuple expected");
|
||||
}
|
||||
if (xy_cnt != 2) {
|
||||
mp_raise_ValueError("Tuple of 2 values expected");
|
||||
}
|
||||
xy[0] = mp_obj_get_int(xy_obj[0]);
|
||||
xy[1] = mp_obj_get_int(xy_obj[1]);
|
||||
display_offset(xy, &x, &y);
|
||||
} else {
|
||||
display_offset(0, &x, &y);
|
||||
}
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
||||
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(x);
|
||||
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(y);
|
||||
return MP_OBJ_FROM_PTR(tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_offset_obj, 1,
|
||||
2, mod_trezorui_Display_offset);
|
||||
|
||||
/// def save(self, prefix: str) -> None:
|
||||
/// """
|
||||
/// Saves current display contents to PNG file with given prefix.
|
||||
@ -592,29 +166,10 @@ STATIC const mp_rom_map_elem_t mod_trezorui_Display_locals_dict_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_refresh),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_refresh_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&mod_trezorui_Display_bar_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_bar_radius),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_bar_radius_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_toif_info),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_toif_info_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_image), MP_ROM_PTR(&mod_trezorui_Display_image_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_avatar), MP_ROM_PTR(&mod_trezorui_Display_avatar_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_icon), MP_ROM_PTR(&mod_trezorui_Display_icon_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_loader), MP_ROM_PTR(&mod_trezorui_Display_loader_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_print), MP_ROM_PTR(&mod_trezorui_Display_print_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_trezorui_Display_text_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_text_center),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_text_center_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_text_right),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_text_right_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_text_width),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_text_width_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_text_split),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_text_split_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_orientation),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_orientation_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_backlight),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_backlight_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_offset), MP_ROM_PTR(&mod_trezorui_Display_offset_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&mod_trezorui_Display_save_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_clear_save),
|
||||
MP_ROM_PTR(&mod_trezorui_Display_clear_save_obj)},
|
||||
@ -624,10 +179,6 @@ STATIC const mp_rom_map_elem_t mod_trezorui_Display_locals_dict_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_FONT_BOLD), MP_ROM_INT(FONT_BOLD)},
|
||||
{MP_ROM_QSTR(MP_QSTR_FONT_DEMIBOLD), MP_ROM_INT(FONT_DEMIBOLD)},
|
||||
{MP_ROM_QSTR(MP_QSTR_FONT_MONO), MP_ROM_INT(FONT_MONO)},
|
||||
{MP_ROM_QSTR(MP_QSTR_TOIF_FULL_COLOR_BE), MP_ROM_INT(TOIF_FULL_COLOR_BE)},
|
||||
{MP_ROM_QSTR(MP_QSTR_TOIF_FULL_COLOR_LE), MP_ROM_INT(TOIF_FULL_COLOR_LE)},
|
||||
{MP_ROM_QSTR(MP_QSTR_TOIF_GRAYSCALE_EH), MP_ROM_INT(TOIF_GRAYSCALE_EH)},
|
||||
{MP_ROM_QSTR(MP_QSTR_TOIF_GRAYSCALE_OH), MP_ROM_INT(TOIF_GRAYSCALE_OH)},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mod_trezorui_Display_locals_dict,
|
||||
mod_trezorui_Display_locals_dict_table);
|
||||
|
@ -29,10 +29,6 @@
|
||||
#include "dma2d.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_RUST_LOADER
|
||||
#include "rust_ui.h"
|
||||
#endif
|
||||
|
||||
#include "fonts/fonts.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
@ -337,71 +333,6 @@ void display_image(int x, int y, int w, int h, const void *data,
|
||||
}
|
||||
#endif
|
||||
|
||||
#define AVATAR_BORDER_SIZE 4
|
||||
#define AVATAR_BORDER_LOW \
|
||||
(AVATAR_IMAGE_SIZE / 2 - AVATAR_BORDER_SIZE) * \
|
||||
(AVATAR_IMAGE_SIZE / 2 - AVATAR_BORDER_SIZE)
|
||||
#define AVATAR_BORDER_HIGH (AVATAR_IMAGE_SIZE / 2) * (AVATAR_IMAGE_SIZE / 2)
|
||||
#define AVATAR_ANTIALIAS 1
|
||||
|
||||
void display_avatar(int x, int y, const void *data, uint32_t datalen,
|
||||
uint16_t fgcolor, uint16_t bgcolor) {
|
||||
#if defined TREZOR_MODEL_T
|
||||
x += DISPLAY_OFFSET.x;
|
||||
y += DISPLAY_OFFSET.y;
|
||||
int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
clamp_coords(x, y, AVATAR_IMAGE_SIZE, AVATAR_IMAGE_SIZE, &x0, &y0, &x1, &y1);
|
||||
display_set_window(x0, y0, x1, y1);
|
||||
x0 -= x;
|
||||
x1 -= x;
|
||||
y0 -= y;
|
||||
y1 -= y;
|
||||
|
||||
struct uzlib_uncomp decomp = {0};
|
||||
uint8_t decomp_window[UZLIB_WINDOW_SIZE] = {0};
|
||||
uint8_t decomp_out[2] = {0};
|
||||
uzlib_prepare(&decomp, decomp_window, data, datalen, decomp_out,
|
||||
sizeof(decomp_out));
|
||||
|
||||
for (uint32_t pos = 0; pos < AVATAR_IMAGE_SIZE * AVATAR_IMAGE_SIZE; pos++) {
|
||||
int st = uzlib_uncompress(&decomp);
|
||||
if (st == TINF_DONE) break; // all OK
|
||||
if (st < 0) break; // error
|
||||
const int px = pos % AVATAR_IMAGE_SIZE;
|
||||
const int py = pos / AVATAR_IMAGE_SIZE;
|
||||
if (px >= x0 && px <= x1 && py >= y0 && py <= y1) {
|
||||
int d = (px - AVATAR_IMAGE_SIZE / 2) * (px - AVATAR_IMAGE_SIZE / 2) +
|
||||
(py - AVATAR_IMAGE_SIZE / 2) * (py - AVATAR_IMAGE_SIZE / 2);
|
||||
if (d < AVATAR_BORDER_LOW) {
|
||||
// inside border area
|
||||
PIXELDATA((decomp_out[0] << 8) | decomp_out[1]);
|
||||
} else if (d > AVATAR_BORDER_HIGH) {
|
||||
// outside border area
|
||||
PIXELDATA(bgcolor);
|
||||
} else {
|
||||
// border area
|
||||
#if AVATAR_ANTIALIAS
|
||||
d = 31 * (d - AVATAR_BORDER_LOW) /
|
||||
(AVATAR_BORDER_HIGH - AVATAR_BORDER_LOW);
|
||||
uint16_t c = 0;
|
||||
if (d >= 16) {
|
||||
c = interpolate_color(bgcolor, fgcolor, d - 16);
|
||||
} else {
|
||||
c = interpolate_color(fgcolor, (decomp_out[0] << 8) | decomp_out[1],
|
||||
d);
|
||||
}
|
||||
PIXELDATA(c);
|
||||
#else
|
||||
PIXELDATA(fgcolor);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
decomp.dest = (uint8_t *)&decomp_out;
|
||||
}
|
||||
PIXELDATA_DIRTY();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef USE_DMA2D
|
||||
void display_icon(int x, int y, int w, int h, const void *data,
|
||||
uint32_t datalen, uint16_t fgcolor, uint16_t bgcolor) {
|
||||
@ -620,16 +551,6 @@ void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
PIXELDATA_DIRTY();
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
|
||||
void display_loader(uint16_t progress, bool indeterminate, int yoffset,
|
||||
uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon,
|
||||
uint32_t iconlen, uint16_t iconfgcolor) {
|
||||
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R
|
||||
loader_uncompress_r(yoffset, fgcolor, bgcolor, iconfgcolor, progress,
|
||||
indeterminate, icon, iconlen);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef TREZOR_PRINT_DISABLE
|
||||
|
@ -2,11 +2,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void loader_uncompress_r(int32_t y_offset, uint16_t fg_color, uint16_t bg_color,
|
||||
uint16_t icon_color, int32_t progress,
|
||||
int32_t indeterminate, const uint8_t* icon_data,
|
||||
uint32_t icon_data_size);
|
||||
|
||||
uint32_t screen_install_confirm(const char* vendor_str, uint8_t vendor_str_len,
|
||||
const char* version_str,
|
||||
const uint8_t* fingerprint,
|
||||
|
@ -3,7 +3,6 @@ mod rectangular;
|
||||
mod starry;
|
||||
|
||||
use crate::ui::display::{Color, Icon};
|
||||
use core::slice::from_raw_parts;
|
||||
|
||||
#[cfg(feature = "model_tt")]
|
||||
use crate::ui::display::loader::circular::{
|
||||
@ -39,33 +38,3 @@ pub fn loader_indeterminate(
|
||||
) {
|
||||
indeterminate(progress, y_offset, fg_color, bg_color, icon);
|
||||
}
|
||||
|
||||
//TODO: remove when loader is no longer called from C
|
||||
#[no_mangle]
|
||||
pub extern "C" fn loader_uncompress_r(
|
||||
y_offset: cty::int32_t,
|
||||
fg_color: cty::uint16_t,
|
||||
bg_color: cty::uint16_t,
|
||||
icon_color: cty::uint16_t,
|
||||
progress: cty::int32_t,
|
||||
indeterminate: cty::int32_t,
|
||||
icon_data: cty::uintptr_t,
|
||||
icon_data_size: cty::uint32_t,
|
||||
) {
|
||||
let fg = Color::from_u16(fg_color);
|
||||
let bg = Color::from_u16(bg_color);
|
||||
let ic_color = Color::from_u16(icon_color);
|
||||
|
||||
let i = if icon_data != 0 {
|
||||
let data_slice = unsafe { from_raw_parts(icon_data as _, icon_data_size as _) };
|
||||
Some((Icon::new(data_slice), ic_color))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if indeterminate == 0 {
|
||||
loader(progress as _, y_offset as _, fg, bg, i);
|
||||
} else {
|
||||
loader_indeterminate(progress as _, y_offset as _, fg, bg, i);
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,6 @@ class Display:
|
||||
FONT_NORMAL: int # id of normal-width font
|
||||
FONT_BOLD: int # id of bold-width font
|
||||
FONT_DEMIBOLD: int # id of demibold font
|
||||
TOIF_FULL_COLOR_BE: int # full color big endian TOI image
|
||||
TOIF_FULL_COLOR_LE: int # full color little endian TOI image
|
||||
TOIF_GRAYSCALE_EH: int # grayscale even high TOI image
|
||||
TOIF_FULL_COLOR_BE: int # grayscale odd high TOI image
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
@ -38,147 +34,6 @@ class Display:
|
||||
height h of color color.
|
||||
"""
|
||||
|
||||
def bar_radius(
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
w: int,
|
||||
h: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int | None = None,
|
||||
radius: int | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
Renders a rounded bar at position (x,y = upper left corner) with width w
|
||||
and height h of color fgcolor. Background is set to bgcolor and corners
|
||||
are drawn with radius radius.
|
||||
"""
|
||||
|
||||
def toif_info(self, image: bytes) -> tuple[int, int, int]:
|
||||
"""
|
||||
Returns tuple containing TOIF image dimensions: width, height, and
|
||||
format Raises an exception for corrupted images.
|
||||
"""
|
||||
|
||||
def image(self, x: int, y: int, image: bytes) -> None:
|
||||
"""
|
||||
Renders an image at position (x,y).
|
||||
The image needs to be in Trezor Optimized Image Format (TOIF) -
|
||||
full-color mode.
|
||||
"""
|
||||
|
||||
def avatar(
|
||||
self, x: int, y: int, image: bytes, fgcolor: int, bgcolor: int
|
||||
) -> None:
|
||||
"""
|
||||
Renders an avatar at position (x,y).
|
||||
The image needs to be in Trezor Optimized Image Format (TOIF) -
|
||||
full-color mode. Image needs to be of exactly AVATAR_IMAGE_SIZE x
|
||||
AVATAR_IMAGE_SIZE pixels size.
|
||||
"""
|
||||
|
||||
def icon(
|
||||
self, x: int, y: int, icon: bytes, fgcolor: int, bgcolor: int
|
||||
) -> None:
|
||||
"""
|
||||
Renders an icon at position (x,y), fgcolor is used as foreground color,
|
||||
bgcolor as background. The icon needs to be in Trezor Optimized Image
|
||||
Format (TOIF) - gray-scale mode.
|
||||
"""
|
||||
|
||||
def loader(
|
||||
self,
|
||||
progress: int,
|
||||
indeterminate: bool,
|
||||
yoffset: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int,
|
||||
icon: bytes | None = None,
|
||||
iconfgcolor: int | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
Renders a rotating loader graphic.
|
||||
Progress determines its position (0-1000), fgcolor is used as foreground
|
||||
color, bgcolor as background. When icon and iconfgcolor are provided, an
|
||||
icon is drawn in the middle using the color specified in iconfgcolor.
|
||||
Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels
|
||||
size.
|
||||
"""
|
||||
|
||||
def print(self, text: str) -> None:
|
||||
"""
|
||||
Renders text using 5x8 bitmap font (using special text mode).
|
||||
"""
|
||||
|
||||
def text(
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
text: str,
|
||||
font: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int,
|
||||
text_offset: int | None = None,
|
||||
text_len: int | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
Renders left-aligned text at position (x,y) where x is left position and
|
||||
y is baseline. Font font is used for rendering, fgcolor is used as
|
||||
foreground color, bgcolor as background.
|
||||
Arguments text_offset and text_len can be used to render a substring of
|
||||
the text.
|
||||
"""
|
||||
|
||||
def text_center(
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
text: str,
|
||||
font: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int,
|
||||
) -> None:
|
||||
"""
|
||||
Renders text centered at position (x,y) where x is text center and y is
|
||||
baseline. Font font is used for rendering, fgcolor is used as foreground
|
||||
color, bgcolor as background.
|
||||
"""
|
||||
|
||||
def text_right(
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
text: str,
|
||||
font: int,
|
||||
fgcolor: int,
|
||||
bgcolor: int,
|
||||
) -> None:
|
||||
"""
|
||||
Renders right-aligned text at position (x,y) where x is right position
|
||||
and y is baseline. Font font is used for rendering, fgcolor is used as
|
||||
foreground color, bgcolor as background.
|
||||
"""
|
||||
|
||||
def text_width(
|
||||
self,
|
||||
text: str,
|
||||
font: int,
|
||||
text_offset: int | None = None,
|
||||
text_len: int | None = None,
|
||||
) -> int:
|
||||
"""
|
||||
Returns a width of text in pixels. Font font is used for rendering.
|
||||
Arguments text_offset and text_len can be used to render a substring of
|
||||
the text.
|
||||
"""
|
||||
|
||||
def text_split(self, text: str, font: int, requested_width: int) -> int:
|
||||
"""
|
||||
Returns how many characters of the string can be used before exceeding
|
||||
the requested width. Tries to avoid breaking words if possible. Font
|
||||
font is used for rendering.
|
||||
"""
|
||||
|
||||
def orientation(self, degrees: int | None = None) -> int:
|
||||
"""
|
||||
Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||
@ -193,12 +48,6 @@ class Display:
|
||||
Call without the val parameter to just perform the read of the value.
|
||||
"""
|
||||
|
||||
def offset(self, xy: tuple[int, int] | None = None) -> tuple[int, int]:
|
||||
"""
|
||||
Sets offset (x, y) for all subsequent drawing calls.
|
||||
Call without the xy parameter to just perform the read of the value.
|
||||
"""
|
||||
|
||||
def save(self, prefix: str) -> None:
|
||||
"""
|
||||
Saves current display contents to PNG file with given prefix.
|
||||
|
@ -14,59 +14,6 @@ class TestDisplay(unittest.TestCase):
|
||||
def test_bar(self):
|
||||
display.bar(0, 0, 10, 10, 0xFFFF)
|
||||
|
||||
def test_bar_radius(self):
|
||||
display.bar_radius(0, 0, 10, 10, 0xFFFF, 0x0000, 16)
|
||||
|
||||
def test_image(self):
|
||||
pass
|
||||
|
||||
def test_icon(self):
|
||||
pass
|
||||
|
||||
def test_text(self):
|
||||
display.text(120, 120, 'Test', 0, 0xFFFF, 0x0000)
|
||||
display.text(120, 120, 'Test', 0, 0xFFFF, 0x0000, 2)
|
||||
display.text(120, 120, 'Test', 0, 0xFFFF, 0x0000, 2, 1)
|
||||
display.text(120, 120, 'Těst', 0, 0xFFFF, 0x0000, 2, 2)
|
||||
|
||||
display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000)
|
||||
for off in (0, 2, 3, 8, 16):
|
||||
display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000, off)
|
||||
display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000, off, 0)
|
||||
|
||||
for off, tlen in ((2, 5), (2, 14), (3, 5), (3, 13), (8, 1), (8, 8)):
|
||||
display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000, off, tlen)
|
||||
|
||||
def test_text_center(self):
|
||||
display.text_center(120, 120, 'Test', 0, 0xFFFF, 0x0000)
|
||||
|
||||
def test_text_right(self):
|
||||
display.text_right(120, 120, 'Test', 0, 0xFFFF, 0x0000)
|
||||
|
||||
def test_text_width(self):
|
||||
display.text_width('Test', 0)
|
||||
display.text_width('Test', 0, 2)
|
||||
display.text_width('Test', 0, 2, 1)
|
||||
display.text_width('Těst', 0, 2, 2)
|
||||
|
||||
display.text_width("ǑǑǑǑǑǑǑǑ", 0)
|
||||
for off in (0, 2, 3, 8, 16):
|
||||
display.text_width("ǑǑǑǑǑǑǑǑ", 0, off)
|
||||
self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 0, off, 0), 0)
|
||||
|
||||
for off, tlen in ((0, 8), (0, 16), (2, 5), (2, 14), (3, 5), (3, 13)):
|
||||
display.text_width("ǑǑǑǑǑǑǑǑ", 0, off, tlen)
|
||||
|
||||
self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 8), 0)
|
||||
self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 8, 1), 0)
|
||||
self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 8, 8), 0)
|
||||
self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 9), 0)
|
||||
self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 9, 1), 0)
|
||||
self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 15, 1), 0)
|
||||
|
||||
def test_loader(self):
|
||||
display.loader(333, False, 0, 0xFFFF, 0x0000)
|
||||
|
||||
def test_orientation(self):
|
||||
for o in [0, 90, 180, 270]:
|
||||
display.orientation(o)
|
||||
@ -75,14 +22,6 @@ class TestDisplay(unittest.TestCase):
|
||||
for b in range(256):
|
||||
display.backlight(b)
|
||||
|
||||
def test_offset(self):
|
||||
for x in range(-4, 5):
|
||||
for y in range(-4, 5):
|
||||
o = (x * 57, y * 57)
|
||||
display.offset(o)
|
||||
o2 = display.offset()
|
||||
self.assertEqual(o, o2)
|
||||
|
||||
def test_raw(self):
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user