mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
move text_center and text_right to lower layer, compute text length if not provided
This commit is contained in:
parent
2453b4d0b6
commit
e361eb157d
@ -44,7 +44,6 @@ INC += -I$(CMSIS_DIR)/devinc
|
||||
INC += -I$(HAL_DIR)/inc
|
||||
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/inc
|
||||
#INC += -I$(USBHOST_DIR)
|
||||
INC += -I../extmod/modtrezorui
|
||||
|
||||
CFLAGS_CORTEX_M = -mthumb -mabi=aapcs-linux -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
|
||||
CFLAGS_MCU_f4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DMCU_SERIES_F4
|
||||
@ -76,6 +75,10 @@ endif
|
||||
# uncomment this if you want libgcc
|
||||
LIBS += $(shell $(CC) -print-libgcc-file-name)
|
||||
|
||||
SRC_LIB = $(addprefix lib/,\
|
||||
libc/string0.c \
|
||||
)
|
||||
|
||||
SRC_C = \
|
||||
bootloader.c \
|
||||
bootloader_ui.c \
|
||||
@ -128,18 +131,22 @@ SRC_USBDEV = $(addprefix $(USBDEV_DIR)/,\
|
||||
class/src/usbd_msc_data.c \
|
||||
)
|
||||
|
||||
SRC_MODUI = $(addprefix extmod/modtrezorui/,\
|
||||
ifeq ($(MICROPY_PY_TREZORUI),1)
|
||||
INC += -I../extmod/modtrezorui
|
||||
SRC_MOD += $(addprefix extmod/modtrezorui/,\
|
||||
display.c \
|
||||
inflate.c \
|
||||
font_robotomono_regular.c \
|
||||
)
|
||||
endif
|
||||
|
||||
OBJ =
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_LIB:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_O))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_USBDEV:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_MODUI:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
|
||||
OBJ += $(BUILD)/pins_$(BOARD).o
|
||||
|
||||
# We put ff.o and stm32f4xx_hal_sd.o into the first 16K section with the ISRs.
|
||||
@ -203,6 +210,8 @@ CDCINF_TEMPLATE = pybcdc.inf_template
|
||||
GEN_CDCINF_FILE = $(HEADER_BUILD)/pybcdc.inf
|
||||
GEN_CDCINF_HEADER = $(HEADER_BUILD)/pybcdc_inf.h
|
||||
|
||||
# List of sources for qstr extraction
|
||||
SRC_QSTR += $(SRC_C) $(SRC_MOD) $(SRC_LIB)
|
||||
# Append any auto-generated sources that are needed by sources listed in
|
||||
# SRC_QSTR
|
||||
SRC_QSTR_AUTO_DEPS += $(GEN_CDCINF_HEADER)
|
||||
|
@ -1,10 +1,14 @@
|
||||
#include "display.h"
|
||||
#include "bootloader_trezor.h"
|
||||
|
||||
#define ui_WHITE 0xFFFF
|
||||
#define ui_BLACK 0x0000
|
||||
#define ui_BLUE 0x24BE
|
||||
|
||||
void screen_welcome(void)
|
||||
{
|
||||
display_image(0, 0, 240, 240, toi_trezor, sizeof(toi_trezor));
|
||||
display_text(0, 240, "bootloader", 10, FONT_MONO, 0xFFFF, 0x0000);
|
||||
display_text(0, 240, "bootloader", 10, FONT_MONO, ui_WHITE, ui_BLACK);
|
||||
}
|
||||
|
||||
void screen_info(void)
|
||||
@ -15,8 +19,16 @@ void screen_upload_request(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void screen_upload_progress(int permil)
|
||||
{
|
||||
char label[5] = "100%";
|
||||
char *plabel = label;
|
||||
// TODO: convert permil -> plabel
|
||||
display_text_center(120, 192 + 32, "Uploading firmware", -1, FONT_NORMAL, ui_WHITE, ui_BLACK);
|
||||
display_loader(permil, ui_BLUE, ui_BLACK, 0, 0, 0);
|
||||
display_text_center(120, 192 / 2 + 14 / 2, plabel, -1, FONT_BOLD, ui_WHITE, ui_BLACK);
|
||||
display_refresh();
|
||||
}
|
||||
|
||||
void screen_upload_success(void)
|
||||
|
@ -195,6 +195,10 @@ void display_text(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t f
|
||||
uint16_t colortable[16];
|
||||
set_color_table(colortable, fgcolor, bgcolor);
|
||||
|
||||
// determine text length if not provided
|
||||
if (textlen < 0) {
|
||||
textlen = strlen(text);
|
||||
}
|
||||
// render glyphs
|
||||
for (int i = 0; i < textlen; i++) {
|
||||
const uint8_t *g = get_glyph(font, (uint8_t)text[i]);
|
||||
@ -219,12 +223,28 @@ void display_text(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t f
|
||||
}
|
||||
}
|
||||
|
||||
void display_text_center(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
|
||||
{
|
||||
uint32_t w = display_text_width(text, textlen, font);
|
||||
display_text(x - w / 2, y, text, textlen, font, fgcolor, bgcolor);
|
||||
}
|
||||
|
||||
void display_text_right(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
|
||||
{
|
||||
uint32_t w = display_text_width(text, textlen, font);
|
||||
display_text(x - w, y, text, textlen, font, fgcolor, bgcolor);
|
||||
}
|
||||
|
||||
// compute the width of the text (in pixels)
|
||||
uint32_t display_text_width(const uint8_t *text, int textlen, uint8_t font)
|
||||
uint32_t display_text_width(const char *text, int textlen, uint8_t font)
|
||||
{
|
||||
uint32_t w = 0;
|
||||
// determine text length if not provided
|
||||
if (textlen < 0) {
|
||||
textlen = strlen(text);
|
||||
}
|
||||
for (int i = 0; i < textlen; i++) {
|
||||
const uint8_t *g = get_glyph(font, text[i]);
|
||||
const uint8_t *g = get_glyph(font, (uint8_t)text[i]);
|
||||
if (!g) continue;
|
||||
w += g[2];
|
||||
}
|
||||
|
@ -31,7 +31,9 @@ void display_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data,
|
||||
void display_image(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen);
|
||||
void display_icon(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_text(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
uint32_t display_text_width(const uint8_t *text, int textlen, uint8_t font);
|
||||
void display_text_center(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_text_right(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
uint32_t display_text_width(const char *text, int textlen, uint8_t font);
|
||||
void display_qrcode(uint8_t x, uint8_t y, const char *data, int datalen, int scale);
|
||||
void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
|
||||
void display_raw(uint8_t reg, const uint8_t *data, int datalen);
|
||||
|
@ -175,8 +175,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_text_center(size_t n_args, const mp_obj_t *
|
||||
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]);
|
||||
uint32_t w = display_text_width(text.buf, text.len, font);
|
||||
display_text(x - w / 2, y, text.buf, text.len, font, fgcolor, bgcolor);
|
||||
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);
|
||||
@ -194,8 +193,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_text_right(size_t n_args, const mp_obj_t *a
|
||||
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]);
|
||||
uint32_t w = display_text_width(text.buf, text.len, font);
|
||||
display_text(x - w, y, text.buf, text.len, font, fgcolor, bgcolor);
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user