Skip to content

Commit

Permalink
Adapt NBGL to support LNS+ & LNX, and use NBGL for LNS+ & LNX
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Oct 5, 2023
1 parent e8b56c4 commit e258147
Show file tree
Hide file tree
Showing 412 changed files with 7,441 additions and 411 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
cmake -Bbuild -H. && make -C build && make -C build test
cd ../lib_nbgl/
cmake -Bbuild -H. && make -C build && CTEST_OUTPUT_ON_FAILURE=1 make -C build test
STAX=1 cmake -Bbuild -H. && make -C build && CTEST_OUTPUT_ON_FAILURE=1 make -C build test
- name: Generate code coverage
run: |
Expand Down
22 changes: 20 additions & 2 deletions Makefile.defines
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ ifeq ($(filter $(TARGET),$(TARGETS)),)
$(error TARGET not set to a valid value (possible values: $(TARGETS)))
endif

# for Stax, NBGL must be used
ifeq ($(TARGET),stax)
USE_NBGL ?= 1
endif

API_LEVEL := 0
TARGET_PATH := $(BOLOS_SDK)/target/$(TARGET)
TARGET_ID := $(shell cat $(TARGET_PATH)/include/bolos_target.h | grep TARGET_ID | cut -f3 -d' ')
Expand All @@ -55,8 +60,13 @@ endif

# Command to print ICONNAME hexadecimal bitmap on stdout
# according to the hardware target.
ifeq ($(TARGET_NAME),TARGET_STAX)
ifneq ($(TARGET),nanos)
#inverse B&W for non Stax
ifneq ($(TARGET_NAME),TARGET_STAX)
ICONHEX_CMD=python3 $(BOLOS_SDK)/lib_nbgl/tools/icon2glyph.py --reverse --hexbitmaponly $(ICONNAME)
else
ICONHEX_CMD=python3 $(BOLOS_SDK)/lib_nbgl/tools/icon2glyph.py --hexbitmaponly $(ICONNAME)
endif
else
ICONHEX_CMD=python3 $(BOLOS_SDK)/icon3.py --hexbitmaponly $(ICONNAME)
endif
Expand Down Expand Up @@ -187,13 +197,21 @@ DEFINES += NBGL_PAGE
DEFINES += NBGL_USE_CASE
#DEFINES += HAVE_DISPLAY_FAST_MODE
else
DEFINES += HAVE_BAGL
DEFINES += BAGL_WIDTH=128
ifdef USE_NBGL
DEFINES += HAVE_NBGL
DEFINES += NBGL_STEP
DEFINES += NBGL_USE_CASE
else
DEFINES += HAVE_BAGL
endif
ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += BAGL_HEIGHT=32
endif
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
ifndef USE_NBGL
DEFINES += HAVE_UX_FLOW
endif
DEFINES += BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
Expand Down
15 changes: 11 additions & 4 deletions Makefile.glyphs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,27 @@ endif
GLYPH_DESTC := $(GLYPH_SRC_DIR)/glyphs.c
GLYPH_DESTH := $(GLYPH_SRC_DIR)/glyphs.h
ifeq ($(TARGET_NAME),TARGET_STAX)
# Stax glyphs files and generation script
ifdef USE_NBGL
# Not NanoS glyphs files and generation script
GLYPH_FILES += $(addprefix $(BOLOS_SDK)/lib_nbgl/glyphs/,$(sort $(notdir $(shell find $(BOLOS_SDK)/lib_nbgl/glyphs/))))
GLYPH_FILES += $(addprefix glyphs/,$(sort $(notdir $(shell find glyphs/))))
ifneq (,$(wildcard $(ICONNAME)))
# Do not try to generate app icon glyph, if image does not exist
GLYPH_FILES += $(ICONNAME)
endif
ICON_SCRIPT = $(BOLOS_SDK)/lib_nbgl/tools/icon2glyph.py
GENERATE_GLYPHS_CMD = python3 $(ICON_SCRIPT) --glyphcfile $(GLYPH_FILES)
#inverse B&W for non Stax
ifneq ($(TARGET_NAME),TARGET_STAX)
GLYPH_OPT := --reverse
else
GLYPH_OPT :=
endif
GENERATE_GLYPHS_CMD = python3 $(ICON_SCRIPT) $(GLYPH_OPT) --glyphcfile $(GLYPH_FILES)
else
# Nano glyphs files and generation script
GLYPH_FILES += $(addprefix glyphs/,$(sort $(notdir $(shell find glyphs/))))
GLYPH_FILES += $(addprefix $(BOLOS_SDK)/lib_ux/glyphs/,$(sort $(notdir $(shell find $(BOLOS_SDK)/lib_ux/glyphs/))))
GLYPH_OPT :=
ICON_SCRIPT = $(BOLOS_SDK)/icon3.py
GENERATE_GLYPHS_CMD = python3 $(ICON_SCRIPT) --factorize --glyphcfile $(GLYPH_FILES)
endif
Expand All @@ -54,7 +61,7 @@ $(GLYPH_DESTH): $(GLYPH_FILES) $(ICON_SCRIPT)
$(L)-mkdir -p $(GLYPH_SRC_DIR)
$(L)rm -f $(GLYPH_DESTC) $(GLYPH_DESTH)
@# Use temporary files to prevent issues when build is interrupted
$(L)python3 $(ICON_SCRIPT) --glyphcheader $(GLYPH_FILES) > $(GLYPH_DESTH)_tmp
$(L)python3 $(ICON_SCRIPT) $(GLYPH_OPT) --glyphcheader $(GLYPH_FILES) > $(GLYPH_DESTH)_tmp
$(L)$(GENERATE_GLYPHS_CMD) > $(GLYPH_DESTC)_tmp
$(L)mv $(GLYPH_DESTC)_tmp $(GLYPH_DESTC)
$(L)mv $(GLYPH_DESTH)_tmp $(GLYPH_DESTH)
Expand Down
8 changes: 3 additions & 5 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
#*******************************************************************************

