Embedded SDK
Embedded SDK
ux_layout_pb.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 // clang-format off
27 const bagl_element_t ux_layout_pb_elements[] = {
28 #if (BAGL_WIDTH==128 && BAGL_HEIGHT==64)
29 
30  // erase
31  {{BAGL_RECTANGLE , 0x00, 0, 0, 128, 64, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, .text=NULL},
32 
33  // left right icons
34  {{BAGL_ICON , 0x01, 2, 28, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_left},
35  {{BAGL_ICON , 0x02, 122, 28, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_right},
36 
37 // NX
38 // 29 => 17 (14x14)
39 // 43 => 44
40  {{BAGL_ICON , 0x10, 57, 17, 14, 14, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
41  {{BAGL_LABELINE , 0x11, 0, 44, 128, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_EXTRABOLD_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
42 #elif (BAGL_WIDTH==128 && BAGL_HEIGHT==32)
43  // erase
44  {{BAGL_RECTANGLE , 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, .text=NULL},
45 
46  // left right icons
47  {{BAGL_ICON , 0x01, 2, 12, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_left},
48  {{BAGL_ICON , 0x02, 122, 12, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(const char*)&C_icon_right},
49 
50 // NS
51 // 12 => 2 (16x16)
52 // 26 => 28
53 
54  {{BAGL_ICON , 0x10, 56, 2, 16, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
55  {{BAGL_LABELINE , 0x11, 0, 28, 128, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_EXTRABOLD_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
56 #else
57  #error "BAGL_WIDTH/BAGL_HEIGHT not defined"
58 #endif
59 };
60 // clang-format on
61 
62 const bagl_element_t *ux_layout_pb_prepro(const bagl_element_t *element)
63 {
64  // don't display if null
65  const void *params = ux_stack_get_current_step_params();
66 
67  // copy element before any mod
68  memmove(&G_ux.tmp_element, element, sizeof(bagl_element_t));
69 
70  // for dashboard, setup the current application's name
71  switch (element->component.userid) {
72  case 0x01:
73  if (ux_flow_is_first()) {
74  return NULL;
75  }
76  break;
77 
78  case 0x02:
79  if (ux_flow_is_last()) {
80  return NULL;
81  }
82  break;
83 
84  case 0x10:
85 #if defined(HAVE_INDEXED_STRINGS)
86  G_ux.tmp_element.text
87  = (const char *) (((const ux_loc_layout_icon_params_t *) params)->icon);
88 #else // defined(HAVE_INDEXED_STRINGS)
89  G_ux.tmp_element.text = (const char *) (((const ux_layout_pb_params_t *) params)->icon);
90 #endif // defined(HAVE_INDEXED_STRINGS)
91  break;
92 
93  case 0x11:
94 #if defined(HAVE_INDEXED_STRINGS)
95  G_ux.tmp_element.text
96  = get_ux_loc_string(((const ux_loc_layout_icon_params_t *) params)->index);
97 #else // defined(HAVE_INDEXED_STRINGS)
98  G_ux.tmp_element.text = ((const ux_layout_pb_params_t *) params)->line1;
99 #endif // defined(HAVE_INDEXED_STRINGS)
100  break;
101  }
102  return &G_ux.tmp_element;
103 }
104 
105 void ux_layout_pb_init(unsigned int stack_slot)
106 {
107  ux_stack_init(stack_slot);
108  G_ux.stack[stack_slot].element_arrays[0].element_array = ux_layout_pb_elements;
109  G_ux.stack[stack_slot].element_arrays[0].element_array_count = ARRAYLEN(ux_layout_pb_elements);
110  G_ux.stack[stack_slot].element_arrays_count = 1;
111  G_ux.stack[stack_slot].screen_before_element_display_callback = ux_layout_pb_prepro;
112  G_ux.stack[stack_slot].button_push_callback = ux_flow_button_callback;
113  ux_stack_display(stack_slot);
114 }
115 
116 #endif // HAVE_UX_FLOW
const char * get_ux_loc_string(uint32_t index)
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
unsigned int ux_flow_is_first(void)
const void * ux_stack_get_current_step_params(void)
unsigned int ux_flow_button_callback(unsigned int button_mask, unsigned int button_mask_counter)
unsigned int ux_flow_is_last(void)