Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
lib_ux_nbgl
ux.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 "seproxyhal_protocol.h"
20
#include "ux.h"
21
#include "
nbgl_touch.h
"
22
#include "
nbgl_buttons.h
"
23
#include "os_io.h"
24
#include "os_io_seph_ux.h"
25
#ifndef HAVE_BOLOS
26
// number of 100ms ticks since the start-up of the app
27
static
uint32_t
nbTicks
;
28
36
static
bool
ux_forward_event
(
bool
ignoring_app_if_ux_busy)
37
{
38
G_ux_params
.ux_id = BOLOS_UX_EVENT;
39
G_ux_params
.len = 0;
40
os_ux(&
G_ux_params
);
41
G_ux_params
.len = os_sched_last_status(TASK_BOLOS_UX);
42
if
(
G_ux_params
.len == BOLOS_UX_REDRAW) {
43
// enable drawing according to UX decision
44
nbgl_objAllowDrawing
(
true
);
45
nbgl_screenRedraw
();
46
nbgl_refresh
();
47
}
48
else
if
(!ignoring_app_if_ux_busy
49
|| ((
G_ux_params
.len != BOLOS_UX_IGNORE) && (
G_ux_params
.len != BOLOS_UX_CONTINUE))) {
50
return
true
;
51
}
52
return
false
;
53
}
54
55
#ifdef HAVE_SE_TOUCH
56
static
nbgl_touchStatePosition_t
pos
;
57
65
void
ux_process_finger_event
(
const
uint8_t seph_packet[])
66
{
67
bool
displayEnabled =
ux_forward_event
(
true
);
68
// enable/disable drawing according to UX decision
69
nbgl_objAllowDrawing
(displayEnabled);
70
71
// if the event is not fully consumed by UX, use it for NBGL
72
if
(displayEnabled) {
73
pos
.
state
= (seph_packet[3] == SEPROXYHAL_TAG_FINGER_EVENT_TOUCH) ?
PRESSED
:
RELEASED
;
74
pos
.
x
= (seph_packet[4] << 8) + seph_packet[5];
75
pos
.
y
= (seph_packet[6] << 8) + seph_packet[7];
76
#ifdef HAVE_HW_TOUCH_SWIPE
77
pos
.swipe = seph_packet[10];
78
#endif
// HAVE_HW_TOUCH_SWIPE
79
nbgl_touchHandler
(
false
, &
pos
,
nbTicks
* 100);
80
nbgl_refresh
();
81
}
82
}
83
#else
// HAVE_SE_TOUCH
91
void ux_process_button_event(const uint8_t seph_packet[])
92
{
93
bool
displayEnabled =
ux_forward_event
(
true
);
94
// enable/disable drawing according to UX decision
95
nbgl_objAllowDrawing
(displayEnabled);
96
97
// if the event is not fully consumed by UX, use it for NBGL
98
if
(displayEnabled) {
99
uint8_t buttons_state = seph_packet[3] >> 1;
100
nbgl_buttonsHandler
(buttons_state,
nbTicks
* 100);
101
nbgl_refresh
();
102
}
103
}
104
#endif
// HAVE_SE_TOUCH
105
111
void
ux_process_ticker_event
(
void
)
112
{
113
nbTicks
++;
114
// forward to UX
115
bool
displayEnabled =
ux_forward_event
(
true
);
116
117
// enable/disable drawing according to UX decision
118
nbgl_objAllowDrawing
(displayEnabled);
119
120
// do not do any action on screens if display is disabled, because
121
// UX has the hand
122
if
(!displayEnabled) {
123
return
;
124
}
125
126
// update ticker in NBGL
127
nbgl_screenHandler
(100);
128
129
#ifdef HAVE_SE_TOUCH
130
// handle touch only if detected as pressed in last touch message
131
if
(
pos
.
state
==
PRESSED
) {
132
io_touch_info_t touch_info;
133
touch_get_last_info(&touch_info);
134
pos
.
state
= (touch_info.state == SEPROXYHAL_TAG_FINGER_EVENT_TOUCH) ?
PRESSED
:
RELEASED
;
135
pos
.
x
= touch_info.x;
136
pos
.
y
= touch_info.y;
137
// Send current touch position to nbgl
138
nbgl_touchHandler
(
false
, &
pos
,
nbTicks
* 100);
139
}
140
#endif
// HAVE_SE_TOUCH
141
nbgl_refresh
();
142
}
143
147
void
ux_process_default_event
(
void
)
148
{
149
// forward to UX
150
ux_forward_event
(
false
);
151
}
152
153
#endif
// HAVE_BOLOS
G_ux_params
bolos_ux_params_t G_ux_params
UX command parameters passed to the OS via os_ux()
Definition
main.c:35
nbgl_buttons.h
nbgl_buttonsHandler
void nbgl_buttonsHandler(uint8_t buttonState, uint32_t currentTimeMs)
nbgl_refresh
void nbgl_refresh(void)
nbgl_objAllowDrawing
void nbgl_objAllowDrawing(bool enable)
nbgl_screenRedraw
void nbgl_screenRedraw(void)
nbgl_screenHandler
void nbgl_screenHandler(uint32_t intervaleMs)
nbgl_touch.h
nbgl_touchHandler
void nbgl_touchHandler(bool fromUx, nbgl_touchStatePosition_t *touchEvent, uint32_t currentTimeMs)
PRESSED
@ PRESSED
the finger is currently pressing the screen
Definition
nbgl_types.h:253
RELEASED
@ RELEASED
the finger has been released from the screen
Definition
nbgl_types.h:252
nbgl_touchStatePosition_t
The low level Touchscreen event, coming from driver.
Definition
nbgl_obj.h:217
nbgl_touchStatePosition_t::y
int16_t y
vertical position of the touch (or for a RELEASED the last touched point)
Definition
nbgl_obj.h:224
nbgl_touchStatePosition_t::x
int16_t x
horizontal position of the touch (or for a RELEASED the last touched point)
Definition
nbgl_obj.h:223
nbgl_touchStatePosition_t::state
nbgl_touchState_t state
state of the touch event, e.g PRESSED or RELEASED
Definition
nbgl_obj.h:218
ux_process_default_event
void ux_process_default_event(void)
Definition
ux.c:147
pos
static nbgl_touchStatePosition_t pos
Definition
ux.c:56
ux_forward_event
static bool ux_forward_event(bool ignoring_app_if_ux_busy)
internal bolos ux event processing with callback in case event is to be processed by the application
Definition
ux.c:36
ux_process_finger_event
void ux_process_finger_event(const uint8_t seph_packet[])
Process finger event.
Definition
ux.c:65
nbTicks
static uint32_t nbTicks
Definition
ux.c:27
ux_process_ticker_event
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:111
Generated by
1.9.8