Skip to content

Commit bff902e

Browse files
authored
Merge pull request #1448 from NickeZ/nickez/bootaoder-pairing-beautify
ble: Make bootloader pairing confirmation better
2 parents 3e0dcf5 + 8503ae2 commit bff902e

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

src/bootloader/bootloader.c

+29-5
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static void _render_message(const char* message, int duration)
299299
delay_ms(duration);
300300
}
301301

302-
static void _render_default_screen(void)
302+
void bootloader_render_default_screen(void)
303303
{
304304
UG_ClearBuffer();
305305
_load_logo();
@@ -310,6 +310,30 @@ static void _render_default_screen(void)
310310
UG_SendBuffer();
311311
}
312312

313+
extern bool bootloader_pairing_request;
314+
extern uint8_t bootloader_pairing_code_bytes[16];
315+
316+
void bootloader_render_ble_confirm_screen(bool confirmed)
317+
{
318+
bootloader_pairing_request = true;
319+
uint32_t pairing_code_int = (*(uint32_t*)&bootloader_pairing_code_bytes[0]) % 1000000;
320+
char code_str[10] = {0};
321+
snprintf(code_str, sizeof(code_str), "%06u", (unsigned)pairing_code_int);
322+
UG_ClearBuffer();
323+
uint16_t check_width = IMAGE_DEFAULT_CHECKMARK_HEIGHT + IMAGE_DEFAULT_CHECKMARK_HEIGHT / 2 - 1;
324+
UG_FontSelect(&font_font_a_11X10);
325+
if (confirmed) {
326+
UG_PutString(15, 0, "Confirm on app", false);
327+
} else {
328+
UG_PutString(30, 0, "Pairing code", false);
329+
image_cross(SCREEN_WIDTH / 16, 0, IMAGE_DEFAULT_CROSS_HEIGHT);
330+
image_checkmark(SCREEN_WIDTH * 15 / 16 - check_width, 0, IMAGE_DEFAULT_CHECKMARK_HEIGHT);
331+
}
332+
UG_FontSelect(&font_monogram_5X9);
333+
UG_PutString(45, SCREEN_HEIGHT / 2 - 9, code_str, false);
334+
UG_SendBuffer();
335+
}
336+
313337
static void _render_progress(float progress)
314338
{
315339
UG_ClearBuffer();
@@ -378,7 +402,7 @@ static void _render_hash(const char* title, const uint8_t* hash)
378402
UG_SendBuffer();
379403
delay_ms(1000);
380404
}
381-
_render_default_screen();
405+
bootloader_render_default_screen();
382406
}
383407

384408
// Sets _is_app_flash_empty by computing a "bare" hash, identical to _firmware_hash
@@ -786,7 +810,7 @@ static size_t _api_screen_rotate(uint8_t* output)
786810
return _report_status(OP_STATUS_ERR_LOAD_FLAG, output);
787811
}
788812
screen_rotate();
789-
_render_default_screen();
813+
bootloader_render_default_screen();
790814
return _report_status(OP_STATUS_OK, output);
791815
}
792816

