Skip to content

Commit

Permalink
Adapt font structure for API LEVEL 15 (different from 14)
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Feb 19, 2024
1 parent 514b404 commit ba39f9c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/bolos/fonts_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ static void parse_nbgl_font(nbgl_font_t *nbgl_font)
uint8_t *bitmap = nbgl_font->bitmap;
nbgl_font_character_t *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 (%u) 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 NBGL font and add bitmap/character pairs
static void parse_nbgl_font_14(nbgl_font_t_14 *nbgl_font)
{
uint8_t *bitmap = nbgl_font->bitmap;
nbgl_font_character_t_14 *characters = nbgl_font->characters;

for (uint32_t c = nbgl_font->first_char; c <= nbgl_font->last_char;
c++, characters++) {
// Be sure data is coherent
Expand Down Expand Up @@ -243,6 +262,9 @@ void parse_fonts(void *code, unsigned long text_load_addr,
case SDK_API_LEVEL_13:
parse_nbgl_font_12((void *)fonts[i]);
break;
case SDK_API_LEVEL_14:
parse_nbgl_font_14((void *)fonts[i]);
break;
default:
parse_nbgl_font((void *)fonts[i]);
break;
Expand Down
36 changes: 31 additions & 5 deletions src/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// ============================================================================

#define STAX_FONTS_ARRAY_ADDR 0x00805000
#define STAX_NB_FONTS 7
#define STAX_NB_FONTS 6

#define MAX_NB_FONTS STAX_NB_FONTS

Expand Down Expand Up @@ -81,7 +81,33 @@ typedef struct {
// (They are defined in the SDK, in lib_nbgl/include/nbgl_fonts.h
// ============================================================================

// Current API_LEVEL (14)
// Current API_LEVEL (15)
typedef struct {
uint32_t bitmap_offset; ///< offset of this character in chars buffer
uint32_t encoding : 1; ///< method used to encode bitmap data
uint32_t width : 6; ///< width of character in pixels
uint32_t x_min_offset : 4; ///< x_min = x_min_offset
uint32_t y_min_offset : 6; ///< y_min = (y_min + y_min_offset)
uint32_t x_max_offset : 4; ///< x_max = width - x_max_offset
uint32_t y_max_offset : 6; ///< y_max = (height - y_max_offset)
} 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_14
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_14;

typedef struct {
uint32_t bitmap_len;
Expand All @@ -103,9 +129,9 @@ typedef struct {
uint8_t y_min;
uint8_t first_char;
uint8_t last_char;
nbgl_font_character_t *characters;
nbgl_font_character_t_14 *characters;
uint8_t *bitmap;
} nbgl_font_t;
} nbgl_font_t_14;

// SDK_API_LEVEL_12 and SDK_API_LEVEL_13
typedef struct {
Expand Down
3 changes: 2 additions & 1 deletion tests/c/test_environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ static void check_is_default(field_e field)
assert_memory_equal(&key[0], default_seed, MAX_SEED_SIZE);
break;
}
case FIELD_RNG:
case FIELD_RNG: {
unsigned int now = time(NULL);
// RNG is initialized in the past, not that long ago, but still
// assert_int_equal(env_get_rng(), time(NULL)); can sometimes fail
assert_in_range(env_get_rng(), now - 1, now);
break;
}
case FIELD_USER_KEY: {
assert_memory_equal(env_get_user_private_key(1)->d,
default_user_private_key,
Expand Down

0 comments on commit ba39f9c

Please sign in to comment.