mouse.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include <ipc/ipc.h>
00030 #include <async.h>
00031 #include <kbd.h>
00032 #include <keys.h>
00033 
00034 #define i8042_MOUSE_DATA   0x20
00035 
00036 #define BUFSIZE 3
00037 
00038 typedef struct {
00039         union {
00040                 unsigned char data[BUFSIZE];
00041                 struct {
00042                         unsigned leftbtn : 1;
00043                         unsigned rightbtn : 1;
00044                         unsigned middlebtn : 1;
00045                         unsigned isone : 1; /* Always one */
00046                         unsigned xsign : 1;
00047                         unsigned ysign : 1;
00048                         unsigned xovfl : 1;
00049                         unsigned yovfl : 1;
00050                         unsigned char x;
00051                         unsigned char y;
00052                 } val;
00053         }u;
00054 }ps2packet_t;
00055 
00056 static ps2packet_t buf;
00057 static int bufpos = 0;
00058 static int leftbtn = 0;
00059 static int rightbtn = 0;
00060 static int middlebtn = 0;
00061 
00063 static int bit9toint(int sign, unsigned char data)
00064 {
00065         int tmp;
00066 
00067         if (!sign)
00068                 return data;
00069 
00070         tmp = ((unsigned char)~data) + 1;
00071         return -tmp;
00072 }
00073 
00078 int mouse_arch_process(int phoneid, ipc_call_t *call)
00079 {
00080         int status = IPC_GET_ARG1(*call);
00081         int data = IPC_GET_ARG2(*call);
00082         int x,y;
00083 
00084         if (!(status & i8042_MOUSE_DATA))
00085                 return 0;
00086 
00087         /* Check that we have not lost synchronization */
00088         if (bufpos == 0 && !(data & 0x8))
00089                 return 1; /* Synchro lost, ignore byte */
00090 
00091         buf.u.data[bufpos++] = data;
00092         if (bufpos == BUFSIZE) {
00093                 bufpos = 0;
00094                 if (phoneid != -1) {
00095                         if (buf.u.val.leftbtn ^ leftbtn) {
00096                                 leftbtn = buf.u.val.leftbtn;
00097                                 async_msg(phoneid, KBD_MS_LEFT, leftbtn);
00098                         }
00099                         if (buf.u.val.rightbtn & rightbtn) {
00100                                 rightbtn = buf.u.val.middlebtn;
00101                                 async_msg(phoneid, KBD_MS_RIGHT, rightbtn);
00102                         }
00103                         if (buf.u.val.rightbtn & rightbtn) {
00104                                 middlebtn = buf.u.val.middlebtn;
00105                                 async_msg(phoneid, KBD_MS_MIDDLE, middlebtn);
00106                         }
00107                         x = bit9toint(buf.u.val.xsign, buf.u.val.x);
00108                         y = bit9toint(buf.u.val.ysign, buf.u.val.y);
00109                         if (x || y)
00110                                 async_msg_2(phoneid, KBD_MS_MOVE, (ipcarg_t)x, (ipcarg_t)(-y));
00111                 }
00112         }
00113 
00114         
00115         return 1;
00116 }

Generated on Sun Jun 18 17:54:21 2006 for HelenOS Userspace (ia32) by  doxygen 1.4.6