Skip to content

Commit

Permalink
Merge pull request #610 from LedgerHQ/abo_update_level_18_2
Browse files Browse the repository at this point in the history
Update API_LEVEL_18
  • Loading branch information
abonnaudet-ledger authored Apr 5, 2024
2 parents 3a95bd5 + 4507d56 commit 3798f44
Show file tree
Hide file tree
Showing 17 changed files with 1,343 additions and 470 deletions.
4 changes: 3 additions & 1 deletion Makefile.defines
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ DEFINES += HAVE_INAPP_BLE_PAIRING
DEFINES += HAVE_NBGL
DEFINES += HAVE_PIEZO_SOUND
DEFINES += HAVE_SE_TOUCH
DEFINES += HAVE_SE_EINK_DISPLAY
DEFINES += NBGL_PAGE
DEFINES += NBGL_USE_CASE
DEFINES += SCREEN_SIZE_WALLET
Expand All @@ -189,7 +190,8 @@ DEFINES += HAVE_INAPP_BLE_PAIRING
DEFINES += HAVE_NBGL
DEFINES += HAVE_PIEZO_SOUND
DEFINES += HAVE_SE_TOUCH
DEFINES += HAVE_HW_TOUCH_SWIPE
DEFINES += HAVE_SE_EINK_DISPLAY
# DEFINES += HAVE_HW_TOUCH_SWIPE
DEFINES += NBGL_PAGE
DEFINES += NBGL_USE_CASE
DEFINES += SCREEN_SIZE_WALLET
Expand Down
29 changes: 29 additions & 0 deletions lib_cxng/include/lcx_crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,35 @@ uint16_t cx_crc16(const void *buffer, size_t len);
*/
uint16_t cx_crc16_update(uint16_t crc, const void *buffer, size_t len);

/** CRC32 initial value */
#define CX_CRC32_INIT 0xFFFFFFFF

/**
* @brief Computes a 32-bit checksum value.
*
* @details The 32-bit value is computed according to the CRC32 CCITT definition.
*
* @param[in] buffer The buffer to compute the CRC over.
*
* @param[in] len Bytes length of the buffer.
*
* @return Current CRC value.
*/
uint32_t cx_crc32(const void *buf, size_t len);

/**
* @brief Accumulates more data to CRC.
*
* @param[in] crc CRC value to be updated.
*
* @param[in] buffer The buffer to compute the CRC over.
*
* @param[in] len Bytes length of the buffer.
*
* @return Updated CRC value.
*/
uint32_t cx_crc32_update(uint32_t crc_state, const void *buf, size_t len);

#endif // HAVE_CRC

#endif // LCX_CRC_H
9 changes: 1 addition & 8 deletions lib_cxng/src/cx_crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@

#ifdef HAVE_CRC

#include <stddef.h>
#include <stdint.h>

/** CRC32 initial value */
#define CX_CRC32_INIT 0xFFFFFFFF

uint32_t cx_crc32(const void *buf, size_t len);
uint32_t cx_crc32_update(uint32_t crc_state, const void *buf, size_t len);
#include "lcx_crc.h"

#endif // HAVE_CRC

Expand Down
2 changes: 1 addition & 1 deletion lib_cxng/src/cx_crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#ifdef HAVE_CRC

#include "cx_crc.h"
#include "lcx_crc.h"
#include "cx_ram.h"

static uint32_t reverse_32_bits(uint32_t value)
Expand Down
17 changes: 12 additions & 5 deletions lib_nbgl/doc/nbgl_use_case.dox
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ A few APIs are available to draw typical Use-Cases, such as:
- @ref nbgl_useCaseAddressConfirmation() to draw an address confirmation page, with a possibility to see it as QR Code (see @subpage use_case_addr_confirm)
- @ref nbgl_useCaseAddressConfirmationExt() to draw an address confirmation page, with a possibility to see it as QR Code and some extra tag/value pairs (see @subpage use_case_addr_confirm_ext)
- for keypad:
- @ref nbgl_useCaseKeypad() to draw a default keypad implementation (see @subpage use_case_keypad)
- @ref nbgl_useCaseKeypadPIN() to draw a default keypad implementation with hidden digits (see @subpage use_case_keypad)
- @ref nbgl_useCaseKeypadDigits() to draw a default keypad implementation, showing digits (see @subpage use_case_keypad)

