|
|
|
@ -17,8 +17,8 @@
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "inflate.h"
|
|
|
|
|
#include "font_bitmap.h"
|
|
|
|
|
#include "inflate.h"
|
|
|
|
|
#ifdef TREZOR_FONT_NORMAL_ENABLE
|
|
|
|
|
#include "font_roboto_regular_20.h"
|
|
|
|
|
#endif
|
|
|
|
@ -37,17 +37,15 @@
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "display.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "memzero.h"
|
|
|
|
|
|
|
|
|
|
static int DISPLAY_BACKLIGHT = -1;
|
|
|
|
|
static int DISPLAY_ORIENTATION = -1;
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
int x, y;
|
|
|
|
|
} DISPLAY_OFFSET;
|
|
|
|
|
static struct { int x, y; } DISPLAY_OFFSET;
|
|
|
|
|
|
|
|
|
|
#ifdef TREZOR_EMULATOR
|
|
|
|
|
#include "display-unix.h"
|
|
|
|
@ -61,44 +59,52 @@ static struct {
|
|
|
|
|
|
|
|
|
|
// common display functions
|
|
|
|
|
|
|
|
|
|
static inline uint16_t interpolate_color(uint16_t color0, uint16_t color1, uint8_t step)
|
|
|
|
|
{
|
|
|
|
|
static inline uint16_t interpolate_color(uint16_t color0, uint16_t color1,
|
|
|
|
|
uint8_t step) {
|
|
|
|
|
uint8_t cr, cg, cb;
|
|
|
|
|
cr = (((color0 & 0xF800) >> 11) * step + ((color1 & 0xF800) >> 11) * (15 - step)) / 15;
|
|
|
|
|
cg = (((color0 & 0x07E0) >> 5) * step + ((color1 & 0x07E0) >> 5) * (15 - step)) / 15;
|
|
|
|
|
cr = (((color0 & 0xF800) >> 11) * step +
|
|
|
|
|
((color1 & 0xF800) >> 11) * (15 - step)) /
|
|
|
|
|
15;
|
|
|
|
|
cg = (((color0 & 0x07E0) >> 5) * step +
|
|
|
|
|
((color1 & 0x07E0) >> 5) * (15 - step)) /
|
|
|
|
|
15;
|
|
|
|
|
cb = ((color0 & 0x001F) * step + (color1 & 0x001F) * (15 - step)) / 15;
|
|
|
|
|
return (cr << 11) | (cg << 5) | cb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor)
|
|
|
|
|
{
|
|
|
|
|
static inline void set_color_table(uint16_t colortable[16], uint16_t fgcolor,
|
|
|
|
|
uint16_t bgcolor) {
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
colortable[i] = interpolate_color(fgcolor, bgcolor, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void clamp_coords(int x, int y, int w, int h, int *x0, int *y0, int *x1, int *y1)
|
|
|
|
|
{
|
|
|
|
|
static inline void clamp_coords(int x, int y, int w, int h, int *x0, int *y0,
|
|
|
|
|
int *x1, int *y1) {
|
|
|
|
|
*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)
|
|
|
|
|
{
|
|
|
|
|
void display_clear(void) {
|
|
|
|
|
const int saved_orientation = DISPLAY_ORIENTATION;
|
|
|
|
|
display_orientation(0); // set MADCTL first so that we can set the window correctly next
|
|
|
|
|
display_set_window(0, 0, MAX_DISPLAY_RESX - 1, MAX_DISPLAY_RESY - 1); // address the complete frame memory
|
|
|
|
|
display_orientation(
|
|
|
|
|
0); // set MADCTL first so that we can set the window correctly next
|
|
|
|
|
display_set_window(
|
|
|
|
|
0, 0, MAX_DISPLAY_RESX - 1,
|
|
|
|
|
MAX_DISPLAY_RESY - 1); // address the complete frame memory
|
|
|
|
|
for (uint32_t i = 0; i < MAX_DISPLAY_RESX * MAX_DISPLAY_RESY; i++) {
|
|
|
|
|
PIXELDATA(0x0000); // 2 bytes per pixel because we're using RGB 5-6-5 format
|
|
|
|
|
PIXELDATA(
|
|
|
|
|
0x0000); // 2 bytes per pixel because we're using RGB 5-6-5 format
|
|
|
|
|
}
|
|
|
|
|
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1); // go back to restricted window
|
|
|
|
|
display_orientation(saved_orientation); // if valid, go back to the saved orientation
|
|
|
|
|
display_set_window(0, 0, DISPLAY_RESX - 1,
|
|
|
|
|
DISPLAY_RESY - 1); // go back to restricted window
|
|
|
|
|
display_orientation(
|
|
|
|
|
saved_orientation); // if valid, go back to the saved orientation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void display_bar(int x, int y, int w, int h, uint16_t c)
|
|
|
|
|
{
|
|
|
|
|
void display_bar(int x, int y, int w, int h, uint16_t c) {
|
|
|
|
|
x += DISPLAY_OFFSET.x;
|
|
|
|
|
y += DISPLAY_OFFSET.y;
|
|
|
|
|
int x0, y0, x1, y1;
|
|
|
|
@ -112,26 +118,24 @@ void display_bar(int x, int y, int w, int h, uint16_t c)
|
|
|
|
|
#define CORNER_RADIUS 16
|
|
|
|
|
|
|
|
|
|
static const uint8_t cornertable[CORNER_RADIUS * CORNER_RADIUS] = {
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 9, 12, 14, 15,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 3, 9, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 8, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 0, 0, 0, 0, 3, 12, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 0, 0, 0, 3, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 0, 0, 3, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 0, 0, 12, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 0, 8, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 3, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 9, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
1, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
9, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
12, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 9, 12, 14, 15, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 3, 9, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, 8, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 3, 12, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 3, 14, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 0, 0, 0, 3, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
15, 0, 0, 0, 12, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0,
|
|
|
|
|
8, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 3, 15, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 9, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 1, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 15, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
15, 15, 9, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 12,
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 15, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void display_bar_radius(int x, int y, int w, int 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;
|
|
|
|
|
} else {
|
|
|
|
@ -151,17 +155,15 @@ void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint
|
|
|
|
|
if (rx < CORNER_RADIUS / r && ry < CORNER_RADIUS / r) {
|
|
|
|
|
uint8_t c = cornertable[rx * r + ry * r * CORNER_RADIUS];
|
|
|
|
|
PIXELDATA(colortable[c]);
|
|
|
|
|
} else
|
|
|
|
|
if (rx < CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) {
|
|
|
|
|
} else if (rx < CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) {
|
|
|
|
|
uint8_t c = cornertable[rx * r + (h - 1 - ry) * r * CORNER_RADIUS];
|
|
|
|
|
PIXELDATA(colortable[c]);
|
|
|
|
|
} else
|
|
|
|
|
if (rx >= w - CORNER_RADIUS / r && ry < CORNER_RADIUS / r) {
|
|
|
|
|
} else if (rx >= w - CORNER_RADIUS / r && ry < CORNER_RADIUS / r) {
|
|
|
|
|
uint8_t c = cornertable[(w - 1 - rx) * r + ry * r * CORNER_RADIUS];
|
|
|
|
|
PIXELDATA(colortable[c]);
|
|
|
|
|
} else
|
|
|
|
|
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];
|
|
|
|
|
} else 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];
|
|
|
|
|
PIXELDATA(colortable[c]);
|
|
|
|
|
} else {
|
|
|
|
|
PIXELDATA(c);
|
|
|
|
@ -172,8 +174,8 @@ void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint
|
|
|
|
|
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
|
|
|
|
|
static void inflate_callback_image(uint8_t byte1, uint32_t pos, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
static void inflate_callback_image(uint8_t byte1, uint32_t pos,
|
|
|
|
|
void *userdata) {
|
|
|
|
|
static uint8_t byte0;
|
|
|
|
|
if (pos % 2 == 0) {
|
|
|
|
|
byte0 = byte1;
|
|
|
|
@ -193,8 +195,7 @@ static void inflate_callback_image(uint8_t byte1, uint32_t pos, void *userdata)
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void display_image(int x, int y, int w, int h, const void *data, int datalen)
|
|
|
|
|
{
|
|
|
|
|
void display_image(int x, int y, int w, int h, const void *data, int datalen) {
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
x += DISPLAY_OFFSET.x;
|
|
|
|
|
y += DISPLAY_OFFSET.y;
|
|
|
|
@ -208,10 +209,12 @@ void display_image(int x, int y, int w, int h, const void *data, int datalen)
|
|
|
|
|
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
|
|
|
|
|
static void inflate_callback_avatar(uint8_t byte1, uint32_t pos, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
static void inflate_callback_avatar(uint8_t byte1, uint32_t pos,
|
|
|
|
|
void *userdata) {
|
|
|
|
|
#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_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
|
|
|
|
|
static uint8_t byte0;
|
|
|
|
@ -240,12 +243,13 @@ static void inflate_callback_avatar(uint8_t byte1, uint32_t pos, void *userdata)
|
|
|
|
|
// border area
|
|
|
|
|
} else {
|
|
|
|
|
#if AVATAR_ANTIALIAS
|
|
|
|
|
d = 31 * (d - AVATAR_BORDER_LOW) / (AVATAR_BORDER_HIGH - AVATAR_BORDER_LOW);
|
|
|
|
|
d = 31 * (d - AVATAR_BORDER_LOW) /
|
|
|
|
|
(AVATAR_BORDER_HIGH - AVATAR_BORDER_LOW);
|
|
|
|
|
uint16_t c;
|
|
|
|
|
if (d >= 16) {
|
|
|
|
|
c = interpolate_color(bgcolor, fgcolor, d - 16);
|
|
|
|
|
} else {
|
|
|
|
|
c = interpolate_color(fgcolor, (byte0 << 8) | byte1 , d);
|
|
|
|
|
c = interpolate_color(fgcolor, (byte0 << 8) | byte1, d);
|
|
|
|
|
}
|
|
|
|
|
PIXELDATA(c);
|
|
|
|
|
#else
|
|
|
|
@ -257,21 +261,21 @@ static void inflate_callback_avatar(uint8_t byte1, uint32_t pos, void *userdata)
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void display_avatar(int x, int y, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor)
|
|
|
|
|
{
|
|
|
|
|
void display_avatar(int x, int y, const void *data, int datalen,
|
|
|
|
|
uint16_t fgcolor, uint16_t bgcolor) {
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
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);
|
|
|
|
|
int userdata[7] = {AVATAR_IMAGE_SIZE, x0 - x, x1 - x, y0 - y, y1 - y, fgcolor, bgcolor};
|
|
|
|
|
int userdata[7] = {AVATAR_IMAGE_SIZE, x0 - x, x1 - x, y0 - y, y1 - y,
|
|
|
|
|
fgcolor, bgcolor};
|
|
|
|
|
sinf_inflate(data, datalen, inflate_callback_avatar, userdata);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void inflate_callback_icon(uint8_t byte, uint32_t pos, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
static void inflate_callback_icon(uint8_t byte, uint32_t pos, void *userdata) {
|
|
|
|
|
const uint16_t *colortable = (const uint16_t *)(((const int *)userdata) + 5);
|
|
|
|
|
const int w = ((const int *)userdata)[0];
|
|
|
|
|
const int x0 = ((const int *)userdata)[1];
|
|
|
|
@ -286,15 +290,16 @@ 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)
|
|
|
|
|
{
|
|
|
|
|
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.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);
|
|
|
|
|
display_set_window(x0, y0, x1, y1);
|
|
|
|
|
int userdata[5 + 16 * sizeof(uint16_t) / sizeof(int)] = {w, x0 - x, x1 - x, y0 - y, y1 - y};
|
|
|
|
|
int userdata[5 + 16 * sizeof(uint16_t) / sizeof(int)] = {w, x0 - x, x1 - x,
|
|
|
|
|
y0 - y, y1 - y};
|
|
|
|
|
set_color_table((uint16_t *)(userdata + 5), fgcolor, bgcolor);
|
|
|
|
|
sinf_inflate(data, datalen, inflate_callback_icon, userdata);
|
|
|
|
|
}
|
|
|
|
@ -303,16 +308,17 @@ void display_icon(int x, int y, int w, int h, const void *data, int datalen, uin
|
|
|
|
|
|
|
|
|
|
#include "loader.h"
|
|
|
|
|
|
|
|
|
|
static void inflate_callback_loader(uint8_t byte, uint32_t pos, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
static void inflate_callback_loader(uint8_t byte, uint32_t pos,
|
|
|
|
|
void *userdata) {
|
|
|
|
|
uint8_t *out = (uint8_t *)userdata;
|
|
|
|
|
out[pos] = byte;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor)
|
|
|
|
|
{
|
|
|
|
|
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor,
|
|
|
|
|
uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen,
|
|
|
|
|
uint16_t iconfgcolor) {
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
uint16_t colortable[16], iconcolortable[16];
|
|
|
|
|
set_color_table(colortable, fgcolor, bgcolor);
|
|
|
|
@ -323,8 +329,14 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t b
|
|
|
|
|
(DISPLAY_RESY / 2 + img_loader_size - 1 + yoffset >= DISPLAY_RESY)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
display_set_window(DISPLAY_RESX / 2 - img_loader_size, DISPLAY_RESY / 2 - img_loader_size + yoffset, DISPLAY_RESX / 2 + img_loader_size - 1, DISPLAY_RESY / 2 + img_loader_size - 1 + yoffset);
|
|
|
|
|
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)) {
|
|
|
|
|
display_set_window(DISPLAY_RESX / 2 - img_loader_size,
|
|
|
|
|
DISPLAY_RESY / 2 - img_loader_size + yoffset,
|
|
|
|
|
DISPLAY_RESX / 2 + img_loader_size - 1,
|
|
|
|
|
DISPLAY_RESY / 2 + img_loader_size - 1 + yoffset);
|
|
|
|
|
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);
|
|
|
|
|
icon = icondata;
|
|
|
|
@ -339,21 +351,24 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t b
|
|
|
|
|
mx = img_loader_size * 2 - 1 - x;
|
|
|
|
|
my = img_loader_size * 2 - 1 - y;
|
|
|
|
|
a = 499 - (img_loader[my][mx] >> 8);
|
|
|
|
|
} else
|
|
|
|
|
if (mx >= img_loader_size) {
|
|
|
|
|
} else if (mx >= img_loader_size) {
|
|
|
|
|
mx = img_loader_size * 2 - 1 - x;
|
|
|
|
|
a = img_loader[my][mx] >> 8;
|
|
|
|
|
} else
|
|
|
|
|
if (my >= img_loader_size) {
|
|
|
|
|
} else if (my >= img_loader_size) {
|
|
|
|
|
my = img_loader_size * 2 - 1 - y;
|
|
|
|
|
a = 500 + (img_loader[my][mx] >> 8);
|
|
|
|
|
} else {
|
|
|
|
|
a = 999 - (img_loader[my][mx] >> 8);
|
|
|
|
|
}
|
|
|
|
|
// inside of circle - draw glyph
|
|
|
|
|
#define LOADER_ICON_CORNER_CUT 2
|
|
|
|
|
if (icon && mx + my > (((LOADER_ICON_SIZE / 2) + LOADER_ICON_CORNER_CUT) * 2) && mx >= img_loader_size - (LOADER_ICON_SIZE / 2) && my >= img_loader_size - (LOADER_ICON_SIZE / 2)) {
|
|
|
|
|
int i = (x - (img_loader_size - (LOADER_ICON_SIZE / 2))) + (y - (img_loader_size - (LOADER_ICON_SIZE / 2))) * LOADER_ICON_SIZE;
|
|
|
|
|
// inside of circle - draw glyph
|
|
|
|
|
#define LOADER_ICON_CORNER_CUT 2
|
|
|
|
|
if (icon &&
|
|
|
|
|
mx + my > (((LOADER_ICON_SIZE / 2) + LOADER_ICON_CORNER_CUT) * 2) &&
|
|
|
|
|
mx >= img_loader_size - (LOADER_ICON_SIZE / 2) &&
|
|
|
|
|
my >= img_loader_size - (LOADER_ICON_SIZE / 2)) {
|
|
|
|
|
int i =
|
|
|
|
|
(x - (img_loader_size - (LOADER_ICON_SIZE / 2))) +
|
|
|
|
|
(y - (img_loader_size - (LOADER_ICON_SIZE / 2))) * LOADER_ICON_SIZE;
|
|
|
|
|
uint8_t c;
|
|
|
|
|
if (i % 2) {
|
|
|
|
|
c = icon[i / 2] & 0x0F;
|
|
|
|
@ -380,18 +395,17 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t b
|
|
|
|
|
#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];
|
|
|
|
|
static uint16_t display_print_fgcolor = COLOR_WHITE, display_print_bgcolor = COLOR_BLACK;
|
|
|
|
|
static uint16_t display_print_fgcolor = COLOR_WHITE,
|
|
|
|
|
display_print_bgcolor = COLOR_BLACK;
|
|
|
|
|
|
|
|
|
|
// set colors for display_print function
|
|
|
|
|
void display_print_color(uint16_t fgcolor, uint16_t bgcolor)
|
|
|
|
|
{
|
|
|
|
|
void display_print_color(uint16_t fgcolor, uint16_t bgcolor) {
|
|
|
|
|
display_print_fgcolor = fgcolor;
|
|
|
|
|
display_print_bgcolor = bgcolor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// display text using bitmap font
|
|
|
|
|
void display_print(const char *text, int textlen)
|
|
|
|
|
{
|
|
|
|
|
void display_print(const char *text, int textlen) {
|
|
|
|
|
static uint8_t row = 0, col = 0;
|
|
|
|
|
|
|
|
|
|
// determine text length if not provided
|
|
|
|
@ -401,7 +415,6 @@ void display_print(const char *text, int textlen)
|
|
|
|
|
|
|
|
|
|
// print characters to internal buffer (display_print_buf)
|
|
|
|
|
for (int i = 0; i < textlen; i++) {
|
|
|
|
|
|
|
|
|
|
switch (text[i]) {
|
|
|
|
|
case '\r':
|
|
|
|
|
break;
|
|
|
|
@ -422,12 +435,12 @@ void display_print(const char *text, int textlen)
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
memcpy(display_print_buf[j], display_print_buf[j + 1],
|
|
|
|
|
DISPLAY_PRINT_COLS);
|
|
|
|
|
}
|
|
|
|
|
memzero(display_print_buf[DISPLAY_PRINT_ROWS - 1], DISPLAY_PRINT_COLS);
|
|
|
|
|
row = DISPLAY_PRINT_ROWS - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// render buffer to display
|
|
|
|
@ -435,8 +448,10 @@ void display_print(const char *text, int textlen)
|
|
|
|
|
for (int i = 0; i < DISPLAY_RESX * DISPLAY_RESY; i++) {
|
|
|
|
|
int x = (i % DISPLAY_RESX);
|
|
|
|
|
int y = (i / DISPLAY_RESX);
|
|
|
|
|
const int j = y % 8; y /= 8;
|
|
|
|
|
const int k = x % 6; x /= 6;
|
|
|
|
|
const int j = y % 8;
|
|
|
|
|
y /= 8;
|
|
|
|
|
const int k = x % 6;
|
|
|
|
|
x /= 6;
|
|
|
|
|
char c;
|
|
|
|
|
if (x < DISPLAY_PRINT_COLS && y < DISPLAY_PRINT_ROWS) {
|
|
|
|
|
c = display_print_buf[y][x] & 0x7F;
|
|
|
|
@ -465,8 +480,7 @@ void display_print(const char *text, int textlen)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// variadic display_print
|
|
|
|
|
void display_printf(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
void display_printf(const char *fmt, ...) {
|
|
|
|
|
if (!strchr(fmt, '%')) {
|
|
|
|
|
display_print(fmt, strlen(fmt));
|
|
|
|
|
} else {
|
|
|
|
@ -483,8 +497,7 @@ void display_printf(const char *fmt, ...)
|
|
|
|
|
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
|
|
|
|
|
static const uint8_t *get_glyph(int font, uint8_t c)
|
|
|
|
|
{
|
|
|
|
|
static const uint8_t *get_glyph(int font, uint8_t c) {
|
|
|
|
|
if (c >= ' ' && c <= '~') {
|
|
|
|
|
// do nothing - valid ASCII
|
|
|
|
|
} else
|
|
|
|
@ -521,8 +534,8 @@ static const uint8_t *get_glyph(int font, uint8_t c)
|
|
|
|
|
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
|
|
|
|
|
static void display_text_render(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor)
|
|
|
|
|
{
|
|
|
|
|
static void display_text_render(int x, int y, const char *text, int textlen,
|
|
|
|
|
int font, uint16_t fgcolor, uint16_t bgcolor) {
|
|
|
|
|
// determine text length if not provided
|
|
|
|
|
if (textlen < 0) {
|
|
|
|
|
textlen = strlen(text);
|
|
|
|
@ -551,13 +564,13 @@ static void display_text_render(int x, int y, const char *text, int textlen, int
|
|
|
|
|
const int rx = i - sx;
|
|
|
|
|
const int ry = j - sy;
|
|
|
|
|
const int a = rx + ry * w;
|
|
|
|
|
#if FONT_BPP == 2
|
|
|
|
|
#if FONT_BPP == 2
|
|
|
|
|
const uint8_t c = ((g[5 + a / 4] >> (6 - (a % 4) * 2)) & 0x03) * 5;
|
|
|
|
|
#elif FONT_BPP == 4
|
|
|
|
|
#elif FONT_BPP == 4
|
|
|
|
|
const uint8_t c = (g[5 + a / 2] >> (4 - (a % 2) * 4)) & 0x0F;
|
|
|
|
|
#else
|
|
|
|
|
#error Unsupported FONT_BPP value
|
|
|
|
|
#endif
|
|
|
|
|
#else
|
|
|
|
|
#error Unsupported FONT_BPP value
|
|
|
|
|
#endif
|
|
|
|
|
PIXELDATA(colortable[c]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -568,8 +581,8 @@ static void display_text_render(int x, int y, const char *text, int textlen, int
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void display_text(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor)
|
|
|
|
|
{
|
|
|
|
|
void display_text(int x, int y, const char *text, int textlen, int font,
|
|
|
|
|
uint16_t fgcolor, uint16_t bgcolor) {
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
x += DISPLAY_OFFSET.x;
|
|
|
|
|
y += DISPLAY_OFFSET.y;
|
|
|
|
@ -577,8 +590,8 @@ void display_text(int x, int y, const char *text, int textlen, int font, uint16_
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void display_text_center(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor)
|
|
|
|
|
{
|
|
|
|
|
void display_text_center(int x, int y, const char *text, int textlen, int font,
|
|
|
|
|
uint16_t fgcolor, uint16_t bgcolor) {
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
x += DISPLAY_OFFSET.x;
|
|
|
|
|
y += DISPLAY_OFFSET.y;
|
|
|
|
@ -587,8 +600,8 @@ void display_text_center(int x, int y, const char *text, int textlen, int font,
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void display_text_right(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor)
|
|
|
|
|
{
|
|
|
|
|
void display_text_right(int x, int y, const char *text, int textlen, int font,
|
|
|
|
|
uint16_t fgcolor, uint16_t bgcolor) {
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
x += DISPLAY_OFFSET.x;
|
|
|
|
|
y += DISPLAY_OFFSET.y;
|
|
|
|
@ -598,8 +611,7 @@ void display_text_right(int x, int y, const char *text, int textlen, int font, u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// compute the width of the text (in pixels)
|
|
|
|
|
int display_text_width(const char *text, int textlen, int font)
|
|
|
|
|
{
|
|
|
|
|
int display_text_width(const char *text, int textlen, int font) {
|
|
|
|
|
int width = 0;
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
// determine text length if not provided
|
|
|
|
@ -628,30 +640,25 @@ int display_text_width(const char *text, int textlen, int font)
|
|
|
|
|
|
|
|
|
|
#define QR_MAX_VERSION 9
|
|
|
|
|
|
|
|
|
|
void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale)
|
|
|
|
|
{
|
|
|
|
|
void display_qrcode(int x, int y, const char *data, int datalen,
|
|
|
|
|
uint8_t scale) {
|
|
|
|
|
if (scale < 1 || scale > 10) return;
|
|
|
|
|
|
|
|
|
|
uint8_t codedata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)];
|
|
|
|
|
uint8_t tempdata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)];
|
|
|
|
|
|
|
|
|
|
int side = 0;
|
|
|
|
|
if (qrcodegen_encodeText(
|
|
|
|
|
data,
|
|
|
|
|
tempdata,
|
|
|
|
|
codedata,
|
|
|
|
|
qrcodegen_Ecc_MEDIUM,
|
|
|
|
|
qrcodegen_VERSION_MIN,
|
|
|
|
|
QR_MAX_VERSION,
|
|
|
|
|
qrcodegen_Mask_AUTO,
|
|
|
|
|
true)) {
|
|
|
|
|
if (qrcodegen_encodeText(data, tempdata, codedata, qrcodegen_Ecc_MEDIUM,
|
|
|
|
|
qrcodegen_VERSION_MIN, QR_MAX_VERSION,
|
|
|
|
|
qrcodegen_Mask_AUTO, true)) {
|
|
|
|
|
side = qrcodegen_getSize(codedata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
clamp_coords(x, y, (side + 2) * scale, (side + 2) * 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++) {
|
|
|
|
@ -671,8 +678,7 @@ void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void display_offset(int set_xy[2], int *get_x, int *get_y)
|
|
|
|
|
{
|
|
|
|
|
void display_offset(int set_xy[2], int *get_x, int *get_y) {
|
|
|
|
|
if (set_xy) {
|
|
|
|
|
DISPLAY_OFFSET.x = set_xy[0];
|
|
|
|
|
DISPLAY_OFFSET.y = set_xy[1];
|
|
|
|
@ -681,8 +687,7 @@ void display_offset(int set_xy[2], int *get_x, int *get_y)
|
|
|
|
|
*get_y = DISPLAY_OFFSET.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int display_orientation(int degrees)
|
|
|
|
|
{
|
|
|
|
|
int display_orientation(int degrees) {
|
|
|
|
|
if (degrees != DISPLAY_ORIENTATION) {
|
|
|
|
|
#if TREZOR_MODEL == T
|
|
|
|
|
if (degrees == 0 || degrees == 90 || degrees == 180 || degrees == 270) {
|
|
|
|
@ -698,8 +703,7 @@ int display_orientation(int degrees)
|
|
|
|
|
return DISPLAY_ORIENTATION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int display_backlight(int val)
|
|
|
|
|
{
|
|
|
|
|
int display_backlight(int val) {
|
|
|
|
|
#if TREZOR_MODEL == 1
|
|
|
|
|
val = 255;
|
|
|
|
|
#endif
|
|
|
|
@ -710,8 +714,7 @@ int display_backlight(int val)
|
|
|
|
|
return DISPLAY_BACKLIGHT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void display_fade(int start, int end, int delay)
|
|
|
|
|
{
|
|
|
|
|
void display_fade(int start, int end, int delay) {
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
|
display_backlight(start + i * (end - start) / 100);
|
|
|
|
|
hal_delay(delay / 100);
|
|
|
|
|