Skip to content

Commit 421a3e2

Browse files
committed
Merge branch 'waitingscreen'
2 parents 7363fde + 40d1501 commit 421a3e2

File tree

9 files changed

+67
-13
lines changed

9 files changed

+67
-13
lines changed

src/rust/bitbox02-rust/src/hww.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ fn api_attestation(usb_in: &[u8]) -> Vec<u8> {
110110
}
111111

112112
async fn _process_packet(hal: &mut impl crate::hal::Hal, usb_in: Vec<u8>) -> Vec<u8> {
113+
// Update the waiting screen from "See the BitBoxApp" to the logo, now that the host is
114+
// connected. When the device is initialized, we delay this until the unlock call, otherwise
115+
// there would be a flicker where the logo would be shown before the host invokes unlock.
116+
if !bitbox02::memory::is_initialized() || usb_in.as_slice() == [OP_UNLOCK] {
117+
bitbox02::ui::screen_process_waiting_switch_to_logo();
118+
}
119+
113120
match usb_in.split_first() {
114121
Some((&OP_UNLOCK, b"")) => return api_unlock(hal).await,
115122
Some((&OP_ATTESTATION, rest)) => return api_attestation(rest),

src/rust/bitbox02-rust/src/hww/noise.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ pub(crate) async fn process(
8282
) -> Result<(), Error> {
8383
match usb_in.split_first() {
8484
Some((&OP_I_CAN_HAS_HANDSHAEK, b"")) => {
85-
// The previous screen was "See the BitBoxApp".
86-
// Since a handshake was requested, a client was connected, so we pop that screen.
8785
// Pairing is the start of a session, so we clean the screen stack in case
8886
// we started a new session in the middle of something.
8987
bitbox02::ui::screen_stack_pop_all();

src/rust/bitbox02-sys/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const ALLOWLIST_FNS: &[&str] = &[
128128
"reset_ble",
129129
"screen_print_debug",
130130
"screen_process",
131+
"screen_process_waiting_switch_to_logo",
131132
"screen_saver_disable",
132133
"screen_saver_enable",
133134
"sd_card_inserted",

src/rust/bitbox02/src/ui.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ mod types;
2525
mod ui;
2626

2727
pub use ui::*;
28+
29+
pub fn screen_process_waiting_switch_to_logo() {
30+
unsafe { bitbox02_sys::screen_process_waiting_switch_to_logo() }
31+
}

src/ui/components/waiting.c

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "waiting.h"
16+
#include "lockscreen.h"
1617

1718
#include "image.h"
1819
#include "ui_images.h"
@@ -21,13 +22,12 @@
2122
#include <screen.h>
2223
#include <ui/ui_util.h>
2324

25+
#include <stdbool.h>
2426
#include <string.h>
2527

26-
static void _render(component_t* component)
27-
{
28-
// TODO - add an interesting animation?
29-
ui_util_component_render_subcomponents(component);
30-
}
28+
typedef struct {
29+
bool show_logo;
30+
} data_t;
3131

3232
/********************************** Component Functions **********************************/
3333

@@ -36,7 +36,7 @@ static void _render(component_t* component)
3636
*/
3737
static component_functions_t _component_functions = {
3838
.cleanup = ui_util_component_cleanup,
39-
.render = _render,
39+
.render = ui_util_component_render_subcomponents,
4040
.on_event = NULL,
4141
};
4242

@@ -47,6 +47,12 @@ static component_functions_t _component_functions = {
4747
*/
4848
component_t* waiting_create(void)
4949
{
50+
data_t* data = malloc(sizeof(data_t));
51+
if (!data) {
52+
Abort("Error: malloc waiting data");
53+
}
54+
memset(data, 0, sizeof(data_t));
55+
5056
component_t* waiting = malloc(sizeof(component_t));
5157
if (!waiting) {
5258
Abort("Error: malloc waiting");
@@ -57,14 +63,37 @@ component_t* waiting_create(void)
5763
waiting->dimension.height = SCREEN_HEIGHT;
5864
waiting->position.top = 0;
5965
waiting->position.left = 0;
66+
waiting->data = data;
67+
68+
ui_util_add_sub_component(waiting, lockscreen_create());
69+
70+
return waiting;
71+
}
72+
73+
void waiting_switch_to_logo(component_t* component)
74+
{
75+
data_t* data = (data_t*)component->data;
76+
if (data->show_logo) {
77+
return;
78+
}
79+
data->show_logo = true;
80+
81+
if (component->sub_components.amount != 1) {
82+
// Sanity check to avoid memory bugs, should never happen.
83+
Abort("waiting_switch_to_logo");
84+
return;
85+
}
86+
87+
ui_util_component_cleanup(component->sub_components.sub_components[0]);
88+
6089
image_logo_data_t logo = image_logo_data();
6190
component_t* bb2_logo = image_create(
6291
logo.buffer.data,
6392
logo.buffer.len,
6493
logo.dimensions.width,
6594
logo.dimensions.height,
6695
CENTER,
67-
waiting);
68-
ui_util_add_sub_component(waiting, bb2_logo);
69-
return waiting;
96+
component);
97+
98+
component->sub_components.sub_components[0] = bb2_logo;
7099
}

src/ui/components/waiting.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
#include <ui/component.h>
1919

2020
/**
21-
* Creates a waiting screen.
21+
* Creates a waiting screen. It starts out with a lockscreen (see lockscreen.c). Once
22+
* `waiting_switch_to_logo()` is called, the waiting screen will switch to showing the logo image.
2223
*/
2324
component_t* waiting_create(void);
2425

26+
/**
27+
* Switch the waiting screen to show the BitBox logo instead.
28+
*/
29+
void waiting_switch_to_logo(component_t* component);
30+
2531
#endif

src/ui/screen_process.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ static component_t* _get_waiting_screen(void)
4444
return waiting_screen;
4545
}
4646

47+
void screen_process_waiting_switch_to_logo(void)
48+
{
49+
waiting_switch_to_logo(_get_waiting_screen());
50+
}
51+
4752
component_t* screen_process_get_top_component(void)
4853
{
4954
component_t* saver = screen_saver_get();

src/ui/screen_process.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ void ui_screen_render_component(component_t* component);
2727
*/
2828
component_t* screen_process_get_top_component(void);
2929

30+
/**
31+
* Wraps `waiting_switch_to_logo()` for the waiting screen.
32+
*/
33+
void screen_process_waiting_switch_to_logo(void);
34+
3035
/**
3136
* Runs the UI once.
3237
*

src/workflow/orientation_screen.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ static void _idle_timer_cb(const struct timer_task* const timer_task)
7373
}
7474

7575
usb_start();
76-
ui_screen_stack_push(lockscreen_create());
7776
}
7877
#endif
7978

0 commit comments

Comments
 (0)