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

modtrezorui: functions can draw off-canvas now and respect drawing offset

This commit is contained in:
Pavol Rusnak 2016-10-13 17:09:46 +02:00
parent 35beedfcbc
commit 037df3357c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 174 additions and 138 deletions

View File

@ -193,16 +193,14 @@ void display_init(void) {
display_unsleep();
}
static uint8_t WINDOW_OFFSET_X = 0, WINDOW_OFFSET_Y = 0;
static uint16_t BUFFER_OFFSET_X = 0, BUFFER_OFFSET_Y = 0;
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
x += WINDOW_OFFSET_X;
y += WINDOW_OFFSET_Y;
uint16_t x1 = x + w - 1;
uint16_t y1 = y + h - 1;
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
x0 += BUFFER_OFFSET_X; y0 += BUFFER_OFFSET_Y;
x1 += BUFFER_OFFSET_X; y1 += BUFFER_OFFSET_Y;
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
CMD(0x2A); DATA(x >> 8); DATA(x & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
CMD(0x2B); DATA(y >> 8); DATA(y & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
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);
#endif
}
@ -223,13 +221,13 @@ int display_orientation(int degrees)
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(BGR | MX | MY);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
BUFFER_OFFSET_X = 0;
BUFFER_OFFSET_Y = 80;
#endif
#if DISPLAY_ST7789V
DATA(RGB | MX | MY );
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
BUFFER_OFFSET_X = 0;
BUFFER_OFFSET_Y = 80;
#endif
ORIENTATION = 0;
break;
@ -237,13 +235,13 @@ int display_orientation(int degrees)
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(BGR | MV | MX);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
BUFFER_OFFSET_X = 0;
BUFFER_OFFSET_Y = 0;
#endif
#if DISPLAY_ST7789V
DATA(RGB | MV | MY );
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
BUFFER_OFFSET_X = 80;
BUFFER_OFFSET_Y = 0;
#endif
ORIENTATION = 90;
break;
@ -251,13 +249,13 @@ int display_orientation(int degrees)
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(BGR);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
BUFFER_OFFSET_X = 0;
BUFFER_OFFSET_Y = 0;
#endif
#if DISPLAY_ST7789V
DATA(RGB);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
BUFFER_OFFSET_X = 0;
BUFFER_OFFSET_Y = 0;
#endif
ORIENTATION = 180;
break;
@ -265,13 +263,13 @@ int display_orientation(int degrees)
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(BGR | MV | MY);
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
BUFFER_OFFSET_X = 80;
BUFFER_OFFSET_Y = 0;
#endif
#if DISPLAY_ST7789V
DATA(RGB | MV | MX);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
BUFFER_OFFSET_X = 0;
BUFFER_OFFSET_Y = 0;
#endif
ORIENTATION = 270;
break;

View File

@ -17,7 +17,7 @@ void display_init(void)
{
}
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
}

View File

@ -100,10 +100,10 @@ void display_init(void)
SDL_SetTextureAlphaMod(TEXTURE, 0);
}
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
SX = x; SY = y;
EX = x + w - 1; EY = y + h - 1;
SX = x0; SY = y0;
EX = x1; EY = y1;
POSX = SX; POSY = SY;
DATAODD = 0;
}

View File

