Commit 976f8eef23eb571b6707d7bdec488f6c6ae4231b

Authored by balrog
1 parent e108dd01

Try to fix USB HID and make the HID reports readable.

Decode HID report Items in the comments.
Invert mouse wheel direction as per Alexander Graf's report and as we already do in the tablet.
Clamp the Relative values to -127:127 as we claimed in the HID descriptors.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4482 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 71 additions and 48 deletions
hw/usb-hid.c
@@ -256,53 +256,73 @@ static const uint8_t qemu_keyboard_config_descriptor[] = { @@ -256,53 +256,73 @@ static const uint8_t qemu_keyboard_config_descriptor[] = {
256 }; 256 };
257 257
258 static const uint8_t qemu_mouse_hid_report_descriptor[] = { 258 static const uint8_t qemu_mouse_hid_report_descriptor[] = {
259 - 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,  
260 - 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,  
261 - 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,  
262 - 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01,  
263 - 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38,  
264 - 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x03,  
265 - 0x81, 0x06, 0xC0, 0xC0, 259 + 0x05, 0x01, /* Usage Page (Generic Desktop) */
  260 + 0x09, 0x02, /* Usage (Mouse) */
  261 + 0xa1, 0x01, /* Collection (Application) */
  262 + 0x09, 0x01, /* Usage (Pointer) */
  263 + 0xa1, 0x00, /* Collection (Physical) */
  264 + 0x05, 0x09, /* Usage Page (Button) */
  265 + 0x19, 0x01, /* Usage Minimum (1) */
  266 + 0x29, 0x03, /* Usage Maximum (3) */
  267 + 0x15, 0x00, /* Logical Minimum (0) */
  268 + 0x25, 0x01, /* Logical Maximum (1) */
  269 + 0x95, 0x03, /* Report Count (3) */
  270 + 0x75, 0x01, /* Report Size (1) */
  271 + 0x81, 0x02, /* Input (Data, Variable, Absolute) */
  272 + 0x95, 0x01, /* Report Count (1) */
  273 + 0x75, 0x05, /* Report Size (5) */
  274 + 0x81, 0x01, /* Input (Constant) */
  275 + 0x05, 0x01, /* Usage Page (Generic Desktop) */
  276 + 0x09, 0x30, /* Usage (X) */
  277 + 0x09, 0x31, /* Usage (Y) */
  278 + 0x09, 0x38, /* Usage (Wheel) */
  279 + 0x15, 0x81, /* Logical Minimum (-0x7f) */
  280 + 0x25, 0x7f, /* Logical Maximum (0x7f) */
  281 + 0x75, 0x08, /* Report Size (8) */
  282 + 0x95, 0x03, /* Report Count (3) */
  283 + 0x81, 0x06, /* Input (Data, Variable, Relative) */
  284 + 0xc0, /* End Collection */
  285 + 0xc0, /* End Collection */
266 }; 286 };
267 287
268 static const uint8_t qemu_tablet_hid_report_descriptor[] = { 288 static const uint8_t qemu_tablet_hid_report_descriptor[] = {
269 - 0x05, 0x01, /* Usage Page Generic Desktop */  
270 - 0x09, 0x01, /* Usage Pointer */  
271 - 0xA1, 0x01, /* Collection Application */  
272 - 0x09, 0x01, /* Usage Pointer */  
273 - 0xA1, 0x00, /* Collection Physical */  
274 - 0x05, 0x09, /* Usage Page Button */  
275 - 0x19, 0x01, /* Usage Minimum Button 1 */  
276 - 0x29, 0x03, /* Usage Maximum Button 3 */  
277 - 0x15, 0x00, /* Logical Minimum 0 */  
278 - 0x25, 0x01, /* Logical Maximum 1 */  
279 - 0x95, 0x03, /* Report Count 3 */  
280 - 0x75, 0x01, /* Report Size 1 */  
281 - 0x81, 0x02, /* Input (Data, Var, Abs) */  
282 - 0x95, 0x01, /* Report Count 1 */  
283 - 0x75, 0x05, /* Report Size 5 */  
284 - 0x81, 0x01, /* Input (Cnst, Array, Abs) */  
285 - 0x05, 0x01, /* Usage Page Generic Desktop */  
286 - 0x09, 0x30, /* Usage X */  
287 - 0x09, 0x31, /* Usage Y */  
288 - 0x15, 0x00, /* Logical Minimum 0 */  
289 - 0x26, 0xFF, 0x7F, /* Logical Maximum 0x7fff */  
290 - 0x35, 0x00, /* Physical Minimum 0 */  
291 - 0x46, 0xFE, 0x7F, /* Physical Maximum 0x7fff */  
292 - 0x75, 0x10, /* Report Size 16 */  
293 - 0x95, 0x02, /* Report Count 2 */  
294 - 0x81, 0x02, /* Input (Data, Var, Abs) */  
295 - 0x05, 0x01, /* Usage Page Generic Desktop */  
296 - 0x09, 0x38, /* Usage Wheel */  
297 - 0x15, 0x81, /* Logical Minimum -127 */  
298 - 0x25, 0x7F, /* Logical Maximum 127 */  
299 - 0x35, 0x00, /* Physical Minimum 0 (same as logical) */  
300 - 0x45, 0x00, /* Physical Maximum 0 (same as logical) */  
301 - 0x75, 0x08, /* Report Size 8 */  
302 - 0x95, 0x01, /* Report Count 1 */  
303 - 0x81, 0x06, /* Input (Data, Var, Rel) */  
304 - 0xC0, /* End Collection */  
305 - 0xC0, /* End Collection */ 289 + 0x05, 0x01, /* Usage Page (Generic Desktop) */
  290 + 0x09, 0x01, /* Usage (Pointer) */
  291 + 0xa1, 0x01, /* Collection (Application) */
  292 + 0x09, 0x01, /* Usage (Pointer) */
  293 + 0xa1, 0x00, /* Collection (Physical) */
  294 + 0x05, 0x09, /* Usage Page (Button) */
  295 + 0x19, 0x01, /* Usage Minimum (1) */
  296 + 0x29, 0x03, /* Usage Maximum (3) */
  297 + 0x15, 0x00, /* Logical Minimum (0) */
  298 + 0x25, 0x01, /* Logical Maximum (1) */
  299 + 0x95, 0x03, /* Report Count (3) */
  300 + 0x75, 0x01, /* Report Size (1) */
  301 + 0x81, 0x02, /* Input (Data, Variable, Absolute) */
  302 + 0x95, 0x01, /* Report Count (1) */
  303 + 0x75, 0x05, /* Report Size (5) */
  304 + 0x81, 0x01, /* Input (Constant) */
  305 + 0x05, 0x01, /* Usage Page (Generic Desktop) */
  306 + 0x09, 0x30, /* Usage (X) */
  307 + 0x09, 0x31, /* Usage (Y) */
  308 + 0x15, 0x00, /* Logical Minimum (0) */
  309 + 0x26, 0xfe, 0x7f, /* Logical Maximum (0x7fff) */
  310 + 0x35, 0x00, /* Physical Minimum (0) */
  311 + 0x46, 0xfe, 0x7f, /* Physical Maximum (0x7fff) */
  312 + 0x75, 0x10, /* Report Size (16) */
  313 + 0x95, 0x02, /* Report Count (2) */
  314 + 0x81, 0x02, /* Input (Data, Variable, Absolute) */
  315 + 0x05, 0x01, /* Usage Page (Generic Desktop) */
  316 + 0x09, 0x38, /* Usage (Wheel) */
  317 + 0x15, 0x81, /* Logical Minimum (-0x7f) */
  318 + 0x25, 0x7f, /* Logical Maximum (0x7f) */
  319 + 0x35, 0x00, /* Physical Minimum (same as logical) */
  320 + 0x45, 0x00, /* Physical Maximum (same as logical) */
  321 + 0x75, 0x08, /* Report Size (8) */
  322 + 0x95, 0x01, /* Report Count (1) */
  323 + 0x81, 0x06, /* Input (Data, Variable, Relative) */
  324 + 0xc0, /* End Collection */
  325 + 0xc0, /* End Collection */
306 }; 326 };
307 327
308 static const uint8_t qemu_keyboard_hid_report_descriptor[] = { 328 static const uint8_t qemu_keyboard_hid_report_descriptor[] = {
@@ -477,14 +497,17 @@ static int usb_mouse_poll(USBHIDState *hs, uint8_t *buf, int len) @@ -477,14 +497,17 @@ static int usb_mouse_poll(USBHIDState *hs, uint8_t *buf, int len)
477 s->mouse_grabbed = 1; 497 s->mouse_grabbed = 1;
478 } 498 }
479 499
480 - dx = int_clamp(s->dx, -128, 127);  
481 - dy = int_clamp(s->dy, -128, 127);  
482 - dz = int_clamp(s->dz, -128, 127); 500 + dx = int_clamp(s->dx, -127, 127);
  501 + dy = int_clamp(s->dy, -127, 127);
  502 + dz = int_clamp(s->dz, -127, 127);
483 503
484 s->dx -= dx; 504 s->dx -= dx;
485 s->dy -= dy; 505 s->dy -= dy;
486 s->dz -= dz; 506 s->dz -= dz;
487 507
  508 + /* Appears we have to invert the wheel direction */
  509 + dz = 0 - dz;
  510 +
488 b = 0; 511 b = 0;
489 if (s->buttons_state & MOUSE_EVENT_LBUTTON) 512 if (s->buttons_state & MOUSE_EVENT_LBUTTON)
490 b |= 0x01; 513 b |= 0x01;
@@ -516,7 +539,7 @@ static int usb_tablet_poll(USBHIDState *hs, uint8_t *buf, int len) @@ -516,7 +539,7 @@ static int usb_tablet_poll(USBHIDState *hs, uint8_t *buf, int len)
516 s->mouse_grabbed = 1; 539 s->mouse_grabbed = 1;
517 } 540 }
518 541
519 - dz = int_clamp(s->dz, -128, 127); 542 + dz = int_clamp(s->dz, -127, 127);
520 s->dz -= dz; 543 s->dz -= dz;
521 544
522 /* Appears we have to invert the wheel direction */ 545 /* Appears we have to invert the wheel direction */