diff --git a/core/SConscript.unix b/core/SConscript.unix index b141002e41..30777ff7a5 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -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') diff --git a/core/embed/io/ble/unix/ble.c b/core/embed/io/ble/unix/ble.c new file mode 100644 index 0000000000..0165da4c8f --- /dev/null +++ b/core/embed/io/ble/unix/ble.c @@ -0,0 +1,30 @@ +#include +#include + +#include + +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; } diff --git a/core/embed/upymod/modtrezorio/modtrezorio-ble.h b/core/embed/upymod/modtrezorio/modtrezorio-ble.h index 593ac56db1..0c67c485be 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-ble.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-ble.h @@ -19,62 +19,8 @@ #include -// #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)}, diff --git a/core/mocks/generated/trezorio/ble.pyi b/core/mocks/generated/trezorio/ble.pyi index edae01d981..27a8411401 100644 --- a/core/mocks/generated/trezorio/ble.pyi +++ b/core/mocks/generated/trezorio/ble.pyi @@ -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 """ diff --git a/core/site_scons/models/T3W1/emulator.py b/core/site_scons/models/T3W1/emulator.py index 48e9929667..3873c1e5e5 100644 --- a/core/site_scons/models/T3W1/emulator.py +++ b/core/site_scons/models/T3W1/emulator.py @@ -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")] diff --git a/core/src/main.py b/core/src/main.py index f6433b5fcf..8b03772723 100644 --- a/core/src/main.py +++ b/core/src/main.py @@ -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: