aboutsummaryrefslogtreecommitdiff
path: root/stmhal/usb.c
diff options
context:
space:
mode:
authorDamien George2015-04-13 16:59:05 +0100
committerDamien George2015-04-13 16:59:05 +0100
commitb1f68685ec462bcde572455c262cb78a53112816 (patch)
tree9f320ba8e128e1888dcf68a049b52791b31ad0df /stmhal/usb.c
parent99f718407336bf2bd1c07035399e9809f72d4586 (diff)
stmhal: In USB HID driver, make polling interval configurable.
When setting usb_mode to "HID", hid config object now has polling-interval (in ms) as the 4th element. It mmust now be a 5-tuple of the form: (subclass, protocol, max_packet_len, polling_interval, report_desc) The mouse and keyboard defaults have polling interval at 8ms.
Diffstat (limited to 'stmhal/usb.c')
-rw-r--r--stmhal/usb.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/stmhal/usb.c b/stmhal/usb.c
index 24aae1857..96833175f 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