Skip to content

Commit

Permalink
nbgl: Implement NBGL for LNS
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Chapron committed May 3, 2024
1 parent e638735 commit 89c8da1
Show file tree
Hide file tree
Showing 23 changed files with 3,071 additions and 108 deletions.
11 changes: 10 additions & 1 deletion Makefile.defines
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,18 @@ else
LDFLAGS += -nostartfiles
endif

# For LNS devices, by default NBGL is not used
USE_NBGL ?= 0

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_BAGL
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=32

ifeq ($(USE_NBGL),0)
DEFINES += HAVE_BAGL
else
DEFINES += HAVE_NBGL
DEFINES += NBGL_USE_CASE
endif # USE_NBGL
endif

ifeq ($(TARGET_NAME),TARGET_NANOX)
Expand Down
4 changes: 3 additions & 1 deletion Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#*******************************************************************************

# temporary redef, to ensure wider compliance of the SDK with pre-1.6 apps
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOS TARGET_NANOX TARGET_NANOS2))
ifeq ($(USE_NBGL),0)
SDK_SOURCE_PATH += lib_bagl lib_ux
else
SDK_SOURCE_PATH += lib_nbgl lib_ux_nbgl lib_ux_sync
endif

define uniq =
Expand Down
68 changes: 42 additions & 26 deletions Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ ifneq ($(DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE), 1)
endif
endif

#####################################################################
# NBGL #
#####################################################################
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOS TARGET_NANOX TARGET_NANOS2))
ifeq ($(ENABLE_NBGL_FOR_NANO_DEVICES), 1)
USE_NBGL = 1
else
USE_NBGL = 0
endif
else
USE_NBGL = 1
endif

