Skip to content

Commit

Permalink
Merge pull request #768 from LedgerHQ/use-nbgl-shared-function
Browse files Browse the repository at this point in the history
Use nbgl shared functions
  • Loading branch information
nroggeman-ledger authored Oct 24, 2024
2 parents 0aad933 + 1cf37a5 commit 83e09a6
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 122 deletions.
10 changes: 7 additions & 3 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
ifeq ($(USE_NBGL),0)
SDK_SOURCE_PATH += lib_bagl lib_ux
else
SDK_SOURCE_PATH += lib_nbgl lib_ux_nbgl lib_ux_sync
SDK_SOURCE_PATH += lib_ux_nbgl lib_ux_sync
NBGL_SOURCES := $(shell find $(BOLOS_SDK)/lib_nbgl/src -name 'nbgl_layout*.[csS]')
NBGL_SOURCES += $(shell find $(BOLOS_SDK)/lib_nbgl/src -name 'nbgl_page*.[csS]')
NBGL_SOURCES += $(shell find $(BOLOS_SDK)/lib_nbgl/src -name 'nbgl_use_case*.[csS]')
NBGL_INCLUDE_PATH := lib_nbgl
endif

define uniq =
Expand Down Expand Up @@ -65,7 +69,7 @@ APP_SRC_PROTOC = $(filter %.pb.c, $(APP_SOURCE_FILES) $(SOURCE_FILES)) $(shell f
APP_SRC_FILTER = $(filter-out $(APP_SRC_FROM_SDK) $(APP_SRC_GEN), $(APP_SOURCE_FILES))

# Separate SDK and APP and GEN sources
SOURCES_SDK += $(foreach libdir, src $(SDK_SOURCE_PATH), $(shell find $(BOLOS_SDK)/$(libdir) -name '*.[csS]')) $(APP_SRC_FROM_SDK)
SOURCES_SDK += $(foreach libdir, src $(SDK_SOURCE_PATH), $(shell find $(BOLOS_SDK)/$(libdir) -name '*.[csS]')) $(APP_SRC_FROM_SDK) $(NBGL_SOURCES)
SOURCES_APP += $(filter-out %.pb.c, $(abspath $(SOURCE_FILES) $(foreach libdir, $(SOURCE_PATH) $(APP_SOURCE_PATH), $(shell find $(libdir) -name '*.[csS]')) $(APP_SRC_FILTER)))
SOURCES_GEN += $(GLYPH_DESTC) $(APP_SRC_GEN)
VPATH += $(call uniq, $(dir $(SOURCES_SDK) $(SOURCES_APP) $(GLYPH_DESTC)))
Expand All @@ -75,7 +79,7 @@ INCLUDES_APP += $(shell find $(APP_SOURCE_PATH) -name '*.h')
# Warn if a same header filename is found in both APP and SDK
$(call check_duplicate, $(INCLUDES_APP), $(BOLOS_SDK))
# Compute header directories list
INCLUDES_PATH += $(call uniq, $(dir $(foreach libdir, $(SDK_SOURCE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) -name '*.h')))) include $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm $(dir $(INCLUDES_APP)) $(GLYPH_SRC_DIR))
INCLUDES_PATH += $(call uniq, $(dir $(foreach libdir, $(SDK_SOURCE_PATH) $(NBGL_INCLUDE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) -name '*.h')))) include $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm $(dir $(INCLUDES_APP)) $(GLYPH_SRC_DIR))

# Separate object files from SDK and APP to avoid name conflicts
OBJECTS_SDK += $(sort $(subst $(BOLOS_SDK), $(OBJ_DIR)/sdk, $(addsuffix .o, $(basename $(SOURCES_SDK)))))
Expand Down
54 changes: 54 additions & 0 deletions include/nbgl_stubs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

