00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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;
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
00088 if (bufpos == 0 && !(data & 0x8))
00089 return 1;
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 }