Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
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
27static uint32_t nbTicks;
28
36static 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
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
57
65void ux_process_finger_event(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);
81 }
82}
83#else // HAVE_SE_TOUCH
91void ux_process_button_event(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
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
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
148{
149 // forward to UX
150 ux_forward_event(false);
151}
152
153#endif // HAVE_BOLOS
void nbgl_buttonsHandler(uint8_t buttonState, uint32_t currentTimeMs)
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
Definition nbgl_obj.c:1660
void nbgl_objAllowDrawing(bool enable)
This functions enables or disables drawing/refresh for all further calls.
Definition nbgl_obj.c:1750
void nbgl_screenRedraw(void)
This function redraws the whole screen on top of stack and its children.
Definition nbgl_screen.c:66
void nbgl_screenHandler(uint32_t intervaleMs)
Function to be called periodically by system to enable using ticker.
void nbgl_touchHandler(bool fromUx, nbgl_touchStatePosition_t *touchEvent, uint32_t currentTimeMs)
Function to be called periodically to check touchscreen state and coordinates.
Definition nbgl_touch.c:286
@ PRESSED
the finger is currently pressing the screen
Definition nbgl_types.h:223
@ RELEASED
the finger has been released from the screen
Definition nbgl_types.h:222
The low level Touchscreen event, coming from driver.
Definition nbgl_obj.h:231
int16_t y
vertical position of the touch (or for a RELEASED the last touched point)
Definition nbgl_obj.h:238
int16_t x
horizontal position of the touch (or for a RELEASED the last touched point)
Definition nbgl_obj.h:237
nbgl_touchState_t state
state of the touch event, e.g PRESSED or RELEASED
Definition nbgl_obj.h:232
void ux_process_default_event(void)
Definition ux.c:147
void ux_process_finger_event(uint8_t seph_packet[])
Process finger event.
Definition ux.c:65
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
#define G_ux_params
Definition ux_bagl.h:339