fix(core): improve homescreen upload speed over BLE

[no changelog]
This commit is contained in:
tychovrahe
2025-09-22 14:13:53 +02:00
committed by TychoVrahe
parent 812b5baaf9
commit bbcab3f507
9 changed files with 49 additions and 1 deletions

View File

@@ -430,6 +430,7 @@ fn generate_trezorhal_bindings() {
.allowlist_function("ble_set_name")
.allowlist_function("ble_unpair")
.allowlist_function("ble_get_bond_list")
.allowlist_function("ble_set_high_speed")
.allowlist_type("ble_command_t")
.allowlist_type("ble_state_t")
.allowlist_type("ble_event_t")

View File

@@ -792,6 +792,7 @@ static void _librust_qstrs(void) {
MP_QSTR_send__transaction_signed;
MP_QSTR_send__you_are_contributing;
MP_QSTR_set_brightness;
MP_QSTR_set_high_speed;
MP_QSTR_set_name;
MP_QSTR_setting__adjust;
MP_QSTR_setting__apply;

View File

@@ -87,6 +87,17 @@ extern "C" fn py_set_name(name: Obj) -> Obj {
unsafe { util::try_or_raise(block) }
}
extern "C" fn py_set_high_speed(enable: Obj) -> Obj {
let block = || {
let enable: bool = enable.try_into()?;
set_high_speed(enable);
Ok(Obj::const_none())
};
unsafe { util::try_or_raise(block) }
}
extern "C" fn py_switch_off() -> Obj {
let block = || {
switch_off()?;
@@ -323,6 +334,12 @@ pub static mp_module_trezorble: Module = obj_module! {
/// """
Qstr::MP_QSTR_set_name => obj_fn_1!(py_set_name).as_obj(),
/// def set_high_speed(enable: bool):
/// """
/// Set high speed connection.
/// """
Qstr::MP_QSTR_set_high_speed => obj_fn_1!(py_set_high_speed).as_obj(),
/// def switch_off():
/// """
/// Stop advertising and disconnect any connected devices.

View File

@@ -170,6 +170,10 @@ pub fn set_name(name: &str) {
unsafe { ffi::ble_set_name(bytes.as_ptr(), bytes.len()) }
}
pub fn set_high_speed(enable: bool) {
unsafe { ffi::ble_set_high_speed(enable) }
}
pub fn start_comm() {
unsafe { ffi::ble_start() }
}

View File

@@ -129,6 +129,7 @@ typedef enum {
SYSCALL_BLE_SET_NAME,
SYSCALL_BLE_UNPAIR,
SYSCALL_BLE_GET_BOND_LIST,
SYSCALL_BLE_SET_HIGH_SPEED,
SYSCALL_NRF_UPDATE_REQUIRED,
SYSCALL_NRF_UPDATE,

View File

@@ -639,6 +639,11 @@ __attribute((no_stack_protector)) void syscall_handler(uint32_t *args,
size_t list_size = args[1];
args[0] = ble_get_bond_list__verified(list, list_size);
} break;
case SYSCALL_BLE_SET_HIGH_SPEED: {
bool enable = args[0];
ble_set_high_speed(enable);
} break;
#endif
#ifdef USE_NRF

View File

@@ -621,6 +621,10 @@ uint8_t ble_get_bond_list(bt_le_addr_t *bonds, size_t count) {
SYSCALL_BLE_GET_BOND_LIST);
}
void ble_set_high_speed(bool enable) {
syscall_invoke1((uint32_t)enable, SYSCALL_BLE_SET_HIGH_SPEED);
}
#endif
#ifdef USE_NRF

View File

@@ -68,6 +68,13 @@ def set_name(name: str | None):
"""
# rust/src/trezorhal/ble/micropython.rs
def set_high_speed(enable: bool):
"""
Set high speed connection.
"""
# rust/src/trezorhal/ble/micropython.rs
def switch_off():
"""

View File

@@ -92,8 +92,16 @@ async def apply_settings(msg: ApplySettings) -> Success:
if homescreen_length is not None:
if homescreen is not None:
raise ProcessError("Mutually exclusive settings")
if utils.USE_BLE:
from trezorble import set_high_speed
homescreen = await _load_homescreen(homescreen_length)
set_high_speed(True)
try:
homescreen = await _load_homescreen(homescreen_length)
finally:
if utils.USE_BLE:
set_high_speed(False)
if homescreen is not None:
_validate_homescreen(homescreen)