// auto-generated by shared_export.py
#define _NR_nbgl_refresh 0x91
#define _NR_nbgl_refreshSpecial 0x92
#define _NR_nbgl_refreshSpecialWithPostRefresh 0x93
#define _NR_nbgl_refreshIsNeeded 0x94
#define _NR_nbgl_refreshReset 0x95
#define _NR_nbgl_objInit 0x96
#define _NR_nbgl_objDraw 0x97
#define _NR_nbgl_objAllowDrawing 0x98
#define _NR_nbgl_objGetRAMBuffer 0x99
#define _NR_nbgl_screenContainsObjType 0x9a
#define _NR_nbgl_screenSet 0x9b
#define _NR_nbgl_screenPush 0x9c
#define _NR_nbgl_screenRedraw 0x9d
#define _NR_nbgl_screenPop 0x9e
#define _NR_nbgl_screenGetElements 0x9f
#define _NR_nbgl_screenGetCurrentStackSize 0xa0
#define _NR_nbgl_screenGetUxStackSize 0xa1
#define _NR_nbgl_screenGetAt 0xa2
#define _NR_nbgl_screenGetTop 0xa3
#define _NR_nbgl_screenUpdateTicker 0xa4
#define _NR_nbgl_screenUpdateBackgroundColor 0xa5
#define _NR_nbgl_screenReset 0xa6
#define _NR_nbgl_screenHandler 0xa7
#define _NR_nbgl_objPoolGet 0xa8
#define _NR_nbgl_objPoolGetArray 0xa9
#define _NR_nbgl_containerPoolGet 0xaa
#define _NR_nbgl_getCharWidth 0xab
#define _NR_nbgl_getFont 0xac
#define _NR_nbgl_getFontHeight 0xad
#define _NR_nbgl_getFontLineHeight 0xae
#define _NR_nbgl_getSingleLineTextWidth 0xaf
#define _NR_nbgl_getSingleLineTextWidthInLen 0xb0
#define _NR_nbgl_getTextHeight 0xb1
#define _NR_nbgl_getTextHeightInWidth 0xb2
#define _NR_nbgl_getTextNbLinesInWidth 0xb3
#define _NR_nbgl_getTextNbPagesInWidth 0xb4
#define _NR_nbgl_getTextWidth 0xb5
#define _NR_nbgl_getTextMaxLenInNbLines 0xb6
#define _NR_nbgl_textReduceOnNbLines 0xb7
#define _NR_nbgl_textWrapOnNbLines 0xb8
#define _NR_nbgl_refreshUnicodeFont 0xb9
#define _NR_nbgl_touchHandler 0xba
#define _NR_nbgl_touchGetTouchDuration 0xbb
#define _NR_nbgl_touchGetTouchedPosition 0xbc
#define _NR_nbgl_buttonsHandler 0xbd
#define _NR_nbgl_buttonsReset 0xbe
#define _NR_nbgl_keyboardCallback 0xbf
#define _NR_nbgl_keypadCallback 0xc0
#define _NR_nbgl_drawText 0xc1
#define _NR_pic_shared 0xc2
#define _NR_pic_init 0xc3
7 changes: 6 additions & 1 deletion include/os_pic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
// Function that align the dereferenced value in a rom struct to use it depending on the execution
// address. Can be used even if code is executing at the same place where it had been linked.
#if defined(HAVE_BOLOS) && !defined(BOLOS_OS_UPGRADER_APP)
#ifndef OS_UNIT_TEST
#define PIC(x) pic_shared((const void *) x)
void *pic_shared(const void *linked_address);
#else // !OS_UNIT_TEST
#define PIC(x) (x)
#endif // !OS_UNIT_TEST
#endif
#ifndef PIC
#define PIC(x) pic((void *) x)
void *pic(void *linked_address);
void *pic_internal(void *link_address);
#endif
void pic_init(void *pic_flash_start, void *pic_ram_start);
6 changes: 3 additions & 3 deletions include/shared_trampoline.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#elif defined(TARGET_NANOX)
#define SHARED_TRAMPOLINE_ADDR 0x00210001
#elif defined(TARGET_NANOS2)
#define SHARED_TRAMPOLINE_ADDR 0x00810001
#define SHARED_TRAMPOLINE_ADDR 0x00808001
#elif defined(TARGET_STAX)
#define SHARED_TRAMPOLINE_ADDR 0x00818001
#define SHARED_TRAMPOLINE_ADDR 0x00810001
#elif defined(TARGET_FLEX)
#define SHARED_TRAMPOLINE_ADDR 0x00818001
#define SHARED_TRAMPOLINE_ADDR 0x00810001
#endif
1 change: 0 additions & 1 deletion include/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@
#define SYSCALL_nbgl_side_draw_horizontal_line_ID 0x03fa0006
#define SYSCALL_nbgl_side_draw_img_ID 0x04fa0007
#define SYSCALL_nbgl_side_refresh_area_ID 0x02fa0008
#define SYSCALL_nbgl_get_font_ID 0x01fa000c
#define SYSCALL_nbgl_screen_reinit_ID 0x00fa000d
#define SYSCALL_nbgl_front_draw_img_rle_ID 0x05fa0010
#define SYSCALL_nbgl_front_control_area_masking_ID 0x03fa0012
Expand Down
1 change: 0 additions & 1 deletion lib_nbgl/include/nbgl_fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ typedef struct nbgl_unicode_ctx_s {
/**********************
* GLOBAL PROTOTYPES
**********************/
const nbgl_font_t *nbgl_font_getFont(unsigned int fontId);
const nbgl_font_t *nbgl_getFont(nbgl_font_id_e fontId);
uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text);
uint16_t nbgl_getSingleLineTextWidthInLen(nbgl_font_id_e fontId, const char *text, uint16_t maxLen);
Expand Down
8 changes: 5 additions & 3 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,11 @@ void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refr
bool nbgl_refreshIsNeeded(void);
void nbgl_refreshReset(void);

