diff --git a/stmhal/usb.c b/stmhal/usb.c index 24aae1857d..96833175ff 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -58,11 +58,12 @@ STATIC const mp_obj_str_t pyb_usb_hid_mouse_desc_obj = { }; const mp_obj_tuple_t pyb_usb_hid_mouse_obj = { {&mp_type_tuple}, - 4, + 5, { MP_OBJ_NEW_SMALL_INT(1), // subclass: boot MP_OBJ_NEW_SMALL_INT(2), // protocol: mouse MP_OBJ_NEW_SMALL_INT(USBD_HID_MOUSE_MAX_PACKET), + MP_OBJ_NEW_SMALL_INT(8), // polling interval: 8ms (mp_obj_t)&pyb_usb_hid_mouse_desc_obj, }, }; @@ -76,11 +77,12 @@ STATIC const mp_obj_str_t pyb_usb_hid_keyboard_desc_obj = { }; const mp_obj_tuple_t pyb_usb_hid_keyboard_obj = { {&mp_type_tuple}, - 4, + 5, { MP_OBJ_NEW_SMALL_INT(1), // subclass: boot MP_OBJ_NEW_SMALL_INT(1), // protocol: keyboard MP_OBJ_NEW_SMALL_INT(USBD_HID_KEYBOARD_MAX_PACKET), + MP_OBJ_NEW_SMALL_INT(8), // polling interval: 8ms (mp_obj_t)&pyb_usb_hid_keyboard_desc_obj, }, }; @@ -184,7 +186,7 @@ void usb_vcp_send_strn_cooked(const char *str, int len) { pyb.usb_mode('VCP+HID', vid=0xf055, pid=0x9800) # specify VID and PID pyb.usb_mode('VCP+HID', hid=pyb.hid_mouse) pyb.usb_mode('VCP+HID', hid=pyb.hid_keyboard) - pyb.usb_mode('VCP+HID', pid=0x1234, hid=(subclass, protocol, max_packet_len, report_desc)) + pyb.usb_mode('VCP+HID', pid=0x1234, hid=(subclass, protocol, max_packet_len, polling_interval, report_desc)) vcp = pyb.USB_VCP() # get the VCP device for read/write hid = pyb.USB_HID() # get the HID device for write/poll @@ -265,17 +267,18 @@ STATIC mp_obj_t pyb_usb_mode(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ USBD_HID_ModeInfoTypeDef hid_info; if (mode & USBD_MODE_HID) { mp_obj_t *items; - mp_obj_get_array_fixed_n(args[3].u_obj, 4, &items); + mp_obj_get_array_fixed_n(args[3].u_obj, 5, &items); hid_info.subclass = mp_obj_get_int(items[0]); hid_info.protocol = mp_obj_get_int(items[1]); hid_info.max_packet_len = mp_obj_get_int(items[2]); + hid_info.polling_interval = mp_obj_get_int(items[3]); mp_buffer_info_t bufinfo; - mp_get_buffer_raise(items[3], &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(items[4], &bufinfo, MP_BUFFER_READ); hid_info.report_desc = bufinfo.buf; hid_info.report_desc_len = bufinfo.len; // need to keep a copy of this so report_desc does not get GC'd - MP_STATE_PORT(pyb_hid_report_desc) = items[3]; + MP_STATE_PORT(pyb_hid_report_desc) = items[4]; } // init the USB device diff --git a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h b/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h index 7bf2cf955d..bc9d0d21a6 100644 --- a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h +++ b/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h @@ -44,6 +44,7 @@ typedef struct _USBD_HID_ModeInfoTypeDef { uint8_t subclass; // 0=no sub class, 1=boot uint8_t protocol; // 0=none, 1=keyboard, 2=mouse uint8_t max_packet_len; // only support up to 255 + uint8_t polling_interval; // in units of 1ms uint8_t report_desc_len; const uint8_t *report_desc; } USBD_HID_ModeInfoTypeDef; diff --git a/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c b/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c index 8af2124dc0..bbb666861b 100644 --- a/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c +++ b/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c @@ -38,6 +38,7 @@ #define HID_DESC_OFFSET_REPORT_DESC_LEN (16) #define HID_DESC_OFFSET_MAX_PACKET_LO (22) #define HID_DESC_OFFSET_MAX_PACKET_HI (23) +#define HID_DESC_OFFSET_POLLING_INTERVAL (24) #define HID_SUBDESC_LEN (9) #define CDC_IFACE_NUM_ALONE (0) @@ -605,6 +606,7 @@ int USBD_SelectMode(uint32_t mode, USBD_HID_ModeInfoTypeDef *hid_info) { hid_desc[HID_DESC_OFFSET_REPORT_DESC_LEN] = hid_info->report_desc_len; hid_desc[HID_DESC_OFFSET_MAX_PACKET_LO] = hid_info->max_packet_len; hid_desc[HID_DESC_OFFSET_MAX_PACKET_HI] = 0; + hid_desc[HID_DESC_OFFSET_POLLING_INTERVAL] = hid_info->polling_interval; hid_report_desc = hid_info->report_desc; }