refactor(core): conditional inclusion of BLE

tychovrahe/bluetooth/unification2
tychovrahe 1 year ago
parent 03dee83036
commit e1381f901b

@ -18,7 +18,7 @@ FEATURE_FLAGS = {
"SYSTEM_VIEW": False,
}
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", dma2d"]
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "ble", "dma2d"]
CCFLAGS_MOD = ''
CPPPATH_MOD = []
@ -379,10 +379,6 @@ SOURCE_TREZORHAL = [
'embed/trezorhal/usbd_ioreq.c',
'embed/trezorhal/util.s',
'embed/trezorhal/vectortable.s',
'embed/trezorhal/ble/comm.c',
'embed/trezorhal/ble/dfu.c',
'embed/trezorhal/ble/fwu.c',
'embed/trezorhal/ble/state.c',
]

@ -131,7 +131,9 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
ret->items[1] = usb_connected ? mp_const_true : mp_const_false;
return mp_const_true;
}
} else if (iface == BLE_EVENTS_IFACE) {
}
#ifdef USE_BLE
else if (iface == BLE_EVENTS_IFACE) {
ble_event_poll();
uint8_t connected = ble_connected();
if (connected != ble_connected_previously) {
@ -142,6 +144,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
}
}
#endif
#endif
#if USE_BUTTON
else if (iface == BUTTON_IFACE) {
const uint32_t evt = button_read();
@ -190,7 +193,9 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
return mp_const_true;
}
}
} else if (iface == BLE_IFACE_INT) {
}
#ifdef USE_BLE
else if (iface == BLE_IFACE_INT) {
if (mode == POLL_READ) {
uint8_t buf[64] = {0};
int len = ble_int_comm_receive(buf, sizeof(buf));
@ -219,6 +224,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
return mp_const_true;
}
}
#endif
}
if (mp_hal_ticks_ms() >= deadline) {

@ -50,7 +50,9 @@ bool ble_last_internal = false;
#include "modtrezorio-webusb.h"
#include "modtrezorio-usb.h"
// clang-format on
#ifdef USE_BLE
#include "modtrezorio-ble.h"
#endif
#ifdef USE_SBU
#include "modtrezorio-sbu.h"
#endif
@ -92,8 +94,9 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR_fatfs), MP_ROM_PTR(&mod_trezorio_fatfs_module)},
{MP_ROM_QSTR(MP_QSTR_sdcard), MP_ROM_PTR(&mod_trezorio_sdcard_module)},
#endif
#ifdef USE_BLE
{MP_ROM_QSTR(MP_QSTR_ble), MP_ROM_PTR(&mod_trezorio_BLE_module)},
#endif
#ifdef USE_TOUCH
{MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_INT(TOUCH_IFACE)},
{MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_ROM_INT((TOUCH_START >> 24) & 0xFFU)},

@ -230,6 +230,7 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
/// VERSION_MAJOR: int
/// VERSION_MINOR: int
/// VERSION_PATCH: int
/// USE_BLE: bool
/// USE_SD_CARD: bool
/// MODEL: str
/// EMULATOR: bool
@ -257,6 +258,11 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
#else
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_false},
#endif
#ifdef USE_BLE
{MP_ROM_QSTR(MP_QSTR_USE_BLE), mp_const_true},
#else
{MP_ROM_QSTR(MP_QSTR_USE_BLE), mp_const_false},
#endif
#if defined TREZOR_MODEL_1
{MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_QSTR(MP_QSTR_1)},
#elif defined TREZOR_MODEL_T

@ -63,6 +63,9 @@
#ifdef USE_SD_CARD
#include "sdcard.h"
#endif
#ifdef USE_BLE
#include "ble/comm.h"
#endif
#ifdef SYSTEM_VIEW
#include "systemview.h"
@ -73,8 +76,6 @@
#ifdef USE_SECP256K1_ZKP
#include "zkp_context.h"
#include "ble/comm.h"
#endif
// from util.s
@ -146,7 +147,9 @@ int main(void) {
sdcard_init();
#endif
#ifdef USE_BLE
ble_comm_init();
#endif
#if !defined TREZOR_MODEL_1
// jump to unprivileged mode

@ -69,6 +69,7 @@ SCM_REVISION: bytes
VERSION_MAJOR: int
VERSION_MINOR: int
VERSION_PATCH: int
USE_BLE: bool
USE_SD_CARD: bool
MODEL: str
EMULATOR: bool

@ -4,7 +4,6 @@ if TYPE_CHECKING:
from trezor.wire import Handler, Msg
from trezorio import WireInterface
workflow_handlers: dict[int, Handler] = {}
@ -55,17 +54,17 @@ def _find_message_handler_module(msg_type: int, iface: WireInterface) -> str:
if utils.USE_SD_CARD and msg_type == MessageType.SdProtect:
return "apps.management.sd_protect"
# BLE
if iface.iface_num() != 16 and iface.iface_num() != 17:
# cannot update over BLE
if msg_type == MessageType.UploadBLEFirmwareInit:
return "apps.management.ble.upload_ble_firmware_init"
if iface.iface_num() == 16:
if msg_type == MessageType.PairingRequest:
return "apps.management.ble.pairing_request"
if msg_type == MessageType.RepairRequest:
return "apps.management.ble.repair_request"
if utils.USE_BLE:
if iface.iface_num() != 16 and iface.iface_num() != 17:
# cannot update over BLE
if msg_type == MessageType.UploadBLEFirmwareInit:
return "apps.management.ble.upload_ble_firmware_init"
if iface.iface_num() == 16:
if msg_type == MessageType.PairingRequest:
return "apps.management.ble.pairing_request"
if msg_type == MessageType.RepairRequest:
return "apps.management.ble.repair_request"
# bitcoin
if msg_type == MessageType.AuthorizeCoinJoin:

@ -3,7 +3,6 @@ from mutex import Mutex
from trezor import log, loop, utils, wire, workflow
import apps.base
import bluetooth
import usb
apps.base.boot()
@ -27,15 +26,19 @@ mutex = Mutex()
mutex.add(usb.iface_wire.iface_num())
mutex.add(usb.iface_debug.iface_num())
mutex.add(bluetooth.iface_ble_int.iface_num())
mutex.add(bluetooth.iface_ble_ext.iface_num())
# initialize the wire codec
wire.setup(usb.iface_wire, mutex=mutex)
if __debug__:
wire.setup(usb.iface_debug, is_debug_session=True, mutex=mutex)
wire.setup(bluetooth.iface_ble_int, mutex=mutex)
wire.setup(bluetooth.iface_ble_ext, mutex=mutex)
if utils.USE_BLE:
import bluetooth
mutex.add(bluetooth.iface_ble_int.iface_num())
mutex.add(bluetooth.iface_ble_ext.iface_num())
wire.setup(bluetooth.iface_ble_int, mutex=mutex)
wire.setup(bluetooth.iface_ble_ext, mutex=mutex)
loop.run()

@ -5,6 +5,7 @@ from trezorutils import ( # noqa: F401
EMULATOR,
MODEL,
SCM_REVISION,
USE_BLE,
USE_SD_CARD,
VERSION_MAJOR,
VERSION_MINOR,

Loading…
Cancel
Save