mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-06 14:52:33 +00:00
refactor(core): ble: expose connection state in micropython
[no changelog]
This commit is contained in:
parent
fe20466ed7
commit
23cc83f3ba
@ -126,6 +126,27 @@ STATIC mp_obj_t mod_trezorio_BLE_peer_count(void) {
|
|||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_BLE_peer_count_obj,
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_BLE_peer_count_obj,
|
||||||
mod_trezorio_BLE_peer_count);
|
mod_trezorio_BLE_peer_count);
|
||||||
|
|
||||||
|
/// def connection_state() -> int:
|
||||||
|
/// """
|
||||||
|
/// Returns current connection state as flags:
|
||||||
|
///
|
||||||
|
/// 0x01 state known
|
||||||
|
/// 0x02 connectable
|
||||||
|
/// 0x04 connected
|
||||||
|
/// 0x08 pairing
|
||||||
|
/// 0x10 pairing request
|
||||||
|
/// """
|
||||||
|
STATIC mp_obj_t mod_trezorio_BLE_connection_state(void) {
|
||||||
|
ble_state_t state;
|
||||||
|
ble_get_state(&state);
|
||||||
|
mp_int_t flags = (state.state_known << 0) | (state.connectable << 1) |
|
||||||
|
(state.connected << 2) | (state.pairing << 3) |
|
||||||
|
(state.pairing_requested << 4);
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(flags);
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_BLE_connection_state_obj,
|
||||||
|
mod_trezorio_BLE_connection_state);
|
||||||
|
|
||||||
const size_t CODE_LEN = 6;
|
const size_t CODE_LEN = 6;
|
||||||
static bool encode_pairing_code(mp_obj_t obj, uint8_t *outbuf) {
|
static bool encode_pairing_code(mp_obj_t obj, uint8_t *outbuf) {
|
||||||
mp_int_t code = mp_obj_get_int(obj);
|
mp_int_t code = mp_obj_get_int(obj);
|
||||||
@ -295,6 +316,8 @@ STATIC const mp_rom_map_elem_t mod_trezorio_BLE_globals_table[] = {
|
|||||||
MP_ROM_PTR(&mod_trezorio_BLE_disconnect_obj)},
|
MP_ROM_PTR(&mod_trezorio_BLE_disconnect_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_peer_count),
|
{MP_ROM_QSTR(MP_QSTR_peer_count),
|
||||||
MP_ROM_PTR(&mod_trezorio_BLE_peer_count_obj)},
|
MP_ROM_PTR(&mod_trezorio_BLE_peer_count_obj)},
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_connection_state),
|
||||||
|
MP_ROM_PTR(&mod_trezorio_BLE_connection_state_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_allow_pairing),
|
{MP_ROM_QSTR(MP_QSTR_allow_pairing),
|
||||||
MP_ROM_PTR(&mod_trezorio_BLE_allow_pairing_obj)},
|
MP_ROM_PTR(&mod_trezorio_BLE_allow_pairing_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_reject_pairing),
|
{MP_ROM_QSTR(MP_QSTR_reject_pairing),
|
||||||
|
@ -51,6 +51,19 @@ def peer_count() -> int:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# upymod/modtrezorio/modtrezorio-ble.h
|
||||||
|
def connection_state() -> int:
|
||||||
|
"""
|
||||||
|
Returns current connection state as flags:
|
||||||
|
|
||||||
|
0x01 state known
|
||||||
|
0x02 connectable
|
||||||
|
0x04 connected
|
||||||
|
0x08 pairing
|
||||||
|
0x10 pairing request
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
# upymod/modtrezorio/modtrezorio-ble.h
|
# upymod/modtrezorio/modtrezorio-ble.h
|
||||||
def allow_pairing(code: int) -> bool:
|
def allow_pairing(code: int) -> bool:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user