10 static void nbgl_appendU8(
uint8_t value,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
12 if (*w_cnt < max_len) {
18 static void nbgl_appendU32(uint32_t value,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
20 nbgl_appendU8((
uint8_t) ((value >> 24) & 0xFF), out, w_cnt, max_len);
21 nbgl_appendU8((
uint8_t) ((value >> 16) & 0xFF), out, w_cnt, max_len);
22 nbgl_appendU8((
uint8_t) ((value >> 8) & 0xFF), out, w_cnt, max_len);
23 nbgl_appendU8((
uint8_t) (value & 0xFF), out, w_cnt, max_len);
26 static void nbgl_appendPtr(
const void *value,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
28 if (max_len < (*w_cnt +
sizeof(
void *))) {
31 memcpy(&out[*w_cnt], &value,
sizeof(
void *));
32 (*w_cnt) = (*w_cnt) +
sizeof(
void *);
35 static void nbgl_appendU16(
uint16_t value,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
37 nbgl_appendU8((
uint8_t) ((value >> 8) & 0xFF), out, w_cnt, max_len);
38 nbgl_appendU8((
uint8_t) (value & 0xFF), out, w_cnt, max_len);
42 static void nbgl_serializeArea(
nbgl_area_t *area,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
44 nbgl_appendU16(area->x0, out, w_cnt, max_len);
45 nbgl_appendU16(area->y0, out, w_cnt, max_len);
46 nbgl_appendU16(area->width, out, w_cnt, max_len);
47 nbgl_appendU16(area->height, out, w_cnt, max_len);
48 nbgl_appendU8((
uint8_t) area->backgroundColor, out, w_cnt, max_len);
49 nbgl_appendU8((
uint8_t) area->bpp, out, w_cnt, max_len);
63 static void nbgl_serializeObj(
nbgl_obj_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
66 nbgl_appendU8(getObjId(obj), out, w_cnt, max_len);
68 nbgl_appendU8((
uint8_t) obj->type, out, w_cnt, max_len);
70 nbgl_serializeArea((
nbgl_area_t *) &obj->area, out, w_cnt, max_len);
75 static void nbgl_serializeText(
const char *text,
82 nbgl_appendU8(
'\0', out, w_cnt, max_len);
85 while (*w_cnt < max_len) {
86 nbgl_appendU8(*text, out, w_cnt, max_len);
124 return NBGL_BPP_MAPPING[nbgl_bpp];
143 int32_t nb_bits = (width * height * nbgl_bpp_get_number_of_bits_per_pixel(nbgl_bpp));
152 return (nb_bits + (8 - remain)) / 8;
163 nbgl_appendU16(0, out, w_cnt, max_len);
164 nbgl_appendU16(0, out, w_cnt, max_len);
165 nbgl_appendU8(0, out, w_cnt, max_len);
166 nbgl_appendU8(0, out, w_cnt, max_len);
169 nbgl_appendU16(icon->width, out, w_cnt, max_len);
170 nbgl_appendU16(icon->height, out, w_cnt, max_len);
171 nbgl_appendU8(icon->bpp, out, w_cnt, max_len);
172 nbgl_appendU8(icon->isFile, out, w_cnt, max_len);
174 size = nbgl_bpp_get_window_size(icon->width, icon->height, icon->bpp);
181 nbgl_appendU32(size, out, w_cnt, max_len);
182 #ifdef SERIALIZE_DATA
183 for (int32_t i = 0; i < size; i++) {
184 nbgl_appendU8(icon->bitmap[i], out, w_cnt, max_len);
194 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
196 nbgl_appendU8((
uint8_t) obj->textColor, out, w_cnt, max_len);
197 nbgl_appendU8((
uint8_t) obj->textAlignment, out, w_cnt, max_len);
198 nbgl_appendU8((
uint8_t) obj->style, out, w_cnt, max_len);
199 nbgl_appendU8((
uint8_t) obj->fontId, out, w_cnt, max_len);
200 nbgl_appendU8(0, out, w_cnt, max_len);
201 nbgl_appendU8((
uint8_t) obj->autoHideLongLine, out, w_cnt, max_len);
202 nbgl_appendU16((
uint16_t) obj->len, out, w_cnt, max_len);
204 nbgl_serializeText(PIC(obj->text), obj->len, out, w_cnt, max_len);
207 static void nbgl_serializeLine(
nbgl_line_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
209 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
211 nbgl_appendU8((
uint8_t) obj->direction, out, w_cnt, max_len);
212 nbgl_appendU8((
uint8_t) obj->lineColor, out, w_cnt, max_len);
213 nbgl_appendU8((
uint8_t) obj->thickness, out, w_cnt, max_len);
214 nbgl_appendU8((
uint8_t) obj->offset, out, w_cnt, max_len);
217 static void nbgl_serializeQrCode(
nbgl_qrcode_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
219 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
221 nbgl_appendU8((
uint8_t) obj->foregroundColor, out, w_cnt, max_len);
222 nbgl_appendU8((
uint8_t) obj->version, out, w_cnt, max_len);
223 nbgl_serializeText(PIC(obj->text), 0, out, w_cnt, max_len);
226 static void nbgl_serializeRadio(
nbgl_radio_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
228 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
230 nbgl_appendU8((
uint8_t) obj->activeColor, out, w_cnt, max_len);
231 nbgl_appendU8((
uint8_t) obj->borderColor, out, w_cnt, max_len);
232 nbgl_appendU8((
uint8_t) obj->state, out, w_cnt, max_len);
235 static void nbgl_serializeSwitch(
nbgl_switch_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
237 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
239 nbgl_appendU8((
uint8_t) obj->onColor, out, w_cnt, max_len);
240 nbgl_appendU8((
uint8_t) obj->offColor, out, w_cnt, max_len);
241 nbgl_appendU8((
uint8_t) obj->state, out, w_cnt, max_len);
249 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
251 nbgl_appendU8((
uint8_t) obj->withBorder, out, w_cnt, max_len);
252 nbgl_appendU8((
uint8_t) obj->state, out, w_cnt, max_len);
260 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
262 nbgl_appendU8((
uint8_t) obj->activePage, out, w_cnt, max_len);
263 nbgl_appendU8((
uint8_t) obj->nbPages, out, w_cnt, max_len);
266 static void nbgl_serializeButton(
nbgl_button_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
268 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
270 nbgl_appendU8((
uint8_t) obj->innerColor, out, w_cnt, max_len);
271 nbgl_appendU8((
uint8_t) obj->borderColor, out, w_cnt, max_len);
272 nbgl_appendU8((
uint8_t) obj->foregroundColor, out, w_cnt, max_len);
273 nbgl_appendU8((
uint8_t) obj->radius, out, w_cnt, max_len);
274 nbgl_appendU8((
uint8_t) obj->fontId, out, w_cnt, max_len);
275 nbgl_appendU8(0, out, w_cnt, max_len);
276 nbgl_serializeText(PIC(obj->text), 0, out, w_cnt, max_len);
277 nbgl_serializeIcon(PIC(obj->icon), out, w_cnt, max_len);
280 static void nbgl_serializeImage(
nbgl_image_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
282 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
283 nbgl_serializeIcon(PIC(obj->buffer), out, w_cnt, max_len);
284 nbgl_appendU8((
uint8_t) obj->foregroundColor, out, w_cnt, max_len);
289 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
290 nbgl_appendU8(obj->position, out, w_cnt, max_len);
298 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
300 nbgl_appendU8((
uint8_t) obj->textColor, out, w_cnt, max_len);
301 nbgl_appendU8((
uint8_t) obj->borderColor, out, w_cnt, max_len);
302 nbgl_appendU8((
uint8_t) obj->lettersOnly, out, w_cnt, max_len);
304 nbgl_appendU8((
uint8_t) obj->casing, out, w_cnt, max_len);
306 nbgl_appendU8((
uint8_t) obj->selectedCharIndex, out, w_cnt, max_len);
308 nbgl_appendU8((
uint8_t) obj->mode, out, w_cnt, max_len);
309 nbgl_appendU32(obj->keyMask, out, w_cnt, max_len);
312 static void nbgl_serializeKeypad(
nbgl_keypad_t *obj,
uint8_t *out,
size_t *w_cnt,
size_t max_len)
314 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
317 nbgl_appendU8((
uint8_t) obj->textColor, out, w_cnt, max_len);
318 nbgl_appendU8((
uint8_t) obj->borderColor, out, w_cnt, max_len);
320 nbgl_appendU8((
uint8_t) obj->enableBackspace, out, w_cnt, max_len);
321 nbgl_appendU8((
uint8_t) obj->enableValidate, out, w_cnt, max_len);
323 nbgl_appendU8((
uint8_t) obj->enableDigits, out, w_cnt, max_len);
325 nbgl_appendU8((
uint8_t) obj->shuffled, out, w_cnt, max_len);
327 nbgl_appendU8((
uint8_t) obj->digitIndexes[0], out, w_cnt, max_len);
328 nbgl_appendU8((
uint8_t) obj->digitIndexes[1], out, w_cnt, max_len);
329 nbgl_appendU8((
uint8_t) obj->digitIndexes[2], out, w_cnt, max_len);
330 nbgl_appendU8((
uint8_t) obj->digitIndexes[3], out, w_cnt, max_len);
331 nbgl_appendU8((
uint8_t) obj->digitIndexes[4], out, w_cnt, max_len);
333 nbgl_appendU8((
uint8_t) obj->selectedKey, out, w_cnt, max_len);
342 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
343 nbgl_appendPtr((
const void *) obj->buffer, out, w_cnt, max_len);
351 nbgl_serializeObj((
nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);
353 nbgl_appendU8((
uint8_t) obj->layout, out, w_cnt, max_len);
354 nbgl_appendU8((
uint8_t) obj->nbChildren, out, w_cnt, max_len);
355 nbgl_appendU8((
uint8_t) obj->forceClean, out, w_cnt, max_len);
362 nbgl_serializeObj((
nbgl_obj_t *) obj, out, w_cnt, max_len);
368 nbgl_serializeImage((
nbgl_image_t *) obj, out, w_cnt, max_len);
371 nbgl_serializeLine((
nbgl_line_t *) obj, out, w_cnt, max_len);
377 nbgl_serializeButton((
nbgl_button_t *) obj, out, w_cnt, max_len);
380 nbgl_serializeSwitch((
nbgl_switch_t *) obj, out, w_cnt, max_len);
389 nbgl_serializeRadio((
nbgl_radio_t *) obj, out, w_cnt, max_len);
392 nbgl_serializeQrCode((
nbgl_qrcode_t *) obj, out, w_cnt, max_len);
398 nbgl_serializeKeypad((
nbgl_keypad_t *) obj, out, w_cnt, max_len);
401 nbgl_serializeSpinner((
nbgl_spinner_t *) obj, out, w_cnt, max_len);
417 nbgl_serializeArea(obj, out, w_cnt, max_len);
428 nbgl_appendU8((
uint8_t) type, out, w_cnt, max_len);
433 return nbgl_serializeObject(obj, out, w_cnt, max_len);
435 return nbgl_serializeRefreshEvent((
nbgl_area_t *) obj, out, w_cnt, max_len);
Utilities for Ledger image files processing.
#define IMAGE_FILE_HEADER_SIZE
#define GET_IMAGE_FILE_BUFFER_LEN(image_file)
macro to get the buffer len of the image file
API to draw all basic graphic objects.
struct PACKED__ nbgl_line_s nbgl_line_t
struct to represent a vertical or horizontal line
struct PACKED__ nbgl_navigation_bar_s nbgl_page_indicator_t
struct to represent a navigation bar (PAGE_INDICATOR type) There can be up to 5 page indicators,...
struct PACKED__ nbgl_radio_s nbgl_radio_t
struct to represent a radio button (RADIO_BUTTON type)
struct PACKED__ nbgl_text_area_s nbgl_text_area_t
struct to represent a text area (TEXT_AREA type)
struct PACKED__ nbgl_progress_bar_s nbgl_progress_bar_t
struct to represent a progress bar (PROGRESS_BAR type)
struct PACKED__ nbgl_keypad_s nbgl_keypad_t
struct to represent a keypad (KEYPAD type)
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
uint8_t nbgl_objPoolGetId(nbgl_obj_t *obj)
Gets a unique index for the given object, in the pool.
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
struct PACKED__ nbgl_switch_s nbgl_switch_t
struct to represent a switch (size is fixed) (SWITCH type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
struct PACKED__ nbgl_spinner_s nbgl_spinner_t
struct to represent a "spinner", represented by the Ledger corners, in gray, with one of the corners ...
struct PACKED__ nbgl_image_file_s nbgl_image_file_t
struct to represent an image file object (IMAGE_FILE type) The source of the data is an image file wi...
struct PACKED__ nbgl_qrcode_s nbgl_qrcode_t
struct to represent a QR code (QR_CODE type), whose size is fixed
uint8_t nbgl_serializeNbglEvent(nbgl_serialized_event_type_e type, nbgl_obj_t *obj, uint8_t *out, size_t *w_cnt, size_t max_len)
nbgl_serialized_event_type_e
#define NBGL_SERIALIZE_OK
#define NBGL_SERIALIZE_ERROR
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
@ IMAGE_FILE
Image file (with Ledger compression)
@ SWITCH
Switch to turn on/off something.
@ RADIO_BUTTON
Indicator to inform whether something is on or off.
@ BUTTON
Rounded rectangle button with icon and/or text.
@ PROGRESS_BAR
horizontal bar to indicate progression of something (between 0% and 100%)
@ PAGE_INDICATOR
horizontal bar to indicate position within pages
@ LINE
Vertical or Horizontal line.
@ CONTAINER
Empty container.
@ TEXT_AREA
Area to contain text line(s)
nbgl_bpp_t
Enum to represent the number of bits per pixel (BPP)
@ NB_NBGL_BPP
Number of NBGL_BPP enums.
@ NBGL_BPP_1
1 bit per pixel
@ NBGL_BPP_4
4 bits per pixel
@ NBGL_BPP_2
2 bits per pixel
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.