From d207e8c242c1a72132c382bb16a5b4b57614b866 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 21 Apr 2017 18:12:33 +0200 Subject: [PATCH] modtrezormsg: add mock for unix build --- .../extmod/modtrezormsg/modtrezormsg-unix.h | 2 ++ .../extmod/modtrezormsg/modtrezormsg.c | 12 ++++---- .../extmod/modtrezormsg/unix-usb-mock.h | 28 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 micropython/extmod/modtrezormsg/unix-usb-mock.h diff --git a/micropython/extmod/modtrezormsg/modtrezormsg-unix.h b/micropython/extmod/modtrezormsg/modtrezormsg-unix.h index 76ffade130..375bf57bde 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg-unix.h +++ b/micropython/extmod/modtrezormsg/modtrezormsg-unix.h @@ -11,6 +11,8 @@ #include #include +#include "unix-usb-mock.h" + #define TREZOR_UDP_PORT 21324 static int s; diff --git a/micropython/extmod/modtrezormsg/modtrezormsg.c b/micropython/extmod/modtrezormsg/modtrezormsg.c index f2ddfcfc77..a988986aed 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg.c +++ b/micropython/extmod/modtrezormsg/modtrezormsg.c @@ -57,11 +57,11 @@ STATIC mp_obj_t mod_TrezorMsg_USB_make_new(const mp_obj_type_t *type, size_t n_a const mp_int_t vendor_id = vals[0].u_int; const mp_int_t product_id = vals[1].u_int; const mp_int_t release_num = vals[2].u_int; - const char *manufacturer_str = get_0str(vals[3].u_obj, 1, 32); - const char *product_str = get_0str(vals[4].u_obj, 1, 32); - const char *serial_number_str = get_0str(vals[5].u_obj, 1, 32); - const char *configuration_str = get_0str(vals[6].u_obj, 1, 32); - const char *interface_str = get_0str(vals[7].u_obj, 1, 32); + const char *manufacturer_str = get_0str(vals[3].u_obj, 0, 32); + const char *product_str = get_0str(vals[4].u_obj, 0, 32); + const char *serial_number_str = get_0str(vals[5].u_obj, 0, 32); + const char *configuration_str = get_0str(vals[6].u_obj, 0, 32); + const char *interface_str = get_0str(vals[7].u_obj, 0, 32); if (vendor_id < 0 || vendor_id > 65535) { mp_raise_ValueError("vendor_id is invalid"); @@ -317,14 +317,12 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_init_usb(mp_obj_t self, mp_obj_t usb_info, mp_ usb_deinit(); mp_raise_msg(&mp_type_RuntimeError, "failed to add HID interface"); } - } else if (MP_OBJ_IS_TYPE(iface, &mod_TrezorMsg_VCP_type)) { mp_obj_VCP_t *vcp = MP_OBJ_TO_PTR(iface); if (usb_vcp_add(&vcp->info) != 0) { usb_deinit(); mp_raise_msg(&mp_type_RuntimeError, "failed to add VCP interface"); } - } else { usb_deinit(); mp_raise_TypeError("expected HID or VCP type"); diff --git a/micropython/extmod/modtrezormsg/unix-usb-mock.h b/micropython/extmod/modtrezormsg/unix-usb-mock.h new file mode 100644 index 0000000000..6ee160a558 --- /dev/null +++ b/micropython/extmod/modtrezormsg/unix-usb-mock.h @@ -0,0 +1,28 @@ +#include "../../trezorhal/usb.h" + +int usb_init(const usb_dev_info_t *dev_info) { + return 0; +} + +int usb_deinit(void) { + return 0; +} + +int usb_start(void) { + return 0; +} + +int usb_stop(void) { + return 0; +} + +int usb_hid_add(const usb_hid_info_t *info) { + return 0; +} + +int usb_vcp_add(const usb_vcp_info_t *info) { + return 0; +} + +void pendsv_kbd_intr(void) { +}