Revision 5fafdf24 hw/usb-hid.c
b/hw/usb-hid.c | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* QEMU USB HID devices |
3 |
*
|
|
3 |
* |
|
4 | 4 |
* Copyright (c) 2005 Fabrice Bellard |
5 | 5 |
* Copyright (c) 2007 OpenMoko, Inc. (andrew@openedhand.com) |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | 8 |
* of this software and associated documentation files (the "Software"), to deal |
9 | 9 |
* in the Software without restriction, including without limitation the rights |
... | ... | |
96 | 96 |
0x01, /* u8 bNumInterfaces; (1) */ |
97 | 97 |
0x01, /* u8 bConfigurationValue; */ |
98 | 98 |
0x04, /* u8 iConfiguration; */ |
99 |
0xa0, /* u8 bmAttributes;
|
|
99 |
0xa0, /* u8 bmAttributes; |
|
100 | 100 |
Bit 7: must be set, |
101 | 101 |
6: Self-powered, |
102 | 102 |
5: Remote wakeup, |
103 | 103 |
4..0: resvd */ |
104 | 104 |
50, /* u8 MaxPower; */ |
105 |
|
|
105 |
|
|
106 | 106 |
/* USB 1.1: |
107 | 107 |
* USB 2.0, single TT organization (mandatory): |
108 | 108 |
* one interface, protocol 0 |
... | ... | |
124 | 124 |
0x01, /* u8 if_bInterfaceSubClass; */ |
125 | 125 |
0x02, /* u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ |
126 | 126 |
0x07, /* u8 if_iInterface; */ |
127 |
|
|
127 |
|
|
128 | 128 |
/* HID descriptor */ |
129 | 129 |
0x09, /* u8 bLength; */ |
130 | 130 |
0x21, /* u8 bDescriptorType; */ |
... | ... | |
151 | 151 |
0x01, /* u8 bNumInterfaces; (1) */ |
152 | 152 |
0x01, /* u8 bConfigurationValue; */ |
153 | 153 |
0x05, /* u8 iConfiguration; */ |
154 |
0xa0, /* u8 bmAttributes;
|
|
154 |
0xa0, /* u8 bmAttributes; |
|
155 | 155 |
Bit 7: must be set, |
156 | 156 |
6: Self-powered, |
157 | 157 |
5: Remote wakeup, |
158 | 158 |
4..0: resvd */ |
159 | 159 |
50, /* u8 MaxPower; */ |
160 |
|
|
160 |
|
|
161 | 161 |
/* USB 1.1: |
162 | 162 |
* USB 2.0, single TT organization (mandatory): |
163 | 163 |
* one interface, protocol 0 |
... | ... | |
206 | 206 |
0x01, /* u8 bNumInterfaces; (1) */ |
207 | 207 |
0x01, /* u8 bConfigurationValue; */ |
208 | 208 |
0x06, /* u8 iConfiguration; */ |
209 |
0xa0, /* u8 bmAttributes;
|
|
209 |
0xa0, /* u8 bmAttributes; |
|
210 | 210 |
Bit 7: must be set, |
211 | 211 |
6: Self-powered, |
212 | 212 |
5: Remote wakeup, |
... | ... | |
254 | 254 |
}; |
255 | 255 |
|
256 | 256 |
static const uint8_t qemu_mouse_hid_report_descriptor[] = { |
257 |
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,
|
|
257 |
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, |
|
258 | 258 |
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, |
259 |
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,
|
|
259 |
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, |
|
260 | 260 |
0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, |
261 |
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81,
|
|
261 |
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, |
|
262 | 262 |
0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06, |
263 | 263 |
0xC0, 0xC0, |
264 | 264 |
}; |
... | ... | |
474 | 474 |
0, "QEMU USB Mouse"); |
475 | 475 |
s->mouse_grabbed = 1; |
476 | 476 |
} |
477 |
|
|
477 |
|
|
478 | 478 |
dx = int_clamp(s->dx, -128, 127); |
479 | 479 |
dy = int_clamp(s->dy, -128, 127); |
480 | 480 |
dz = int_clamp(s->dz, -128, 127); |
... | ... | |
482 | 482 |
s->dx -= dx; |
483 | 483 |
s->dy -= dy; |
484 | 484 |
s->dz -= dz; |
485 |
|
|
485 |
|
|
486 | 486 |
b = 0; |
487 | 487 |
if (s->buttons_state & MOUSE_EVENT_LBUTTON) |
488 | 488 |
b |= 0x01; |
... | ... | |
490 | 490 |
b |= 0x02; |
491 | 491 |
if (s->buttons_state & MOUSE_EVENT_MBUTTON) |
492 | 492 |
b |= 0x04; |
493 |
|
|
493 |
|
|
494 | 494 |
buf[0] = b; |
495 | 495 |
buf[1] = dx; |
496 | 496 |
buf[2] = dy; |
... | ... | |
512 | 512 |
1, "QEMU USB Tablet"); |
513 | 513 |
s->mouse_grabbed = 1; |
514 | 514 |
} |
515 |
|
|
515 |
|
|
516 | 516 |
dz = int_clamp(s->dz, -128, 127); |
517 | 517 |
s->dz -= dz; |
518 | 518 |
|
... | ... | |
622 | 622 |
case DeviceRequest | USB_REQ_GET_DESCRIPTOR: |
623 | 623 |
switch(value >> 8) { |
624 | 624 |
case USB_DT_DEVICE: |
625 |
memcpy(data, qemu_mouse_dev_descriptor,
|
|
625 |
memcpy(data, qemu_mouse_dev_descriptor, |
|
626 | 626 |
sizeof(qemu_mouse_dev_descriptor)); |
627 | 627 |
ret = sizeof(qemu_mouse_dev_descriptor); |
628 | 628 |
break; |
629 | 629 |
case USB_DT_CONFIG: |
630 | 630 |
if (s->kind == USB_MOUSE) { |
631 |
memcpy(data, qemu_mouse_config_descriptor,
|
|
631 |
memcpy(data, qemu_mouse_config_descriptor, |
|
632 | 632 |
sizeof(qemu_mouse_config_descriptor)); |
633 | 633 |
ret = sizeof(qemu_mouse_config_descriptor); |
634 | 634 |
} else if (s->kind == USB_TABLET) { |
635 |
memcpy(data, qemu_tablet_config_descriptor,
|
|
635 |
memcpy(data, qemu_tablet_config_descriptor, |
|
636 | 636 |
sizeof(qemu_tablet_config_descriptor)); |
637 | 637 |
ret = sizeof(qemu_tablet_config_descriptor); |
638 | 638 |
} else if (s->kind == USB_KEYBOARD) { |
639 |
memcpy(data, qemu_keyboard_config_descriptor,
|
|
639 |
memcpy(data, qemu_keyboard_config_descriptor, |
|
640 | 640 |
sizeof(qemu_keyboard_config_descriptor)); |
641 | 641 |
ret = sizeof(qemu_keyboard_config_descriptor); |
642 | 642 |
} |
... | ... | |
702 | 702 |
switch(value >> 8) { |
703 | 703 |
case 0x22: |
704 | 704 |
if (s->kind == USB_MOUSE) { |
705 |
memcpy(data, qemu_mouse_hid_report_descriptor,
|
|
705 |
memcpy(data, qemu_mouse_hid_report_descriptor, |
|
706 | 706 |
sizeof(qemu_mouse_hid_report_descriptor)); |
707 | 707 |
ret = sizeof(qemu_mouse_hid_report_descriptor); |
708 | 708 |
} else if (s->kind == USB_TABLET) { |
709 |
memcpy(data, qemu_tablet_hid_report_descriptor,
|
|
709 |
memcpy(data, qemu_tablet_hid_report_descriptor, |
|
710 | 710 |
sizeof(qemu_tablet_hid_report_descriptor)); |
711 | 711 |
ret = sizeof(qemu_tablet_hid_report_descriptor); |
712 | 712 |
} else if (s->kind == USB_KEYBOARD) { |
713 |
memcpy(data, qemu_keyboard_hid_report_descriptor,
|
|
713 |
memcpy(data, qemu_keyboard_hid_report_descriptor, |
|
714 | 714 |
sizeof(qemu_keyboard_hid_report_descriptor)); |
715 | 715 |
ret = sizeof(qemu_keyboard_hid_report_descriptor); |
716 | 716 |
} |
Also available in: Unified diff