# 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 ($(NO_UI), 0)
ifndef USE_NBGL
SDK_SOURCE_PATH += lib_bagl lib_ux
endif
else ifeq ($(TARGET_NAME),TARGET_STAX)
ifeq ($(NO_UI), 0)
else
SDK_SOURCE_PATH += lib_nbgl lib_ux_stax
endif
endif
endif # NO_UI

# adding the correct target header to sources
SDK_SOURCE_PATH += target/$(TARGET)/include
Expand Down
2 changes: 1 addition & 1 deletion Makefile.rules_generic
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ifeq ($(shell $(CC) -v 2>&1 | grep clang),)
$(error Compiler is not CLANG)
endif

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2 TARGET_STAX))
ifneq ($(TARGET_NAME),TARGET_NANOS)
ifeq ($(shell $(LD) -v 2>&1 | grep clang),)
LD := $(CC)
ifneq ($(shell [ `$(CC) -v 2>&1 | grep -o "version .*" | cut -f2 -d' ' | cut -f1 -d'.'` -ge 7 ] && echo ok),ok)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ifneq ($(DISABLE_STANDARD_WEBUSB), 1)
endif

ifneq ($(DISABLE_STANDARD_BAGL_UX_FLOW), 1)
ifneq ($(TARGET_NAME), TARGET_STAX)
ifndef USE_NBGL
DEFINES += HAVE_UX_FLOW
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion include/cx_trampoline.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#elif defined(TARGET_NANOX)
#define CX_TRAMPOLINE_ADDR 0x00210001
#elif defined(TARGET_NANOS2)
#define CX_TRAMPOLINE_ADDR 0x00808001
#define CX_TRAMPOLINE_ADDR 0x00810001
#elif defined(TARGET_STAX)
#define CX_TRAMPOLINE_ADDR 0x00818001
#endif
2 changes: 0 additions & 2 deletions include/os_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "bolos_target.h"
#include "decorators.h"

