mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-25 16:08:32 +00:00
Merge remote-tracking branch 'origin/mmilata/ble-advertise-on-start' into mmilata/pairing
This commit is contained in:
commit
dc672f3e35
@ -21,7 +21,7 @@ if BENCHMARK and PYOPT != '0':
|
||||
print("BENCHMARK=1 works only with PYOPT=0.")
|
||||
exit(1)
|
||||
|
||||
FEATURES_WANTED = ["input", "sd_card", "dma2d", "optiga"]
|
||||
FEATURES_WANTED = ["input", "sd_card", "dma2d", "optiga", "ble"]
|
||||
|
||||
if not DISABLE_TROPIC:
|
||||
FEATURES_WANTED.append('tropic')
|
||||
|
30
core/embed/io/ble/unix/ble.c
Normal file
30
core/embed/io/ble/unix/ble.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <io/ble.h>
|
||||
#include <trezor_rtl.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
bool ble_init(void) { return true; }
|
||||
|
||||
void ble_deinit(void) {}
|
||||
|
||||
void ble_start(void) {}
|
||||
|
||||
void ble_stop(void) {}
|
||||
|
||||
bool ble_issue_command(ble_command_t *command) { return true; }
|
||||
|
||||
bool ble_get_event(ble_event_t *event) { return false; }
|
||||
|
||||
void ble_get_state(ble_state_t *state) {
|
||||
memset(state, 0, sizeof(ble_state_t));
|
||||
}
|
||||
|
||||
bool ble_can_write(void) { return true; }
|
||||
|
||||
bool ble_write(const uint8_t *data, uint16_t len) { return len; }
|
||||
|
||||
bool ble_can_read(void) { return false; }
|
||||
|
||||
uint32_t ble_read(uint8_t *data, uint16_t max_len) { return 0; }
|
||||
|
||||
bool ble_get_mac(uint8_t *mac, size_t max_len) { return false; }
|
@ -19,62 +19,8 @@
|
||||
|
||||
#include <sys/sysevent.h>
|
||||
|
||||
// #include "ble/dfu.h"
|
||||
// #include "ble/messages.h"
|
||||
|
||||
/// package: trezorio.ble
|
||||
|
||||
// /// def update_init(data: bytes, binsize: int) -> int:
|
||||
// /// """
|
||||
// /// Initializes the BLE firmware update
|
||||
// /// """
|
||||
// STATIC mp_obj_t mod_trezorio_BLE_update_init(mp_obj_t data, mp_obj_t binsize)
|
||||
// {
|
||||
// mp_buffer_info_t buffer = {0};
|
||||
// mp_int_t binsize_int = mp_obj_get_int(binsize);
|
||||
//
|
||||
// mp_get_buffer_raise(data, &buffer, MP_BUFFER_READ);
|
||||
//
|
||||
// ble_set_dfu_mode(true);
|
||||
//
|
||||
// dfu_result_t result = dfu_update_init(buffer.buf, buffer.len, binsize_int);
|
||||
// if (result == DFU_NEXT_CHUNK) {
|
||||
// return mp_obj_new_int(0);
|
||||
// } else if (result == DFU_SUCCESS) {
|
||||
// ble_set_dfu_mode(false);
|
||||
// return mp_obj_new_int(1);
|
||||
// } else {
|
||||
// ble_set_dfu_mode(false);
|
||||
// mp_raise_msg(&mp_type_RuntimeError, "Upload failed.");
|
||||
// }
|
||||
// }
|
||||
// STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_BLE_update_init_obj,
|
||||
// mod_trezorio_BLE_update_init);
|
||||
//
|
||||
// /// def update_chunk(chunk: bytes) -> int:
|
||||
// /// """
|
||||
// /// Writes next chunk of BLE firmware update
|
||||
// /// """
|
||||
// STATIC mp_obj_t mod_trezorio_BLE_update_chunk(mp_obj_t data) {
|
||||
// mp_buffer_info_t buffer = {0};
|
||||
//
|
||||
// mp_get_buffer_raise(data, &buffer, MP_BUFFER_READ);
|
||||
//
|
||||
// dfu_result_t result = dfu_update_chunk(buffer.buf, buffer.len);
|
||||
//
|
||||
// if (result == DFU_NEXT_CHUNK) {
|
||||
// return mp_obj_new_int(0);
|
||||
// } else if (result == DFU_SUCCESS) {
|
||||
// ble_set_dfu_mode(false);
|
||||
// return mp_obj_new_int(1);
|
||||
// } else {
|
||||
// ble_set_dfu_mode(false);
|
||||
// mp_raise_msg(&mp_type_RuntimeError, "Upload failed.");
|
||||
// }
|
||||
// }
|
||||
// STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_BLE_update_chunk_obj,
|
||||
// mod_trezorio_BLE_update_chunk);
|
||||
|
||||
///
|
||||
/// def erase_bonds() -> bool:
|
||||
/// """
|
||||
@ -146,7 +92,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
|
||||
mod_trezorio_BLE_start_advertising_obj, 1, 2,
|
||||
mod_trezorio_BLE_start_advertising);
|
||||
|
||||
/// def stop_advertising(whitelist: bool) -> bool:
|
||||
/// def stop_advertising() -> bool:
|
||||
/// """
|
||||
/// Stop advertising
|
||||
/// """
|
||||
@ -357,10 +303,6 @@ STATIC const mp_obj_type_t mod_trezorio_BleInterface_type = {
|
||||
|
||||
STATIC const mp_rom_map_elem_t mod_trezorio_BLE_globals_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ble)},
|
||||
// {MP_ROM_QSTR(MP_QSTR_update_init),
|
||||
// MP_ROM_PTR(&mod_trezorio_BLE_update_init_obj)},
|
||||
// {MP_ROM_QSTR(MP_QSTR_update_chunk),
|
||||
// MP_ROM_PTR(&mod_trezorio_BLE_update_chunk_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_erase_bonds),
|
||||
MP_ROM_PTR(&mod_trezorio_BLE_erase_bonds_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_unpair), MP_ROM_PTR(&mod_trezorio_BLE_unpair_obj)},
|
||||
|
@ -31,7 +31,7 @@ def start_advertising(whitelist: bool, name: str | None) -> bool:
|
||||
|
||||
|
||||
# upymod/modtrezorio/modtrezorio-ble.h
|
||||
def stop_advertising(whitelist: bool) -> bool:
|
||||
def stop_advertising() -> bool:
|
||||
"""
|
||||
Stop advertising
|
||||
"""
|
||||
|
@ -87,6 +87,18 @@ def configure(
|
||||
features_available.append("touch")
|
||||
defines += [("USE_TOUCH", "1")]
|
||||
|
||||
sources += ["embed/io/button/unix/button.c"]
|
||||
sources += ["embed/io/button/button_fsm.c"]
|
||||
paths += ["embed/io/button/inc"]
|
||||
features_available.append("button")
|
||||
defines += [("USE_BUTTON", "1")]
|
||||
|
||||
if "ble" in features_wanted:
|
||||
sources += ["embed/io/ble/unix/ble.c"]
|
||||
paths += ["embed/io/ble/inc"]
|
||||
features_available.append("ble")
|
||||
defines += [("USE_BLE", "1")]
|
||||
|
||||
features_available.append("backlight")
|
||||
defines += [("USE_BACKLIGHT", "1")]
|
||||
|
||||
|
@ -50,10 +50,17 @@ import storage.device
|
||||
usb.bus.open(storage.device.get_device_id())
|
||||
|
||||
|
||||
# enable BLE, allow connections
|
||||
if utils.USE_BLE:
|
||||
from trezorio import ble
|
||||
ble.start_comm()
|
||||
|
||||
# allow connections from bonded peers if any
|
||||
if ble.peer_count() > 0:
|
||||
ble.start_advertising(True, storage.device.get_label())
|
||||
|
||||
del ble
|
||||
|
||||
|
||||
# run the endless loop
|
||||
while True:
|
||||
|
Loading…
Reference in New Issue
Block a user