Embedded SDK
Embedded SDK
ux_layouts.h
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 #pragma once
20 
21 #include "bolos_target.h"
22 
23 #include "bagl.h"
24 
25 #ifdef HAVE_UX_FLOW
26 
27 #if (BAGL_WIDTH == 128 && BAGL_HEIGHT == 64)
28 /*********************************************************************************
29  * 1 bold text line
30  * 3 text lines
31  */
32 
33 typedef struct ux_layout_bnnn_params_s {
34  const char *line1;
35  const char *line2;
36  const char *line3;
37  const char *line4;
38 } ux_layout_bnnn_params_t;
39 
40 /*********************************************************************************
41  * 4 text lines
42  */
43 
44 typedef struct ux_layout_nnnn_params_s {
45  const char *line1;
46  const char *line2;
47  const char *line3;
48  const char *line4;
49 } ux_layout_nnnn_params_t;
50 
51 /*********************************************************************************
52  * 3 normal text lines
53  */
54 
55 typedef struct ux_layout_nnn_params_s {
56  const char *line1;
57  const char *line2;
58  const char *line3;
59 } ux_layout_nnn_params_t;
60 
61 /*********************************************************************************
62  * 1 bold text lines
63  * 2 normal text lines
64  */
65 
66 typedef struct ux_layout_bnn_params_s {
67  const char *line1;
68  const char *line2;
69  const char *line3;
70 } ux_layout_bnn_params_t;
71 
72 void ux_layout_bnnn_init(unsigned int stack_slot);
73 void ux_layout_nnnn_init(unsigned int stack_slot);
74 void ux_layout_nnn_init(unsigned int stack_slot);
75 void ux_layout_bnn_init(unsigned int stack_slot);
76 
77 #endif //(BAGL_WIDTH==128 && BAGL_HEIGHT==64)
78 
79 /*********************************************************************************
80  * 1 bold text line with the title
81  * 1-3 text lines [nano s/nano x]
82  */
83 #if (BAGL_WIDTH == 128 && BAGL_HEIGHT == 64)
84 #define UX_LAYOUT_PAGING_LINE_COUNT 3
85 #elif (BAGL_WIDTH == 128 && BAGL_HEIGHT == 32)
86 #define UX_LAYOUT_PAGING_LINE_COUNT 1
87 #else
88 #error "BAGL_WIDTH/BAGL_HEIGHT not defined"
89 #endif
90 
92 
93 typedef struct ux_layout_paging_params_s {
94  const char *title;
95  const char *text;
96 } ux_layout_paging_params_t;
97 
98 void ux_layout_paging_init(unsigned int stack_slot);
99 
100 // For paging layouts, the first n/b deals with the first line (the title),
101 // and the second n/b deals with the rest of the lines.
102 void ux_layout_nn_paging_init(unsigned int stack_slot);
103 void ux_layout_nb_paging_init(unsigned int stack_slot);
104 void ux_layout_bn_paging_init(unsigned int stack_slot);
105 void ux_layout_bb_paging_init(unsigned int stack_slot);
106 
107 // The layout params are always the same independently of the boldness of the lines.
108 #define ux_layout_nn_paging_params_t ux_layout_paging_params_t
109 #define ux_layout_nb_paging_params_t ux_layout_paging_params_t
110 #define ux_layout_bn_paging_params_t ux_layout_paging_params_t
111 #define ux_layout_bb_paging_params_t ux_layout_paging_params_t
112 
113 // Call to reset the paging component to the first page
114 void ux_layout_paging_reset(void);
115 
116 // deprecation
117 #define ux_layout_bnnn_paging_params_t ux_layout_paging_params_t
118 #define ux_layout_bnnn_paging_init ux_layout_bn_paging_init
119 #define ux_layout_bnnn_paging_reset ux_layout_paging_reset
120 #define ux_layout_bn_paging_reset ux_layout_paging_reset
121 
122 /*********************************************************************************
123  * 2 text lines
124  * 1 bold text lines
125  * 2 text lines
126  */
127 
128 typedef struct ux_layout_nnbnn_params_s {
129  const char *line1;
130  const char *line2;
131  const char *line3;
132  const char *line4;
133  const char *line5;
134 } ux_layout_nnbnn_params_t;
135 
136 /*********************************************************************************
137  * ICON
138  * 1 bold text line
139  */
140 
141 typedef struct ux_layout_pb_params_s {
142  const bagl_icon_details_t *icon;
143  const char *line1;
144 } ux_layout_pb_params_t;
145 
146 /*********************************************************************************
147  * 2 bold text line
148  */
149 
150 typedef struct ux_layout_bb_params_s {
151  const char *line1;
152  const char *line2;
153 } ux_layout_bb_params_t;
154 
155 /*********************************************************************************
156  * 1 text line
157  * 1 bold text line
158  */
159 
160 typedef struct ux_layout_bn_params_s {
161  const char *line1;
162  const char *line2;
163 } ux_layout_bn_params_t;
164 
165 /*********************************************************************************
166  * ICON
167  * 2 bold text lines
168  */
169 
170 typedef struct ux_layout_pbb_params_s {
171  const bagl_icon_details_t *icon;
172  const char *line1;
173  const char *line2;
174 } ux_layout_pbb_params_t;
175 
176 void ux_layout_nnbnn_init(unsigned int stack_slot);
177 void ux_layout_pb_init(unsigned int stack_slot);
178 void ux_layout_bb_init(unsigned int stack_slot);
179 void ux_layout_bn_init(unsigned int stack_slot);
180 void ux_layout_pbb_init(unsigned int stack_slot);
181 /*********************************************************************************
182  * ICON
183  * 2 normal text lines
184  */
185 
186 typedef struct ux_layout_pnn_params_s {
187  const bagl_icon_details_t *icon;
188  const char *line1;
189  const char *line2;
190 } ux_layout_pnn_params_t;
191 
192 /*********************************************************************************
193  * ICON
194  * 1 bold text lines
195  * 1 normal text lines
196  */
197 
198 typedef struct ux_layout_pbn_params_s {
199  const bagl_icon_details_t *icon;
200  const char *line1;
201  const char *line2;
202 } ux_layout_pbn_params_t;
203 
204 /*********************************************************************************
205  * ICON
206  * 1 normal text lines
207  */
208 
209 typedef struct ux_layout_pn_params_s {
210  const bagl_icon_details_t *icon;
211  const char *line1;
212 } ux_layout_pn_params_t;
213 
214 /*********************************************************************************
215  * 2 normal text lines
216  */
217 
218 typedef struct ux_layout_nn_params_s {
219  const char *line1;
220  const char *line2;
221 } ux_layout_nn_params_t;
222 
223 void ux_layout_nnbnn_init(unsigned int stack_slot);
224 void ux_layout_pb_init(unsigned int stack_slot);
225 void ux_layout_bb_init(unsigned int stack_slot);
226 void ux_layout_bn_init(unsigned int stack_slot);
227 void ux_layout_pbb_init(unsigned int stack_slot);
228 void ux_layout_pnn_init(unsigned int stack_slot);
229 void ux_layout_pbn_init(unsigned int stack_slot);
230 void ux_layout_pn_init(unsigned int stack_slot);
231 void ux_layout_nn_init(unsigned int stack_slot);
232 
233 /*********************************************************************************
234  * Browsable component
235  */
236 
237 // activate an item by index, do nothing when item_idx is invalid
238 typedef void (*list_item_select_t)(unsigned int item_idx);
239 
240 // return NULL when item_idx is invalid
241 typedef const char *(*list_item_value_t)(unsigned int item_idx);
242 
243 void ux_menulist_init(unsigned int stack_slot,
244  list_item_value_t getter,
245  list_item_select_t selector);
246 void ux_menulist_init_select(unsigned int stack_slot,
247  list_item_value_t getter,
248  list_item_select_t selector,
249  unsigned int selected_item_idx);
250 
251 #define UX_STEP_MENULIST(stepname, getter, selector) \
252  void stepname##_init(unsigned int stack_slot) \
253  { \
254  ux_menulist_init(stack_slot, getter, selector); \
255  } \
256  const ux_flow_step_t stepname = { \
257  stepname##_init, \
258  &G_ux.menulist_params, \
259  NULL, \
260  NULL, \
261  }
262 
263 #define UX_STEP_MENULIST_INIT(stepname, initfunc) \
264  const ux_flow_step_t stepname = { \
265  initfunc, \
266  &G_ux.menulist_params, \
267  NULL, \
268  NULL, \
269  }
270 
271 /*********************************************************************************
272  * Utilities
273  */
274 
279 void ux_layout_set_timeout(unsigned int stack_slot, unsigned int ms);
280 
281 #endif // HAVE_UX_FLOW