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 Sep 25, 2023
1 parent 80b72e7 commit 13f8377
Show file tree
Hide file tree
Showing 402 changed files with 6,627 additions and 315 deletions.
8 changes: 5 additions & 3 deletions Makefile.defines
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ endif

# Command to print ICONNAME hexadecimal bitmap on stdout
# according to the hardware target.
ifeq ($(TARGET_NAME),TARGET_STAX)
ifneq ($(TARGET_NAME),TARGET_NANOS)
ICONHEX_CMD=python3 $(BOLOS_SDK)/lib_nbgl/tools/icon2glyph.py --hexbitmaponly $(ICONNAME)
else
ICONHEX_CMD=python3 $(BOLOS_SDK)/icon3.py --hexbitmaponly $(ICONNAME)
Expand Down Expand Up @@ -186,13 +186,15 @@ DEFINES += NBGL_PAGE
DEFINES += NBGL_USE_CASE
#DEFINES += HAVE_DISPLAY_FAST_MODE
else
DEFINES += HAVE_BAGL
DEFINES += BAGL_WIDTH=128
ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_BAGL
DEFINES += BAGL_HEIGHT=32
endif
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
DEFINES += HAVE_UX_FLOW
DEFINES += HAVE_NBGL
DEFINES += NBGL_STEP
DEFINES += NBGL_USE_CASE
DEFINES += BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
Expand Down
12 changes: 8 additions & 4 deletions Makefile.glyphs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ 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
ifneq ($(TARGET_NAME),TARGET_NANOS)
# 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
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/))))
Expand All @@ -54,7 +58,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
4 changes: 2 additions & 2 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#*******************************************************************************

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

Please sign in to comment.