All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 01/10] Elo touchpad 10 bytes emulator
@ 2010-03-29 15:29 Ricardo Ribalda Delgado
  0 siblings, 0 replies; only message in thread
From: Ricardo Ribalda Delgado @ 2010-03-29 15:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ricardo Ribalda Delgado

From: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.es>

New char device emulating an Elo serial touchpad.

TODO: The output of the touchpad should be in the range of the
resolution. But I don't know a clean way to get the screen resolution.
Any help will be very wellcomed
---


Please, be nice it is my first patch to the list :)

 Makefile.objs   |    2 +-
 hw/elo.c        |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/elo.h        |    2 +
 qemu-char.c     |    3 ++
 qemu-options.hx |    5 ++-
 5 files changed, 105 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..c79a8db
--- /dev/null
+++ b/hw/elo.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <stdlib.h>
+#include "../qemu-common.h"
+#include "../qemu-char.h"
+#include "../console.h"
+#include "elo.h"
+
+static void elo_event(void *opaque,
+                          int ax, int ay, int az, int buttons_state)
+{
+    CharDriverState *chr = (CharDriverState *)opaque;
+
+    unsigned char bytes[10];
+    static int is_down=0;
+    /*Only 1 button is supported*/
+    buttons_state&=1;
+
+    /*A touchpad cannot capture flight events*/
+    if ((!is_down)&&(!buttons_state))
+	    return;
+
+    /*Move event*/
+    if (is_down&&buttons_state){
+	    bytes[2]=0x2;
+    }
+
+    /*Click*/
+    if ((!is_down)&&buttons_state){
+	    bytes[2]=0x1;
+	    is_down=1;
+    }
+    /*Release*/
+    if (is_down&&(!buttons_state)){
+	    bytes[2]=0x4;
+	    is_down=0;
+    }
+
+    bytes[0]=0x55;
+    bytes[1]=0x54;
+    bytes[3]=ax&0xff;
+    bytes[4]=(ax>>8)&0xff;
+    bytes[5]=ay&0xff;
+    bytes[6]=(ay>>8)&0xff;
+    bytes[7]=0x0;
+    bytes[8]=0x0;
+    bytes[9]=0x0;
+
+    qemu_chr_read(chr, bytes, 10);
+}
+
+static int elo_chr_write (struct CharDriverState *s, const uint8_t *buf, int len)
+{
+    /* Ignore writes to mouse port */
+    return len;
+}
+
+static void elo_chr_close (struct CharDriverState *chr)
+{
+    qemu_free (chr);
+}
+
+CharDriverState *qemu_chr_open_elo(QemuOpts *opts)
+{
+    CharDriverState *chr;
+
+    chr = qemu_mallocz(sizeof(CharDriverState));
+    chr->chr_write = elo_chr_write;
+    chr->chr_close = elo_chr_close;
+
+    qemu_add_mouse_event_handler(elo_event, chr, 1, "QEMU Elo Touchpad");
+
+    return 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 <unistd.h>
@@ -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
 
-- 
1.7.0.3

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-03-29 16:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-29 15:29 [Qemu-devel] [PATCH 01/10] Elo touchpad 10 bytes emulator Ricardo Ribalda Delgado

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.