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

feat(core): add smaller loader for model R

This commit is contained in:
tychovrahe 2022-04-29 10:50:41 +02:00 committed by matejcik
parent bd476769cc
commit 8a092bde21
5 changed files with 71 additions and 33 deletions

View File

@ -432,13 +432,15 @@ bool display_toif_info(const uint8_t *data, uint32_t len, uint16_t *out_w,
}
#if defined TREZOR_MODEL_T
#include "loader.h"
#include "loader_T.h"
#elif defined TREZOR_MODEL_R
#include "loader_R.h"
#endif
void display_loader(uint16_t progress, bool indeterminate, int yoffset,
uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon,
uint32_t iconlen, uint16_t iconfgcolor) {
#if defined TREZOR_MODEL_T
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R
uint16_t colortable[16] = {0}, iconcolortable[16] = {0};
set_color_table(colortable, fgcolor, bgcolor);
if (icon) {

View File

@ -53,7 +53,13 @@
#endif
#define AVATAR_IMAGE_SIZE 144
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_1
#define LOADER_ICON_SIZE 64
#elif defined TREZOR_MODEL_R
#define LOADER_ICON_SIZE 24
#else
#error Unknown Trezor model
#endif
#ifdef TREZOR_MODEL_T
#define RGB16(R, G, B) ((R & 0xF8) << 8) | ((G & 0xFC) << 3) | ((B & 0xF8) >> 3)

View File

@ -0,0 +1,24 @@
// clang-format off
static const int img_loader_size = 20;
static const uint16_t img_loader[20][20] = {
{31744,30720,29440,28160,26880,25600,24320,22784,21248,19456,17920,16128,14080,12288,10240,8208,6193,4177,2162,114,},
{32768,31744,30464,29440,28160,26624,25344,23808,22016,20480,18688,16896,14880,13170,10948,8949,6901,4597,2293,245,},
{34048,33024,31744,30464,29184,27904,26368,24832,23296,21504,19761,17827,15861,13813,11765,9461,7157,4853,2549,245,},
{35328,34048,33024,31744,30464,28928,27648,26112,24336,22675,20981,18933,16885,14581,12533,9973,7671,5112,2553,250,},
{36608,35328,34304,33024,31744,30464,28928,27201,25812,24053,22005,19957,17909,15608,13307,10750,8191,5631,2815,255,},
{37888,36864,35584,34560,33024,31744,30289,28917,27125,25333,23285,21240,18941,16639,14079,11519,8652,5785,2952,119,},
{39168,38144,37120,35840,34560,33361,31989,30453,28661,26613,24571,22527,20223,17612,14950,12049,8960,6144,3072,0,},
{40704,39680,38656,37376,36417,35061,33525,31989,30199,28413,26367,24029,21333,18688,15872,13056,9728,6656,3328,0,},
{42240,41472,40192,39184,38100,36853,35317,33783,31998,29951,27818,25361,22784,20224,17152,14080,10752,7168,3584,0,},
{44032,43008,41984,41107,39925,38645,37365,35581,34047,31897,29696,27136,24576,21760,18688,15360,11776,7936,3840,0,},
{45568,44800,43825,42997,41973,40693,39419,37631,36010,33792,31744,29440,26624,23808,20480,16896,13056,8704,4352,0,},
{47360,46592,45987,45045,44021,42744,41471,39901,38161,36352,34048,31744,28928,26112,22528,18688,14336,9728,4864,0,},
{49408,48672,48117,47093,46069,45053,43775,42325,40704,38912,36864,34560,31744,28672,25088,20992,16384,11264,5632,0,},
{51200,50546,50165,49397,48376,47359,46284,44800,43264,41728,39680,37376,34816,31744,28160,23808,18688,13056,6656,0,},
{53248,52932,52213,51445,50683,49919,48742,47616,46336,44800,43008,40960,38400,35328,31744,27136,21760,15360,7936,0,},
{55312,55029,54517,54005,53246,52479,51473,50432,49408,48128,46592,44800,42496,39680,36352,31744,26112,18688,9728,0,},
{57393,57077,56821,56311,55807,55244,54528,53760,52736,51712,50432,49152,47104,44800,41728,37376,31744,23808,13056,0,},
{59473,59381,59125,58872,58367,58009,57344,56832,56320,55552,54784,53760,52224,50432,48128,44800,39680,31744,18688,0,},
{61554,61685,61429,61433,61183,60808,60416,60160,59904,59648,59136,58624,57856,56832,55552,53760,50432,44800,31744,0,},
{63858,63989,63989,63994,63999,63863,63744,63744,63744,63744,63744,63744,63744,63744,63744,63744,63744,63744,63744,0,},
};

View File

@ -1,37 +1,43 @@
#!/usr/bin/env python3
# script used to generate /embed/extmod/modtrezorui/loader.h
# script used to generate /embed/extmod/modtrezorui/loader_X.h
import math
outer = 60
inner = 42
with open("loader.h", "wt") as f:
f.write("static const int img_loader_size = %d;\n" % outer)
f.write("static const uint16_t img_loader[%d][%d] = {\n" % (outer, outer))
for y in range(outer):
f.write(" {")
for x in range(outer):
d = math.sqrt((outer - 1 - x) ** 2 + (outer - 1 - y) ** 2)
c = {}
for i in [5, 15]:
if (inner - 0.5 <= d) and (d <= inner + 0.5):
c[i] = 15 * (d - inner + 0.5)
elif (inner + 0.5 <= d) and (d <= inner + 1.5):
c[i] = 15
elif (inner + 1.5 <= d) and (d <= inner + 2.5):
c[i] = 15 if i == 15 else 15 - (15 - i) * (d - inner - 1.5)
elif (outer - 1.5 <= d) and (d <= outer - 0.5):
c[i] = i - i * (d - outer + 1.5)
elif (inner + 2.5 < d) and (d < outer - 1.5):
c[i] = i
else:
c[i] = 0
# clamp (should not be needed)
c[i] = max(0, min(int(c[i]), 15))
a = int(math.atan2((outer - 1 - x), (outer - 1 - y)) * 2 * 249 / math.pi)
v = (a << 8) | (c[15] << 4) | c[5]
f.write("%d," % v)
f.write("},\n")
f.write("};\n")
def gen_loader(model, outer, inner):
with open(f"loader_{model}.h", "wt") as f:
f.write("// clang-format off\n")
f.write("static const int img_loader_size = %d;\n" % outer)
f.write("static const uint16_t img_loader[%d][%d] = {\n" % (outer, outer))
for y in range(outer):
f.write(" {")
for x in range(outer):
d = math.sqrt((outer - 1 - x) ** 2 + (outer - 1 - y) ** 2)
c = {}
for i in [5, 15]:
if (inner - 0.5 <= d) and (d <= inner + 0.5):
c[i] = 15 * (d - inner + 0.5)
elif (inner + 0.5 <= d) and (d <= inner + 1.5):
c[i] = 15
elif (inner + 1.5 <= d) and (d <= inner + 2.5):
c[i] = 15 if i == 15 else 15 - (15 - i) * (d - inner - 1.5)
elif (outer - 1.5 <= d) and (d <= outer - 0.5):
c[i] = i - i * (d - outer + 1.5)
elif (inner + 2.5 < d) and (d < outer - 1.5):
c[i] = i
else:
c[i] = 0
# clamp (should not be needed)
c[i] = max(0, min(int(c[i]), 15))
a = int(math.atan2((outer - 1 - x), (outer - 1 - y)) * 2 * 249 / math.pi)
v = (a << 8) | (c[15] << 4) | c[5]
f.write("%d," % v)
f.write("},\n")
f.write("};\n")
if __name__ == "__main__":
gen_loader("T", 60, 42)
gen_loader("R", 20, 14)