Skip to content

Commit

Permalink
Merge pull request #618 from LedgerHQ/xch/cherry-pick-18
Browse files Browse the repository at this point in the history
Update API LEVEL 18
  • Loading branch information
xchapron-ledger authored Apr 12, 2024
2 parents 3798f44 + b62bef6 commit 557ce7a
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 64 deletions.
5 changes: 4 additions & 1 deletion Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ endif
ifeq ($(TARGET_NAME), TARGET_NANOS2)
ICONNAME ?= $(ICON_NANOSP)
endif
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
ifeq ($(TARGET_NAME), TARGET_STAX)
ICONNAME ?= $(ICON_STAX)
endif
ifeq ($(TARGET_NAME), TARGET_FLEX)
ICONNAME ?= $(ICON_FLEX)
endif

include $(BOLOS_SDK)/Makefile.glyphs

Expand Down
8 changes: 4 additions & 4 deletions lib_nbgl/include/nbgl_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area,
uint16_t textLen,
nbgl_font_id_e fontId,
color_t fontColor);
void nbgl_drawQrCode(const nbgl_area_t *area,
uint8_t version,
const char *text,
color_t backgroundColor);
void nbgl_drawQrCode(const nbgl_area_t *area,
nbgl_qrcode_version_t version,
const char *text,
color_t backgroundColor);

/**********************
* MACROS
Expand Down
4 changes: 4 additions & 0 deletions lib_nbgl/include/nbgl_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ extern "C" {
#define NBGL_NO_TUNE NB_TUNES
#define NBGL_NO_PROGRESS_INDICATOR 0xFF

///< To be used when a control token shall not be used
#define NBGL_INVALID_TOKEN 0xFF

#ifdef HAVE_SE_TOUCH
///< special code used as index of action callback to inform when Exit key (X) is
///< pressed in the navigation bar
Expand Down Expand Up @@ -413,6 +416,7 @@ typedef struct {
struct {
const nbgl_icon_details_t *actionIcon; ///< right button icon
const char *text; ///< centered text (can be NULL if no text)
uint8_t textToken; ///< when text is touched
uint8_t backToken; ///< when back key is pressed
uint8_t actionToken; ///< when right key is pressed
tune_index_e tuneId; ///< when back key is pressed
Expand Down
5 changes: 3 additions & 2 deletions lib_nbgl/include/nbgl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ typedef enum {
*
*/
typedef enum {
QRCODE_V4 = 0, ///< QRCode V4, can encode text len up to 114 chars
QRCODE_V10 ///< QRCode V10, can encode text len up to 1500 chars
QRCODE_V4 = 0, ///< QRCode V4, can encode text len up to 62 chars, display size = 264*264
QRCODE_V10, ///< QRCode V10, can encode text len up to 1500 chars, display size = 228*228
QRCODE_V4_SMALL ///< QRCode V4, can encode text len up to 1500 chars, display size = 132*132
} nbgl_qrcode_version_t;

