22#include "os_helpers.h"
27#ifdef SCREEN_SIZE_WALLET
34 BAGL_FILL_CIRCLE_0_PI2,
35 BAGL_FILL_CIRCLE_PI2_PI,
36 BAGL_FILL_CIRCLE_PI_3PI2,
37 BAGL_FILL_CIRCLE_3PI2_2PI
41#define QR_PIXEL_WIDTH_HEIGHT 4
48 uint8_t
qrcode[qrcodegen_BUFFER_LEN_MAX];
53#define qrcode ((QrCodeBuffer_t *) ramBuffer)->qrcode
54#define tempBuffer ((QrCodeBuffer_t *) ramBuffer)->tempBuffer
55#define QrDrawBuffer ((QrCodeBuffer_t *) ramBuffer)->QrDrawBuffer
59#ifdef SCREEN_SIZE_WALLET
66 const uint8_t *topLeftDisc;
67 const uint8_t *bottomLeftDisc;
68 const uint8_t *topLeftCircle;
69 const uint8_t *bottomLeftCircle;
84#ifndef SCREEN_SIZE_WALLET
85static const uint8_t quarter_disc_3px_1bpp[] = {0xEC, 0xFF};
86static const uint8_t quarter_disc_3px_90_1bpp[] = {0x2F, 0xFF};
87static const uint8_t quarter_disc_3px_180_1bpp[] = {0x9B, 0xFF};
88static const uint8_t quarter_disc_3px_270_1bpp[] = {0xFA, 0x00};
90static const uint8_t quarter_circle_3px_1bpp[] = {0x4C, 0x00};
91static const uint8_t quarter_circle_3px_90_1bpp[] = {0x0D, 0x00};
92static const uint8_t quarter_circle_3px_180_1bpp[] = {0x19, 0x00};
93static const uint8_t quarter_circle_3px_270_1bpp[] = {0x58, 0x00};
97static const uint8_t radiusValues[
RADIUS_MAX + 1] = {
98#ifdef SCREEN_SIZE_WALLET
110#ifdef SCREEN_SIZE_WALLET
112#if COMMON_RADIUS == 28
114 = {&C_half_disc_left_56px_1bpp, &C_half_circle_left_56px_1bpp};
115#elif COMMON_RADIUS == 40
117 = {&C_half_disc_left_80px_1bpp, &C_half_circle_left_80px_1bpp};
118#elif COMMON_RADIUS == 44
120 = {&C_half_disc_left_88px_1bpp, &C_half_circle_left_88px_1bpp};
122#if SMALL_BUTTON_RADIUS == 20
124 = {&C_half_disc_left_40px_1bpp, &C_half_circle_left_40px_1bpp};
125#elif SMALL_BUTTON_RADIUS == 32
127 = {&C_half_disc_left_64px_1bpp, &C_half_circle_left_64px_1bpp};
132#if SMALL_BUTTON_RADIUS == 20
137#if COMMON_RADIUS == 28
142#if SMALL_BUTTON_RADIUS == 32
147#if COMMON_RADIUS == 40
152#if COMMON_RADIUS == 44
173#ifdef SCREEN_SIZE_WALLET
174static void draw_circle_helper(
int x0,
189 if (borderColor == innerColor) {
190 half_icon = PIC(radiusIcons[radiusIndex]->leftDisc);
193#if NB_COLOR_BITS == 1
196 half_icon = PIC(radiusIcons[radiusIndex]->leftCircle);
198 area.width = half_icon->width;
199 area.height = half_icon->height;
207 area.x0 = x0 - half_icon->width;
214static void draw_circle_helper(
int x_center,
222 const uint8_t *quarter_buffer = NULL;
229 area.width = area.height = radiusValues[radiusIndex];
231 case BAGL_FILL_CIRCLE_3PI2_2PI:
234 quarter_buffer = (borderColor == innerColor) ? quarter_disc_3px_180_1bpp
235 : quarter_circle_3px_180_1bpp;
237 case BAGL_FILL_CIRCLE_PI_3PI2:
238 area.x0 = x_center - area.width;
240 quarter_buffer = (borderColor == innerColor) ? quarter_disc_3px_270_1bpp
241 : quarter_circle_3px_270_1bpp;
243 case BAGL_FILL_CIRCLE_0_PI2:
245 area.y0 = y_center - area.width;
246 quarter_buffer = (borderColor == innerColor) ? quarter_disc_3px_90_1bpp
247 : quarter_circle_3px_90_1bpp;
249 case BAGL_FILL_CIRCLE_PI2_PI:
250 area.x0 = x_center - area.width;
251 area.y0 = y_center - area.width;
253 = (borderColor == innerColor) ? quarter_disc_3px_1bpp : quarter_circle_3px_1bpp;
279 "nbgl_drawRoundedRect x0 = %d, y0 = %d, width =%d, height =%d\n",
286 radius = radiusValues[radiusIndex];
298 rectArea.x0 = area->x0;
299 rectArea.y0 = area->y0;
300 rectArea.width = area->width;
301 rectArea.height = area->height;
302 rectArea.backgroundColor = innerColor;
309#ifdef SCREEN_SIZE_WALLET
312 draw_circle_helper(area->x0,
318 area->backgroundColor);
319 draw_circle_helper(area->x0 + area->width,
325 area->backgroundColor);
327 if (radiusIndex == RADIUS_1_PIXEL) {
331 draw_circle_helper(area->x0 + radius,
334 BAGL_FILL_CIRCLE_PI2_PI,
337 area->backgroundColor);
338 draw_circle_helper(area->x0 + area->width - radius,
341 BAGL_FILL_CIRCLE_0_PI2,
344 area->backgroundColor);
345 draw_circle_helper(area->x0 + radius,
346 area->y0 + area->height - radius,
348 BAGL_FILL_CIRCLE_PI_3PI2,
351 area->backgroundColor);
352 draw_circle_helper(area->x0 + area->width - radius,
353 area->y0 + area->height - radius,
355 BAGL_FILL_CIRCLE_3PI2_2PI,
358 area->backgroundColor);
383 "nbgl_drawRoundedBorderedRect: innerColor = %d, borderColor = %d, backgroundColor=%d\n",
386 area->backgroundColor);
389 radius = radiusValues[radiusIndex];
397 DRAW_LOGGER,
"nbgl_drawRoundedBorderedRect forbidden radius index =%d\n", radiusIndex);
400 rectArea.backgroundColor = innerColor;
403 rectArea.x0 = area->x0;
404 rectArea.y0 = area->y0;
405 rectArea.width = area->width;
406 rectArea.height = area->height;
409 if ((innerColor == borderColor) && (borderColor == area->backgroundColor)) {
414#ifdef SCREEN_SIZE_WALLET
415 uint16_t circle_width = 0;
418 circle_width = half_icon->width;
420 if ((2 * circle_width) < area->width) {
421 if ((area->height - stroke) > VERTICAL_ALIGNMENT) {
423 rectArea.height = stroke;
424 rectArea.width = area->width - 2 * circle_width;
425 rectArea.x0 += circle_width;
427 rectArea.y0 = area->y0 + area->height - stroke;
433 for (i = 0; i < stroke; i++) {
434 pattern |= 1 << (7 - i);
436 for (i = area->height - stroke; i < area->height; i++) {
437 pattern |= 1 << (7 - i);
445 if ((2 * radius) < area->height) {
446 rectArea.x0 = area->x0;
447 rectArea.y0 = area->y0;
448 rectArea.width = stroke;
449 rectArea.height = area->height;
450 rectArea.backgroundColor = area->backgroundColor;
452 rectArea.x0 = area->x0 + area->width - stroke;
457 draw_circle_helper(area->x0,
463 area->backgroundColor);
464 draw_circle_helper(area->x0 + area->width,
470 area->backgroundColor);
473 rectArea.x0 = area->x0 + radius;
474 rectArea.y0 = area->y0;
475 rectArea.width = area->width - 2 * radius;
476 rectArea.height = stroke;
477 rectArea.backgroundColor = borderColor;
479 rectArea.y0 = area->y0 + area->height - stroke;
481 if ((2 * radius) < area->height) {
482 rectArea.x0 = area->x0;
483 rectArea.y0 = area->y0 + radius;
484 rectArea.width = stroke;
485 rectArea.height = area->height - 2 * radius;
486 rectArea.backgroundColor = area->backgroundColor;
488 rectArea.x0 = area->x0 + area->width - stroke;
494 draw_circle_helper(area->x0 + radius,
497 BAGL_FILL_CIRCLE_PI2_PI,
500 area->backgroundColor);
501 draw_circle_helper(area->x0 + area->width - radius,
504 BAGL_FILL_CIRCLE_0_PI2,
507 area->backgroundColor);
508 draw_circle_helper(area->x0 + radius,
509 area->y0 + area->height - radius,
511 BAGL_FILL_CIRCLE_PI_3PI2,
514 area->backgroundColor);
515 draw_circle_helper(area->x0 + area->width - radius,
516 area->y0 + area->height - radius,
518 BAGL_FILL_CIRCLE_3PI2_2PI,
521 area->backgroundColor);
553static void push_bits(uint8_t *buffer, uint16_t current_bits, uint8_t bits, uint8_t nb_bits)
555 uint8_t
byte = current_bits / 8;
556 uint8_t remaining_bits = 8 - current_bits % 8;
558 if (remaining_bits >= nb_bits) {
560 buffer[byte] |= bits << (remaining_bits - nb_bits);
564 buffer[byte] |= bits >> (nb_bits - remaining_bits);
565 nb_bits -= remaining_bits;
567 buffer[
byte + 1] |= bits << (8 - nb_bits);
572static void nbgl_frontDrawQrInternal(
const nbgl_area_t *area,
576 int size = qrcodegen_getSize(
qrcode);
581 .backgroundColor = area->backgroundColor,
590 for (
int x = 0; x < size; x++) {
592 for (
int y = 0; y < size; y++) {
610 qrArea.height = 5 * size;
611 for (
int x = 0; x < size; x++) {
615 for (
int y = 0; y < size; y++) {
618 for (
int z = 0; z < 5; z++) {
630 for (
int x = 0; x < size; x++) {
633 for (
int y = 0; y < size; y++) {
668 uint8_t versionNum = (version ==
QRCODE_V10) ? 10 : 4;
669 bool ok = qrcodegen_encodeText(text,
679 nbgl_frontDrawQrInternal(area, foregroundColor, version);
683 DRAW_LOGGER,
"Impossible to draw QRCode text %s with version %d\n", text, versionNum);
#define LOG_WARN(__logger,...)
#define LOG_DEBUG(__logger,...)
void nbgl_drawIcon(nbgl_area_t *area, nbgl_transformation_t transformation, nbgl_color_map_t color_map, const nbgl_icon_details_t *icon)
Helper function to render an icon directly from its nbgl_icon_details_t structure.
#define QR_PIXEL_WIDTH_HEIGHT
void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area, nbgl_radius_t radiusIndex, uint8_t stroke, color_t innerColor, color_t borderColor)
This functions draws a rounded corners rectangle with a border, with the given parameters.
CCASSERT(qr_code_buffer, sizeof(QrCodeBuffer_t)<=GZLIB_UNCOMPRESSED_CHUNK)
void nbgl_drawQrCode(const nbgl_area_t *area, nbgl_qrcode_version_t version, const char *text, color_t foregroundColor)
Draws the given text into a V10 QR code (QR code version is fixed using qrcodegen_VERSION_MIN/qrcodeg...
void nbgl_drawRoundedRect(const nbgl_area_t *area, nbgl_radius_t radiusIndex, color_t innerColor)
This functions draws a rounded corners rectangle (without border), with the given parameters.
Middle Level API of the new BOLOS Graphical Library.
#define QR_V4_NB_PIX_SIZE
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawLine(const nbgl_area_t *area, uint8_t dotStartIdx, color_t lineColor)
void nbgl_frontDrawImage(const nbgl_area_t *area, const uint8_t *buffer, nbgl_transformation_t transformation, nbgl_color_map_t colorMap)
void nbgl_frontDrawImageFile(const nbgl_area_t *area, const uint8_t *buffer, nbgl_color_map_t colorMap, const uint8_t *uzlib_chunk_buffer)
void nbgl_frontDrawRect(const nbgl_area_t *area)
Side screen low-Level driver API, to draw elementary forms.
uint8_t nbgl_transformation_t
Represents the transformation to be applied on the bitmap before rendering This is a bitfield using m...
uint8_t nbgl_color_map_t
Represents the color_map to be used for 2BPP image, or the foreground color for 1BPP image.
nbgl_radius_t
possible radius indexes for objects
@ RADIUS_0_PIXELS
no radius (square angle)
nbgl_qrcode_version_t
possible modes for QR Code
@ QRCODE_V10
QRCode V10, can encode text len up to 1500 chars, display size = 228*228.
@ QRCODE_V4
QRCode V4, can encode text len up to 62 chars, display size = 264*264.
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define GZLIB_UNCOMPRESSED_CHUNK
size of gzlib uncompression buffer in bytes
#define NO_TRANSFORMATION
@ NBGL_BPP_1
1 bit per pixel
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
const nbgl_icon_details_t * leftCircle
const nbgl_icon_details_t * leftDisc