Rev 2337 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2337 | Rev 2350 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Michal Kebrt |
2 | * Copyright (c) 2007 Michal Kebrt |
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 | /** @addtogroup kbdarm32 arm32 |
29 | /** @addtogroup kbdarm32gxemul GXemul |
30 | * @brief HelenOS arm32 arch dependent parts of uspace keyboard handler. |
30 | * @brief HelenOS arm32 GXEmul uspace keyboard handler. |
31 | * @ingroup kbd |
31 | * @ingroup kbdarm32 |
32 | * @{ |
32 | * @{ |
33 | */ |
33 | */ |
34 | /** @file |
34 | /** @file |
- | 35 | * @brief GXemul uspace keyboard handler. |
|
35 | */ |
36 | */ |
36 | 37 | ||
37 | #include <arch/kbd.h> |
- | |
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <sysinfo.h> |
39 | #include <sysinfo.h> |
40 | #include <kbd.h> |
40 | #include <kbd.h> |
41 | #include <keys.h> |
41 | #include <keys.h> |
42 | 42 | ||
43 | #define GXEMUL_KEY_F1 0x504f1bL |
43 | #define GXEMUL_KEY_F1 0x504f1bL |
44 | #define GXEMUL_KEY_F2 0x514f1bL |
44 | #define GXEMUL_KEY_F2 0x514f1bL |
45 | #define GXEMUL_KEY_F3 0x524f1bL |
45 | #define GXEMUL_KEY_F3 0x524f1bL |
46 | #define GXEMUL_KEY_F4 0x534f1bL |
46 | #define GXEMUL_KEY_F4 0x534f1bL |
47 | #define GXEMUL_KEY_F5 0x35315b1bL |
47 | #define GXEMUL_KEY_F5 0x35315b1bL |
48 | #define GXEMUL_KEY_F6 0x37315b1bL |
48 | #define GXEMUL_KEY_F6 0x37315b1bL |
49 | #define GXEMUL_KEY_F7 0x38315b1bL |
49 | #define GXEMUL_KEY_F7 0x38315b1bL |
50 | #define GXEMUL_KEY_F8 0x39315b1bL |
50 | #define GXEMUL_KEY_F8 0x39315b1bL |
51 | #define GXEMUL_KEY_F9 0x30325b1bL |
51 | #define GXEMUL_KEY_F9 0x30325b1bL |
52 | #define GXEMUL_KEY_F10 0x31325b1bL |
52 | #define GXEMUL_KEY_F10 0x31325b1bL |
53 | #define GXEMUL_KEY_F11 0x33325d1bL |
53 | #define GXEMUL_KEY_F11 0x33325d1bL |
54 | #define GXEMUL_KEY_F12 0x34325b1bL |
54 | #define GXEMUL_KEY_F12 0x34325b1bL |
55 | 55 | ||
- | 56 | /** Function keys start code (F1=0x101) */ |
|
56 | #define FUNCTION_KEYS 0x100 |
57 | #define FUNCTION_KEYS 0x100 |
57 | 58 | ||
58 | irq_cmd_t gxemul_cmds[] = { |
59 | irq_cmd_t gxemul_cmds[] = { |
59 | { |
60 | { |
60 | CMD_MEM_READ_1, |
61 | CMD_MEM_READ_1, |
61 | (void *) 0, |
62 | (void *) 0, |
62 | 0, |
63 | 0, |
63 | 2 |
64 | 2 |
64 | } |
65 | } |
65 | }; |
66 | }; |
66 | 67 | ||
67 | irq_code_t gxemul_kbd = { |
68 | irq_code_t gxemul_kbd = { |
68 | 1, |
69 | 1, |
69 | gxemul_cmds |
70 | gxemul_cmds |
70 | }; |
71 | }; |
71 | 72 | ||
72 | 73 | ||
73 | /* |
74 | /* |
74 | // Please preserve this code (it can be used to determine scancodes) |
75 | // Please preserve this code (it can be used to determine scancodes) |
75 | int to_hex(int v) |
76 | int to_hex(int v) |
76 | { |
77 | { |
77 | return "0123456789ABCDEF"[v]; |
78 | return "0123456789ABCDEF"[v]; |
78 | } |
79 | } |
79 | */ |
80 | */ |
80 | 81 | ||
- | 82 | ||
- | 83 | /** Process data sent when a key is pressed. |
|
- | 84 | * |
|
- | 85 | * @param keybuffer Buffer of scan codes. |
|
- | 86 | * @param scan_code Scan code. |
|
- | 87 | * |
|
- | 88 | * @return Code of the pressed key. |
|
- | 89 | */ |
|
81 | static int gxemul_process_no_fb(keybuffer_t *keybuffer, int scan_code) |
90 | static int gxemul_process_no_fb(keybuffer_t *keybuffer, int scan_code) |
82 | { |
91 | { |
83 | 92 | ||
84 | static unsigned long buf = 0; |
93 | static unsigned long buf = 0; |
85 | static int count = 0; |
94 | static int count = 0; |
86 | 95 | ||
87 | /* Preserve for detecting scan codes. |
96 | /* Preserve for detecting scan codes. |
88 | keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf)); |
97 | keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf)); |
89 | keybuffer_push(keybuffer, to_hex(scan_code&0xf)); |
98 | keybuffer_push(keybuffer, to_hex(scan_code&0xf)); |
90 | keybuffer_push(keybuffer, 'X'); |
99 | keybuffer_push(keybuffer, 'X'); |
91 | keybuffer_push(keybuffer, 'Y'); |
100 | keybuffer_push(keybuffer, 'Y'); |
92 | return 1; |
101 | return 1; |
93 | */ |
102 | */ |
94 | 103 | ||
95 | if (scan_code == '\r') |
104 | if (scan_code == '\r') |
96 | scan_code = '\n'; |
105 | scan_code = '\n'; |
97 | 106 | ||
98 | if(scan_code == 0x7e) { |
107 | if(scan_code == 0x7e) { |
99 | switch (buf) { |
108 | switch (buf) { |
100 | case GXEMUL_KEY_F5: |
109 | case GXEMUL_KEY_F5: |
101 | keybuffer_push(keybuffer,FUNCTION_KEYS | 5); |
110 | keybuffer_push(keybuffer,FUNCTION_KEYS | 5); |
102 | buf = count = 0; |
111 | buf = count = 0; |
103 | return 1; |
112 | return 1; |
104 | case GXEMUL_KEY_F6: |
113 | case GXEMUL_KEY_F6: |
105 | keybuffer_push(keybuffer,FUNCTION_KEYS | 6); |
114 | keybuffer_push(keybuffer,FUNCTION_KEYS | 6); |
106 | buf = count = 0; |
115 | buf = count = 0; |
107 | return 1; |
116 | return 1; |
108 | case GXEMUL_KEY_F7: |
117 | case GXEMUL_KEY_F7: |
109 | keybuffer_push(keybuffer,FUNCTION_KEYS | 7); |
118 | keybuffer_push(keybuffer,FUNCTION_KEYS | 7); |
110 | buf = count = 0; |
119 | buf = count = 0; |
111 | return 1; |
120 | return 1; |
112 | case GXEMUL_KEY_F8: |
121 | case GXEMUL_KEY_F8: |
113 | keybuffer_push(keybuffer,FUNCTION_KEYS | 8); |
122 | keybuffer_push(keybuffer,FUNCTION_KEYS | 8); |
114 | buf = count = 0; |
123 | buf = count = 0; |
115 | return 1; |
124 | return 1; |
116 | case GXEMUL_KEY_F9: |
125 | case GXEMUL_KEY_F9: |
117 | keybuffer_push(keybuffer,FUNCTION_KEYS | 9); |
126 | keybuffer_push(keybuffer,FUNCTION_KEYS | 9); |
118 | buf = count = 0; |
127 | buf = count = 0; |
119 | return 1; |
128 | return 1; |
120 | case GXEMUL_KEY_F10: |
129 | case GXEMUL_KEY_F10: |
121 | keybuffer_push(keybuffer,FUNCTION_KEYS | 10); |
130 | keybuffer_push(keybuffer,FUNCTION_KEYS | 10); |
122 | buf = count = 0; |
131 | buf = count = 0; |
123 | return 1; |
132 | return 1; |
124 | case GXEMUL_KEY_F11: |
133 | case GXEMUL_KEY_F11: |
125 | keybuffer_push(keybuffer,FUNCTION_KEYS | 11); |
134 | keybuffer_push(keybuffer,FUNCTION_KEYS | 11); |
126 | buf = count = 0; |
135 | buf = count = 0; |
127 | return 1; |
136 | return 1; |
128 | case GXEMUL_KEY_F12: |
137 | case GXEMUL_KEY_F12: |
129 | keybuffer_push(keybuffer,FUNCTION_KEYS | 12); |
138 | keybuffer_push(keybuffer,FUNCTION_KEYS | 12); |
130 | buf = count = 0; |
139 | buf = count = 0; |
131 | return 1; |
140 | return 1; |
132 | default: |
141 | default: |
133 | keybuffer_push(keybuffer, buf & 0xff); |
142 | keybuffer_push(keybuffer, buf & 0xff); |
134 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
143 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
135 | keybuffer_push(keybuffer, (buf >> 16) &0xff); |
144 | keybuffer_push(keybuffer, (buf >> 16) &0xff); |
136 | keybuffer_push(keybuffer, (buf >> 24) &0xff); |
145 | keybuffer_push(keybuffer, (buf >> 24) &0xff); |
137 | keybuffer_push(keybuffer, scan_code); |
146 | keybuffer_push(keybuffer, scan_code); |
138 | buf = count = 0; |
147 | buf = count = 0; |
139 | return 1; |
148 | return 1; |
140 | } |
149 | } |
141 | } |
150 | } |
142 | 151 | ||
143 | buf |= ((unsigned long) scan_code)<<(8*(count++)); |
152 | buf |= ((unsigned long) scan_code)<<(8*(count++)); |
144 | 153 | ||
145 | if((buf & 0xff) != (GXEMUL_KEY_F1 & 0xff)) { |
154 | if((buf & 0xff) != (GXEMUL_KEY_F1 & 0xff)) { |
146 | keybuffer_push(keybuffer, buf); |
155 | keybuffer_push(keybuffer, buf); |
147 | buf = count = 0; |
156 | buf = count = 0; |
148 | return 1; |
157 | return 1; |
149 | } |
158 | } |
150 | 159 | ||
151 | if (count <= 1) |
160 | if (count <= 1) |
152 | return 1; |
161 | return 1; |
153 | 162 | ||
154 | if ((buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff) |
163 | if ((buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff) |
155 | && (buf & 0xffff) != (GXEMUL_KEY_F5 & 0xffff) ) { |
164 | && (buf & 0xffff) != (GXEMUL_KEY_F5 & 0xffff) ) { |
156 | 165 | ||
157 | keybuffer_push(keybuffer, buf & 0xff); |
166 | keybuffer_push(keybuffer, buf & 0xff); |
158 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
167 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
159 | buf = count = 0; |
168 | buf = count = 0; |
160 | return 1; |
169 | return 1; |
161 | } |
170 | } |
162 | 171 | ||
163 | if (count <= 2) |
172 | if (count <= 2) |
164 | return 1; |
173 | return 1; |
165 | 174 | ||
166 | switch (buf) { |
175 | switch (buf) { |
167 | case GXEMUL_KEY_F1: |
176 | case GXEMUL_KEY_F1: |
168 | keybuffer_push(keybuffer,FUNCTION_KEYS | 1); |
177 | keybuffer_push(keybuffer,FUNCTION_KEYS | 1); |
169 | buf = count = 0; |
178 | buf = count = 0; |
170 | return 1; |
179 | return 1; |
171 | case GXEMUL_KEY_F2: |
180 | case GXEMUL_KEY_F2: |
172 | keybuffer_push(keybuffer,FUNCTION_KEYS | 2); |
181 | keybuffer_push(keybuffer,FUNCTION_KEYS | 2); |
173 | buf = count = 0; |
182 | buf = count = 0; |
174 | return 1; |
183 | return 1; |
175 | case GXEMUL_KEY_F3: |
184 | case GXEMUL_KEY_F3: |
176 | keybuffer_push(keybuffer,FUNCTION_KEYS | 3); |
185 | keybuffer_push(keybuffer,FUNCTION_KEYS | 3); |
177 | buf = count = 0; |
186 | buf = count = 0; |
178 | return 1; |
187 | return 1; |
179 | case GXEMUL_KEY_F4: |
188 | case GXEMUL_KEY_F4: |
180 | keybuffer_push(keybuffer,FUNCTION_KEYS | 4); |
189 | keybuffer_push(keybuffer,FUNCTION_KEYS | 4); |
181 | buf = count = 0; |
190 | buf = count = 0; |
182 | return 1; |
191 | return 1; |
183 | } |
192 | } |
184 | 193 | ||
185 | 194 | ||
186 | if((buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff) |
195 | if((buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff) |
187 | && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff)) { |
196 | && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff)) { |
188 | 197 | ||
189 | keybuffer_push(keybuffer, buf & 0xff); |
198 | keybuffer_push(keybuffer, buf & 0xff); |
190 | keybuffer_push(keybuffer, (buf >> 8) & 0xff); |
199 | keybuffer_push(keybuffer, (buf >> 8) & 0xff); |
191 | keybuffer_push(keybuffer, (buf >> 16) & 0xff); |
200 | keybuffer_push(keybuffer, (buf >> 16) & 0xff); |
192 | buf=count=0; |
201 | buf=count=0; |
193 | return 1; |
202 | return 1; |
194 | } |
203 | } |
195 | 204 | ||
196 | if (count <= 3) |
205 | if (count <= 3) |
197 | return 1; |
206 | return 1; |
198 | 207 | ||
199 | switch (buf) { |
208 | switch (buf) { |
200 | case GXEMUL_KEY_F5: |
209 | case GXEMUL_KEY_F5: |
201 | case GXEMUL_KEY_F6: |
210 | case GXEMUL_KEY_F6: |
202 | case GXEMUL_KEY_F7: |
211 | case GXEMUL_KEY_F7: |
203 | case GXEMUL_KEY_F8: |
212 | case GXEMUL_KEY_F8: |
204 | case GXEMUL_KEY_F9: |
213 | case GXEMUL_KEY_F9: |
205 | case GXEMUL_KEY_F10: |
214 | case GXEMUL_KEY_F10: |
206 | case GXEMUL_KEY_F11: |
215 | case GXEMUL_KEY_F11: |
207 | case GXEMUL_KEY_F12: |
216 | case GXEMUL_KEY_F12: |
208 | return 1; |
217 | return 1; |
209 | default: |
218 | default: |
210 | keybuffer_push(keybuffer, buf & 0xff); |
219 | keybuffer_push(keybuffer, buf & 0xff); |
211 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
220 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
212 | keybuffer_push(keybuffer, (buf >> 16) &0xff); |
221 | keybuffer_push(keybuffer, (buf >> 16) &0xff); |
213 | keybuffer_push(keybuffer, (buf >> 24) &0xff); |
222 | keybuffer_push(keybuffer, (buf >> 24) &0xff); |
214 | buf = count = 0; |
223 | buf = count = 0; |
215 | return 1; |
224 | return 1; |
216 | } |
225 | } |
217 | return 1; |
226 | return 1; |
218 | } |
227 | } |
219 | 228 | ||
220 | 229 | ||
- | 230 | /** Initializes keyboard handler. */ |
|
221 | int kbd_arch_init(void) |
231 | int kbd_arch_init(void) |
222 | { |
232 | { |
223 | gxemul_cmds[0].addr = (void *) sysinfo_value("kbd.address.virtual"); |
233 | gxemul_cmds[0].addr = (void *) sysinfo_value("kbd.address.virtual"); |
224 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &gxemul_kbd); |
234 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &gxemul_kbd); |
225 | return 0; |
235 | return 0; |
226 | } |
236 | } |
227 | 237 | ||
228 | 238 | ||
- | 239 | /** Process data sent when a key is pressed. |
|
- | 240 | * |
|
- | 241 | * @param keybuffer Buffer of scan codes. |
|
- | 242 | * @param call IPC call. |
|
- | 243 | * |
|
- | 244 | * @return Code of the pressed key. |
|
- | 245 | */ |
|
229 | int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call) |
246 | int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call) |
230 | { |
247 | { |
231 | int scan_code = IPC_GET_ARG2(*call); |
248 | int scan_code = IPC_GET_ARG2(*call); |
232 | static int esc_count=0; |
249 | static int esc_count = 0; |
233 | 250 | ||
234 | if (scan_code == 0x1b) { |
251 | if (scan_code == 0x1b) { |
235 | esc_count++; |
252 | esc_count++; |
236 | if (esc_count == 3) { |
253 | if (esc_count == 3) { |
237 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
254 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
238 | } |
255 | } |
239 | } else { |
256 | } else { |
240 | esc_count = 0; |
257 | esc_count = 0; |
241 | } |
258 | } |
242 | 259 | ||
243 | return gxemul_process_no_fb(keybuffer, scan_code); |
260 | return gxemul_process_no_fb(keybuffer, scan_code); |
244 | } |
261 | } |
245 | 262 | ||
246 | /** @} |
263 | /** @} |
247 | */ |
264 | */ |
248 | 265 |