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