/**
Expand Down
34 changes: 22 additions & 12 deletions lib_nbgl/src/nbgl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area,
}

#ifdef NBGL_QRCODE
static void nbgl_frontDrawQrInternal(const nbgl_area_t *area, color_t foregroundColor)
static void nbgl_frontDrawQrInternal(const nbgl_area_t *area,
color_t foregroundColor,
nbgl_qrcode_version_t version)
{
int size = qrcodegen_getSize(qrcode);
uint16_t idx = 0;
Expand All @@ -705,7 +707,7 @@ static void nbgl_frontDrawQrInternal(const nbgl_area_t *area, color_t foreground
.backgroundColor = area->backgroundColor,
// QR codes are 1 BPP only
.bpp = NBGL_BPP_1};
if (size == QR_V4_NB_PIX_SIZE) {
if (version == QRCODE_V4) {
// for each point of the V4 QR code, paint 64 pixels in image (8 in width, 8 in height)
qrArea.width = 2;
qrArea.height = QR_PIXEL_WIDTH_HEIGHT * 2 * size;
Expand All @@ -728,7 +730,7 @@ static void nbgl_frontDrawQrInternal(const nbgl_area_t *area, color_t foreground
qrArea.x0 += 2;
}
}
else {
else { // V4 small or V10
// for each point of the V10 QR code, paint 16 pixels in image (4 in width, 4 in height)
qrArea.width = QR_PIXEL_WIDTH_HEIGHT * size;
qrArea.height = QR_PIXEL_WIDTH_HEIGHT;
Expand All @@ -753,23 +755,31 @@ static void nbgl_frontDrawQrInternal(const nbgl_area_t *area, color_t foreground
* bitmap.
*
* @param area position, size and color of the QR code to draw
* @param version version of QR Code (4, 10, ...)
* @param version version of QR Code
* @param text text to encode
* @param foregroundColor color to be applied to the 1's in QR code
*/
void nbgl_drawQrCode(const nbgl_area_t *area,
uint8_t version,
const char *text,
color_t foregroundColor)
void nbgl_drawQrCode(const nbgl_area_t *area,
nbgl_qrcode_version_t version,
const char *text,
color_t foregroundColor)
{
bool ok = qrcodegen_encodeText(
text, tempBuffer, qrcode, qrcodegen_Ecc_LOW, version, version, qrcodegen_Mask_AUTO, true);
uint8_t versionNum = (version == QRCODE_V10) ? 10 : 4;
bool ok = qrcodegen_encodeText(text,
tempBuffer,
qrcode,
qrcodegen_Ecc_LOW,
versionNum,
versionNum,
qrcodegen_Mask_AUTO,
true);

if (ok) {
nbgl_frontDrawQrInternal(area, foregroundColor);
nbgl_frontDrawQrInternal(area, foregroundColor, version);
}
else {
LOG_WARN(DRAW_LOGGER, "Impossible to draw QRCode text %s with version %d\n", text, version);
LOG_WARN(
DRAW_LOGGER, "Impossible to draw QRCode text %s with version %d\n", text, versionNum);
}
}
#endif // NBGL_QRCODE
85 changes: 72 additions & 13 deletions lib_nbgl/src/nbgl_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ static void touchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
|| (eventType == SWIPED_RIGHT))
&& (obj->type == CONTAINER)) {
#if (!defined(TARGET_STAX) && defined(NBGL_KEYBOARD))
if (keyboardSwipeCallback(obj, eventType)) {
if ((layout->swipeUsage == SWIPE_USAGE_SUGGESTIONS)
&& keyboardSwipeCallback(obj, eventType)) {
// if this swipe event is consumed, return here
return;
}
Expand Down Expand Up @@ -1456,7 +1457,7 @@ int nbgl_layoutAddCenteredInfo(nbgl_layout_t *layout, const nbgl_layoutCenteredI
*
* @param layout the current layout
* @param info structure giving the description of buttons (texts, icons, layout)
* @return >= 0 if OK
* @return height of the control if OK
*/
int nbgl_layoutAddQRCode(nbgl_layout_t *layout, const nbgl_layoutQRCode_t *info)
{
Expand Down Expand Up @@ -1545,6 +1546,15 @@ int nbgl_layoutAddQRCode(nbgl_layout_t *layout, const nbgl_layoutQRCode_t *info)
container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
container->nbChildren++;
}
// ensure that fullHeight is fitting in main container height (with 16 px margin)
if ((fullHeight >= (layoutInt->container->obj.area.height - 16))
&& (qrcode->version == QRCODE_V4)) {
qrcode->version = QRCODE_V4_SMALL;
// in QR V4 small, we use 4*4 screen pixels for one QR pixel
qrcode->obj.area.width = QR_V4_NB_PIX_SIZE * 4;
qrcode->obj.area.height = qrcode->obj.area.width;
fullHeight -= QR_V4_NB_PIX_SIZE * 4;
}
container->obj.area.height = fullHeight;
container->layout = VERTICAL;
if (info->centered) {
Expand All @@ -1562,7 +1572,7 @@ int nbgl_layoutAddQRCode(nbgl_layout_t *layout, const nbgl_layoutQRCode_t *info)
// set this new container as child of main container
layoutAddObject(layoutInt, (nbgl_obj_t *) container);

return 0;
return fullHeight;
}
#endif // NBGL_QRCODE

Expand Down Expand Up @@ -2172,13 +2182,17 @@ int nbgl_layoutAddHeader(nbgl_layout_t *layout, const nbgl_layoutHeader_t *heade
layoutInt->headerContainer->obj.area.height = headerDesc->emptySpace.height;
break;
}
case HEADER_BACK_AND_TEXT: {
case HEADER_BACK_AND_TEXT:
case HEADER_EXTENDED_BACK: {
// add back button
button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
obj = layoutAddCallbackObj(layoutInt,
(nbgl_obj_t *) button,
headerDesc->backAndText.token,
headerDesc->backAndText.tuneId);
obj = layoutAddCallbackObj(
layoutInt,
(nbgl_obj_t *) button,
(headerDesc->type == HEADER_EXTENDED_BACK) ? headerDesc->extendedBack.backToken
: headerDesc->backAndText.token,
(headerDesc->type == HEADER_EXTENDED_BACK) ? headerDesc->extendedBack.tuneId
: headerDesc->backAndText.tuneId);
if (obj == NULL) {
return -1;
}
Expand All @@ -2200,18 +2214,63 @@ int nbgl_layoutAddHeader(nbgl_layout_t *layout, const nbgl_layoutHeader_t *heade
// add optional text if needed
if (headerDesc->backAndText.text != NULL) {
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
if ((headerDesc->type == HEADER_EXTENDED_BACK)
&& (headerDesc->extendedBack.textToken != NBGL_INVALID_TOKEN)) {
obj = layoutAddCallbackObj(layoutInt,
(nbgl_obj_t *) textArea,
headerDesc->extendedBack.textToken,
headerDesc->extendedBack.tuneId);
if (obj == NULL) {
return -1;
}
textArea->obj.touchMask = (1 << TOUCHED);
}
textArea->obj.alignment = CENTER;
textArea->textColor = BLACK;
textArea->obj.area.width
= layoutInt->headerContainer->obj.area.width - 2 * BACK_KEY_WIDTH;
textArea->text = PIC(headerDesc->backAndText.text);
textArea->fontId = SMALL_BOLD_FONT;
textArea->textAlignment = CENTER;
textArea->wrapping = true;
textArea->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
textArea->text = (headerDesc->type == HEADER_EXTENDED_BACK)
? PIC(headerDesc->extendedBack.text)
: PIC(headerDesc->backAndText.text);
textArea->fontId = SMALL_BOLD_FONT;
textArea->textAlignment = CENTER;
textArea->wrapping = true;
layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
= (nbgl_obj_t *) textArea;
layoutInt->headerContainer->nbChildren++;
}
// add action key if the type is HEADER_EXTENDED_BACK
if ((headerDesc->type == HEADER_EXTENDED_BACK)
&& (headerDesc->extendedBack.actionIcon)) {
button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
// if token is valid
if (headerDesc->extendedBack.actionToken != NBGL_INVALID_TOKEN) {
obj = layoutAddCallbackObj(layoutInt,
(nbgl_obj_t *) button,
headerDesc->extendedBack.actionToken,
headerDesc->extendedBack.tuneId);
if (obj == NULL) {
return -1;
}
button->obj.touchMask = (1 << TOUCHED);
}

button->obj.alignment = MID_RIGHT;
button->innerColor = WHITE;
button->foregroundColor
= (headerDesc->extendedBack.actionToken != NBGL_INVALID_TOKEN) ? BLACK
: LIGHT_GRAY;
button->borderColor = WHITE;
button->obj.area.width = BACK_KEY_WIDTH;
button->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
button->text = NULL;
button->icon = PIC(headerDesc->extendedBack.actionIcon);
button->obj.touchId = EXTRA_BUTTON_ID;
layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
= (nbgl_obj_t *) button;
layoutInt->headerContainer->nbChildren++;
}

layoutInt->headerContainer->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
break;
Expand Down Expand Up @@ -2542,7 +2601,7 @@ int nbgl_layoutAddExtendedFooter(nbgl_layout_t *layout, const nbgl_layoutFooter_
separationLine->thickness = 1;
separationLine->obj.alignment = MID_LEFT;
separationLine->obj.alignTo = (nbgl_obj_t *) navContainer;
separationLine->obj.alignmentMarginY = -1;
separationLine->obj.alignmentMarginX = -1;

layoutInt->activePage = footerDesc->textAndNav.navigation.activePage;
layoutInt->nbPages = footerDesc->textAndNav.navigation.nbPages;
Expand Down
4 changes: 4 additions & 0 deletions lib_nbgl/src/nbgl_layout_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ extern "C" {
*/
#define LAYOUT_OBJ_POOL_LEN 10

#define KEYBOARD_FOOTER_TYPE 99
#define KEYPAD_FOOTER_TYPE 98

/**********************
* TYPEDEFS
**********************/
Expand All @@ -44,6 +47,7 @@ typedef struct {
typedef enum {
SWIPE_USAGE_NAVIGATION,
SWIPE_USAGE_CUSTOM,
SWIPE_USAGE_SUGGESTIONS, // for suggestion buttons
NB_SWIPE_USAGE
} nbgl_swipe_usage_t;

Expand Down
Loading

0 comments on commit 557ce7a

Please sign in to comment.