From patchwork Tue Mar 30 15:01:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 48976 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 ozlabs.org (Postfix) with ESMTPS id 3128AB7C48 for ; Wed, 31 Mar 2010 02:04:20 +1100 (EST) Received: from localhost ([127.0.0.1]:42085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwczJ-0008N2-FJ for incoming@patchwork.ozlabs.org; Tue, 30 Mar 2010 11:04:17 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NwcxT-0007yc-UM for qemu-devel@nongnu.org; Tue, 30 Mar 2010 11:02:23 -0400 Received: from [140.186.70.92] (port=47281 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwcxS-0007xQ-4C for qemu-devel@nongnu.org; Tue, 30 Mar 2010 11:02:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NwcxL-0006Tn-EO for qemu-devel@nongnu.org; Tue, 30 Mar 2010 11:02:21 -0400 Received: from mail-bw0-f218.google.com ([209.85.218.218]:50408) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NwcxL-0006TZ-3X for qemu-devel@nongnu.org; Tue, 30 Mar 2010 11:02:15 -0400 Received: by bwz10 with SMTP id 10so14562207bwz.2 for ; Tue, 30 Mar 2010 08:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=Dy6ETD2bY5pvMQSE2+/H7ln+NYA8wc9Hao/FgfmK6dE=; b=mIUBHtF214m9o4t5mSTSUcHxZu54zieTuq3RsZHRAklm6sBdU5Z5eP0CXwEwTlI7Sq AixJmayhUAczF6h8CrZijMZbcqadxT13Zm0pW7d/SuX61hMHPjo5HixJ7IvGyOxuv5u4 6wufhMjoiFcgRsxY+EHqXMbbmZ/vEUuhhFLl0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=vz/bIOPsT3K5LTk52OAv9njl4uww/7fTxknz2X4q9mk4Cgm2CS9armGC1cFwUT0afu gdd2lNRDU9ZbB7/pGEmghzqqiXi6LvYiEJOsQKutLNhB2B163NZL/8klGS/ebj5GOTd/ LLbm0J43pbQ1OVnEpy5DcdNX/qtOKrcec203E= Received: by 10.204.15.134 with SMTP id k6mr5759910bka.96.1269961333165; Tue, 30 Mar 2010 08:02:13 -0700 (PDT) Received: from localhost (aragorn.ii.uam.es [150.244.56.212]) by mx.google.com with ESMTPS id a11sm48638374bkc.21.2010.03.30.08.02.12 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 30 Mar 2010 08:02:12 -0700 (PDT) From: Ricardo Ribalda Delgado To: qemu-devel@nongnu.org, zhur@ispras.ru, paul@codesourcery.com, quintela@redhat.com Date: Tue, 30 Mar 2010 17:01:39 +0200 Message-Id: <1269961299-8181-1-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 1.7.0.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Ricardo Ribalda Delgado Subject: [Qemu-devel] [PATCH] Elo touchpad 10 bytes emulator v3 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 From: Ricardo Ribalda Delgado New char device emulating an Elo serial touchpad. v2: -Emulate id packages (linux recognizes the hw) -Limit output to 96-4000 (thanks to Dmitry Zhurikhin) v3: -Output buffer (thanks to Juan Quintela) -Code Style --- Makefile.objs | 2 +- hw/elo.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/elo.h | 2 + qemu-char.c | 3 + qemu-options.hx | 5 +- 5 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 hw/elo.c create mode 100644 hw/elo.h diff --git a/Makefile.objs b/Makefile.objs index b73e2cb..07c2e68 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -75,7 +75,7 @@ common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o u common-obj-y += bt-hci-csr.o common-obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o common-obj-y += qemu-char.o savevm.o #aio.o -common-obj-y += msmouse.o ps2.o +common-obj-y += msmouse.o ps2.o elo.o common-obj-y += qdev.o qdev-properties.o common-obj-y += qemu-config.o block-migration.o diff --git a/hw/elo.c b/hw/elo.c new file mode 100644 index 0000000..d5b4124 --- /dev/null +++ b/hw/elo.c @@ -0,0 +1,189 @@ +/* + * QEMU ELO Touchpad via serial port + * + * Copyright (c) 2010 Ricardo Ribalda: QTechnology http://qtec.com + * + * 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. + */ +#include +#include "qemu-common.h" +#include "qemu-char.h" +#include "console.h" +#include "elo.h" + +#define ELO_DOWN 0x1 +#define ELO_MOVE 0x2 +#define ELO_UP 0x4 +#define ELO_PACKET_SIZE 10 + +typedef struct { + CharDriverState chr; + uint8_t out_buf[ELO_PACKET_SIZE]; + uint8_t send_out; +} EloDriverState; + +static void elo_event(void *opaque, + int ax, int ay, int az, int buttons_state) +{ + EloDriverState *elo=(EloDriverState *)opaque; + CharDriverState *chr = &elo->chr; + unsigned char bytes[ELO_PACKET_SIZE]; + static int is_down=0; + int old_ax=0,old_ay=0; + int i; + + /*A touchpad cannot capture flight events*/ + if ((!is_down)&&(!buttons_state)) + return; + + ax=(ax*(4000-96))/0x7fff; + ax+=96; + ay=(ay*(4000-96))/0x7fff; + ay+=96; + + /*Move event*/ + if (is_down&&buttons_state){ + bytes[2]=ELO_MOVE; + is_down++; + if ((old_ay==ay)&&(old_ax==ax)) + return; + /*SDL move is much more precise than the real elo*/ + if (qemu_chr_can_read(chr)>8)&0xff; + bytes[5]=ay&0xff; + bytes[6]=(ay>>8)&0xff; + bytes[7]=0x0;/*No presure capabilities*/ + bytes[8]=0x0; + bytes[9]=0xaa; + for(i=0;i<9;i++) + bytes[9]+=bytes[i]; + + qemu_chr_read(chr, bytes, ELO_PACKET_SIZE); + return; +} + +static int elo_chr_write(struct CharDriverState *s, const uint8_t *buf, int len) +{ + EloDriverState *elo=(EloDriverState *)s->opaque; + unsigned char bytes[ELO_PACKET_SIZE]; + static int in_cmd=0,i; + + if (buf[0]==0x55) + in_cmd=0; + + /*Only response to ID*/ + in_cmd+=len; + if (in_cmdsend_out=1; + memcpy(elo->out_buf,bytes,ELO_PACKET_SIZE); + in_cmd=0; + return len; + } + qemu_chr_read(s, bytes, ELO_PACKET_SIZE); + in_cmd=0; + return len; +} + +static void elo_chr_accept_input(struct CharDriverState *chr){ + EloDriverState *elo=(EloDriverState *)chr->opaque; + + if (!elo->send_out) + return; + if (qemu_chr_can_read(chr)out_buf, ELO_PACKET_SIZE); + return; +} + +static void elo_chr_close(struct CharDriverState *chr) +{ + qemu_free(chr->opaque); +} + +CharDriverState *qemu_chr_open_elo(QemuOpts *opts) +{ + EloDriverState *elo; + elo = qemu_mallocz(sizeof(EloDriverState)); + elo->chr.chr_write = elo_chr_write; + elo->chr.chr_close = elo_chr_close; + elo->chr.chr_accept_input= elo_chr_accept_input; + elo->chr.opaque=elo; + elo->send_out=0; + + qemu_add_mouse_event_handler(elo_event, elo, 1, "QEMU Elo Touchpad"); + + return &elo->chr; +} diff --git a/hw/elo.h b/hw/elo.h new file mode 100644 index 0000000..4b4e09a --- /dev/null +++ b/hw/elo.h @@ -0,0 +1,2 @@ +/* elo.c */ +CharDriverState *qemu_chr_open_elo(QemuOpts *opts); diff --git a/qemu-char.c b/qemu-char.c index 40cfefa..2f95767 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -32,6 +32,7 @@ #include "hw/usb.h" #include "hw/baum.h" #include "hw/msmouse.h" +#include "hw/elo.h" #include "qemu-objects.h" #include @@ -2278,6 +2279,7 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) if (strcmp(filename, "null") == 0 || strcmp(filename, "pty") == 0 || strcmp(filename, "msmouse") == 0 || + strcmp(filename, "elo") == 0 || strcmp(filename, "braille") == 0 || strcmp(filename, "stdio") == 0) { qemu_opt_set(opts, "backend", filename); @@ -2391,6 +2393,7 @@ static const struct { { .name = "socket", .open = qemu_chr_open_socket }, { .name = "udp", .open = qemu_chr_open_udp }, { .name = "msmouse", .open = qemu_chr_open_msmouse }, + { .name = "elo", .open = qemu_chr_open_elo }, { .name = "vc", .open = text_console_init }, #ifdef _WIN32 { .name = "file", .open = qemu_chr_open_win_file_out }, diff --git a/qemu-options.hx b/qemu-options.hx index 7c33736..7ee62cb 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1183,7 +1183,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, "-chardev socket,id=id,path=path[,server][,nowait][,telnet] (unix)\n" "-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]\n" " [,localport=localport][,ipv4][,ipv6]\n" - "-chardev msmouse,id=id\n" + "-chardev elo,id=id\n" "-chardev vc,id=id[[,width=width][,height=height]][[,cols=cols][,rows=rows]]\n" "-chardev file,id=id,path=path\n" "-chardev pipe,id=id,path=path\n" @@ -1650,6 +1650,9 @@ or fake device. @item msmouse Three button serial mouse. Configure the guest to use Microsoft protocol. + +@item elo +Elo Touchpad 10bytes emulator. @end table ETEXI