1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

introduce msg.setup proof-of-concept

This commit is contained in:
Pavol Rusnak 2016-05-25 02:38:10 +02:00
parent bf02fe0ddf
commit 38b66cb6d8
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 40 additions and 0 deletions

View File

@ -36,6 +36,37 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_make_new(const mp_obj_type_t *type, size_t n_a
return MP_OBJ_FROM_PTR(o);
}
/// def trezor.msg.setup(ifaces: list) -> None
///
/// Setups USB interfaces with a list of tuples
///
STATIC mp_obj_t mod_TrezorMsg_Msg_setup(mp_obj_t self, mp_obj_t ifaces) {
mp_uint_t iface_cnt;
mp_obj_t *iface;
if (MP_OBJ_IS_TYPE(ifaces, &mp_type_tuple)) {
mp_obj_tuple_get(ifaces, &iface_cnt, &iface);
} else
if (MP_OBJ_IS_TYPE(ifaces, &mp_type_list)) {
mp_obj_list_get(ifaces, &iface_cnt, &iface);
} else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "List or tuple expected"));
}
for (mp_uint_t i = 0; i < iface_cnt; i++) {
if (!MP_OBJ_IS_TYPE(iface[i], &mp_type_tuple)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Tuple expected"));
}
mp_uint_t attr_cnt;
mp_obj_t *attr;
mp_obj_tuple_get(iface[i], &attr_cnt, &attr);
assert(attr_cnt == 2);
uint8_t ep = mp_obj_get_int(attr[0]);
uint16_t up = mp_obj_get_int(attr[1]);
printf("iface %d: ep=%d up=%04x\n", i, ep, up);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_setup_obj, mod_TrezorMsg_Msg_setup);
/// def trezor.msg.send(iface: int, message: bytes) -> int
///
/// Sends message using USB HID (device) or UDP (emulator).
@ -100,6 +131,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_select_obj, mod_TrezorMsg_Msg
STATIC const mp_rom_map_elem_t mod_TrezorMsg_Msg_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mod_TrezorMsg_Msg_select_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&mod_TrezorMsg_Msg_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_setup), MP_ROM_PTR(&mod_TrezorMsg_Msg_setup_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorMsg_Msg_locals_dict, mod_TrezorMsg_Msg_locals_dict_table);

View File

@ -1,4 +1,5 @@
import trezor.main
from trezor import msg
# Load all applications
from apps import homescreen
@ -10,6 +11,9 @@ homescreen.boot()
playground.boot()
# wallet.boot()
# just a demo to show how to register USB ifaces
msg.setup( [ (1, 0xF53C), (2, 0xF1D0) ] )
# Load default homescreen
from apps.homescreen.layout_homescreen import layout_homescreen

View File

@ -6,6 +6,10 @@ from TrezorMsg import Msg
_msg = Msg()
def setup(ifaces):
return _msg.setup(ifaces)
def select(timeout_us):
return _msg.select(timeout_us)