Skip to content

Commit

Permalink
Flex: Add nbgl masking syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
abonnaudet-ledger committed Aug 20, 2024
1 parent fddeb90 commit f8355d5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
#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

#ifdef HAVE_SE_EINK_DISPLAY
#define SYSCALL_nbgl_wait_pipeline_ID 0x00fa0011
Expand Down
1 change: 1 addition & 0 deletions lib_nbgl/include/nbgl_front.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void nbgl_frontDrawImageRle(const nbgl_area_t *area,
void nbgl_frontRefreshArea(const nbgl_area_t *area,
nbgl_refresh_mode_t mode,
nbgl_post_refresh_t post_refresh);
void nbgl_frontControlAreaMasking(uint8_t mask_index, nbgl_area_t *masked_area_or_null);

/**********************
* MACROS
Expand Down
6 changes: 6 additions & 0 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ typedef struct PACKED__ nbgl_text_entry_s {
const char *text; ///< text to display (up to nbChars chars).
} nbgl_text_entry_t;

typedef struct PACKED__ nbgl_mask_control_s {
nbgl_obj_t obj; ///< common part
bool enableMasking; ///< true: Enable masking of area / false: Disable masking of area
uint8_t maskIndex; ///< index of mask
} nbgl_mask_control_t;

/**
* @brief struct to represent a "spinner", represented by the Ledger corners, in gray, with one of
* the corners in black (@ref SPINNER type)
Expand Down
3 changes: 2 additions & 1 deletion lib_nbgl/include/nbgl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ typedef enum {
KEYPAD, ///< Keypad
SPINNER, ///< Spinner
IMAGE_FILE, ///< Image file (with Ledger compression)
TEXT_ENTRY ///< area for entered text, only for Nanos
TEXT_ENTRY, ///< area for entered text, only for Nanos
MASK_CONTROL,
} nbgl_obj_type_t;

/**
Expand Down
25 changes: 25 additions & 0 deletions lib_nbgl/src/nbgl_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,26 @@ static void draw_image_file(nbgl_image_file_t *obj, nbgl_obj_t *prevObj, bool co
nbgl_frontDrawImageFile((nbgl_area_t *) obj, obj->buffer, BLACK, ramBuffer);
}

#ifdef HAVE_NBGL_MASKING
static void draw_mask_control(nbgl_mask_control_t *obj, nbgl_obj_t *prevObj, bool computePosition)
{
if (computePosition) {
compute_position((nbgl_obj_t *) obj, prevObj);
}

if (objDrawingDisabled) {
return;
}

if (obj->enableMasking) {
nbgl_frontControlAreaMasking(obj->maskIndex, &obj->obj.area);
}
else {
nbgl_frontControlAreaMasking(obj->maskIndex, NULL);
}
}
#endif // HAVE_NBGL_MASKING

/**
* @brief internal function used to draw an object of any type
*
Expand Down Expand Up @@ -1447,6 +1467,11 @@ draw_object(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
draw_textEntry((nbgl_text_entry_t *) obj, prevObj, computePosition);
break;
#endif // HAVE_SE_TOUCH
#ifdef HAVE_NBGL_MASKING
case MASK_CONTROL:
draw_mask_control((nbgl_mask_control_t *) obj, prevObj, computePosition);
break;
#endif // HAVE_NBGL_MASKING
default:
LOG_DEBUG(OBJ_LOGGER, "Not existing object type\n");
break;
Expand Down
11 changes: 11 additions & 0 deletions src/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ void nbgl_frontDrawImageRle(nbgl_area_t *area,
return;
}

#ifdef HAVE_NBGL_MASKING
void nbgl_frontControlAreaMasking(uint8_t mask_index, nbgl_area_t *masked_area_or_null)
{
unsigned int parameters[2];
parameters[0] = (unsigned int) mask_index;
parameters[1] = (unsigned int) masked_area_or_null;
SVC_Call(SYSCALL_nbgl_front_control_area_masking_ID, parameters);
return;
}
#endif // HAVE_NBGL_MASKING

void nbgl_frontDrawImageFile(nbgl_area_t *area,
uint8_t *buffer,
nbgl_color_map_t colorMap,
Expand Down

0 comments on commit f8355d5

Please sign in to comment.