ifeq ($(ENABLE_NBGL_QRCODE), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
endif
endif

ifeq ($(ENABLE_NBGL_KEYBOARD), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_KEYBOARD
endif
endif

ifeq ($(ENABLE_NBGL_KEYPAD), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_KEYPAD
endif
endif

#####################################################################
# STANDARD DEFINES #
#####################################################################
Expand Down Expand Up @@ -112,7 +144,7 @@ ifneq ($(DISABLE_STANDARD_WEBUSB), 1)
endif

ifneq ($(DISABLE_STANDARD_BAGL_UX_FLOW), 1)
ifeq ($(USE_NBGL),0)
ifneq ($(USE_NBGL), 1)
DEFINES += HAVE_UX_FLOW
endif
endif
Expand All @@ -126,31 +158,15 @@ SDK_SOURCE_PATH += lib_standard_app
endif

ifneq ($(DISABLE_STANDARD_APP_SYNC_RAPDU), 1)
# On LNS only activate it by default if using NBGL.
# This impact stack usage and shouldn't be activated on all apps silently
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += STANDARD_APP_SYNC_RAPDU
else
ifeq ($(ENABLE_NBGL_FOR_NANO_DEVICES), 1)
DEFINES += STANDARD_APP_SYNC_RAPDU
endif
endif

#####################################################################
# NBGL #
#####################################################################
ifeq ($(ENABLE_NBGL_QRCODE), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
endif
endif

ifeq ($(ENABLE_NBGL_KEYBOARD), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_KEYBOARD
endif
endif

ifeq ($(ENABLE_NBGL_KEYPAD), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_KEYPAD
endif
endif

#####################################################################
Expand Down Expand Up @@ -219,13 +235,13 @@ include $(BOLOS_SDK)/Makefile.defines
include $(BOLOS_SDK)/Makefile.glyphs

load: all
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

load-offline: all
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS) --offline
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS) --offline

delete:
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)

include $(BOLOS_SDK)/Makefile.rules

Expand All @@ -242,4 +258,4 @@ include $(BOLOS_SDK)/Makefile.rules
# available variants and then call `make -j <VARIANT_PARAM>=<VALUE>` for each
# <VALUE> in <VARIANT_VALUES>.
listvariants:
@echo VARIANTS $(VARIANT_PARAM) $(VARIANT_VALUES)
@echo VARIANTS $(VARIANT_PARAM) $(VARIANT_VALUES)
8 changes: 4 additions & 4 deletions icon3.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,20 @@ def main():
print("};")

if args.glyphcheader:
print("""#ifdef HAVE_BAGL
print("""#if defined(HAVE_BAGL) || defined(HAVE_NBGL)
#include \"bagl.h\"
extern const bagl_icon_details_t C_{0};
#endif // GLYPH_{0}_BPP
#endif // HAVE_BAGL""".format(image_name))
#endif // HAVE_BAGL || HAVE_NBGL""".format(image_name))
elif args.glyphcfile:
color_ref = image_name
if args.factorize:
if color_array_serialized in colors_array:
color_ref = colors_array[color_array_serialized]
print("""#ifdef HAVE_BAGL
print("""#if defined(HAVE_BAGL) || defined(HAVE_NBGL)
#include \"bagl.h\"
const bagl_icon_details_t C_{0} = {{ GLYPH_{0}_WIDTH, GLYPH_{0}_HEIGHT, {1}, C_{2}_colors, C_{0}_bitmap }};
#endif // HAVE_BAGL""".format(image_name, int(math.log(num_colors, 2)), color_ref))
#endif // HAVE_BAGL || HAVE_NBGL""".format(image_name, int(math.log(num_colors, 2)), color_ref))
else:
# Origin 0,0 is left top for blue, instead of left bottom for all image encodings
print("{{ {0:d}, {1:d}, {2:d}, C_{3}_colors, C_{3}_bitmap }},".format(
Expand Down
70 changes: 70 additions & 0 deletions lib_nbgl/include/nbgl_buttons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @file nbgl_buttons.h
* Buttons management of NBGL
*
*/

#ifndef NBGL_BUTTONS_H
#define NBGL_BUTTONS_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
* INCLUDES
*********************/
#include <stdint.h>

/*********************
* DEFINES
*********************/
///< Time after the beginning of continuous press on button(s) after which "continuous press" event
///< start to be sent (in 100ms)
#define CONTINOUS_PRESS_THRESHOLD 8
///< Periodicity of "continuous press" events (in 100ms)
#define CONTINUOUS_PRESS_PERIOD 3

/**********************
* TYPEDEFS
**********************/

/**
* @brief The different pressed buttons
*
*/
#define LEFT_BUTTON 0x01 ///< Left button event
#define RIGHT_BUTTON 0x02 ///< Right button event
#define BOTH_BUTTONS 0x03 ///< Both buttons event
#define RELEASED_MASK 0x80 ///< released (see LSB bits to know what buttons are released)
#define CONTINUOUS_MASK \
0x40 ///< if set, means that the button(s) is continuously pressed (this event is sent every
///< 300ms after the first 800ms)

typedef enum {
BUTTON_LEFT_PRESSED = 0, ///< Sent when Left button is released
BUTTON_RIGHT_PRESSED, ///< Send when Right button is released
BUTTON_LEFT_CONTINUOUS_PRESSED, ///< Send when Left button is continuouly pressed (sent every
///< 300ms after the first 800ms)
BUTTON_RIGHT_CONTINUOUS_PRESSED, ///< Send when Right button is continuouly pressed (sent every
///< 300ms after the first 800ms)
BUTTON_BOTH_PRESSED, ///< Sent when both buttons are released
BUTTON_BOTH_TOUCHED, ///< Sent when both buttons are touched
INVALID_BUTTON_EVENT
} nbgl_buttonEvent_t;

/**********************
* GLOBAL PROTOTYPES
**********************/
void nbgl_buttonsHandler(uint8_t buttonState);
void nbgl_buttonsReset(void);

/**********************
* MACROS
**********************/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* NBGL_BUTTONS_H */
Loading

0 comments on commit 89c8da1

Please sign in to comment.