|
|
|
@ -33,6 +33,7 @@ typedef struct _mp_obj_HID_t {
|
|
|
|
|
/// iface_num: int,
|
|
|
|
|
/// ep_in: int,
|
|
|
|
|
/// ep_out: int,
|
|
|
|
|
/// emu_port: int,
|
|
|
|
|
/// report_desc: bytes,
|
|
|
|
|
/// subclass: int = 0,
|
|
|
|
|
/// protocol: int = 0,
|
|
|
|
@ -54,6 +55,9 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
|
|
|
|
|
{MP_QSTR_ep_out,
|
|
|
|
|
MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT,
|
|
|
|
|
{.u_int = 0}},
|
|
|
|
|
{MP_QSTR_emu_port,
|
|
|
|
|
MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT,
|
|
|
|
|
{.u_int = 0}},
|
|
|
|
|
{MP_QSTR_subclass, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0}},
|
|
|
|
|
{MP_QSTR_protocol, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0}},
|
|
|
|
|
{MP_QSTR_polling_interval, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1}},
|
|
|
|
@ -69,12 +73,13 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
|
|
|
|
|
const mp_int_t iface_num = vals[0].u_int;
|
|
|
|
|
const mp_int_t ep_in = vals[1].u_int;
|
|
|
|
|
const mp_int_t ep_out = vals[2].u_int;
|
|
|
|
|
const mp_int_t subclass = vals[3].u_int;
|
|
|
|
|
const mp_int_t protocol = vals[4].u_int;
|
|
|
|
|
const mp_int_t polling_interval = vals[5].u_int;
|
|
|
|
|
const mp_int_t max_packet_len = vals[6].u_int;
|
|
|
|
|
const mp_int_t emu_port = vals[3].u_int;
|
|
|
|
|
const mp_int_t subclass = vals[4].u_int;
|
|
|
|
|
const mp_int_t protocol = vals[5].u_int;
|
|
|
|
|
const mp_int_t polling_interval = vals[6].u_int;
|
|
|
|
|
const mp_int_t max_packet_len = vals[7].u_int;
|
|
|
|
|
mp_buffer_info_t report_desc = {0};
|
|
|
|
|
mp_get_buffer_raise(vals[7].u_obj, &report_desc, MP_BUFFER_READ);
|
|
|
|
|
mp_get_buffer_raise(vals[8].u_obj, &report_desc, MP_BUFFER_READ);
|
|
|
|
|
|
|
|
|
|
if (report_desc.buf == NULL || report_desc.len == 0 ||
|
|
|
|
|
report_desc.len > 255) {
|
|
|
|
@ -83,6 +88,7 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
|
|
|
|
|
CHECK_PARAM_RANGE(iface_num, 0, 32)
|
|
|
|
|
CHECK_PARAM_RANGE(ep_in, 0, 255)
|
|
|
|
|
CHECK_PARAM_RANGE(ep_out, 0, 255)
|
|
|
|
|
CHECK_PARAM_RANGE(emu_port, 0, 65535)
|
|
|
|
|
CHECK_PARAM_RANGE(subclass, 0, 255)
|
|
|
|
|
CHECK_PARAM_RANGE(protocol, 0, 255)
|
|
|
|
|
CHECK_PARAM_RANGE(polling_interval, 1, 255)
|
|
|
|
@ -94,8 +100,12 @@ STATIC mp_obj_t mod_trezorio_HID_make_new(const mp_obj_type_t *type,
|
|
|
|
|
o->info.rx_buffer = m_new(uint8_t, max_packet_len);
|
|
|
|
|
o->info.report_desc = report_desc.buf;
|
|
|
|
|
o->info.iface_num = (uint8_t)(iface_num);
|
|
|
|
|
#ifdef TREZOR_EMULATOR
|
|
|
|
|
o->info.emu_port = (uint16_t)(emu_port);
|
|
|
|
|
#else
|
|
|
|
|
o->info.ep_in = (uint8_t)(ep_in);
|
|
|
|
|
o->info.ep_out = (uint8_t)(ep_out);
|
|
|
|
|
#endif
|
|
|
|
|
o->info.subclass = (uint8_t)(subclass);
|
|
|
|
|
o->info.protocol = (uint8_t)(protocol);
|
|
|
|
|
o->info.polling_interval = (uint8_t)(polling_interval);
|
|
|
|
|