Rev 3661 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3661 | vana | 1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #include <ipc/ipc.h> |
||
30 | #include <async.h> |
||
31 | #include <kbd.h> |
||
32 | #include <keys.h> |
||
33 | |||
34 | #define i8042_MOUSE_DATA 0x20 |
||
35 | |||
36 | #define BUFSIZE 3 |
||
37 | |||
38 | typedef struct { |
||
39 | union { |
||
40 | unsigned char data[BUFSIZE]; |
||
41 | struct { |
||
42 | unsigned leftbtn : 1; |
||
43 | unsigned rightbtn : 1; |
||
44 | unsigned middlebtn : 1; |
||
45 | unsigned isone : 1; /* Always one */ |
||
46 | unsigned xsign : 1; |
||
47 | unsigned ysign : 1; |
||
48 | unsigned xovfl : 1; |
||
49 | unsigned yovfl : 1; |
||
50 | unsigned char x; |
||
51 | unsigned char y; |
||
52 | } val; |
||
53 | }u; |
||
54 | }ps2packet_t; |
||
55 | |||
56 | static ps2packet_t buf; |
||
57 | static int bufpos = 0; |
||
58 | static int leftbtn = 0; |
||
59 | static int rightbtn = 0; |
||
60 | static int middlebtn = 0; |
||
61 | |||
62 | /** Convert 9-bit 2-complement signed number to integer */ |
||
63 | static int bit9toint(int sign, unsigned char data) |
||
64 | { |
||
65 | int tmp; |
||
66 | |||
67 | if (!sign) |
||
68 | return data; |
||
69 | |||
70 | tmp = ((unsigned char)~data) + 1; |
||
71 | return -tmp; |
||
72 | } |
||
73 | |||
74 | /** Process mouse data |
||
75 | * |
||
76 | * @return True if mouse command was recognized and processed |
||
77 | */ |
||
78 | int mouse_arch_process(int phoneid, ipc_call_t *call) |
||
79 | { |
||
80 | int status = IPC_GET_ARG1(*call); |
||
81 | int data = IPC_GET_ARG2(*call); |
||
82 | int x,y; |
||
83 | |||
84 | if (!(status & i8042_MOUSE_DATA)) |
||
85 | return 0; |
||
86 | |||
87 | /* Check that we have not lost synchronization */ |
||
88 | if (bufpos == 0 && !(data & 0x8)) |
||
89 | return 1; /* Synchro lost, ignore byte */ |
||
90 | |||
91 | buf.u.data[bufpos++] = data; |
||
92 | if (bufpos == BUFSIZE) { |
||
93 | bufpos = 0; |
||
94 | if (phoneid != -1) { |
||
95 | if (buf.u.val.leftbtn ^ leftbtn) { |
||
96 | leftbtn = buf.u.val.leftbtn; |
||
97 | async_msg_1(phoneid, KBD_MS_LEFT, leftbtn); |
||
98 | } |
||
99 | if (buf.u.val.rightbtn & rightbtn) { |
||
100 | rightbtn = buf.u.val.middlebtn; |
||
101 | async_msg_1(phoneid, KBD_MS_RIGHT, rightbtn); |
||
102 | } |
||
103 | if (buf.u.val.rightbtn & rightbtn) { |
||
104 | middlebtn = buf.u.val.middlebtn; |
||
105 | async_msg_1(phoneid, KBD_MS_MIDDLE, middlebtn); |
||
106 | } |
||
107 | x = bit9toint(buf.u.val.xsign, buf.u.val.x); |
||
108 | y = bit9toint(buf.u.val.ysign, buf.u.val.y); |
||
109 | if (x || y) |
||
110 | async_msg_2(phoneid, KBD_MS_MOVE, (ipcarg_t)x, |
||
111 | (ipcarg_t)(-y)); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | |||
116 | return 1; |
||
117 | } |