void nbgl_objInit(void);
void nbgl_objDraw(nbgl_obj_t *obj);
void nbgl_objAllowDrawing(bool enable);
void nbgl_objInit(void);
void nbgl_objDraw(nbgl_obj_t *obj);
void nbgl_objAllowDrawing(bool enable);
uint8_t *nbgl_objGetRAMBuffer(void);
bool nbgl_objIsUx(nbgl_obj_t *obj);

void nbgl_objPoolRelease(uint8_t layer);
nbgl_obj_t *nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer);
Expand Down
3 changes: 0 additions & 3 deletions lib_nbgl/include/nbgl_step.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ extern "C" {
#include "nbgl_layout.h"
#include "nbgl_obj.h"
#include "nbgl_types.h"
#ifdef HAVE_LANGUAGE_PACK
#include "bolos_ux_loc_strings.h"
#endif // HAVE_LANGUAGE_PACK

/*********************
* DEFINES
Expand Down
11 changes: 6 additions & 5 deletions lib_nbgl/include/nbgl_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ extern "C" {
// duration of a short touch on touch panel (in ms)
#define SHORT_TOUCH_DURATION 0
// duration of a long touch on touch panel (in ms)
#define LONG_TOUCH_DURATION 1500
#define LONG_TOUCH_DURATION 3000
/**********************
* TYPEDEFS
**********************/

/**********************
* GLOBAL PROTOTYPES
**********************/
void nbgl_touchHandler(nbgl_touchStatePosition_t *touchEvent, uint32_t currentTimeMs);
bool nbgl_touchGetTouchedPosition(nbgl_obj_t *obj,
nbgl_touchStatePosition_t **firstPos,
nbgl_touchStatePosition_t **lastPos);
void nbgl_touchInit(bool fromUx);
void nbgl_touchHandler(bool fromUx, nbgl_touchStatePosition_t *touchEvent, uint32_t currentTimeMs);
bool nbgl_touchGetTouchedPosition(nbgl_obj_t *obj,
nbgl_touchStatePosition_t **firstPos,
nbgl_touchStatePosition_t **lastPos);
uint32_t nbgl_touchGetTouchDuration(nbgl_obj_t *obj);
nbgl_obj_t *nbgl_touchGetObjectFromId(nbgl_obj_t *obj, uint8_t id);

Expand Down
60 changes: 60 additions & 0 deletions lib_nbgl/nbgl.export
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This file contains the functions exported by shared lib. It is used by shared_export.py to
# generate asm stubs for the SDK and the NBGL functions table in shared lib.
#
# Making changes to this file (ie. removal, addition, ordering) require apps to
# be re-built since the ID of the exported functions will likely be different.

nbgl_refresh
nbgl_refreshSpecial
nbgl_refreshSpecialWithPostRefresh
nbgl_refreshIsNeeded
nbgl_refreshReset
nbgl_objInit
nbgl_objDraw
nbgl_objAllowDrawing
nbgl_objGetRAMBuffer
nbgl_screenContainsObjType
nbgl_screenSet
nbgl_screenPush
nbgl_screenRedraw
nbgl_screenPop
nbgl_screenGetElements
nbgl_screenGetCurrentStackSize
nbgl_screenGetUxStackSize
nbgl_screenGetAt
nbgl_screenGetTop
nbgl_screenUpdateTicker
nbgl_screenUpdateBackgroundColor
nbgl_screenReset
nbgl_screenHandler
nbgl_objPoolGet
nbgl_objPoolGetArray
nbgl_containerPoolGet
nbgl_getCharWidth
nbgl_getFont
nbgl_getFontHeight
nbgl_getFontLineHeight
nbgl_getSingleLineTextWidth
nbgl_getSingleLineTextWidthInLen
nbgl_getTextHeight
nbgl_getTextHeightInWidth
nbgl_getTextNbLinesInWidth
nbgl_getTextNbPagesInWidth
nbgl_getTextWidth
nbgl_getTextMaxLenInNbLines
nbgl_textReduceOnNbLines
nbgl_textWrapOnNbLines
nbgl_refreshUnicodeFont
#ifdef HAVE_SE_TOUCH
nbgl_touchHandler
nbgl_touchGetTouchDuration
nbgl_touchGetTouchedPosition
#else // HAVE_SE_TOUCH
nbgl_buttonsHandler
nbgl_buttonsReset
nbgl_keyboardCallback
nbgl_keypadCallback
#endif // HAVE_SE_TOUCH
nbgl_drawText
pic_shared
pic_init
3 changes: 3 additions & 0 deletions lib_nbgl/src/nbgl_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "glyphs.h"
#include "os_pic.h"
#include "ux.h"
#ifdef HAVE_LANGUAGE_PACK
#include "bolos_ux_loc_strings.h"
#endif // HAVE_LANGUAGE_PACK

/*********************
* DEFINES
Expand Down
16 changes: 4 additions & 12 deletions lib_nbgl/src/nbgl_fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static nbgl_unicode_ctx_t unicodeCtx = {0};
static const LANGUAGE_PACK *language_pack;
#endif // HAVE_LANGUAGE_PACK

#if defined(BOLOS_OS_UPGRADER_APP)
#ifdef SCREEN_SIZE_WALLET
#ifdef TARGET_STAX
#include "nbgl_font_inter_regular_24.inc"
Expand All @@ -67,14 +66,13 @@ static const LANGUAGE_PACK *language_pack;
#include "nbgl_font_open_sans_light_16.inc"
#endif // SCREEN_SIZE_WALLET

const nbgl_font_t *const C_nbgl_fonts[] = {
__attribute__((section("._nbgl_fonts_"))) const nbgl_font_t *const C_nbgl_fonts[] = {

#include "nbgl_font_rom_struct.inc"

};
const unsigned int C_nbgl_fonts_count = sizeof(C_nbgl_fonts) / sizeof(C_nbgl_fonts[0]);

#endif
__attribute__((section("._nbgl_fonts_"))) const unsigned int C_nbgl_fonts_count
= sizeof(C_nbgl_fonts) / sizeof(C_nbgl_fonts[0]);

#if (defined(HAVE_BOLOS) && !defined(BOLOS_OS_UPGRADER_APP))
#if !defined(HAVE_LANGUAGE_PACK)
Expand Down Expand Up @@ -116,7 +114,6 @@ bool hard_caesura = false;
* @param fontId font ID
* @return the found font or NULL
*/
#if defined(BOLOS_OS_UPGRADER_APP)
const nbgl_font_t *nbgl_getFont(nbgl_font_id_e fontId)
{
unsigned int i = C_nbgl_fonts_count;
Expand All @@ -132,12 +129,7 @@ const nbgl_font_t *nbgl_getFont(nbgl_font_id_e fontId)
// id not found
return NULL;
}
#else
const nbgl_font_t *nbgl_getFont(nbgl_font_id_e fontId)
{
return nbgl_font_getFont(fontId);
}
#endif // BOLOS_OS_UPGRADER_APP

/**
* @brief Get the coming unicode value on the given UTF-8 string. If the value is a simple ASCII
* character, is_unicode is set to false.
Expand Down
37 changes: 37 additions & 0 deletions lib_nbgl/src/nbgl_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "nbgl_front.h"
#include "nbgl_debug.h"
#include "nbgl_screen.h"
#include "nbgl_touch.h"
#include "os_print.h"
#include "os_helpers.h"
#include "os_pic.h"
Expand Down Expand Up @@ -1629,12 +1630,17 @@ void nbgl_refreshReset(void)

/**
* @brief This functions inits all internal of nbgl objects layer
* @note it is supposed to be called only from App
*
*/
void nbgl_objInit(void)
{
// init area to the smallest size
nbgl_refreshReset();
objDrawingDisabled = false;
#ifdef HAVE_SE_TOUCH
nbgl_touchInit(false);
#endif
}

/**
Expand All @@ -1646,3 +1652,34 @@ void nbgl_objAllowDrawing(bool enable)
{
objDrawingDisabled = !enable;
}

/**
* @brief This function is used to get the all purpose RAM buffer
*
* @return a pointer to the all purpose RAM buffer
*/
uint8_t *nbgl_objGetRAMBuffer(void)
{
return ramBuffer;
}

/**
* @brief This function returns true if the object belongs to a UxScreen
*
* @return true if the object belongs to a UxScreen
*/
bool nbgl_objIsUx(nbgl_obj_t *obj)
{
nbgl_obj_t *parent = obj;
// search screen in parenthood
while (parent->parent != NULL) {
parent = parent->parent;
}
if (parent->type == SCREEN) {
return (((nbgl_screen_t *) parent)->isUxScreen);
}
else {
// should never happen
return true;
}
}
2 changes: 1 addition & 1 deletion lib_nbgl/src/nbgl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ int nbgl_screenPush(nbgl_obj_t ***elements,
nbgl_touchStatePosition_t touchStatePosition = {.state = RELEASED, .x = 0, .y = 0};
// make a fake touch release for the current top-of-stack to avoid issue
// (for example in long-touch press)
nbgl_touchHandler(&touchStatePosition, 0);
nbgl_touchHandler(topOfStack->isUxScreen, &touchStatePosition, 0);
#endif // HAVE_SE_TOUCH
// new top of stack
topOfStack = &screenStack[screenIndex];
Expand Down
Loading

0 comments on commit 83e09a6

Please sign in to comment.