#ifdef HAVE_BAGL
#ifdef HAVE_SE_SCREEN
// SYSCALL void screen_write_frame(unsigned char* framebuffer PLENGTH(BAGL_WIDTH*BAGL_HEIGHT/8));
/**
Expand Down Expand Up @@ -53,4 +52,3 @@ SYSCALL void bagl_hal_draw_rect(unsigned int color,
unsigned int width,
unsigned int height);
#endif // HAVE_SE_SCREEN
#endif // HAVE_BAGL
2 changes: 2 additions & 0 deletions lib_nbgl/doc/mainpage.dox
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef HAVE_SE_TOUCH
/** @page nbgl_mainpage New BOLOS Graphic API

@section mainpage_intro Introduction
Expand Down Expand Up @@ -57,3 +58,4 @@ Applications are free to define \b NBGL_KEYBOARD, \b NBGL_KEYPAD or \b NBGL_QRCO
"rare" objects.

*/
#endif // HAVE_SE_TOUCH
65 changes: 65 additions & 0 deletions lib_nbgl/doc/mainpage_nanos.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef HAVE_SE_TOUCH
/** @page nbgl_mainpage New BOLOS Graphic API

@section mainpage_intro Introduction

This documentation describes the different interfaces of <b>NBGL</b>, the library that
is targeted to be integrated in Stax product.

<b>NBGL Engine</b> is responsible for constructing screens and handling Touchscreen input.

@section mainpage_overall_archi Overall architecture

<b>NBGL Engine</b> is a library to be integrated in SDK.
It is intended to replace existing BAGL/FLOW Graphical Engine (used on Nanos/Blue products)

\image{inline} html NBGLArchi.png "caption" height=600

@section nbgl_drawing_api Screen drawing APIs

@subsection nbgl_app_use_case_api_1 Application Use-cases API
This is the most preferred API level to write an embedded Application.

The @subpage nbgl_app_use_case_nanos page contains all information necessary to understand
and use \b NBGL Application Use cases API

@subsection nbgl_flow_level_api_1 Flow API
The @subpage nbgl_flow page contains all information necessary to understand
and use \b NBGL Flow API, managing a scenario flow, made of one or several steps

@subsection nbgl_step_level_api_1 Step API
The @subpage nbgl_step page contains all information necessary to understand
and use \b NBGL Step API, managing the page(s) of a scenario step

@subsection nbgl_mid_level_api_1 Complex objects (layout) API
The @subpage nbgl_layout page contains all information necessary to understand
and use \b NBGL Mid-Level API, using complex objects

@subsection nbgl_low_level_api_1 Low-Level API
The @subpage nbgl_obj page contains all information necessary to understand
and use \b NBGL Low-Level API

@section nbgl_screen_objs Screen and objects management
The @subpage nbgl_screens_and_objs page contains all information necessary to understand
how \b NBGL manages the screens stack and the dynamically allocated objects

@section nbgl_touch_api Touchscreen events management
The @subpage nbgl_touchscreen page contains all information necessary to understand
how \b NBGL manages the touchscreen events and how to receive and process these events.

@section nbgl_building Compilation options
In order to reduce the footprint (RAM+Flash), some features are only activated if some building options are defined.

Define | Meaning | Default state
------------- | ------------- | -------------
\b NBGL_PAGE | Activate High-Level API | Active in SDK, not in OS
\b NBGL_USE_CASE | Activate Use Case API | Active in SDK, not in OS
\b NBGL_KEYBOARD | Activate Keyboard object | Active in OS, not in SDK
\b NBGL_KEYPAD | Activate Keypad object | Active in OS, not in SDK
\b NBGL_QRCODE | Activate QRCode object | Active in OS, not in SDK

Applications are free to define \b NBGL_KEYBOARD, \b NBGL_KEYPAD or \b NBGL_QRCODE in their own Makefile if they need to use these
"rare" objects.

*/
#endif // HAVE_SE_TOUCH
104 changes: 104 additions & 0 deletions lib_nbgl/doc/nbgl_flow.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#ifdef NBGL_STEP
/** @page nbgl_flow Flow API

@section nbgl_flow_intro Introduction
This chapter describes briefly the Flow API of Advanced BOLOS Graphic Library.

This layer offers a way to handle multi-steps flows in typical scenarios of Nanos OS or Apps, like a transaction, a navigation in a menu.

A full description of the way to create and interact with a flow can be found in this document

@section nbgl_flow_concepts Concepts

This layer uses the step API described in @ref nbgl_step, but for list of steps. The navigation between steps is entirely managed
by the flow engine.

@subsection nbgl_flow_example Example

\image{inline} html layout_nanos_flow1.png "caption" height=200

In this example, a flow made of 4 steps (each on one page) is built. The navigation is possible between these steps (no loop), and the
last step can be selected (double button press).

@section nbgl_flow_operations Operations

@subsection create_flow Draw a flow

The configuration of a flow is provided in a single function call, through @ref nbgl_flowDraw() which will:

- draw the first step
- Refresh after first step drawing

The arguments of @ref nbgl_flowDraw() are:

- An array of step descriptions (see below)
- The index of the step to start with in step descriptions array
- A boolean indicating whether the flow shall be modal or not
- A boolean indicating whether the flow is circular or not (loop)

@code
static char string_buffer[128];

static void onPrepareOSversion(void);
static void onPrepareMCUversion(void);
static void onPrepareBootloaderversion(void);
static void onBack(void);

static nbgl_flow_t flowContext;

static const nbgl_stepDesc_t flowSteps[] = {
{
.text = "\bSecure Element",
.subText = string_buffer,
.init = onPrepareOSversion
},
{
.text = "\bMicrocontroller",
.subText = string_buffer,
.init = onPrepareMCUversion
},
{
.text = "\bBootloader",
.subText = string_buffer,
.init = onPrepareBootloaderversion
},
{
.text = "\bBack",
.callback = onBack,
.icon = &C_icon_back
}
};

static void onPrepareOSversion(void) {
os_version((unsigned char*)string_buffer, 32);
}

static void onPrepareMCUversion(void) {
os_seph_version((unsigned char*)string_buffer, 32);
}

static void onPrepareBootloaderversion(void) {
os_bootloader_version((unsigned char*)string_buffer, 32);
}

static void onBack(void) {
nbgl_flowRelease(flowContext);
// go to parent flow
}

void displayInfo() {
// use string_buffer as temporary buffer
memset(string_buffer, 0, 128);
flowContext = nbgl_flowDraw(flowSteps, 4, 0, false, false);
}

@endcode

@subsection page_release Releasing a predefined page

Before leaving a screen built with a layout, it must be released with a call to @ref nbgl_flowRelease(). It will free the allocated
objects.


*/
#endif // NBGL_STEP
2 changes: 2 additions & 0 deletions lib_nbgl/doc/nbgl_layout.dox
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef HAVE_SE_TOUCH
/** @page nbgl_layout Complex objects layout API

@section nbgl_layout_intro Introduction
Expand Down Expand Up @@ -743,3 +744,4 @@ objects.


*/
#endif // HAVE_SE_TOUCH
Loading

0 comments on commit e258147

Please sign in to comment.