Embedded SDK
Embedded SDK
ux_layout_nnbnn.c
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Ledger Nano S - Secure firmware
4  * (c) 2022 Ledger
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  ********************************************************************************/
18 
19 #include "ux.h"
20 #include "os_utils.h"
21 
22 #ifdef HAVE_UX_FLOW
23 
24 #include <string.h>
25 
26 /*********************************************************************************
27  * 1/2 text lines
28  * 1 bold line
29  * 1/2 text lines
30  */
31 
32 // clang-format off
33 const bagl_element_t ux_layout_nnbnn_elements[] = {
34 #if (BAGL_WIDTH==128 && BAGL_HEIGHT==64)
35  // erase
36  {{BAGL_RECTANGLE , 0x00, 0, 0, 128, 64, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, .text=NULL},
37 
38  // up / down
39  {{BAGL_ICON , 0x01, 0, 30, 7, 4, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_up},
40  {{BAGL_ICON , 0x02, 120, 30, 7, 4, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_down},
41 
42  {{BAGL_LABELINE , 0x10, 6, 4, 116, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
43  {{BAGL_LABELINE , 0x11, 6, 20, 116, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
44  {{BAGL_LABELINE , 0x12, 8, 36, 112, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_EXTRABOLD_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
45  {{BAGL_LABELINE , 0x13, 6, 52, 116, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
46  {{BAGL_LABELINE , 0x14, 6, 68, 116, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
47 #elif (BAGL_WIDTH==128 && BAGL_HEIGHT==32)
48  // erase
49  {{BAGL_RECTANGLE , 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, .text=NULL},
50 
51  // up / down
52  {{BAGL_ICON , 0x01, 0, 14, 7, 4, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_up},
53  {{BAGL_ICON , 0x02, 120, 14, 7, 4, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_down},
54 
55  {{BAGL_LABELINE , 0x11, 6, 3, 116, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
56  {{BAGL_LABELINE , 0x12, 8, 19, 112, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_EXTRABOLD_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
57  {{BAGL_LABELINE , 0x13, 6, 35, 116, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
58 #else
59  #error "BAGL_WIDTH/BAGL_HEIGHT not defined"
60 #endif
61 };
62 // clang-format on
63 
64 const bagl_element_t *ux_layout_nnbnn_prepro(const bagl_element_t *element)
65 {
66  // don't display if null
67  const void *params = ux_stack_get_current_step_params();
68 
69  // copy element before any mod
70  memmove(&G_ux.tmp_element, element, sizeof(bagl_element_t));
71 
72  // for dashboard, setup the current application's name
73  switch (element->component.userid) {
74  case 0x01: {
75  if (!((const ux_layout_strings_params_t *) params)->lines[1]) {
76  return NULL;
77  }
78  break;
79  }
80 
81  case 0x02: {
82  if (!((const ux_layout_strings_params_t *) params)->lines[3]) {
83  return NULL;
84  }
85  break;
86  }
87  case 0x10:
88  case 0x11:
89  case 0x12:
90  case 0x13:
91  case 0x14: {
92  G_ux.tmp_element.text = ((const ux_layout_strings_params_t *) params)
93  ->lines[G_ux.tmp_element.component.userid & 0xF];
94  break;
95  }
96  }
97  return &G_ux.tmp_element;
98 }
99 
100 void ux_layout_nnbnn_init(unsigned int stack_slot)
101 {
102  ux_stack_init(stack_slot);
103  G_ux.stack[stack_slot].element_arrays[0].element_array = ux_layout_nnbnn_elements;
104  G_ux.stack[stack_slot].element_arrays[0].element_array_count
105  = ARRAYLEN(ux_layout_nnbnn_elements);
106  G_ux.stack[stack_slot].element_arrays_count = 1;
107  G_ux.stack[stack_slot].screen_before_element_display_callback = ux_layout_nnbnn_prepro;
108  G_ux.stack[stack_slot].button_push_callback = ux_flow_button_callback;
109  ux_stack_display(stack_slot);
110 }
111 
112 #endif // HAVE_UX_FLOW
const char * text
Definition: ux_bagl.h:68
bagl_component_t component
Definition: ux_bagl.h:58
#define G_ux
Definition: ux_bagl.h:345
void ux_stack_display(unsigned int stack_slot)
Definition: ux_stack.c:331
void ux_stack_init(unsigned int stack_slot)
Definition: ux_stack.c:171
const void * ux_stack_get_current_step_params(void)
unsigned int ux_flow_button_callback(unsigned int button_mask, unsigned int button_mask_counter)