From patchwork Tue Aug 25 09:14:10 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Revol?= X-Patchwork-Id: 32028 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 2E055B7B61 for ; Tue, 25 Aug 2009 19:16:42 +1000 (EST) Received: from localhost ([127.0.0.1]:52148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mfs8o-0003Sc-Il for incoming@patchwork.ozlabs.org; Tue, 25 Aug 2009 05:16:34 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mfs5d-0002Zh-7e for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:13:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mfs5Y-0002Yo-8I for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:13:16 -0400 Received: from [199.232.76.173] (port=35028 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mfs5X-0002Yi-Sq for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:13:12 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]:46438) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mfs5X-0005PL-3j for qemu-devel@nongnu.org; Tue, 25 Aug 2009 05:13:11 -0400 Received: from smtp2-g21.free.fr (localhost [127.0.0.1]) by smtp2-g21.free.fr (Postfix) with ESMTP id 44E914B01C5 for ; Tue, 25 Aug 2009 11:13:06 +0200 (CEST) Received: from laptop (vaf26-2-82-244-111-82.fbx.proxad.net [82.244.111.82]) by smtp2-g21.free.fr (Postfix) with ESMTP id 00CBF4B0198 for ; Tue, 25 Aug 2009 11:13:03 +0200 (CEST) To: qemu-devel@nongnu.org X-Mailer: BeMail - Mail Daemon Replacement 3.0.0 Final From: "=?utf-8?q?Fran=C3=A7ois?= Revol" Date: Tue, 25 Aug 2009 11:14:10 +0200 CEST Message-Id: <4081524112-BeMail@laptop> Mime-Version: 1.0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH] Fixed wacom emulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi, it's been several times I've submitted this wacom fix, I've been told it was better to refactor the hid stuff first, but then the hid wacom merge diff was rejected... cf. http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query=wacom&submit=Search%21&idxname=qemu-devel&max=20&result=normal&sort=score Note it wasn't change a single line since last year(s?). So please consider fixing it first, as I need it, and then merge, split or whatever you want since I really do not have the time to do this a 2nd time. François. 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 --- hw/usb-wacom.c | 38 ++++++++++++++++++++++++-------------- 1 files changed, 24 insertions(+), 14 deletions(-) diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c index eaf0d29..7bdb765 100644 --- a/hw/usb-wacom.c +++ b/hw/usb-wacom.c @@ -50,6 +50,8 @@ typedef struct USBWacomState { WACOM_MODE_HID = 1, WACOM_MODE_WACOM = 2, } mode; + uint8_t idle; + int changed; } USBWacomState; static const uint8_t qemu_wacom_dev_descriptor[] = { @@ -125,6 +127,7 @@ static void usb_mouse_event(void *opaque, s->dy += dy1; s->dz += dz1; s->buttons_state = buttons_state; + s->changed = 1; } static void usb_wacom_event(void *opaque, @@ -132,10 +135,12 @@ static void usb_wacom_event(void *opaque, { USBWacomState *s = opaque; - s->x = x; - s->y = y; + /* scale to Penpartner resolution */ + s->x = (x * 5040 / 0x7FFF); + s->y = (y * 3780 / 0x7FFF); s->dz += dz; s->buttons_state = buttons_state; + s->changed = 1; } static inline int int_clamp(int val, int vmin, int vmax) @@ -199,26 +204,22 @@ static int usb_wacom_poll(USBWacomState *s, uint8_t *buf, int len) if (s->buttons_state & MOUSE_EVENT_LBUTTON) b |= 0x01; if (s->buttons_state & MOUSE_EVENT_RBUTTON) - b |= 0x02; + b |= 0x40; if (s->buttons_state & MOUSE_EVENT_MBUTTON) - b |= 0x04; + b |= 0x20; /* eraser */ if (len < 7) return 0; buf[0] = s->mode; - buf[5] = 0x00; - if (b) { - buf[1] = s->x & 0xff; - buf[2] = s->x >> 8; - buf[3] = s->y & 0xff; - buf[4] = s->y >> 8; + 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) { buf[6] = 0; } else { - buf[1] = 0; - buf[2] = 0; - buf[3] = 0; - buf[4] = 0; buf[6] = (unsigned char) -127; } @@ -350,7 +351,12 @@ static int usb_wacom_handle_control(USBDevice *dev, int request, int value, else if (s->mode == WACOM_MODE_WACOM) ret = usb_wacom_poll(s, data, length); break; + case HID_GET_IDLE: + ret = 1; + data[0] = s->idle; + break; case HID_SET_IDLE: + s->idle = (uint8_t) (value >> 8); ret = 0; break; default: @@ -369,6 +375,9 @@ static int usb_wacom_handle_data(USBDevice *dev, USBPacket *p) switch (p->pid) { case USB_TOKEN_IN: if (p->devep == 1) { + if (!(s->changed || s->idle)) + return USB_RET_NAK; + s->changed = 0; if (s->mode == WACOM_MODE_HID) ret = usb_mouse_poll(s, p->data, p->len); else if (s->mode == WACOM_MODE_WACOM) @@ -404,6 +413,7 @@ USBDevice *usb_wacom_init(void) s->dev.handle_control = usb_wacom_handle_control; s->dev.handle_data = usb_wacom_handle_data; s->dev.handle_destroy = usb_wacom_handle_destroy; + s->changed = 1; pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU PenPartner Tablet"); -- 1.4.4.4