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