@subsection use_case_home Home screen Use Case

Expand Down Expand Up @@ -872,22 +873,28 @@ The @ref nbgl_useCaseSpinner() function enables to create such a page, with the

\image{inline} html UseCase-Keypad.png "caption" height=350

When a pincode is requested, a default keypad can be displayed. As show on the image above, it consists of:
We have here 2 different variants, allowing to show or hide the entered digits.

When a pincode is requested, a default keypad can be displayed, with hidden digits.
As shown on the image above, it consists of:

- a navigation bar at the top
- a title area, specifying the type of pin code or operation requested
- a hidden Digits area (the max nb of supported digits is 12)
- the keypad at the bottom

The @ref nbgl_useCaseKeypad() function enables to create such page, with the following parameters:
The @ref nbgl_useCaseKeypadPIN() function enables to create such page, with the following parameters:

- the title
- min and max pin code length
- min and max pin code lengths
- a token for the navigation callback (if not provided, no navigation bar will appear)
- a boolean to request a shuffled keypad
- a tune value
- callbacks for navigation and pin validation

The other variant, where digits don't need to be hidden is @ref nbgl_useCaseKeypadDigits();
it takes the same parameters.

@note The \em backspace and \em validate buttons will be shown or hidden automatically.

Here is the code to display something similar to example picture:
Expand All @@ -907,7 +914,7 @@ static void pinentry_cb(int token, uint8_t index) {

void ui_menu_pinentry_display(unsigned int value) {
// Draw the keypad
nbgl_useCaseKeypad("Enter User PIN",
nbgl_useCaseKeypadPIN("Enter User PIN",
6,
12,
TOKEN_PIN_ENTRY_BACK,
Expand Down
143 changes: 105 additions & 38 deletions lib_nbgl/include/nbgl_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,59 @@ typedef struct {
#endif // HAVE_PIEZO_SOUND
} nbgl_layoutButton_t;

/**
* @brief The different types of keyboard contents
*
*/
typedef enum {
KEYBOARD_WITH_SUGGESTIONS, ///< text entry area + suggestion buttons
KEYBOARD_WITH_BUTTON, ///< text entry area + confirmation button
NB_KEYBOARD_CONTENT_TYPES
} nbgl_layoutKeyboardContentType_t;

/**
* @brief This structure contains info to build suggestion buttons
*/
typedef struct {
const char **buttons; ///< array of 4 strings for buttons (last ones can be NULL)
int firstButtonToken; ///< first token used for buttons, provided in onActionCallback (the next
///< 3 values will be used for other buttons)
uint8_t nbUsedButtons; ///< the number of actually used buttons
} nbgl_layoutSuggestionButtons_t;

/**
* @brief This structure contains info to build a confirmation button
*/
typedef struct {
const char *text; ///< text of the button
int token; ///< token of the button
bool active; ///< if true, button is active, otherwise inactive (grayed-out)
} nbgl_layoutConfirmationButton_t;

/**
* @brief This structure contains info to build a keyboard content (controls that are linked to
* keyboard)
*/
typedef struct {
nbgl_layoutKeyboardContentType_t type; ///< type of content
const char *title; ///< centered title explaining the screen
const char *text; ///< already entered text
bool numbered; ///< if set to true, the text is preceded on the left by 'number.'
uint8_t number; ///< if numbered is true, number used to build 'number.' text
bool grayedOut; ///< if true, the text is grayed out (but not the potential number)
int textToken; ///< the token that will be used as argument of the callback when text is
///< touched
union {
nbgl_layoutSuggestionButtons_t
suggestionButtons; /// used if type is @ref KEYBOARD_WITH_SUGGESTIONS
nbgl_layoutConfirmationButton_t
confirmationButton; /// used if type is @ref KEYBOARD_WITH_BUTTON
};
#ifdef HAVE_PIEZO_SOUND
tune_index_e tuneId; ///< if not @ref NBGL_NO_TUNE, a tune will be played
#endif // HAVE_PIEZO_SOUND
} nbgl_layoutKeyboardContent_t;

/**
* @brief The different types of extended header
*
Expand Down Expand Up @@ -527,43 +580,46 @@ int nbgl_layoutAddMenuList(nbgl_layout_t *layout, nbgl_layoutMenuList_t *list);
/* layout objects for page with keyboard */
int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo);
#ifdef HAVE_SE_TOUCH
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout,
uint8_t index,
uint32_t keyMask,
bool updateCasing,
keyboardCase_t casing);
bool nbgl_layoutKeyboardNeedsRefresh(nbgl_layout_t *layout, uint8_t index);
int nbgl_layoutAddSuggestionButtons(nbgl_layout_t *layout,
uint8_t nbUsedButtons,
const char *buttonTexts[NB_MAX_SUGGESTION_BUTTONS],
int firstButtonToken,
tune_index_e tuneId);
int nbgl_layoutUpdateSuggestionButtons(nbgl_layout_t *layout,
uint8_t index,
uint8_t nbUsedButtons,
const char *buttonTexts[NB_MAX_SUGGESTION_BUTTONS]);
int nbgl_layoutAddEnteredText(nbgl_layout_t *layout,
bool numbered,
uint8_t number,
const char *text,
bool grayedOut,
int offsetY,
int token);
int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout,
uint8_t index,
bool numbered,
uint8_t number,
const char *text,
bool grayedOut);
int nbgl_layoutAddConfirmationButton(nbgl_layout_t *layout,
bool active,
const char *text,
int token,
tune_index_e tuneId);
int nbgl_layoutUpdateConfirmationButton(nbgl_layout_t *layout,
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout,
uint8_t index,
bool active,
const char *text);
uint32_t keyMask,
bool updateCasing,
keyboardCase_t casing);
bool nbgl_layoutKeyboardNeedsRefresh(nbgl_layout_t *layout, uint8_t index);
DEPRECATED int nbgl_layoutAddSuggestionButtons(nbgl_layout_t *layout,
uint8_t nbUsedButtons,
const char *buttonTexts[NB_MAX_SUGGESTION_BUTTONS],
int firstButtonToken,
tune_index_e tuneId);
DEPRECATED int nbgl_layoutUpdateSuggestionButtons(
nbgl_layout_t *layout,
uint8_t index,
uint8_t nbUsedButtons,
const char *buttonTexts[NB_MAX_SUGGESTION_BUTTONS]);
DEPRECATED int nbgl_layoutAddEnteredText(nbgl_layout_t *layout,
bool numbered,
uint8_t number,
const char *text,
bool grayedOut,
int offsetY,
int token);
DEPRECATED int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout,
uint8_t index,
bool numbered,
uint8_t number,
const char *text,
bool grayedOut);
DEPRECATED int nbgl_layoutAddConfirmationButton(nbgl_layout_t *layout,
bool active,
const char *text,
int token,
tune_index_e tuneId);
DEPRECATED int nbgl_layoutUpdateConfirmationButton(nbgl_layout_t *layout,
uint8_t index,
bool active,
const char *text);
int nbgl_layoutAddKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardContent_t *content);
int nbgl_layoutUpdateKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardContent_t *content);
#else // HAVE_SE_TOUCH
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask);
int nbgl_layoutAddEnteredText(nbgl_layout_t *layout, const char *text, bool lettersOnly);
Expand All @@ -580,8 +636,19 @@ int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout,
bool enableValidate,
bool enableBackspace,
bool enableDigits);
int nbgl_layoutAddHiddenDigits(nbgl_layout_t *layout, uint8_t nbDigits);
int nbgl_layoutUpdateHiddenDigits(nbgl_layout_t *layout, uint8_t index, uint8_t nbActive);
DEPRECATED int nbgl_layoutAddHiddenDigits(nbgl_layout_t *layout, uint8_t nbDigits);
DEPRECATED int nbgl_layoutUpdateHiddenDigits(nbgl_layout_t *layout,
uint8_t index,
uint8_t nbActive);
int nbgl_layoutAddKeypadContent(nbgl_layout_t *layout,
const char *title,
bool hidden,
uint8_t nbDigits,
const char *text);
int nbgl_layoutUpdateKeypadContent(nbgl_layout_t *layout,
bool hidden,
uint8_t nbActiveDigits,
const char *text);