@ -40,7 +40,7 @@ void DATAS(const void *bytes, int len)
}
}
void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor)
static void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor)
{
uint8_t cr, cg, cb;
for (int i = 0; i < 16; i++) {
@ -51,18 +51,32 @@ void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor
}
}
static inline void clamp_coords(int x, int y, int w, int h, int *x0, int *y0, int *x1, int *y1)
{
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
*x0 = MAX(x, 0);
*y0 = MAX(y, 0);
*x1 = MIN(x + w - 1, DISPLAY_RESX - 1);
*y1 = MIN(y + h - 1, DISPLAY_RESY - 1);
}
void display_clear(void)
{
display_set_window(0, 0, DISPLAY_RESX, DISPLAY_RESY);
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
for (int i = 0; i < DISPLAY_RESX * DISPLAY_RESY * 2; i++) {
DATA(0);
DATA(0x00);
}
}
void display_bar(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c)
void display_bar(int x, int y, int w, int h, uint16_t c)
{
display_set_window(x, y, w, h);
for (int i = 0; i < w * h; i++) {
x += OFFSET[0];
y += OFFSET[1];
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
for (int i = 0; i < (x1 - x0 + 1) * (y1 - y0 + 1); i++) {
DATA(c >> 8);
DATA(c & 0xFF);
}
@ -89,7 +103,7 @@ static const uint8_t cornertable[CORNER_RADIUS*CORNER_RADIUS] = {
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
};
void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c, uint16_t b, uint8_t r)
void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint8_t r)
{
if (r != 2 && r != 4 && r != 8 && r != 16) {
return;
@ -98,26 +112,32 @@ void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c,
}
uint16_t colortable[16];
set_color_table(colortable, c, b);
display_set_window(x, y, w, h);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (x < CORNER_RADIUS / r && y < CORNER_RADIUS / r) {
uint8_t c = cornertable[x * r + y * r * CORNER_RADIUS];
x += OFFSET[0];
y += OFFSET[1];
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
for (int j = y0; j <= y1; j++) {
for (int i = x0; i <= x1; i++) {
int rx = i - x;
int ry = j - y;
if (rx < CORNER_RADIUS / r && ry < CORNER_RADIUS / r) {
uint8_t c = cornertable[rx * r + ry * r * CORNER_RADIUS];
DATA(colortable[c] >> 8);
DATA(colortable[c] & 0xFF);
} else
if (x < CORNER_RADIUS / r && y >= h - CORNER_RADIUS / r) {
uint8_t c = cornertable[x * r + (h - 1 - y) * r * CORNER_RADIUS];
if (rx < CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) {
uint8_t c = cornertable[rx * r + (h - 1 - ry) * r * CORNER_RADIUS];
DATA(colortable[c] >> 8);
DATA(colortable[c] & 0xFF);
} else
if (x >= w - CORNER_RADIUS / r && y < CORNER_RADIUS / r) {
uint8_t c = cornertable[(w - 1 - x) * r + y * r * CORNER_RADIUS];
if (rx >= w - CORNER_RADIUS / r && ry < CORNER_RADIUS / r) {
uint8_t c = cornertable[(w - 1 - rx) * r + ry * r * CORNER_RADIUS];
DATA(colortable[c] >> 8);
DATA(colortable[c] & 0xFF);
} else
if (x >= w - CORNER_RADIUS / r && y >= h - CORNER_RADIUS / r) {
uint8_t c = cornertable[(w - 1 - x) * r + (h - 1 - y) * r * CORNER_RADIUS];
if (rx >= w - CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) {
uint8_t c = cornertable[(w - 1 - rx) * r + (h - 1 - ry) * r * CORNER_RADIUS];
DATA(colortable[c] >> 8);
DATA(colortable[c] & 0xFF);
} else {
@ -128,38 +148,70 @@ void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c,
}
}
void display_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen)
{
display_set_window(x, y, w, h);
DATAS(data, datalen);
}
static void inflate_callback_image(uint8_t byte, uint32_t pos, void *userdata)
{
DATA(byte);
int w = ((int *)userdata)[0];
int x0 = ((int *)userdata)[1];
int x1 = ((int *)userdata)[2];
int y0 = ((int *)userdata)[3];
int y1 = ((int *)userdata)[4];
int px = (pos / 2) % w;
int py = (pos / 2) / w;
if (px >= x0 && px <= x1 && py >= y0 && py <= y1) {
DATA(byte);
}
}
void display_image(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen)
void display_image(int x, int y, int w, int h, const void *data, int datalen)
{
display_set_window(x, y, w, h);
sinf_inflate(data, datalen, inflate_callback_image, NULL);
x += OFFSET[0];
y += OFFSET[1];
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
int userdata[5];
userdata[0] = w;
userdata[1] = x0 - x;
userdata[2] = x1 - x;
userdata[3] = y0 - y;
userdata[4] = y1 - y;
sinf_inflate(data, datalen, inflate_callback_image, userdata);
}
static void inflate_callback_icon(uint8_t byte, uint32_t pos, void *userdata)
{
uint16_t *colortable = (uint16_t *)userdata;
DATA(colortable[byte >> 4] >> 8);
DATA(colortable[byte >> 4] & 0xFF);
DATA(colortable[byte & 0x0F] >> 8);
DATA(colortable[byte & 0x0F] & 0xFF);
uint16_t *colortable = (uint16_t *)(((int *)userdata) + 5);
int w = ((int *)userdata)[0];
int x0 = ((int *)userdata)[1];
int x1 = ((int *)userdata)[2];
int y0 = ((int *)userdata)[3];
int y1 = ((int *)userdata)[4];
int px = (pos * 2) % w;
int py = (pos * 2) / w;
if (px >= x0 && px <= x1 && py >= y0 && py <= y1) {
DATA(colortable[byte >> 4] >> 8);
DATA(colortable[byte >> 4] & 0xFF);
DATA(colortable[byte & 0x0F] >> 8);
DATA(colortable[byte & 0x0F] & 0xFF);
}
}
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_icon(int x, int y, int w, int h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor)
{
display_set_window(x, y, w, h);
uint16_t colortable[16];
set_color_table(colortable, fgcolor, bgcolor);
sinf_inflate(data, datalen, inflate_callback_icon, colortable);
x += OFFSET[0];
y += OFFSET[1];
x &= ~1; // cannot draw at odd coordinate
int x0, y0, x1, y1;
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
int userdata[5 + 16 * sizeof(uint16_t) / sizeof(int)];
userdata[0] = w;
userdata[1] = x0 - x;
userdata[2] = x1 - x;
userdata[3] = y0 - y;
userdata[4] = y1 - y;
set_color_table((uint16_t *)(userdata + 5), fgcolor, bgcolor);
sinf_inflate(data, datalen, inflate_callback_icon, userdata);
}
static const uint8_t *get_glyph(uint8_t font, uint8_t c)
@ -189,9 +241,8 @@ static const uint8_t *get_glyph(uint8_t font, uint8_t c)
// first two bytes are width and height of the glyph
// third, fourth and fifth bytes are advance, bearingX and bearingY of the horizontal metrics of the glyph
// rest is packed 4-bit glyph data
void display_text(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t font, 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)
{
uint32_t px = x;
uint16_t colortable[16];
set_color_table(colortable, fgcolor, bgcolor);
@ -199,6 +250,9 @@ void display_text(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t f
if (textlen < 0) {
textlen = strlen(text);
}
int px = x + OFFSET[0];
y += OFFSET[1];
// render glyphs
for (int i = 0; i < textlen; i++) {
const uint8_t *g = get_glyph(font, (uint8_t)text[i]);
@ -207,38 +261,49 @@ void display_text(uint8_t x, uint8_t y, const char *text, int textlen, uint8_t f
// g[2] = advance
// g[3], g[4] = bearingX, bearingY
if (g[0] && g[1]) {
display_set_window(px + (int8_t)(g[3]), y - (int8_t)(g[4]), g[0], g[1]);
for (int j = 0; j < g[0] * g[1]; j++) {
uint8_t c;
if (j % 2 == 0) {
c = g[5 + j/2] >> 4;
} else {
c = g[5 + j/2] & 0x0F;
int sx = px + (int8_t)(g[3]);
int sy = y - (int8_t)(g[4]);
int w = g[0];
int h = g[1];
int x0, y0, x1, y1;
clamp_coords(sx, sy, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
for (int j = y0; j <= y1; j++) {
for (int i = x0; i <= x1; i++) {
int rx = i - sx;
int ry = j - sy;
int a = rx + ry * w;
uint8_t c;
if (a % 2 == 0) {
c = g[5 + a/2] >> 4;
} else {
c = g[5 + a/2] & 0x0F;
}
DATA(colortable[c] >> 8);
DATA(colortable[c] & 0xFF);
}
DATA(colortable[c] >> 8);
DATA(colortable[c] & 0xFF);
}
}
px += g[2];
}
}
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_center(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
{
uint32_t w = display_text_width(text, textlen, font);
int 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)
void display_text_right(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
{
uint32_t w = display_text_width(text, textlen, font);
int 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 char *text, int textlen, uint8_t font)
int display_text_width(const char *text, int textlen, uint8_t font)
{
uint32_t w = 0;
int w = 0;
// determine text length if not provided
if (textlen < 0) {
textlen = strlen(text);
@ -251,18 +316,25 @@ uint32_t display_text_width(const char *text, int textlen, uint8_t font)
return w;
}
void display_qrcode(uint8_t x, uint8_t y, const char *data, int datalen, int scale)
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);
display_set_window(x, y, side * scale, side * scale);
for (int i = 0; i < side * scale; i++) {
for (int j = 0; j < side; j++) {
int a = j * side + (i / scale);
x += OFFSET[0];
y += OFFSET[1];
int x0, y0, x1, y1;
clamp_coords(x, y, side * scale, side * scale, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1);
for (int j = y0; j <= y1; j++) {
for (int i = x0; i <= x1; i++) {
int rx = i - x;
int ry = j - y;
int a = (rx / scale) * side + (ry / scale);
if (bitdata[a / 8] & (1 << (7 - a % 8))) {
for (a = 0; a < scale * 2; a++) { DATA(0x00); }
DATA(0x00); DATA(0x00);
} else {
for (a = 0; a < scale * 2; a++) { DATA(0xFF); }
DATA(0xFF); DATA(0xFF);
}
}
}
@ -283,7 +355,7 @@ void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const
if (icon) {
set_color_table(iconcolortable, iconfgcolor, bgcolor);
}
display_set_window(DISPLAY_RESX / 2 - img_loader_size, DISPLAY_RESY / 2 - img_loader_size, img_loader_size * 2, img_loader_size * 2);
display_set_window(DISPLAY_RESX / 2 - img_loader_size, DISPLAY_RESY / 2 - img_loader_size, DISPLAY_RESX / 2 + img_loader_size - 1, DISPLAY_RESY / 2 + img_loader_size - 1);
if (icon && memcmp(icon, "TOIg", 4) == 0 && LOADER_ICON_SIZE == *(uint16_t *)(icon + 4) && LOADER_ICON_SIZE == *(uint16_t *)(icon + 6) && iconlen == 12 + *(uint32_t *)(icon + 8)) {
uint8_t icondata[LOADER_ICON_SIZE * LOADER_ICON_SIZE / 2];
sinf_inflate(icon + 12, iconlen - 12, inflate_callback_loader, icondata);

View File

@ -20,25 +20,26 @@
#define LOADER_ICON_SIZE 64
void display_init(void);
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
int display_orientation(int degrees);
int display_backlight(int val);
int *display_offset(int xy[2]);
void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor);
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void display_clear(void);
void display_refresh(void);
void display_bar(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c);
void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c, uint16_t b, uint8_t r);
void display_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen);
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);
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_bar(int x, int y, int w, int h, uint16_t c);
void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint8_t r);
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_qrcode(int x, int y, const char *data, int datalen, uint8_t 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_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);
void display_text_right(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
int display_text_width(const char *text, int textlen, uint8_t font);
void display_raw(uint8_t reg, const uint8_t *data, int datalen);
void display_save(const char *filename);

View File

@ -51,9 +51,6 @@ STATIC mp_obj_t mod_TrezorUi_Display_bar(size_t n_args, const mp_obj_t *args) {
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]);
if ((x < 0) || (y < 0) || (x + w > DISPLAY_RESX) || (y + h > DISPLAY_RESY)) {
mp_raise_ValueError("Coordinates out of bounds");
}
display_bar(x, y, w, h, c);
return mp_const_none;
}
@ -72,36 +69,11 @@ STATIC mp_obj_t mod_TrezorUi_Display_bar_radius(size_t n_args, const mp_obj_t *a
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]);
if ((x < 0) || (y < 0) || (x + w > DISPLAY_RESX) || (y + h > DISPLAY_RESY)) {
mp_raise_ValueError("Coordinates out of bounds");
}
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 trezor.ui.display.blit(x: int, y: int, w: int, h: int, data: bytes) -> None:
/// '''
/// Renders rectangle at position (x,y = upper left corner) with width w and height h with data.
/// The data needs to have the correct format.
/// '''
STATIC mp_obj_t mod_TrezorUi_Display_blit(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]);
mp_buffer_info_t data;
mp_get_buffer_raise(args[5], &data, MP_BUFFER_READ);
if (data.len != 2 * w * h) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Wrong data size (got %d bytes, expected %d bytes)", data.len, 2 * w * h));
}
if (w > 0 && h > 0) {
display_blit(x, y, w, h, data.buf, data.len);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_blit_obj, 6, 6, mod_TrezorUi_Display_blit);
/// def trezor.ui.display.image(x: int, y: int, image: bytes) -> None:
/// '''
/// Renders an image at position (x,y).
@ -119,9 +91,6 @@ STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args)
mp_int_t w = *(uint16_t *)(data + 4);
mp_int_t h = *(uint16_t *)(data + 6);
mp_int_t datalen = *(uint32_t *)(data + 8);
if ((x < 0) || (y < 0) || (x + w > DISPLAY_RESX) || (y + h > DISPLAY_RESY)) {
mp_raise_ValueError("Coordinates out of bounds");
}
if (datalen != image.len - 12) {
mp_raise_ValueError("Invalid size of data");
}
@ -147,9 +116,6 @@ STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
mp_int_t w = *(uint16_t *)(data + 4);
mp_int_t h = *(uint16_t *)(data + 6);
mp_int_t datalen = *(uint32_t *)(data + 8);
if ((x < 0) || (y < 0) || (x + w > DISPLAY_RESX) || (y + h > DISPLAY_RESY)) {
mp_raise_ValueError("Coordinates out of bounds");
}
if (datalen != icon.len - 12) {
mp_raise_ValueError("Invalid size of data");
}
@ -403,7 +369,6 @@ 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_blit), MP_ROM_PTR(&mod_TrezorUi_Display_blit_obj) },
{ MP_ROM_QSTR(MP_QSTR_image), MP_ROM_PTR(&mod_TrezorUi_Display_image_obj) },
{ MP_ROM_QSTR(MP_QSTR_icon), MP_ROM_PTR(&mod_TrezorUi_Display_icon_obj) },
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_TrezorUi_Display_text_obj) },