Skip to content

Commit

Permalink
Add support for API_LEVEL_14 (nbgl_font_t) for STAX
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorais-ledger authored and PhilippeBonnaz committed Dec 1, 2023
1 parent a7b2fb7 commit ff87b12
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
29 changes: 28 additions & 1 deletion src/bolos/fonts_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ static void parse_nbgl_font(nbgl_font_t *nbgl_font)
}
}

// Parse provided NBGL font and add bitmap/character pairs
static void parse_nbgl_font_12(nbgl_font_t_12 *nbgl_font)
{
uint8_t *bitmap = nbgl_font->bitmap;
nbgl_font_character_t_12 *characters = nbgl_font->characters;

for (uint32_t c = nbgl_font->first_char; c <= nbgl_font->last_char;
c++, characters++) {
// Be sure data is coherent
if (characters->bitmap_offset >= nbgl_font->bitmap_len) {
fprintf(stdout, "bitmap_offset (%d) is >= bitmap_len (%u)!\n",
characters->bitmap_offset, nbgl_font->bitmap_len);
return;
}
uint8_t *ptr = bitmap + characters->bitmap_offset;
add_bitmap_character(ptr, c);
}
}

// Parse provided BAGL font and add bitmap/character pairs
static void parse_bagl_font(bagl_font_t *bagl_font, void *code,
unsigned long text_load_addr)
Expand Down Expand Up @@ -218,7 +237,15 @@ void parse_fonts(void *code, unsigned long text_load_addr,
// Parse all those fonts and add bitmap/character pairs
for (uint32_t i = 0; i < nb_fonts; i++) {
if (hw_model == MODEL_STAX) {
parse_nbgl_font((void *)fonts[i]);
switch (sdk_version) {
case SDK_API_LEVEL_12:
case SDK_API_LEVEL_13:
parse_nbgl_font_12((void *)fonts[i]);
break;
default:
parse_nbgl_font((void *)fonts[i]);
break;
}
} else {
void *font = remap_addr(code, fonts[i], text_load_addr);

Expand Down
34 changes: 30 additions & 4 deletions src/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,33 @@ typedef struct {
// (They are defined in the SDK, in lib_nbgl/include/nbgl_fonts.h
// ============================================================================

// Current API_LEVEL (12)
// Current API_LEVEL (14)
typedef struct {
uint32_t encoding : 1;
uint32_t bitmap_offset : 14;
uint32_t width : 6;
uint32_t x_min_offset : 3;
uint32_t y_min_offset : 3;
uint32_t x_max_offset : 2;
uint32_t y_max_offset : 3;
} nbgl_font_character_t;

typedef struct {
uint32_t bitmap_len;
uint8_t font_id;
uint8_t bpp;
uint8_t height;
uint8_t line_height;
uint8_t char_kerning;
uint8_t crop;
uint8_t y_min;
uint8_t first_char;
uint8_t last_char;
nbgl_font_character_t *characters;
uint8_t *bitmap;
} nbgl_font_t;

// SDK_API_LEVEL_12
typedef struct {
uint32_t encoding : 1;
uint32_t bitmap_offset : 14;
Expand All @@ -90,7 +116,7 @@ typedef struct {
uint32_t y_min_offset : 3;
uint32_t x_max_offset : 2;
uint32_t y_max_offset : 3;
} nbgl_font_character_t;
} nbgl_font_character_t_12;

typedef struct {
uint32_t bitmap_len;
Expand All @@ -102,9 +128,9 @@ typedef struct {
uint8_t y_min;
uint8_t first_char;
uint8_t last_char;
nbgl_font_character_t *characters;
nbgl_font_character_t_12 *characters;
uint8_t *bitmap;
} nbgl_font_t;
} nbgl_font_t_12;

// ============================================================================

Expand Down

0 comments on commit ff87b12

Please sign in to comment.