1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

embed/extmod/modtrezorui: refactor DISPLAY_OFFSET

This commit is contained in:
Pavol Rusnak 2018-02-22 16:27:38 +01:00
parent b0aae19929
commit d5ab82ae2b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 35 additions and 32 deletions

View File

@ -49,9 +49,9 @@ static struct {
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
x0 += BUFFER_OFFSET.x; x1 += BUFFER_OFFSET.x;
y0 += BUFFER_OFFSET.y; y1 += BUFFER_OFFSET.y;
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
CMD(0x2A); DATA(x0 >> 8); DATA(x0 & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
CMD(0x2B); DATA(y0 >> 8); DATA(y0 & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
CMD(0x2C);

View File

@ -27,7 +27,10 @@
static int DISPLAY_BACKLIGHT = -1;
static int DISPLAY_ORIENTATION = -1;
static int DISPLAY_OFFSET[2] = {0, 0};
static struct {
int x, y;
} DISPLAY_OFFSET;
#if defined TREZOR_STM32
#include "display-stm32.h"
@ -80,8 +83,8 @@ void display_clear(void)
void display_bar(int x, int y, int w, int h, uint16_t c)
{
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
@ -120,8 +123,8 @@ void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint
}
uint16_t colortable[16];
set_color_table(colortable, c, b);
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
@ -172,8 +175,8 @@ static void inflate_callback_image(uint8_t byte1, uint32_t pos, void *userdata)
void display_image(int x, int y, int w, int h, const void *data, int datalen)
{
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
@ -230,8 +233,8 @@ static void inflate_callback_avatar(uint8_t byte1, uint32_t pos, void *userdata)
void display_avatar(int x, int y, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int x0, y0, x1, y1;
clamp_coords(x, y, AVATAR_IMAGE_SIZE, AVATAR_IMAGE_SIZE, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
@ -257,8 +260,8 @@ static void inflate_callback_icon(uint8_t byte, uint32_t pos, void *userdata)
void display_icon(int x, int y, int w, int h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
x &= ~1; // cannot draw at odd coordinate
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
@ -444,23 +447,23 @@ static void display_text_render(int x, int y, const char *text, int textlen, uin
void display_text(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
display_text_render(x, y, text, textlen, font, fgcolor, bgcolor);
}
void display_text_center(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int w = display_text_width(text, textlen, font);
display_text_render(x - w / 2, y, text, textlen, font, fgcolor, bgcolor);
}
void display_text_right(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET[0];
y += DISPLAY_OFFSET[1];
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
int w = display_text_width(text, textlen, font);
display_text_render(x - w, y, text, textlen, font, fgcolor, bgcolor);
}
@ -497,8 +500,8 @@ void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale)
if (scale < 1 || scale > 10) return;
uint8_t bitdata[QR_MAX_BITDATA];
int side = qr_encode(QR_LEVEL_M, 0, data, datalen, bitdata);
x += DISPLAY_OFFSET[0] - (side + 2) * scale / 2;
y += DISPLAY_OFFSET[1] - (side + 2) * scale / 2;
x += DISPLAY_OFFSET.x - (side + 2) * scale / 2;
y += DISPLAY_OFFSET.y - (side + 2) * scale / 2;
int x0, y0, x1, y1;
clamp_coords(x, y, (side + 2) * scale, (side + 2) * scale, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
@ -591,13 +594,14 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t b
}
}
int *display_offset(int xy[2])
void display_offset(int set_xy[2], int *get_x, int *get_y)
{
if (xy) {
DISPLAY_OFFSET[0] = xy[0];
DISPLAY_OFFSET[1] = xy[1];
if (set_xy) {
DISPLAY_OFFSET.x = set_xy[0];
DISPLAY_OFFSET.y = set_xy[1];
}
return DISPLAY_OFFSET;
*get_x = DISPLAY_OFFSET.x;
*get_y = DISPLAY_OFFSET.y;
}
int display_orientation(int degrees)

View File

@ -69,7 +69,7 @@ int display_text_width(const char *text, int textlen, uint8_t font);
void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale);
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
int *display_offset(int xy[2]);
void display_offset(int set_xy[2], int *get_x, int *get_y);
int display_orientation(int degrees);
int display_backlight(int val);
void display_fade(int start, int end, int delay);

View File

@ -377,7 +377,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_backlight_obj, 1
/// 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], *ret;
int xy[2], x, y;
if (n_args > 1) {
size_t xy_cnt;
mp_obj_t *xy_obj;
@ -391,15 +391,14 @@ STATIC mp_obj_t mod_trezorui_Display_offset(size_t n_args, const mp_obj_t *args)
}
xy[0] = mp_obj_get_int(xy_obj[0]);
xy[1] = mp_obj_get_int(xy_obj[1]);
ret = display_offset(xy);
display_offset(xy, &x, &y);
} else {
ret = display_offset(0);
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(ret[0]);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(ret[1]);
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);