Skip to content

Commit

Permalink
Use different touch contexts for App & UX
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Oct 23, 2024
1 parent abcb312 commit f4a2c2b
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 111 deletions.
102 changes: 51 additions & 51 deletions include/nbgl_stubs.h
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
#pragma once

// auto-generated by shared_export.py
#define _NR_nbgl_refresh 0x90
#define _NR_nbgl_refreshSpecial 0x91
#define _NR_nbgl_refreshSpecialWithPostRefresh 0x92
#define _NR_nbgl_refreshIsNeeded 0x93
#define _NR_nbgl_refreshReset 0x94
#define _NR_nbgl_objInit 0x95
#define _NR_nbgl_objDraw 0x96
#define _NR_nbgl_objAllowDrawing 0x97
#define _NR_nbgl_objGetRAMBuffer 0x98
#define _NR_nbgl_screenContainsObjType 0x99
#define _NR_nbgl_screenSet 0x9a
#define _NR_nbgl_screenPush 0x9b
#define _NR_nbgl_screenRedraw 0x9c
#define _NR_nbgl_screenPop 0x9d
#define _NR_nbgl_screenGetElements 0x9e
#define _NR_nbgl_screenGetCurrentStackSize 0x9f
#define _NR_nbgl_screenGetUxStackSize 0xa0
#define _NR_nbgl_screenGetAt 0xa1
#define _NR_nbgl_screenGetTop 0xa2
#define _NR_nbgl_screenUpdateTicker 0xa3
#define _NR_nbgl_screenUpdateBackgroundColor 0xa4
#define _NR_nbgl_screenReset 0xa5
#define _NR_nbgl_screenHandler 0xa6
#define _NR_nbgl_objPoolGet 0xa7
#define _NR_nbgl_objPoolGetArray 0xa8
#define _NR_nbgl_containerPoolGet 0xa9
#define _NR_nbgl_getCharWidth 0xaa
#define _NR_nbgl_getFont 0xab
#define _NR_nbgl_getFontHeight 0xac
#define _NR_nbgl_getFontLineHeight 0xad
#define _NR_nbgl_getSingleLineTextWidth 0xae
#define _NR_nbgl_getSingleLineTextWidthInLen 0xaf
#define _NR_nbgl_getTextHeight 0xb0
#define _NR_nbgl_getTextHeightInWidth 0xb1
#define _NR_nbgl_getTextNbLinesInWidth 0xb2
#define _NR_nbgl_getTextNbPagesInWidth 0xb3
#define _NR_nbgl_getTextWidth 0xb4
#define _NR_nbgl_getTextMaxLenInNbLines 0xb5
#define _NR_nbgl_textReduceOnNbLines 0xb6
#define _NR_nbgl_textWrapOnNbLines 0xb7
#define _NR_nbgl_refreshUnicodeFont 0xb8
#define _NR_nbgl_touchHandler 0xb9
#define _NR_nbgl_touchGetTouchDuration 0xba
#define _NR_nbgl_touchGetTouchedPosition 0xbb
#define _NR_nbgl_buttonsHandler 0xbc
#define _NR_nbgl_buttonsReset 0xbd
#define _NR_nbgl_keyboardCallback 0xbe
#define _NR_nbgl_keypadCallback 0xbf
#define _NR_nbgl_drawText 0xc0
#define _NR_pic_shared 0xc1
#define _NR_pic_init 0xc2
#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
1 change: 1 addition & 0 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ 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
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
5 changes: 3 additions & 2 deletions lib_nbgl/src/nbgl_fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +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]);
__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
29 changes: 28 additions & 1 deletion 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 @@ -1650,9 +1656,30 @@ void nbgl_objAllowDrawing(bool enable)
/**
* @brief This function is used to get the all purpose RAM buffer
*
* @param enable if true, enables drawing/refresh, otherwise disables
* @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 f4a2c2b

Please sign in to comment.