Rev 2071 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1339 | cejka | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2006 Josef Cejka |
1339 | cejka | 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 | |||
1649 | cejka | 29 | /** @addtogroup kbdmips32 mips32 |
30 | * @brief HelenOS mips32 arch dependent parts of uspace keyboard handler. |
||
31 | * @ingroup kbd |
||
32 | * @{ |
||
33 | */ |
||
34 | /** @file |
||
35 | */ |
||
1339 | cejka | 36 | #include <arch/kbd.h> |
1353 | jermar | 37 | #include <ipc/ipc.h> |
1632 | vana | 38 | #include <sysinfo.h> |
1694 | palkovsky | 39 | #include <kbd.h> |
40 | #include <keys.h> |
||
1339 | cejka | 41 | |
1632 | vana | 42 | #define MSIM_KEY_F1 0x504f1bL |
43 | #define MSIM_KEY_F2 0x514f1bL |
||
44 | #define MSIM_KEY_F3 0x524f1bL |
||
45 | #define MSIM_KEY_F4 0x534f1bL |
||
46 | #define MSIM_KEY_F5 0x35315b1bL |
||
47 | #define MSIM_KEY_F6 0x37315b1bL |
||
48 | #define MSIM_KEY_F7 0x38315b1bL |
||
49 | #define MSIM_KEY_F8 0x39315b1bL |
||
50 | #define MSIM_KEY_F9 0x30325b1bL |
||
51 | #define MSIM_KEY_F10 0x31325b1bL |
||
52 | #define MSIM_KEY_F11 0x33325b1bL |
||
53 | #define MSIM_KEY_F12 0x34325b1bL |
||
1622 | vana | 54 | |
1632 | vana | 55 | #define GXEMUL_KEY_F1 0x504f5b1bL |
56 | #define GXEMUL_KEY_F2 0x514f5b1bL |
||
57 | #define GXEMUL_KEY_F3 0x524f5b1bL |
||
58 | #define GXEMUL_KEY_F4 0x534f5b1bL |
||
59 | #define GXEMUL_KEY_F5 0x35315b1bL |
||
60 | #define GXEMUL_KEY_F6 0x37315b1bL |
||
61 | #define GXEMUL_KEY_F7 0x38315b1bL |
||
62 | #define GXEMUL_KEY_F8 0x39315b1bL |
||
63 | #define GXEMUL_KEY_F9 0x38325b1bL |
||
64 | #define GXEMUL_KEY_F10 0x39325b1bL |
||
65 | #define GXEMUL_KEY_F11 0x33325b1bL |
||
66 | #define GXEMUL_KEY_F12 0x34325b1bL |
||
67 | |||
1622 | vana | 68 | #define FUNCTION_KEYS 0x100 |
69 | |||
1339 | cejka | 70 | irq_cmd_t msim_cmds[1] = { |
1938 | decky | 71 | { CMD_MEM_READ_1, (void *) 0, 0, 2 } |
1339 | cejka | 72 | }; |
73 | |||
74 | irq_code_t msim_kbd = { |
||
75 | 1, |
||
76 | msim_cmds |
||
77 | }; |
||
78 | |||
1632 | vana | 79 | static int msim,gxemul; |
1699 | vana | 80 | static int fb_fb; |
1632 | vana | 81 | |
1699 | vana | 82 | |
1347 | palkovsky | 83 | int kbd_arch_init(void) |
1339 | cejka | 84 | { |
1874 | jermar | 85 | fb_fb = (sysinfo_value("fb.kind") == 1); |
1938 | decky | 86 | msim_cmds[0].addr = sysinfo_value("kbd.address.virtual"); |
87 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &msim_kbd); |
||
1694 | palkovsky | 88 | return 0; |
1339 | cejka | 89 | } |
90 | |||
1622 | vana | 91 | |
1699 | vana | 92 | /* |
1632 | vana | 93 | //* |
94 | //* Please preserve this code (it can be used to determine scancodes) |
||
95 | //* |
||
1622 | vana | 96 | int to_hex(int v) |
97 | { |
||
98 | return "0123456789ABCDEF"[v]; |
||
99 | } |
||
1699 | vana | 100 | */ |
1622 | vana | 101 | |
1699 | vana | 102 | static int kbd_arch_process_no_fb(keybuffer_t *keybuffer, int scan_code) |
1347 | palkovsky | 103 | { |
1622 | vana | 104 | |
1874 | jermar | 105 | static unsigned long buf = 0; |
106 | static int count = 0; |
||
1622 | vana | 107 | |
1699 | vana | 108 | /* Please preserve this code (it can be used to determine scancodes) |
1622 | vana | 109 | |
1699 | vana | 110 | keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf)); |
111 | keybuffer_push(keybuffer, to_hex(scan_code&0xf)); |
||
112 | keybuffer_push(keybuffer, ' '); |
||
113 | keybuffer_push(keybuffer, ' '); |
||
1622 | vana | 114 | |
1699 | vana | 115 | return 1; |
116 | */ |
||
117 | |||
1874 | jermar | 118 | if(scan_code == 0x7e) { |
119 | switch (buf) { |
||
120 | case MSIM_KEY_F5: |
||
121 | keybuffer_push(keybuffer,FUNCTION_KEYS | 5); |
||
122 | buf = count = 0; |
||
123 | return 1; |
||
124 | case MSIM_KEY_F6: |
||
125 | keybuffer_push(keybuffer,FUNCTION_KEYS | 6); |
||
126 | buf = count = 0; |
||
127 | return 1; |
||
128 | case MSIM_KEY_F7: |
||
129 | keybuffer_push(keybuffer,FUNCTION_KEYS | 7); |
||
130 | buf = count = 0; |
||
131 | return 1; |
||
132 | case MSIM_KEY_F8: |
||
133 | keybuffer_push(keybuffer,FUNCTION_KEYS | 8); |
||
134 | buf = count = 0; |
||
135 | return 1; |
||
136 | case MSIM_KEY_F9: |
||
137 | keybuffer_push(keybuffer,FUNCTION_KEYS | 9); |
||
138 | buf = count = 0; |
||
139 | return 1; |
||
140 | case MSIM_KEY_F10: |
||
141 | keybuffer_push(keybuffer,FUNCTION_KEYS | 10); |
||
142 | buf = count = 0; |
||
143 | return 1; |
||
144 | case MSIM_KEY_F11: |
||
145 | keybuffer_push(keybuffer,FUNCTION_KEYS | 11); |
||
146 | buf = count = 0; |
||
147 | return 1; |
||
148 | case MSIM_KEY_F12: |
||
149 | keybuffer_push(keybuffer,FUNCTION_KEYS | 12); |
||
150 | buf = count = 0; |
||
151 | return 1; |
||
152 | default: |
||
153 | keybuffer_push(keybuffer, buf & 0xff); |
||
154 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
||
155 | keybuffer_push(keybuffer, (buf >> 16) &0xff); |
||
156 | keybuffer_push(keybuffer, (buf >> 24) &0xff); |
||
157 | keybuffer_push(keybuffer, scan_code); |
||
158 | buf = count = 0; |
||
159 | return 1; |
||
1622 | vana | 160 | } |
161 | } |
||
162 | |||
1874 | jermar | 163 | buf |= ((unsigned long) scan_code)<<(8*(count++)); |
1622 | vana | 164 | |
1874 | jermar | 165 | if((buf & 0xff) != (MSIM_KEY_F1 & 0xff)) { |
166 | keybuffer_push(keybuffer, buf); |
||
167 | buf = count = 0; |
||
1622 | vana | 168 | return 1; |
169 | } |
||
170 | |||
1874 | jermar | 171 | if (count <= 1) |
1622 | vana | 172 | return 1; |
173 | |||
1874 | jermar | 174 | if ((buf & 0xffff) != (MSIM_KEY_F1 & 0xffff) |
175 | && (buf & 0xffff) != (MSIM_KEY_F5 & 0xffff) ) { |
||
1622 | vana | 176 | |
1874 | jermar | 177 | keybuffer_push(keybuffer, buf & 0xff); |
178 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
||
179 | buf = count = 0; |
||
1622 | vana | 180 | return 1; |
181 | } |
||
182 | |||
1874 | jermar | 183 | if (count <= 2) |
1622 | vana | 184 | return 1; |
185 | |||
1874 | jermar | 186 | switch (buf) { |
187 | case MSIM_KEY_F1: |
||
188 | keybuffer_push(keybuffer,FUNCTION_KEYS | 1); |
||
189 | buf = count = 0; |
||
190 | return 1; |
||
191 | case MSIM_KEY_F2: |
||
192 | keybuffer_push(keybuffer,FUNCTION_KEYS | 2); |
||
193 | buf = count = 0; |
||
194 | return 1; |
||
195 | case MSIM_KEY_F3: |
||
196 | keybuffer_push(keybuffer,FUNCTION_KEYS | 3); |
||
197 | buf = count = 0; |
||
198 | return 1; |
||
199 | case MSIM_KEY_F4: |
||
200 | keybuffer_push(keybuffer,FUNCTION_KEYS | 4); |
||
201 | buf = count = 0; |
||
202 | return 1; |
||
1622 | vana | 203 | } |
204 | |||
205 | |||
1874 | jermar | 206 | if((buf & 0xffffff) != (MSIM_KEY_F5 & 0xffffff) |
207 | && (buf & 0xffffff) != (MSIM_KEY_F9 & 0xffffff)) { |
||
1622 | vana | 208 | |
1874 | jermar | 209 | keybuffer_push(keybuffer, buf & 0xff); |
210 | keybuffer_push(keybuffer, (buf >> 8) & 0xff); |
||
211 | keybuffer_push(keybuffer, (buf >> 16) & 0xff); |
||
1622 | vana | 212 | buf=count=0; |
213 | return 1; |
||
214 | } |
||
215 | |||
1874 | jermar | 216 | if (count <= 3) |
1622 | vana | 217 | return 1; |
218 | |||
1874 | jermar | 219 | switch (buf) { |
220 | case MSIM_KEY_F5: |
||
221 | case MSIM_KEY_F6: |
||
222 | case MSIM_KEY_F7: |
||
223 | case MSIM_KEY_F8: |
||
224 | case MSIM_KEY_F9: |
||
225 | case MSIM_KEY_F10: |
||
226 | case MSIM_KEY_F11: |
||
227 | case MSIM_KEY_F12: |
||
228 | return 1; |
||
229 | default: |
||
230 | keybuffer_push(keybuffer, buf & 0xff); |
||
231 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
||
232 | keybuffer_push(keybuffer, (buf >> 16) &0xff); |
||
233 | keybuffer_push(keybuffer, (buf >> 24) &0xff); |
||
234 | buf = count = 0; |
||
235 | return 1; |
||
236 | } |
||
1622 | vana | 237 | return 1; |
1347 | palkovsky | 238 | } |
1632 | vana | 239 | |
240 | |||
241 | |||
1699 | vana | 242 | static int kbd_arch_process_fb(keybuffer_t *keybuffer, int scan_code) |
1632 | vana | 243 | { |
1874 | jermar | 244 | static unsigned long buf = 0; |
245 | static int count = 0; |
||
1632 | vana | 246 | |
1699 | vana | 247 | /* Please preserve this code (it can be used to determine scancodes) |
1632 | vana | 248 | |
1699 | vana | 249 | keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf)); |
250 | keybuffer_push(keybuffer, to_hex(scan_code&0xf)); |
||
251 | keybuffer_push(keybuffer, ' '); |
||
252 | keybuffer_push(keybuffer, ' '); |
||
1644 | vana | 253 | |
1699 | vana | 254 | return 1; |
255 | */ |
||
256 | |||
1874 | jermar | 257 | if (scan_code == '\r') |
258 | scan_code = '\n'; |
||
1644 | vana | 259 | |
1874 | jermar | 260 | buf |= ((unsigned long) scan_code)<<(8*(count++)); |
1632 | vana | 261 | |
262 | |||
1874 | jermar | 263 | if ((buf & 0xff) != (GXEMUL_KEY_F1 & 0xff)) { |
264 | keybuffer_push(keybuffer, buf); |
||
265 | buf = count = 0; |
||
1632 | vana | 266 | return 1; |
267 | } |
||
268 | |||
1874 | jermar | 269 | if (count <= 1) |
1632 | vana | 270 | return 1; |
271 | |||
1874 | jermar | 272 | if ((buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)) { |
273 | keybuffer_push(keybuffer, buf & 0xff); |
||
274 | keybuffer_push(keybuffer, (buf >> 8) &0xff); |
||
275 | buf = count = 0; |
||
1632 | vana | 276 | return 1; |
277 | } |
||
278 | |||
1874 | jermar | 279 | if (count <= 2) |
1632 | vana | 280 | return 1; |
281 | |||
282 | |||
1874 | jermar | 283 | if ((buf & 0xffffff) != (GXEMUL_KEY_F1 & 0xffffff) |
284 | && (buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff) |
||
285 | && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff)) { |
||
1632 | vana | 286 | |
1874 | jermar | 287 | keybuffer_push(keybuffer, buf & 0xff); |
288 | keybuffer_push(keybuffer, (buf >> 8) & 0xff); |
||
289 | keybuffer_push(keybuffer, (buf >> 16) & 0xff); |
||
290 | buf = count = 0; |
||
1632 | vana | 291 | return 1; |
292 | } |
||
293 | |||
294 | if ( count <= 3 ) |
||
295 | return 1; |
||
296 | |||
297 | |||
1874 | jermar | 298 | switch (buf) { |
299 | case GXEMUL_KEY_F1: |
||
300 | keybuffer_push(keybuffer,FUNCTION_KEYS | 1 ); |
||
301 | buf=count=0; |
||
302 | return 1; |
||
303 | case GXEMUL_KEY_F2: |
||
304 | keybuffer_push(keybuffer,FUNCTION_KEYS | 2 ); |
||
305 | buf=count=0; |
||
306 | return 1; |
||
307 | case GXEMUL_KEY_F3: |
||
308 | keybuffer_push(keybuffer,FUNCTION_KEYS | 3 ); |
||
309 | buf=count=0; |
||
310 | return 1; |
||
311 | case GXEMUL_KEY_F4: |
||
312 | keybuffer_push(keybuffer,FUNCTION_KEYS | 4 ); |
||
313 | buf=count=0; |
||
314 | return 1; |
||
315 | case GXEMUL_KEY_F5: |
||
316 | keybuffer_push(keybuffer,FUNCTION_KEYS | 5 ); |
||
317 | buf=count=0; |
||
318 | return 1; |
||
319 | case GXEMUL_KEY_F6: |
||
320 | keybuffer_push(keybuffer,FUNCTION_KEYS | 6 ); |
||
321 | buf=count=0; |
||
322 | return 1; |
||
323 | case GXEMUL_KEY_F7: |
||
324 | keybuffer_push(keybuffer,FUNCTION_KEYS | 7 ); |
||
325 | buf=count=0; |
||
326 | return 1; |
||
327 | case GXEMUL_KEY_F8: |
||
328 | keybuffer_push(keybuffer,FUNCTION_KEYS | 8 ); |
||
329 | buf=count=0; |
||
330 | return 1; |
||
331 | case GXEMUL_KEY_F9: |
||
332 | keybuffer_push(keybuffer,FUNCTION_KEYS | 9 ); |
||
333 | buf=count=0; |
||
334 | return 1; |
||
335 | case GXEMUL_KEY_F10: |
||
336 | keybuffer_push(keybuffer,FUNCTION_KEYS | 10 ); |
||
337 | buf=count=0; |
||
338 | return 1; |
||
339 | case GXEMUL_KEY_F11: |
||
340 | keybuffer_push(keybuffer,FUNCTION_KEYS | 11 ); |
||
341 | buf=count=0; |
||
342 | return 1; |
||
343 | case GXEMUL_KEY_F12: |
||
344 | keybuffer_push(keybuffer,FUNCTION_KEYS | 12 ); |
||
345 | buf=count=0; |
||
346 | return 1; |
||
347 | default: |
||
348 | keybuffer_push(keybuffer, buf & 0xff ); |
||
349 | keybuffer_push(keybuffer, (buf >> 8) &0xff ); |
||
350 | keybuffer_push(keybuffer, (buf >> 16) &0xff ); |
||
351 | keybuffer_push(keybuffer, (buf >> 24) &0xff ); |
||
352 | buf=count=0; |
||
353 | return 1; |
||
354 | } |
||
1632 | vana | 355 | return 1; |
356 | } |
||
357 | |||
1694 | palkovsky | 358 | int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call) |
1632 | vana | 359 | { |
1694 | palkovsky | 360 | int scan_code = IPC_GET_ARG2(*call); |
1645 | vana | 361 | static int esc_count=0; |
362 | |||
1874 | jermar | 363 | if (scan_code == 0x1b) { |
1645 | vana | 364 | esc_count++; |
1874 | jermar | 365 | if (esc_count == 3) |
1645 | vana | 366 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
367 | } else { |
||
368 | esc_count=0; |
||
369 | } |
||
370 | |||
1874 | jermar | 371 | if (fb_fb) |
372 | return kbd_arch_process_fb(keybuffer, scan_code); |
||
373 | |||
1699 | vana | 374 | return kbd_arch_process_no_fb(keybuffer, scan_code); |
1632 | vana | 375 | } |
1699 | vana | 376 | /** @} |
377 | */ |