Embedded SDK
Embedded SDK
ux_layout_utils.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_helpers.h"
21 #include "os.h"
22 
23 #ifdef HAVE_UX_FLOW
24 
25 #include <string.h>
26 
27 static unsigned int ux_layout_ticker_callback(unsigned int unused)
28 {
29  UNUSED(unused);
30  // when the callback is called, then the slot is forcefully the top of stack
31  G_ux.stack[G_ux.stack_count - 1].ticker_interval = 0;
32  G_ux.stack[G_ux.stack_count - 1].ticker_value = 0;
33  G_ux.stack[G_ux.stack_count - 1].ticker_callback = NULL;
34  // auto validate the step
36  return 0;
37 }
38 
39 void ux_layout_set_timeout(unsigned int stack_slot, unsigned int ms)
40 {
41  if (ms) {
42  G_ux.stack[stack_slot].ticker_callback = ux_layout_ticker_callback;
43  G_ux.stack[stack_slot].ticker_value = ms;
44  G_ux.stack[stack_slot].ticker_interval = ms; // restart
45  }
46 }
47 
49 {
50  // don't display if null
51  const void *params = ux_stack_get_current_step_params();
52 
53  // copy element before any mod
54  memmove(&G_ux.tmp_element, element, sizeof(bagl_element_t));
55 
56  // for dashboard, setup the current application's name
57  switch (element->component.userid) {
58  case 0x01:
59  if (ux_flow_is_first()) {
60  return NULL;
61  }
62  break;
63 
64  case 0x02:
65  if (ux_flow_is_last()) {
66  return NULL;
67  }
68  break;
69 
70  default: {
71  if (G_ux.tmp_element.component.userid & 0xF0) {
72 #if defined(HAVE_INDEXED_STRINGS)
73  UX_LOC_STRINGS_INDEX index = ((const ux_loc_layout_params_t *) params)->index
74  + (G_ux.tmp_element.component.userid & 0xF);
75  // NB: it will call the BOLOS version of the function when linked with
76  // BOLOS, and the app version when linked with the app!
77  G_ux.tmp_element.text = get_ux_loc_string(index);
78 #else // defined(HAVE_INDEXED_STRINGS)
79  G_ux.tmp_element.text = ((const ux_layout_strings_params_t *) params)
80  ->lines[G_ux.tmp_element.component.userid & 0xF];
81 #endif // defined(HAVE_INDEXED_STRINGS)
82  }
83  break;
84  }
85  }
86  return &G_ux.tmp_element;
87 }
88 #endif // HAVE_UX_FLOW
const char * get_ux_loc_string(uint32_t index)
bagl_component_t component
Definition: ux_bagl.h:58
const bagl_element_t * ux_layout_strings_prepro(const bagl_element_t *element)
#define G_ux
Definition: ux_bagl.h:345
unsigned int ux_flow_is_first(void)
const void * ux_stack_get_current_step_params(void)
unsigned int ux_flow_is_last(void)
void ux_flow_validate(void)
BOLOS_UX_LOC_STRINGS UX_LOC_STRINGS_INDEX