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