#else // HAVE_SE_TOUCH
/* layout objects for pages with keypad (nanos) */
Expand Down
9 changes: 5 additions & 4 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,11 @@ typedef struct PACKED__ nbgl_switch_s {
* @note if withBorder, the stroke of the border is fixed (3 pixels)
*/
typedef struct PACKED__ nbgl_progress_bar_s {
nbgl_obj_t obj; // common part
bool withBorder; ///< if set to true, a border in black surround the whole object
uint8_t state; ///< state of the progress, in % (from 0 to 100).
uint8_t previousState; ///< previous state of the progress, in % (from 0 to 100).
nbgl_obj_t obj; // common part
bool withBorder; ///< if set to true, a border in black surround the whole object
uint8_t state; ///< state of the progress, in % (from 0 to 100).
uint8_t previousState; ///< previous state of the progress, in % (from 0 to 100).
uint16_t previousWidth;
color_t foregroundColor; ///< color of the inner progress bar and border (if applicable)
} nbgl_progress_bar_t;

Expand Down
46 changes: 38 additions & 8 deletions lib_nbgl/include/nbgl_use_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,44 @@ void nbgl_useCaseAddressConfirmationExt(const char *address
nbgl_choiceCallback_t callback,
const nbgl_layoutTagValueList_t *tagValueList);
#ifdef NBGL_KEYPAD
void nbgl_useCaseKeypad(const char *title,
uint8_t minDigits,
uint8_t maxDigits,
uint8_t backToken,
bool shuffled,
tune_index_e tuneId,
nbgl_pinValidCallback_t validatePinCallback,
nbgl_layoutTouchCallback_t actionCallback);
void nbgl_useCaseKeypadDigits(const char *title,
uint8_t minDigits,
uint8_t maxDigits,
uint8_t backToken,
bool shuffled,
tune_index_e tuneId,
nbgl_pinValidCallback_t validatePinCallback,
nbgl_layoutTouchCallback_t actionCallback);
void nbgl_useCaseKeypadPIN(const char *title,
uint8_t minDigits,
uint8_t maxDigits,
uint8_t backToken,
bool shuffled,
tune_index_e tuneId,
nbgl_pinValidCallback_t validatePinCallback,
nbgl_layoutTouchCallback_t actionCallback);
/**
* @deprecated
* See #nbgl_useCaseKeypadPIN
*/
DEPRECATED static inline void nbgl_useCaseKeypad(const char *title,
uint8_t minDigits,
uint8_t maxDigits,
uint8_t backToken,
bool shuffled,
tune_index_e tuneId,
nbgl_pinValidCallback_t validatePinCallback,
nbgl_layoutTouchCallback_t actionCallback)
{
nbgl_useCaseKeypadPIN(title,
minDigits,
maxDigits,
backToken,
shuffled,
tuneId,
validatePinCallback,
actionCallback);
}
#endif
#else // HAVE_SE_TOUCH
void nbgl_useCaseHome(const char *appName,
Expand Down
Loading

0 comments on commit 3798f44

Please sign in to comment.