@@ -840,7 +864,7 @@ static size_t _api_command(const uint8_t* input, uint8_t* output, const size_t m
840864
uint8_t chunk_num = input[1];
841865
len = _api_write_chunk(input + 2, chunk_num, output);
842866
if (output[1] != OP_STATUS_OK) {
843-
_render_default_screen();
867+
bootloader_render_default_screen();
844868
} else {
845869
_render_progress((float)chunk_num / (float)(_firmware_num_chunks - 1));
846870
}
@@ -1021,7 +1045,7 @@ void bootloader_jump(void)
10211045
// App not entered. Start USB API to receive boot commands
10221046
util_log("Not jumping to firmware");
10231047
_compute_is_app_flash_empty();
1024-
_render_default_screen();
1048+
bootloader_render_default_screen();
10251049
if (usb_start(_api_setup) != ERR_NONE) {
10261050
_render_message("Failed to initialize USB", 0);
10271051
}

src/bootloader/bootloader.h

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515
#ifndef _BOOTLOADER_H_
1616
#define _BOOTLOADER_H_
1717

18+
#include <stdbool.h>
19+
1820
void bootloader_jump(void);
1921

22+
/**
23+
* Renders the default bootloader screen
24+
*/
25+
void bootloader_render_default_screen(void);
26+
27+
/**
28+
* Renders a BLE pairing confirmations screen. Use the `confirmed` argument to display the
29+
* "user has confirmed on bitbox" version.
30+
*
31+
* confirmed - If false renders Yes/No icons at top, otherwise renders "See app".
32+
*/
33+
void bootloader_render_ble_confirm_screen(bool confirmed);
34+
2035
#endif

src/bootloader/startup.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ int main(void)
156156
bool ok;
157157
UG_ClearBuffer();
158158
if (qtouch_get_scroller_position(top_slider) < 127) {
159-
UG_PutString(0, 0, "deny", false);
159+
bootloader_render_default_screen();
160160
ok = false;
161161
} else {
162-
UG_PutString(0, 0, "confirm", false);
162+
bootloader_render_ble_confirm_screen(true);
163163
ok = true;
164164
}
165165
uint8_t payload[18] = {0};

src/da14531/da14531_handler.c

+7-14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "usb/usb_packet.h"
2323
#include "utils_ringbuffer.h"
2424
#include <ui/components/confirm.h>
25+
#include <ui/components/ui_images.h>
2526
#include <ui/fonts/monogram_5X9.h>
2627

2728
struct da14531_ctrl_frame {
@@ -64,21 +65,9 @@ static void _ble_pairing_callback(bool ok, void* param)
6465
_ble_pairing_component = NULL;
6566
}
6667
#else
68+
#include <bootloader/bootloader.h>
6769
extern bool bootloader_pairing_request;
6870
extern uint8_t bootloader_pairing_code_bytes[16];
69-
70-
static void _bootloader_pairing_code_confirm(void)
71-
{
72-
bootloader_pairing_request = true;
73-
uint32_t pairing_code_int = (*(uint32_t*)&bootloader_pairing_code_bytes[0]) % 1000000;
74-
char code_str[7] = {0};
75-
snprintf(code_str, sizeof(code_str), "%lu", (unsigned long)pairing_code_int);
76-
UG_ClearBuffer();
77-
UG_PutString(0, 0, "Deny", false);
78-
UG_PutString(SCREEN_WIDTH - 50, 0, "Confirm", false);
79-
UG_PutString(80, SCREEN_HEIGHT / 2 + 2, code_str, false);
80-
UG_SendBuffer();
81-
}
8271
#endif
8372

8473
static void _ctrl_handler(struct da14531_ctrl_frame* frame, struct ringbuffer* queue)
@@ -165,11 +154,15 @@ static void _ctrl_handler(struct da14531_ctrl_frame* frame, struct ringbuffer* q
165154
&bootloader_pairing_code_bytes[0],
166155
&frame->cmd_data[0],
167156
sizeof(bootloader_pairing_code_bytes));
168-
_bootloader_pairing_code_confirm();
157+
bootloader_render_ble_confirm_screen(false);
169158
#endif
170159
} break;
171160
case CTRL_CMD_BLE_STATUS:
172161
// util_log("da14531: BLE status update");
162+
#if defined(BOOTLOADER)
163+
bootloader_pairing_request = false;
164+
bootloader_render_default_screen();
165+
#endif
173166
switch (frame->cmd_data[0]) {
174167
case 0:
175168
util_log("da14531: adveritising");

src/sd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ bool sd_list_subdir(sd_list_t* list_out, const char* subdir)
228228
}
229229
list_out->num_files = 0;
230230
size_t allocated_files = 16;
231-
list_out->files = (char**)calloc(sizeof(char*), allocated_files);
231+
list_out->files = (char**)calloc(allocated_files, sizeof(char*));
232232
if (list_out->files == NULL) {
233233
Abort("Error: alloc sd_list_subdir");
234234
}

0 commit comments

Comments
 (0)