root / hw / usb-wacom.c @ 4118a970
History | View | Annotate | Download (11.1 kB)
1 | f6d2a316 | balrog | /*
|
---|---|---|---|
2 | f6d2a316 | balrog | * Wacom PenPartner USB tablet emulation.
|
3 | f6d2a316 | balrog | *
|
4 | f6d2a316 | balrog | * Copyright (c) 2006 Openedhand Ltd.
|
5 | f6d2a316 | balrog | * Author: Andrzej Zaborowski <balrog@zabor.org>
|
6 | f6d2a316 | balrog | *
|
7 | f6d2a316 | balrog | * Based on hw/usb-hid.c:
|
8 | f6d2a316 | balrog | * Copyright (c) 2005 Fabrice Bellard
|
9 | f6d2a316 | balrog | *
|
10 | f6d2a316 | balrog | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
11 | f6d2a316 | balrog | * of this software and associated documentation files (the "Software"), to deal
|
12 | f6d2a316 | balrog | * in the Software without restriction, including without limitation the rights
|
13 | f6d2a316 | balrog | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14 | f6d2a316 | balrog | * copies of the Software, and to permit persons to whom the Software is
|
15 | f6d2a316 | balrog | * furnished to do so, subject to the following conditions:
|
16 | f6d2a316 | balrog | *
|
17 | f6d2a316 | balrog | * The above copyright notice and this permission notice shall be included in
|
18 | f6d2a316 | balrog | * all copies or substantial portions of the Software.
|
19 | f6d2a316 | balrog | *
|
20 | f6d2a316 | balrog | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21 | f6d2a316 | balrog | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22 | f6d2a316 | balrog | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
23 | f6d2a316 | balrog | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24 | f6d2a316 | balrog | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25 | f6d2a316 | balrog | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
26 | f6d2a316 | balrog | * THE SOFTWARE.
|
27 | f6d2a316 | balrog | */
|
28 | f6d2a316 | balrog | #include "vl.h" |
29 | f6d2a316 | balrog | |
30 | f6d2a316 | balrog | /* Interface requests */
|
31 | f6d2a316 | balrog | #define WACOM_GET_REPORT 0x2101 |
32 | f6d2a316 | balrog | #define WACOM_SET_REPORT 0x2109 |
33 | f6d2a316 | balrog | |
34 | f6d2a316 | balrog | /* HID interface requests */
|
35 | f6d2a316 | balrog | #define HID_GET_REPORT 0xa101 |
36 | f6d2a316 | balrog | #define HID_GET_IDLE 0xa102 |
37 | f6d2a316 | balrog | #define HID_GET_PROTOCOL 0xa103 |
38 | f6d2a316 | balrog | #define HID_SET_IDLE 0x210a |
39 | f6d2a316 | balrog | #define HID_SET_PROTOCOL 0x210b |
40 | f6d2a316 | balrog | |
41 | f6d2a316 | balrog | typedef struct USBWacomState { |
42 | f6d2a316 | balrog | USBDevice dev; |
43 | f6d2a316 | balrog | QEMUPutMouseEntry *eh_entry; |
44 | f6d2a316 | balrog | int dx, dy, dz, buttons_state;
|
45 | f6d2a316 | balrog | int x, y;
|
46 | f6d2a316 | balrog | int mouse_grabbed;
|
47 | f6d2a316 | balrog | enum {
|
48 | f6d2a316 | balrog | WACOM_MODE_HID = 1,
|
49 | f6d2a316 | balrog | WACOM_MODE_WACOM = 2,
|
50 | f6d2a316 | balrog | } mode; |
51 | f6d2a316 | balrog | } USBWacomState; |
52 | f6d2a316 | balrog | |
53 | f6d2a316 | balrog | static const uint8_t qemu_wacom_dev_descriptor[] = { |
54 | f6d2a316 | balrog | 0x12, /* u8 bLength; */ |
55 | f6d2a316 | balrog | 0x01, /* u8 bDescriptorType; Device */ |
56 | f6d2a316 | balrog | 0x10, 0x10, /* u16 bcdUSB; v1.10 */ |
57 | f6d2a316 | balrog | |
58 | f6d2a316 | balrog | 0x00, /* u8 bDeviceClass; */ |
59 | f6d2a316 | balrog | 0x00, /* u8 bDeviceSubClass; */ |
60 | f6d2a316 | balrog | 0x00, /* u8 bDeviceProtocol; [ low/full speeds only ] */ |
61 | f6d2a316 | balrog | 0x08, /* u8 bMaxPacketSize0; 8 Bytes */ |
62 | f6d2a316 | balrog | |
63 | f6d2a316 | balrog | 0x6a, 0x05, /* u16 idVendor; */ |
64 | f6d2a316 | balrog | 0x00, 0x00, /* u16 idProduct; */ |
65 | f6d2a316 | balrog | 0x10, 0x42, /* u16 bcdDevice */ |
66 | f6d2a316 | balrog | |
67 | f6d2a316 | balrog | 0x01, /* u8 iManufacturer; */ |
68 | f6d2a316 | balrog | 0x02, /* u8 iProduct; */ |
69 | f6d2a316 | balrog | 0x00, /* u8 iSerialNumber; */ |
70 | f6d2a316 | balrog | 0x01, /* u8 bNumConfigurations; */ |
71 | f6d2a316 | balrog | }; |
72 | f6d2a316 | balrog | |
73 | f6d2a316 | balrog | static const uint8_t qemu_wacom_config_descriptor[] = { |
74 | f6d2a316 | balrog | /* one configuration */
|
75 | f6d2a316 | balrog | 0x09, /* u8 bLength; */ |
76 | f6d2a316 | balrog | 0x02, /* u8 bDescriptorType; Configuration */ |
77 | f6d2a316 | balrog | 0x22, 0x00, /* u16 wTotalLength; */ |
78 | f6d2a316 | balrog | 0x01, /* u8 bNumInterfaces; (1) */ |
79 | f6d2a316 | balrog | 0x01, /* u8 bConfigurationValue; */ |
80 | f6d2a316 | balrog | 0x00, /* u8 iConfiguration; */ |
81 | 5fafdf24 | ths | 0x80, /* u8 bmAttributes; |
82 | f6d2a316 | balrog | Bit 7: must be set,
|
83 | f6d2a316 | balrog | 6: Self-powered,
|
84 | f6d2a316 | balrog | 5: Remote wakeup,
|
85 | f6d2a316 | balrog | 4..0: resvd */
|
86 | f6d2a316 | balrog | 40, /* u8 MaxPower; */ |
87 | f6d2a316 | balrog | |
88 | f6d2a316 | balrog | /* one interface */
|
89 | f6d2a316 | balrog | 0x09, /* u8 if_bLength; */ |
90 | f6d2a316 | balrog | 0x04, /* u8 if_bDescriptorType; Interface */ |
91 | f6d2a316 | balrog | 0x00, /* u8 if_bInterfaceNumber; */ |
92 | f6d2a316 | balrog | 0x00, /* u8 if_bAlternateSetting; */ |
93 | f6d2a316 | balrog | 0x01, /* u8 if_bNumEndpoints; */ |
94 | f6d2a316 | balrog | 0x03, /* u8 if_bInterfaceClass; HID */ |
95 | f6d2a316 | balrog | 0x01, /* u8 if_bInterfaceSubClass; Boot */ |
96 | f6d2a316 | balrog | 0x02, /* u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ |
97 | f6d2a316 | balrog | 0x00, /* u8 if_iInterface; */ |
98 | f6d2a316 | balrog | |
99 | f6d2a316 | balrog | /* HID descriptor */
|
100 | f6d2a316 | balrog | 0x09, /* u8 bLength; */ |
101 | f6d2a316 | balrog | 0x21, /* u8 bDescriptorType; */ |
102 | f6d2a316 | balrog | 0x01, 0x10, /* u16 HID_class */ |
103 | f6d2a316 | balrog | 0x00, /* u8 country_code */ |
104 | f6d2a316 | balrog | 0x01, /* u8 num_descriptors */ |
105 | f6d2a316 | balrog | 0x22, /* u8 type; Report */ |
106 | f6d2a316 | balrog | 0x6e, 0x00, /* u16 len */ |
107 | f6d2a316 | balrog | |
108 | f6d2a316 | balrog | /* one endpoint (status change endpoint) */
|
109 | f6d2a316 | balrog | 0x07, /* u8 ep_bLength; */ |
110 | f6d2a316 | balrog | 0x05, /* u8 ep_bDescriptorType; Endpoint */ |
111 | f6d2a316 | balrog | 0x81, /* u8 ep_bEndpointAddress; IN Endpoint 1 */ |
112 | f6d2a316 | balrog | 0x03, /* u8 ep_bmAttributes; Interrupt */ |
113 | f6d2a316 | balrog | 0x08, 0x00, /* u16 ep_wMaxPacketSize; */ |
114 | f6d2a316 | balrog | 0x0a, /* u8 ep_bInterval; */ |
115 | f6d2a316 | balrog | }; |
116 | f6d2a316 | balrog | |
117 | f6d2a316 | balrog | static void usb_mouse_event(void *opaque, |
118 | f6d2a316 | balrog | int dx1, int dy1, int dz1, int buttons_state) |
119 | f6d2a316 | balrog | { |
120 | f6d2a316 | balrog | USBWacomState *s = opaque; |
121 | f6d2a316 | balrog | |
122 | f6d2a316 | balrog | s->dx += dx1; |
123 | f6d2a316 | balrog | s->dy += dy1; |
124 | f6d2a316 | balrog | s->dz += dz1; |
125 | f6d2a316 | balrog | s->buttons_state = buttons_state; |
126 | f6d2a316 | balrog | } |
127 | f6d2a316 | balrog | |
128 | f6d2a316 | balrog | static void usb_wacom_event(void *opaque, |
129 | f6d2a316 | balrog | int x, int y, int dz, int buttons_state) |
130 | f6d2a316 | balrog | { |
131 | f6d2a316 | balrog | USBWacomState *s = opaque; |
132 | f6d2a316 | balrog | |
133 | f6d2a316 | balrog | s->x = x; |
134 | f6d2a316 | balrog | s->y = y; |
135 | f6d2a316 | balrog | s->dz += dz; |
136 | f6d2a316 | balrog | s->buttons_state = buttons_state; |
137 | f6d2a316 | balrog | } |
138 | f6d2a316 | balrog | |
139 | f6d2a316 | balrog | static inline int int_clamp(int val, int vmin, int vmax) |
140 | f6d2a316 | balrog | { |
141 | f6d2a316 | balrog | if (val < vmin)
|
142 | f6d2a316 | balrog | return vmin;
|
143 | f6d2a316 | balrog | else if (val > vmax) |
144 | f6d2a316 | balrog | return vmax;
|
145 | f6d2a316 | balrog | else
|
146 | f6d2a316 | balrog | return val;
|
147 | f6d2a316 | balrog | } |
148 | f6d2a316 | balrog | |
149 | f6d2a316 | balrog | static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, int len) |
150 | f6d2a316 | balrog | { |
151 | f6d2a316 | balrog | int dx, dy, dz, b, l;
|
152 | f6d2a316 | balrog | |
153 | f6d2a316 | balrog | if (!s->mouse_grabbed) {
|
154 | f6d2a316 | balrog | s->eh_entry = qemu_add_mouse_event_handler(usb_mouse_event, s, 0,
|
155 | f6d2a316 | balrog | "QEMU PenPartner tablet");
|
156 | f6d2a316 | balrog | s->mouse_grabbed = 1;
|
157 | f6d2a316 | balrog | } |
158 | f6d2a316 | balrog | |
159 | f6d2a316 | balrog | dx = int_clamp(s->dx, -128, 127); |
160 | f6d2a316 | balrog | dy = int_clamp(s->dy, -128, 127); |
161 | f6d2a316 | balrog | dz = int_clamp(s->dz, -128, 127); |
162 | f6d2a316 | balrog | |
163 | f6d2a316 | balrog | s->dx -= dx; |
164 | f6d2a316 | balrog | s->dy -= dy; |
165 | f6d2a316 | balrog | s->dz -= dz; |
166 | f6d2a316 | balrog | |
167 | f6d2a316 | balrog | b = 0;
|
168 | f6d2a316 | balrog | if (s->buttons_state & MOUSE_EVENT_LBUTTON)
|
169 | f6d2a316 | balrog | b |= 0x01;
|
170 | f6d2a316 | balrog | if (s->buttons_state & MOUSE_EVENT_RBUTTON)
|
171 | f6d2a316 | balrog | b |= 0x02;
|
172 | f6d2a316 | balrog | if (s->buttons_state & MOUSE_EVENT_MBUTTON)
|
173 | f6d2a316 | balrog | b |= 0x04;
|
174 | f6d2a316 | balrog | |
175 | f6d2a316 | balrog | buf[0] = b;
|
176 | f6d2a316 | balrog | buf[1] = dx;
|
177 | f6d2a316 | balrog | buf[2] = dy;
|
178 | f6d2a316 | balrog | l = 3;
|
179 | f6d2a316 | balrog | if (len >= 4) { |
180 | f6d2a316 | balrog | buf[3] = dz;
|
181 | f6d2a316 | balrog | l = 4;
|
182 | f6d2a316 | balrog | } |
183 | f6d2a316 | balrog | return l;
|
184 | f6d2a316 | balrog | } |
185 | f6d2a316 | balrog | |
186 | f6d2a316 | balrog | static int usb_wacom_poll(USBWacomState *s, uint8_t *buf, int len) |
187 | f6d2a316 | balrog | { |
188 | f6d2a316 | balrog | int b;
|
189 | f6d2a316 | balrog | |
190 | f6d2a316 | balrog | if (!s->mouse_grabbed) {
|
191 | f6d2a316 | balrog | s->eh_entry = qemu_add_mouse_event_handler(usb_wacom_event, s, 1,
|
192 | f6d2a316 | balrog | "QEMU PenPartner tablet");
|
193 | f6d2a316 | balrog | s->mouse_grabbed = 1;
|
194 | f6d2a316 | balrog | } |
195 | f6d2a316 | balrog | |
196 | f6d2a316 | balrog | b = 0;
|
197 | f6d2a316 | balrog | if (s->buttons_state & MOUSE_EVENT_LBUTTON)
|
198 | f6d2a316 | balrog | b |= 0x01;
|
199 | f6d2a316 | balrog | if (s->buttons_state & MOUSE_EVENT_RBUTTON)
|
200 | f6d2a316 | balrog | b |= 0x02;
|
201 | f6d2a316 | balrog | if (s->buttons_state & MOUSE_EVENT_MBUTTON)
|
202 | f6d2a316 | balrog | b |= 0x04;
|
203 | f6d2a316 | balrog | |
204 | f6d2a316 | balrog | if (len < 7) |
205 | f6d2a316 | balrog | return 0; |
206 | f6d2a316 | balrog | |
207 | f6d2a316 | balrog | buf[0] = s->mode;
|
208 | f6d2a316 | balrog | buf[5] = 0x00; |
209 | f6d2a316 | balrog | if (b) {
|
210 | f6d2a316 | balrog | buf[1] = s->x & 0xff; |
211 | f6d2a316 | balrog | buf[2] = s->x >> 8; |
212 | f6d2a316 | balrog | buf[3] = s->y & 0xff; |
213 | f6d2a316 | balrog | buf[4] = s->y >> 8; |
214 | f6d2a316 | balrog | buf[6] = 0; |
215 | f6d2a316 | balrog | } else {
|
216 | f6d2a316 | balrog | buf[1] = 0; |
217 | f6d2a316 | balrog | buf[2] = 0; |
218 | f6d2a316 | balrog | buf[3] = 0; |
219 | f6d2a316 | balrog | buf[4] = 0; |
220 | f6d2a316 | balrog | buf[6] = (unsigned char) -127; |
221 | f6d2a316 | balrog | } |
222 | f6d2a316 | balrog | |
223 | f6d2a316 | balrog | return 7; |
224 | f6d2a316 | balrog | } |
225 | f6d2a316 | balrog | |
226 | f6d2a316 | balrog | static void usb_wacom_handle_reset(USBDevice *dev) |
227 | f6d2a316 | balrog | { |
228 | f6d2a316 | balrog | USBWacomState *s = (USBWacomState *) dev; |
229 | f6d2a316 | balrog | |
230 | f6d2a316 | balrog | s->dx = 0;
|
231 | f6d2a316 | balrog | s->dy = 0;
|
232 | f6d2a316 | balrog | s->dz = 0;
|
233 | f6d2a316 | balrog | s->x = 0;
|
234 | f6d2a316 | balrog | s->y = 0;
|
235 | f6d2a316 | balrog | s->buttons_state = 0;
|
236 | f6d2a316 | balrog | s->mode = WACOM_MODE_HID; |
237 | f6d2a316 | balrog | } |
238 | f6d2a316 | balrog | |
239 | f6d2a316 | balrog | static int usb_wacom_handle_control(USBDevice *dev, int request, int value, |
240 | f6d2a316 | balrog | int index, int length, uint8_t *data) |
241 | f6d2a316 | balrog | { |
242 | f6d2a316 | balrog | USBWacomState *s = (USBWacomState *) dev; |
243 | f6d2a316 | balrog | int ret = 0; |
244 | f6d2a316 | balrog | |
245 | f6d2a316 | balrog | switch (request) {
|
246 | f6d2a316 | balrog | case DeviceRequest | USB_REQ_GET_STATUS:
|
247 | f6d2a316 | balrog | data[0] = (1 << USB_DEVICE_SELF_POWERED) | |
248 | f6d2a316 | balrog | (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP); |
249 | f6d2a316 | balrog | data[1] = 0x00; |
250 | f6d2a316 | balrog | ret = 2;
|
251 | f6d2a316 | balrog | break;
|
252 | f6d2a316 | balrog | case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
|
253 | f6d2a316 | balrog | if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
254 | f6d2a316 | balrog | dev->remote_wakeup = 0;
|
255 | f6d2a316 | balrog | } else {
|
256 | f6d2a316 | balrog | goto fail;
|
257 | f6d2a316 | balrog | } |
258 | f6d2a316 | balrog | ret = 0;
|
259 | f6d2a316 | balrog | break;
|
260 | f6d2a316 | balrog | case DeviceOutRequest | USB_REQ_SET_FEATURE:
|
261 | f6d2a316 | balrog | if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
262 | f6d2a316 | balrog | dev->remote_wakeup = 1;
|
263 | f6d2a316 | balrog | } else {
|
264 | f6d2a316 | balrog | goto fail;
|
265 | f6d2a316 | balrog | } |
266 | f6d2a316 | balrog | ret = 0;
|
267 | f6d2a316 | balrog | break;
|
268 | f6d2a316 | balrog | case DeviceOutRequest | USB_REQ_SET_ADDRESS:
|
269 | f6d2a316 | balrog | dev->addr = value; |
270 | f6d2a316 | balrog | ret = 0;
|
271 | f6d2a316 | balrog | break;
|
272 | f6d2a316 | balrog | case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
|
273 | f6d2a316 | balrog | switch (value >> 8) { |
274 | f6d2a316 | balrog | case USB_DT_DEVICE:
|
275 | 5fafdf24 | ths | memcpy(data, qemu_wacom_dev_descriptor, |
276 | f6d2a316 | balrog | sizeof(qemu_wacom_dev_descriptor));
|
277 | f6d2a316 | balrog | ret = sizeof(qemu_wacom_dev_descriptor);
|
278 | f6d2a316 | balrog | break;
|
279 | f6d2a316 | balrog | case USB_DT_CONFIG:
|
280 | 5fafdf24 | ths | memcpy(data, qemu_wacom_config_descriptor, |
281 | f6d2a316 | balrog | sizeof(qemu_wacom_config_descriptor));
|
282 | f6d2a316 | balrog | ret = sizeof(qemu_wacom_config_descriptor);
|
283 | f6d2a316 | balrog | break;
|
284 | f6d2a316 | balrog | case USB_DT_STRING:
|
285 | f6d2a316 | balrog | switch (value & 0xff) { |
286 | f6d2a316 | balrog | case 0: |
287 | f6d2a316 | balrog | /* language ids */
|
288 | f6d2a316 | balrog | data[0] = 4; |
289 | f6d2a316 | balrog | data[1] = 3; |
290 | f6d2a316 | balrog | data[2] = 0x09; |
291 | f6d2a316 | balrog | data[3] = 0x04; |
292 | f6d2a316 | balrog | ret = 4;
|
293 | f6d2a316 | balrog | break;
|
294 | f6d2a316 | balrog | case 1: |
295 | f6d2a316 | balrog | /* serial number */
|
296 | f6d2a316 | balrog | ret = set_usb_string(data, "1");
|
297 | f6d2a316 | balrog | break;
|
298 | f6d2a316 | balrog | case 2: |
299 | f6d2a316 | balrog | ret = set_usb_string(data, "Wacom PenPartner");
|
300 | f6d2a316 | balrog | break;
|
301 | f6d2a316 | balrog | case 3: |
302 | f6d2a316 | balrog | /* vendor description */
|
303 | f6d2a316 | balrog | ret = set_usb_string(data, "QEMU " QEMU_VERSION);
|
304 | f6d2a316 | balrog | break;
|
305 | f6d2a316 | balrog | case 4: |
306 | f6d2a316 | balrog | ret = set_usb_string(data, "Wacom Tablet");
|
307 | f6d2a316 | balrog | break;
|
308 | f6d2a316 | balrog | case 5: |
309 | f6d2a316 | balrog | ret = set_usb_string(data, "Endpoint1 Interrupt Pipe");
|
310 | f6d2a316 | balrog | break;
|
311 | f6d2a316 | balrog | default:
|
312 | f6d2a316 | balrog | goto fail;
|
313 | f6d2a316 | balrog | } |
314 | f6d2a316 | balrog | break;
|
315 | f6d2a316 | balrog | default:
|
316 | f6d2a316 | balrog | goto fail;
|
317 | f6d2a316 | balrog | } |
318 | f6d2a316 | balrog | break;
|
319 | f6d2a316 | balrog | case DeviceRequest | USB_REQ_GET_CONFIGURATION:
|
320 | f6d2a316 | balrog | data[0] = 1; |
321 | f6d2a316 | balrog | ret = 1;
|
322 | f6d2a316 | balrog | break;
|
323 | f6d2a316 | balrog | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
|
324 | f6d2a316 | balrog | ret = 0;
|
325 | f6d2a316 | balrog | break;
|
326 | f6d2a316 | balrog | case DeviceRequest | USB_REQ_GET_INTERFACE:
|
327 | f6d2a316 | balrog | data[0] = 0; |
328 | f6d2a316 | balrog | ret = 1;
|
329 | f6d2a316 | balrog | break;
|
330 | f6d2a316 | balrog | case DeviceOutRequest | USB_REQ_SET_INTERFACE:
|
331 | f6d2a316 | balrog | ret = 0;
|
332 | f6d2a316 | balrog | break;
|
333 | f6d2a316 | balrog | case WACOM_SET_REPORT:
|
334 | f6d2a316 | balrog | qemu_remove_mouse_event_handler(s->eh_entry); |
335 | f6d2a316 | balrog | s->mouse_grabbed = 0;
|
336 | f6d2a316 | balrog | s->mode = data[0];
|
337 | f6d2a316 | balrog | ret = 0;
|
338 | f6d2a316 | balrog | break;
|
339 | f6d2a316 | balrog | case WACOM_GET_REPORT:
|
340 | f6d2a316 | balrog | data[0] = 0; |
341 | f6d2a316 | balrog | data[1] = s->mode;
|
342 | f6d2a316 | balrog | ret = 2;
|
343 | f6d2a316 | balrog | break;
|
344 | f6d2a316 | balrog | /* USB HID requests */
|
345 | f6d2a316 | balrog | case HID_GET_REPORT:
|
346 | f6d2a316 | balrog | if (s->mode == WACOM_MODE_HID)
|
347 | f6d2a316 | balrog | ret = usb_mouse_poll(s, data, length); |
348 | f6d2a316 | balrog | else if (s->mode == WACOM_MODE_WACOM) |
349 | f6d2a316 | balrog | ret = usb_wacom_poll(s, data, length); |
350 | f6d2a316 | balrog | break;
|
351 | f6d2a316 | balrog | case HID_SET_IDLE:
|
352 | f6d2a316 | balrog | ret = 0;
|
353 | f6d2a316 | balrog | break;
|
354 | f6d2a316 | balrog | default:
|
355 | f6d2a316 | balrog | fail:
|
356 | f6d2a316 | balrog | ret = USB_RET_STALL; |
357 | f6d2a316 | balrog | break;
|
358 | f6d2a316 | balrog | } |
359 | f6d2a316 | balrog | return ret;
|
360 | f6d2a316 | balrog | } |
361 | f6d2a316 | balrog | |
362 | f6d2a316 | balrog | static int usb_wacom_handle_data(USBDevice *dev, USBPacket *p) |
363 | f6d2a316 | balrog | { |
364 | f6d2a316 | balrog | USBWacomState *s = (USBWacomState *) dev; |
365 | f6d2a316 | balrog | int ret = 0; |
366 | f6d2a316 | balrog | |
367 | f6d2a316 | balrog | switch (p->pid) {
|
368 | f6d2a316 | balrog | case USB_TOKEN_IN:
|
369 | f6d2a316 | balrog | if (p->devep == 1) { |
370 | f6d2a316 | balrog | if (s->mode == WACOM_MODE_HID)
|
371 | f6d2a316 | balrog | ret = usb_mouse_poll(s, p->data, p->len); |
372 | f6d2a316 | balrog | else if (s->mode == WACOM_MODE_WACOM) |
373 | f6d2a316 | balrog | ret = usb_wacom_poll(s, p->data, p->len); |
374 | f6d2a316 | balrog | break;
|
375 | f6d2a316 | balrog | } |
376 | f6d2a316 | balrog | /* Fall through. */
|
377 | f6d2a316 | balrog | case USB_TOKEN_OUT:
|
378 | f6d2a316 | balrog | default:
|
379 | f6d2a316 | balrog | ret = USB_RET_STALL; |
380 | f6d2a316 | balrog | break;
|
381 | f6d2a316 | balrog | } |
382 | f6d2a316 | balrog | return ret;
|
383 | f6d2a316 | balrog | } |
384 | f6d2a316 | balrog | |
385 | f6d2a316 | balrog | static void usb_wacom_handle_destroy(USBDevice *dev) |
386 | f6d2a316 | balrog | { |
387 | f6d2a316 | balrog | USBWacomState *s = (USBWacomState *) dev; |
388 | f6d2a316 | balrog | |
389 | f6d2a316 | balrog | qemu_remove_mouse_event_handler(s->eh_entry); |
390 | f6d2a316 | balrog | qemu_free(s); |
391 | f6d2a316 | balrog | } |
392 | f6d2a316 | balrog | |
393 | f6d2a316 | balrog | USBDevice *usb_wacom_init(void)
|
394 | f6d2a316 | balrog | { |
395 | f6d2a316 | balrog | USBWacomState *s; |
396 | f6d2a316 | balrog | |
397 | f6d2a316 | balrog | s = qemu_mallocz(sizeof(USBWacomState));
|
398 | f6d2a316 | balrog | if (!s)
|
399 | f6d2a316 | balrog | return NULL; |
400 | f6d2a316 | balrog | s->dev.speed = USB_SPEED_FULL; |
401 | f6d2a316 | balrog | s->dev.handle_packet = usb_generic_handle_packet; |
402 | f6d2a316 | balrog | |
403 | f6d2a316 | balrog | s->dev.handle_reset = usb_wacom_handle_reset; |
404 | f6d2a316 | balrog | s->dev.handle_control = usb_wacom_handle_control; |
405 | f6d2a316 | balrog | s->dev.handle_data = usb_wacom_handle_data; |
406 | f6d2a316 | balrog | s->dev.handle_destroy = usb_wacom_handle_destroy; |
407 | f6d2a316 | balrog | |
408 | f6d2a316 | balrog | pstrcpy(s->dev.devname, sizeof(s->dev.devname),
|
409 | f6d2a316 | balrog | "QEMU PenPartner Tablet");
|
410 | f6d2a316 | balrog | |
411 | f6d2a316 | balrog | return (USBDevice *) s;
|
412 | f6d2a316 | balrog | } |