From c0b295a9b1ef4981cd8a1266570276165c9ac16d Mon Sep 17 00:00:00 2001 From: cepetr Date: Tue, 2 Jul 2024 10:05:38 +0200 Subject: [PATCH] fix(core/prodtest): fix prodtest build with NEW_RENDERING on [no changelog] --- core/SConscript.prodtest | 21 ++++++++++++++- core/embed/lib/gfx_draw.c | 53 ++++++++++++++++++++++++++++++++++++++ core/embed/lib/gfx_draw.h | 9 +++++++ core/embed/prodtest/main.c | 1 + 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index b505b4337e..946c5ee73c 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -8,6 +8,7 @@ CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0)) PRODUCTION = ARGUMENTS.get('PRODUCTION', '0') == '1' BOOTLOADER_DEVEL = ARGUMENTS.get('BOOTLOADER_DEVEL', '0') == '1' HW_REVISION = ARGUMENTS.get('HW_REVISION', None) +NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' if TREZOR_MODEL in ('DISC1', 'DISC2'): # skip prodtest build @@ -22,6 +23,9 @@ if TREZOR_MODEL in ('DISC1', 'DISC2'): FEATURES_WANTED = ["input", "sbu", "sd_card", "rdb_led", "usb", "consumption_mask", "optiga", "haptic"] +if NEW_RENDERING: + FEATURES_WANTED.append("new_rendering") + CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [ @@ -100,11 +104,14 @@ CPPPATH_MOD += [ SOURCE_MOD += [ 'embed/lib/colors.c', - 'embed/lib/display_draw.c', 'embed/lib/display_utils.c', 'embed/lib/error_handling.c', 'embed/lib/fonts/font_bitmap.c', 'embed/lib/fonts/fonts.c', + 'embed/lib/gfx_color.c', + 'embed/lib/gfx_bitblt_rgb565.c', + 'embed/lib/gfx_bitblt_rgba8888.c', + 'embed/lib/gfx_bitblt_mono8.c', 'embed/lib/image.c', 'embed/lib/mini_printf.c', 'embed/lib/qr-code-generator/qrcodegen.c', @@ -114,6 +121,18 @@ SOURCE_MOD += [ 'vendor/micropython/lib/uzlib/tinflate.c', ] + +if NEW_RENDERING: + CPPDEFINES_MOD += ['NEW_RENDERING'] + SOURCE_MOD += [ + 'embed/lib/gfx_draw.c', + ] +else: + SOURCE_MOD += [ + 'embed/lib/display_draw.c', + ] + + # fonts tools.add_font('NORMAL', FONT_NORMAL, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BOLD', FONT_BOLD, CPPDEFINES_MOD, SOURCE_MOD) diff --git a/core/embed/lib/gfx_draw.c b/core/embed/lib/gfx_draw.c index c8fc4da822..192bfef361 100644 --- a/core/embed/lib/gfx_draw.c +++ b/core/embed/lib/gfx_draw.c @@ -241,6 +241,53 @@ void gfx_draw_text(gfx_offset_t pos, const char* text, size_t maxlen, } } +#ifdef TREZOR_PRODTEST + +#include "qr-code-generator/qrcodegen.h" +#define QR_MAX_VERSION 9 + +void gfx_draw_qrcode(int x, int y, uint8_t scale, const char* data) { + if (scale < 1 || scale > 10) return; + + uint8_t codedata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)] = {0}; + uint8_t tempdata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)] = {0}; + + int side = 0; + if (qrcodegen_encodeText(data, tempdata, codedata, qrcodegen_Ecc_MEDIUM, + qrcodegen_VERSION_MIN, QR_MAX_VERSION, + qrcodegen_Mask_AUTO, true)) { + side = qrcodegen_getSize(codedata); + } + + // Calculate border size (1 extra modules around the QR code) + int border_side = ((side + 2) * scale); + + // Calculate border left-top corner + x -= border_side / 2; + y -= border_side / 2; + + // Fill the backround (including the border) with white color + gfx_rect_t border_rect = gfx_rect_wh(x, y, border_side, border_side); + gfx_draw_bar(border_rect, COLOR_WHITE); + + // Center QR code inside the border + x += scale; + y += scale; + + // Draw black modules + for (int i = 0; i < side; i++) { + for (int j = 0; j < side; j++) { + if (qrcodegen_getModule(codedata, i, j)) { + gfx_rect_t rect = + gfx_rect_wh(x + i * scale, y + j * scale, scale, scale); + gfx_draw_bar(rect, COLOR_BLACK); + } + } + } +} + +#endif // TREZOR_PRODTEST + // =============================================================== // emulation of legacy functions @@ -274,3 +321,9 @@ void display_text_center(int x, int y, const char* text, int textlen, int font, int w = font_text_width(font, text, textlen); gfx_draw_text(gfx_offset(x - w / 2, y), text, maxlen, &attr); } + +#ifdef TREZOR_PRODTEST +void display_qrcode(int x, int y, const char* data, uint8_t scale) { + gfx_draw_qrcode(x, y, scale, data); +} +#endif // TREZOR_PRODTEST diff --git a/core/embed/lib/gfx_draw.h b/core/embed/lib/gfx_draw.h index fcd32bacca..280c13abdb 100644 --- a/core/embed/lib/gfx_draw.h +++ b/core/embed/lib/gfx_draw.h @@ -150,4 +150,13 @@ void gfx_draw_bitmap(gfx_rect_t rect, const gfx_bitmap_t* bitmap); void gfx_draw_text(gfx_offset_t offset, const char* text, size_t maxlen, const gfx_text_attr_t* attr); +#ifdef TREZOR_PRODTEST +// Draws a QR code to the specified position. +// +// `x`, `y` - center of the QR code +// `scale` - size of a single QR code module +// `data` - utf-8 text +void gfx_draw_qrcode(int x, int y, uint8_t scale, const char* data); +#endif + #endif // GFX_DRAW_H diff --git a/core/embed/prodtest/main.c b/core/embed/prodtest/main.c index 436951619f..15484f4aa6 100644 --- a/core/embed/prodtest/main.c +++ b/core/embed/prodtest/main.c @@ -831,6 +831,7 @@ int main(void) { display_qrcode(DISPLAY_RESX / 2, DISPLAY_RESY / 2, dom, 4); display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 30, dom + 8, -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK); + display_refresh(); } display_fade(0, BACKLIGHT_NORMAL, 1000);