2007-06-10 21:21:04 +02:00
|
|
|
/*
|
|
|
|
* Wacom PenPartner USB tablet emulation.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Openedhand Ltd.
|
|
|
|
* Author: Andrzej Zaborowski <balrog@zabor.org>
|
|
|
|
*
|
|
|
|
* Based on hw/usb-hid.c:
|
|
|
|
* Copyright (c) 2005 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2007-11-17 18:14:51 +01:00
|
|
|
#include "hw.h"
|
|
|
|
#include "console.h"
|
|
|
|
#include "usb.h"
|
2010-11-25 16:12:06 +01:00
|
|
|
#include "usb-desc.h"
|
2007-06-10 21:21:04 +02:00
|
|
|
|
|
|
|
/* Interface requests */
|
|
|
|
#define WACOM_GET_REPORT 0x2101
|
|
|
|
#define WACOM_SET_REPORT 0x2109
|
|
|
|
|
|
|
|
/* HID interface requests */
|
|
|
|
#define HID_GET_REPORT 0xa101
|
|
|
|
#define HID_GET_IDLE 0xa102
|
|
|
|
#define HID_GET_PROTOCOL 0xa103
|
|
|
|
#define HID_SET_IDLE 0x210a
|
|
|
|
#define HID_SET_PROTOCOL 0x210b
|
|
|
|
|
|
|
|
typedef struct USBWacomState {
|
|
|
|
USBDevice dev;
|
|
|
|
QEMUPutMouseEntry *eh_entry;
|
|
|
|
int dx, dy, dz, buttons_state;
|
|
|
|
int x, y;
|
|
|
|
int mouse_grabbed;
|
|
|
|
enum {
|
|
|
|
WACOM_MODE_HID = 1,
|
|
|
|
WACOM_MODE_WACOM = 2,
|
|
|
|
} mode;
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
uint8_t idle;
|
|
|
|
int changed;
|
2007-06-10 21:21:04 +02:00
|
|
|
} USBWacomState;
|
|
|
|
|
2010-11-25 16:12:06 +01:00
|
|
|
enum {
|
|
|
|
STR_MANUFACTURER = 1,
|
|
|
|
STR_PRODUCT,
|
|
|
|
STR_SERIALNUMBER,
|
|
|
|
};
|
2007-06-10 21:21:04 +02:00
|
|
|
|
2010-11-25 16:12:06 +01:00
|
|
|
static const USBDescStrings desc_strings = {
|
|
|
|
[STR_MANUFACTURER] = "QEMU " QEMU_VERSION,
|
|
|
|
[STR_PRODUCT] = "Wacom PenPartner",
|
|
|
|
[STR_SERIALNUMBER] = "1",
|
|
|
|
};
|
2007-06-10 21:21:04 +02:00
|
|
|
|
2010-11-25 16:12:06 +01:00
|
|
|
static const USBDescIface desc_iface_wacom = {
|
|
|
|
.bInterfaceNumber = 0,
|
|
|
|
.bNumEndpoints = 1,
|
|
|
|
.bInterfaceClass = USB_CLASS_HID,
|
|
|
|
.bInterfaceSubClass = 0x01, /* boot */
|
|
|
|
.bInterfaceProtocol = 0x02,
|
|
|
|
.ndesc = 1,
|
|
|
|
.descs = (USBDescOther[]) {
|
|
|
|
{
|
|
|
|
/* HID descriptor */
|
|
|
|
.data = (uint8_t[]) {
|
|
|
|
0x09, /* u8 bLength */
|
|
|
|
0x21, /* u8 bDescriptorType */
|
|
|
|
0x01, 0x10, /* u16 HID_class */
|
|
|
|
0x00, /* u8 country_code */
|
|
|
|
0x01, /* u8 num_descriptors */
|
|
|
|
0x22, /* u8 type: Report */
|
|
|
|
0x6e, 0, /* u16 len */
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.eps = (USBDescEndpoint[]) {
|
|
|
|
{
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 0x01,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
|
|
|
.wMaxPacketSize = 8,
|
|
|
|
.bInterval = 0x0a,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2007-06-10 21:21:04 +02:00
|
|
|
|
2010-11-25 16:12:06 +01:00
|
|
|
static const USBDescDevice desc_device_wacom = {
|
|
|
|
.bcdUSB = 0x0110,
|
|
|
|
.bMaxPacketSize0 = 8,
|
|
|
|
.bNumConfigurations = 1,
|
|
|
|
.confs = (USBDescConfig[]) {
|
|
|
|
{
|
|
|
|
.bNumInterfaces = 1,
|
|
|
|
.bConfigurationValue = 1,
|
|
|
|
.bmAttributes = 0x80,
|
|
|
|
.bMaxPower = 40,
|
|
|
|
.ifs = &desc_iface_wacom,
|
|
|
|
},
|
|
|
|
},
|
2007-06-10 21:21:04 +02:00
|
|
|
};
|
|
|
|
|
2010-11-25 16:12:06 +01:00
|
|
|
static const USBDesc desc_wacom = {
|
|
|
|
.id = {
|
|
|
|
.idVendor = 0x056a,
|
|
|
|
.idProduct = 0x0000,
|
|
|
|
.bcdDevice = 0x4210,
|
|
|
|
.iManufacturer = STR_MANUFACTURER,
|
|
|
|
.iProduct = STR_PRODUCT,
|
|
|
|
.iSerialNumber = STR_SERIALNUMBER,
|
|
|
|
},
|
|
|
|
.full = &desc_device_wacom,
|
|
|
|
.str = desc_strings,
|
2007-06-10 21:21:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void usb_mouse_event(void *opaque,
|
|
|
|
int dx1, int dy1, int dz1, int buttons_state)
|
|
|
|
{
|
|
|
|
USBWacomState *s = opaque;
|
|
|
|
|
|
|
|
s->dx += dx1;
|
|
|
|
s->dy += dy1;
|
|
|
|
s->dz += dz1;
|
|
|
|
s->buttons_state = buttons_state;
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
s->changed = 1;
|
2007-06-10 21:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_wacom_event(void *opaque,
|
|
|
|
int x, int y, int dz, int buttons_state)
|
|
|
|
{
|
|
|
|
USBWacomState *s = opaque;
|
|
|
|
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
/* scale to Penpartner resolution */
|
|
|
|
s->x = (x * 5040 / 0x7FFF);
|
|
|
|
s->y = (y * 3780 / 0x7FFF);
|
2007-06-10 21:21:04 +02:00
|
|
|
s->dz += dz;
|
|
|
|
s->buttons_state = buttons_state;
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
s->changed = 1;
|
2007-06-10 21:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int int_clamp(int val, int vmin, int vmax)
|
|
|
|
{
|
|
|
|
if (val < vmin)
|
|
|
|
return vmin;
|
|
|
|
else if (val > vmax)
|
|
|
|
return vmax;
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, int len)
|
|
|
|
{
|
|
|
|
int dx, dy, dz, b, l;
|
|
|
|
|
|
|
|
if (!s->mouse_grabbed) {
|
|
|
|
s->eh_entry = qemu_add_mouse_event_handler(usb_mouse_event, s, 0,
|
|
|
|
"QEMU PenPartner tablet");
|
2010-10-08 12:30:14 +02:00
|
|
|
qemu_activate_mouse_event_handler(s->eh_entry);
|
2007-06-10 21:21:04 +02:00
|
|
|
s->mouse_grabbed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dx = int_clamp(s->dx, -128, 127);
|
|
|
|
dy = int_clamp(s->dy, -128, 127);
|
|
|
|
dz = int_clamp(s->dz, -128, 127);
|
|
|
|
|
|
|
|
s->dx -= dx;
|
|
|
|
s->dy -= dy;
|
|
|
|
s->dz -= dz;
|
|
|
|
|
|
|
|
b = 0;
|
|
|
|
if (s->buttons_state & MOUSE_EVENT_LBUTTON)
|
|
|
|
b |= 0x01;
|
|
|
|
if (s->buttons_state & MOUSE_EVENT_RBUTTON)
|
|
|
|
b |= 0x02;
|
|
|
|
if (s->buttons_state & MOUSE_EVENT_MBUTTON)
|
|
|
|
b |= 0x04;
|
|
|
|
|
|
|
|
buf[0] = b;
|
|
|
|
buf[1] = dx;
|
|
|
|
buf[2] = dy;
|
|
|
|
l = 3;
|
|
|
|
if (len >= 4) {
|
|
|
|
buf[3] = dz;
|
|
|
|
l = 4;
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_wacom_poll(USBWacomState *s, uint8_t *buf, int len)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
|
|
|
|
if (!s->mouse_grabbed) {
|
|
|
|
s->eh_entry = qemu_add_mouse_event_handler(usb_wacom_event, s, 1,
|
|
|
|
"QEMU PenPartner tablet");
|
2010-10-08 12:30:14 +02:00
|
|
|
qemu_activate_mouse_event_handler(s->eh_entry);
|
2007-06-10 21:21:04 +02:00
|
|
|
s->mouse_grabbed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
b = 0;
|
|
|
|
if (s->buttons_state & MOUSE_EVENT_LBUTTON)
|
|
|
|
b |= 0x01;
|
|
|
|
if (s->buttons_state & MOUSE_EVENT_RBUTTON)
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
b |= 0x40;
|
2007-06-10 21:21:04 +02:00
|
|
|
if (s->buttons_state & MOUSE_EVENT_MBUTTON)
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
b |= 0x20; /* eraser */
|
2007-06-10 21:21:04 +02:00
|
|
|
|
|
|
|
if (len < 7)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
buf[0] = s->mode;
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
buf[5] = 0x00 | (b & 0xf0);
|
|
|
|
buf[1] = s->x & 0xff;
|
|
|
|
buf[2] = s->x >> 8;
|
|
|
|
buf[3] = s->y & 0xff;
|
|
|
|
buf[4] = s->y >> 8;
|
|
|
|
if (b & 0x3f) {
|
2007-06-10 21:21:04 +02:00
|
|
|
buf[6] = 0;
|
|
|
|
} else {
|
|
|
|
buf[6] = (unsigned char) -127;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_wacom_handle_reset(USBDevice *dev)
|
|
|
|
{
|
|
|
|
USBWacomState *s = (USBWacomState *) dev;
|
|
|
|
|
|
|
|
s->dx = 0;
|
|
|
|
s->dy = 0;
|
|
|
|
s->dz = 0;
|
|
|
|
s->x = 0;
|
|
|
|
s->y = 0;
|
|
|
|
s->buttons_state = 0;
|
|
|
|
s->mode = WACOM_MODE_HID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_wacom_handle_control(USBDevice *dev, int request, int value,
|
|
|
|
int index, int length, uint8_t *data)
|
|
|
|
{
|
|
|
|
USBWacomState *s = (USBWacomState *) dev;
|
2010-11-25 16:12:06 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = usb_desc_handle_control(dev, request, value, index, length, data);
|
|
|
|
if (ret >= 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
2007-06-10 21:21:04 +02:00
|
|
|
|
2010-11-25 16:12:06 +01:00
|
|
|
ret = 0;
|
2007-06-10 21:21:04 +02:00
|
|
|
switch (request) {
|
|
|
|
case DeviceRequest | USB_REQ_GET_STATUS:
|
|
|
|
data[0] = (1 << USB_DEVICE_SELF_POWERED) |
|
|
|
|
(dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
|
|
|
|
data[1] = 0x00;
|
|
|
|
ret = 2;
|
|
|
|
break;
|
|
|
|
case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
|
|
|
|
if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
|
|
|
dev->remote_wakeup = 0;
|
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case DeviceOutRequest | USB_REQ_SET_FEATURE:
|
|
|
|
if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
|
|
|
dev->remote_wakeup = 1;
|
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case DeviceOutRequest | USB_REQ_SET_ADDRESS:
|
|
|
|
dev->addr = value;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case DeviceRequest | USB_REQ_GET_CONFIGURATION:
|
|
|
|
data[0] = 1;
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case DeviceRequest | USB_REQ_GET_INTERFACE:
|
|
|
|
data[0] = 0;
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
case DeviceOutRequest | USB_REQ_SET_INTERFACE:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case WACOM_SET_REPORT:
|
2010-10-08 12:30:14 +02:00
|
|
|
if (s->mouse_grabbed) {
|
|
|
|
qemu_remove_mouse_event_handler(s->eh_entry);
|
|
|
|
s->mouse_grabbed = 0;
|
|
|
|
}
|
2007-06-10 21:21:04 +02:00
|
|
|
s->mode = data[0];
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case WACOM_GET_REPORT:
|
|
|
|
data[0] = 0;
|
|
|
|
data[1] = s->mode;
|
|
|
|
ret = 2;
|
|
|
|
break;
|
|
|
|
/* USB HID requests */
|
|
|
|
case HID_GET_REPORT:
|
|
|
|
if (s->mode == WACOM_MODE_HID)
|
|
|
|
ret = usb_mouse_poll(s, data, length);
|
|
|
|
else if (s->mode == WACOM_MODE_WACOM)
|
|
|
|
ret = usb_wacom_poll(s, data, length);
|
|
|
|
break;
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
case HID_GET_IDLE:
|
|
|
|
ret = 1;
|
|
|
|
data[0] = s->idle;
|
|
|
|
break;
|
2007-06-10 21:21:04 +02:00
|
|
|
case HID_SET_IDLE:
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
s->idle = (uint8_t) (value >> 8);
|
2007-06-10 21:21:04 +02:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fail:
|
|
|
|
ret = USB_RET_STALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_wacom_handle_data(USBDevice *dev, USBPacket *p)
|
|
|
|
{
|
|
|
|
USBWacomState *s = (USBWacomState *) dev;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (p->pid) {
|
|
|
|
case USB_TOKEN_IN:
|
|
|
|
if (p->devep == 1) {
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
if (!(s->changed || s->idle))
|
|
|
|
return USB_RET_NAK;
|
|
|
|
s->changed = 0;
|
2007-06-10 21:21:04 +02:00
|
|
|
if (s->mode == WACOM_MODE_HID)
|
|
|
|
ret = usb_mouse_poll(s, p->data, p->len);
|
|
|
|
else if (s->mode == WACOM_MODE_WACOM)
|
|
|
|
ret = usb_wacom_poll(s, p->data, p->len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fall through. */
|
|
|
|
case USB_TOKEN_OUT:
|
|
|
|
default:
|
|
|
|
ret = USB_RET_STALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_wacom_handle_destroy(USBDevice *dev)
|
|
|
|
{
|
|
|
|
USBWacomState *s = (USBWacomState *) dev;
|
|
|
|
|
2010-10-08 12:30:14 +02:00
|
|
|
if (s->mouse_grabbed) {
|
|
|
|
qemu_remove_mouse_event_handler(s->eh_entry);
|
|
|
|
s->mouse_grabbed = 0;
|
|
|
|
}
|
2007-06-10 21:21:04 +02:00
|
|
|
}
|
|
|
|
|
2009-08-31 14:23:59 +02:00
|
|
|
static int usb_wacom_initfn(USBDevice *dev)
|
2007-06-10 21:21:04 +02:00
|
|
|
{
|
2009-08-31 14:23:59 +02:00
|
|
|
USBWacomState *s = DO_UPCAST(USBWacomState, dev, dev);
|
2007-06-10 21:21:04 +02:00
|
|
|
s->dev.speed = USB_SPEED_FULL;
|
Fixed wacom emulation
- for absolute mode, scale coordinates to the real device maximum values,
since some drivers (on Haiku and Linux at least) need them as such,
and the HID descriptor is boggus on some models anyway,
- keep the coordinates even when no button is pressed, on real tablet
the pen is sensed on the surface even without direct contact,
and drivers expect this,
- map left button to pressure according to what the Haiku driver wants,
- map the right button to the pen button,
- map the middle button to the eraser,
- use asynchronous reporting as the hid code does, stops the Haiku driver
(and probably others) from spending 50% cpu polling for changes.
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-25 11:14:10 +02:00
|
|
|
s->changed = 1;
|
2009-08-31 14:23:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2007-06-10 21:21:04 +02:00
|
|
|
|
2009-08-31 14:23:59 +02:00
|
|
|
static struct USBDeviceInfo wacom_info = {
|
2009-12-09 17:07:52 +01:00
|
|
|
.product_desc = "QEMU PenPartner Tablet",
|
2009-12-09 17:07:53 +01:00
|
|
|
.qdev.name = "usb-wacom-tablet",
|
|
|
|
.qdev.desc = "QEMU PenPartner Tablet",
|
2009-10-26 15:56:46 +01:00
|
|
|
.usbdevice_name = "wacom-tablet",
|
2010-11-25 16:12:06 +01:00
|
|
|
.usb_desc = &desc_wacom,
|
2009-08-31 14:23:59 +02:00
|
|
|
.qdev.size = sizeof(USBWacomState),
|
|
|
|
.init = usb_wacom_initfn,
|
|
|
|
.handle_packet = usb_generic_handle_packet,
|
|
|
|
.handle_reset = usb_wacom_handle_reset,
|
|
|
|
.handle_control = usb_wacom_handle_control,
|
|
|
|
.handle_data = usb_wacom_handle_data,
|
|
|
|
.handle_destroy = usb_wacom_handle_destroy,
|
|
|
|
};
|
2007-06-10 21:21:04 +02:00
|
|
|
|
2009-08-31 14:23:59 +02:00
|
|
|
static void usb_wacom_register_devices(void)
|
|
|
|
{
|
|
|
|
usb_qdev_register(&wacom_info);
|
2007-06-10 21:21:04 +02:00
|
|
|
}
|
2009-08-31 14:23:59 +02:00
|
|
|
device_init(usb_wacom_register_devices)
|