Embedded SDK
Embedded SDK
ux_nbgl.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 #if defined(HAVE_BOLOS)
22 #include "bolos_privileged_ux.h"
23 #endif // HAVE_BOLOS
24 
25 #include "os_math.h"
26 #include "os_ux.h"
27 #include "os_task.h"
28 #include "nbgl_screen.h"
29 #include "nbgl_touch.h"
30 
31 #include <string.h>
32 
33 #define BUTTON_LEFT 1
34 #define BUTTON_RIGHT 2
35 
36 typedef void (*asynchmodal_end_callback_t)(unsigned int ux_status);
37 
41 typedef struct ux_state_s ux_state_t;
42 
43 struct ux_state_s {
44  bolos_task_status_t exit_code;
45  bool validate_pin_from_dashboard; // set to true when BOLOS_UX_VALIDATE_PIN is received from
46  // Dashboard task
47 
49 
50  char string_buffer[128];
51 };
52 
53 extern ux_state_t G_ux;
54 #if !defined(APP_UX)
55 extern bolos_ux_params_t G_ux_params;
56 
57 extern void ux_process_finger_event(uint8_t seph_packet[]);
58 extern void ux_process_button_event(uint8_t seph_packet[]);
59 extern void ux_process_ticker_event(void);
60 extern void ux_process_default_event(void);
61 #endif // !defined(APP_UX)
62 
66 #define UX_INIT() nbgl_objInit();
67 
68 #ifdef HAVE_BOLOS
69 // to be used only by hal_io.c in BOLOS, for compatibility
70 #define UX_FORWARD_EVENT_REDRAWCB(bypasspincheck, \
71  ux_params, \
72  ux, \
73  os_ux, \
74  os_sched_last_status, \
75  callback, \
76  redraw_cb, \
77  ignoring_app_if_ux_busy) \
78  ux_params.ux_id = BOLOS_UX_EVENT; \
79  ux_params.len = 0; \
80  os_ux(&ux_params); \
81  ux_params.len = os_sched_last_status(TASK_BOLOS_UX); \
82  if (ux.asynchmodal_end_callback \
83  && os_ux_get_status(BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST) != 0) { \
84  asynchmodal_end_callback_t cb = ux.asynchmodal_end_callback; \
85  ux.asynchmodal_end_callback = NULL; \
86  cb(os_ux_get_status(BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST)); \
87  }
88 #endif // HAVE_BOLOS
89 
95 #define UX_WAKE_UP() \
96  G_ux_params.ux_id = BOLOS_UX_WAKE_UP; \
97  G_ux_params.len = 0; \
98  os_ux(&G_ux_params); \
99  G_ux_params.len = os_sched_last_status(TASK_BOLOS_UX);
100 
105 #ifdef HAVE_SE_TOUCH
106 #define UX_BUTTON_PUSH_EVENT(seph_packet)
107 #else // HAVE_SE_TOUCH
108 #define UX_BUTTON_PUSH_EVENT(seph_packet) ux_process_button_event(seph_packet)
109 #endif // HAVE_SE_TOUCH
110 
115 #ifdef HAVE_SE_TOUCH
116 #define UX_FINGER_EVENT(seph_packet) ux_process_finger_event(seph_packet)
117 #else // HAVE_SE_TOUCH
118 #define UX_FINGER_EVENT(seph_packet)
119 #endif // HAVE_SE_TOUCH
120 
125 #define UX_TICKER_EVENT(seph_packet, callback) ux_process_ticker_event()
126 
131 #define UX_DEFAULT_EVENT() ux_process_default_event()
132 
133 // discriminated from io to allow for different memory placement
134 typedef struct ux_seph_s {
135  unsigned int button_mask;
136  unsigned int button_same_mask_counter;
137 #ifdef HAVE_BOLOS
138  unsigned int ux_id;
139  unsigned int ux_status;
140 #endif // HAVE_BOLOS
142 
143 #ifdef HAVE_BACKGROUND_IMG
144 SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX)
145 uint8_t *fetch_background_img(bool allow_candidate);
146 SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX)
147 bolos_err_t delete_background_img(void);
148 #endif
149 
151 
153 void io_seproxyhal_power_off(bool criticalBattery);
154 
155 #if defined(HAVE_LANGUAGE_PACK)
156 const char *get_ux_loc_string(UX_LOC_STRINGS_INDEX index);
157 void bolos_ux_select_language(uint16_t language);
158 void bolos_ux_refresh_language(void);
159 
160 typedef struct ux_loc_language_pack_infos {
161  unsigned char available;
162 
163 } UX_LOC_LANGUAGE_PACK_INFO;
164 
165 // To populate infos about language packs
166 SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void list_language_packs(
167  UX_LOC_LANGUAGE_PACK_INFO *packs PLENGTH(NB_LANG * sizeof(UX_LOC_LANGUAGE_PACK_INFO)));
168 SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) const LANGUAGE_PACK *get_language_pack(
169  unsigned int language);
170 #endif // defined(HAVE_LANGUAGE_PACK)
171 
172 #include "glyphs.h"
#define LANGUAGE_PACK
Definition: nbgl_fonts.h:29
const char * get_ux_loc_string(uint32_t index)
API to manage screens.
unsigned int button_mask
Definition: ux_bagl.h:706
unsigned int button_same_mask_counter
Definition: ux_bagl.h:707
asynchmodal_end_callback_t asynchmodal_end_callback
Definition: ux_nbgl.h:48
bolos_task_status_t exit_code
Definition: ux_bagl.h:301
char string_buffer[128]
Definition: ux_nbgl.h:50
bool validate_pin_from_dashboard
Definition: ux_nbgl.h:45
unsigned short uint16_t
Definition: usbd_conf.h:54
unsigned char uint8_t
Definition: usbd_conf.h:53
BOLOS_UX_LOC_STRINGS UX_LOC_STRINGS_INDEX
void ux_process_default_event(void)
Definition: ux.c:143
bolos_ux_params_t G_ux_params
Definition: main.c:33
void(* asynchmodal_end_callback_t)(unsigned int ux_status)
Definition: ux_nbgl.h:36
void ux_process_finger_event(uint8_t seph_packet[])
Process finger event.
Definition: ux.c:64
struct ux_seph_s ux_seph_os_and_app_t
void io_seproxyhal_power_off(bool criticalBattery)
void ux_process_button_event(uint8_t seph_packet[])
void ux_process_ticker_event(void)
Process the ticker_event to the os ux handler. Ticker event callback is always called whatever the re...
Definition: ux.c:110
ux_seph_os_and_app_t G_ux_os
ux_state_t G_ux
Definition: main.c:32
void io_seproxyhal_request_mcu_status(void)