mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-13 17:00:59 +00:00
modtrezorui: split display_print into display_print and display_print_out
This commit is contained in:
parent
8d4cd85659
commit
e872f54896
@ -8,8 +8,8 @@
|
||||
|
||||
#define STAGE2_START 0x08010000
|
||||
|
||||
#define BOOTLOADER_PRINT(X) display_print(X, -1)
|
||||
#define BOOTLOADER_PRINTLN(X) display_print(X "\n", -1)
|
||||
#define BOOTLOADER_PRINT(X) do { display_print(X, -1); display_print_out(0xFFFF, 0x001F); } while(0)
|
||||
#define BOOTLOADER_PRINTLN(X) do { display_print(X "\n", -1); display_print_out(0xFFFF, 0x001F); } while(0)
|
||||
|
||||
void SystemClock_Config(void);
|
||||
|
||||
@ -23,6 +23,7 @@ void __attribute__((noreturn)) __fatal_error(const char *msg) {
|
||||
display_print("FATAL ERROR:\n", -1);
|
||||
display_print(msg, -1);
|
||||
display_print("\n", -1);
|
||||
display_print_out(0xFFFF, 0x001F);
|
||||
for (;;) {
|
||||
__WFI();
|
||||
}
|
||||
|
@ -226,12 +226,13 @@ static const uint8_t *get_glyph(uint8_t font, uint8_t c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// display text using bitmap font
|
||||
#define DISPLAY_PRINT_COLS (DISPLAY_RESX / 6)
|
||||
#define DISPLAY_PRINT_ROWS (DISPLAY_RESY / 8)
|
||||
static char display_print_buf[DISPLAY_PRINT_ROWS][DISPLAY_PRINT_COLS];
|
||||
|
||||
// display text using bitmap font - print to internal buffer
|
||||
void display_print(const char *text, int textlen)
|
||||
{
|
||||
#define COLS (DISPLAY_RESX / 6)
|
||||
#define ROWS (DISPLAY_RESY / 8)
|
||||
static char textbuf[ROWS][COLS];
|
||||
static uint8_t row = 0, col = 0;
|
||||
|
||||
// determine text length if not provided
|
||||
@ -248,39 +249,42 @@ void display_print(const char *text, int textlen)
|
||||
col = 0;
|
||||
break;
|
||||
default:
|
||||
textbuf[row][col] = text[i];
|
||||
display_print_buf[row][col] = text[i];
|
||||
col++;
|
||||
break;
|
||||
}
|
||||
if (col >= COLS) {
|
||||
if (col >= DISPLAY_PRINT_COLS) {
|
||||
col = 0;
|
||||
row++;
|
||||
}
|
||||
if (row >= ROWS) {
|
||||
for (int j = 0; j < ROWS - 1; j++) {
|
||||
memcpy(textbuf[j], textbuf[j + 1], COLS);
|
||||
if (row >= DISPLAY_PRINT_ROWS) {
|
||||
for (int j = 0; j < DISPLAY_PRINT_ROWS - 1; j++) {
|
||||
memcpy(display_print_buf[j], display_print_buf[j + 1], DISPLAY_PRINT_COLS);
|
||||
}
|
||||
memset(textbuf[ROWS - 1], 0x00, COLS);
|
||||
row = ROWS - 1;
|
||||
memset(display_print_buf[DISPLAY_PRINT_ROWS - 1], 0x00, DISPLAY_PRINT_COLS);
|
||||
row = DISPLAY_PRINT_ROWS - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// display text using bitmap font - send internal buffer to display
|
||||
void display_print_out(uint16_t fgcolor, uint16_t bgcolor) {
|
||||
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
|
||||
for (int i = 0; i < DISPLAY_RESX * DISPLAY_RESY; i++) {
|
||||
int x = (i % DISPLAY_RESX);
|
||||
int y = (i / DISPLAY_RESX);
|
||||
int j = y % 8; y /= 8;
|
||||
int k = x % 6; x /= 6;
|
||||
char c = textbuf[y][x] & 0x7F;
|
||||
// char invert = textbuf[y][x] & 0x80;
|
||||
char c = display_print_buf[y][x] & 0x7F;
|
||||
// char invert = display_print_buf[y][x] & 0x80;
|
||||
if (c < ' ') c = ' ';
|
||||
const uint8_t *g = Font_Bitmap + (5 * (c - ' '));
|
||||
if (k < 5 && (g[k] & (1 << j))) {
|
||||
DATA(0xFF);
|
||||
DATA(0xFF);
|
||||
DATA(fgcolor >> 8);
|
||||
DATA(fgcolor & 0xFF);
|
||||
} else {
|
||||
DATA(0x00);
|
||||
DATA(0x00);
|
||||
DATA(bgcolor >> 8);
|
||||
DATA(bgcolor & 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ void display_image(int x, int y, int w, int h, const void *data, int datalen);
|
||||
void display_icon(int x, int y, int w, int h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor);
|
||||
|
||||
void display_print(const char *text, int textlen);
|
||||
void display_print_out(uint16_t fgcolor, uint16_t bgcolor);
|
||||
|
||||
void display_text(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_text_center(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
|
@ -126,19 +126,22 @@ STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_icon_obj, 6, 6, mod_TrezorUi_Display_icon);
|
||||
|
||||
/// def trezor.ui.display.print(text: str) -> None:
|
||||
/// def trezor.ui.display.print(text: str, fgcolor: int, bgcolor: int) -> 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) {
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_print(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t buf;
|
||||
mp_get_buffer_raise(text, &buf, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[1], &buf, MP_BUFFER_READ);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[2]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[3]);
|
||||
if (buf.len > 0) {
|
||||
display_print(buf.buf, buf.len);
|
||||
}
|
||||
display_print_out(fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_print_obj, mod_TrezorUi_Display_print);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_print_obj, 4, 4, mod_TrezorUi_Display_print);
|
||||
|
||||
/// def trezor.ui.display.text(x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
/// '''
|
||||
|
@ -14,6 +14,7 @@ void __attribute__((noreturn)) __fatal_error(const char *msg) {
|
||||
display_print("FATAL ERROR:\n", -1);
|
||||
display_print(msg, -1);
|
||||
display_print("\n", -1);
|
||||
display_print_out(0xFFFF, 0x001F);
|
||||
for (;;) {
|
||||
__WFI();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user