Subversion Repositories HelenOS

Rev

Rev 2360 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2360 Rev 2409
Line 40... Line 40...
40
#include <kbd.h>
40
#include <kbd.h>
41
#include <keys.h>
41
#include <keys.h>
42
#include <bool.h>
42
#include <bool.h>
43
 
43
 
44
 
44
 
-
 
45
/* GXemul key codes in no-framebuffer mode. */
45
#define GXEMUL_KEY_F1  0x504f1bL
46
#define GXEMUL_KEY_F1  0x504f1bL
46
#define GXEMUL_KEY_F2  0x514f1bL
47
#define GXEMUL_KEY_F2  0x514f1bL
47
#define GXEMUL_KEY_F3  0x524f1bL
48
#define GXEMUL_KEY_F3  0x524f1bL
48
#define GXEMUL_KEY_F4  0x534f1bL
49
#define GXEMUL_KEY_F4  0x534f1bL
49
#define GXEMUL_KEY_F5  0x35315b1bL
50
#define GXEMUL_KEY_F5  0x35315b1bL
Line 53... Line 54...
53
#define GXEMUL_KEY_F9  0x30325b1bL
54
#define GXEMUL_KEY_F9  0x30325b1bL
54
#define GXEMUL_KEY_F10 0x31325b1bL
55
#define GXEMUL_KEY_F10 0x31325b1bL
55
#define GXEMUL_KEY_F11 0x33325d1bL
56
#define GXEMUL_KEY_F11 0x33325d1bL
56
#define GXEMUL_KEY_F12 0x34325b1bL 
57
#define GXEMUL_KEY_F12 0x34325b1bL 
57
 
58
 
-
 
59
/** Start code of F5-F12 keys. */
-
 
60
#define GXEMUL_KEY_F5_F12_START_CODE 0x7e
58
 
61
 
-
 
62
/* GXemul key codes in framebuffer mode. */
59
#define GXEMUL_FB_KEY_F1 0x504f5b1bL
63
#define GXEMUL_FB_KEY_F1 0x504f5b1bL
60
#define GXEMUL_FB_KEY_F2 0x514f5b1bL
64
#define GXEMUL_FB_KEY_F2 0x514f5b1bL
61
#define GXEMUL_FB_KEY_F3 0x524f5b1bL
65
#define GXEMUL_FB_KEY_F3 0x524f5b1bL
62
#define GXEMUL_FB_KEY_F4 0x534f5b1bL
66
#define GXEMUL_FB_KEY_F4 0x534f5b1bL
63
#define GXEMUL_FB_KEY_F5 0x35315b1bL
67
#define GXEMUL_FB_KEY_F5 0x35315b1bL
Line 101... Line 105...
101
*/
105
*/
102
 
106
 
103
 
107
 
104
/** Process data sent when a key is pressed (in no-framebuffer mode).
108
/** Process data sent when a key is pressed (in no-framebuffer mode).
105
 *  
109
 *  
106
 *  @param keybuffer Buffer of scan codes.
110
 *  @param keybuffer Buffer of pressed key.
107
 *  @param scan_code Scan code.
111
 *  @param scan_code Scan code.
108
 *
112
 *
109
 *  @return Code of the pressed key.
113
 *  @return Always 1.
110
 */
114
 */
111
static int gxemul_process_no_fb(keybuffer_t *keybuffer, int scan_code)
115
static int gxemul_kbd_process_no_fb(keybuffer_t *keybuffer, int scan_code)
112
{
116
{
113
 
-
 
-
 
117
    // holds at most 4 latest scan codes
114
    static unsigned long buf = 0;
118
    static unsigned long buf = 0;
-
 
119
 
-
 
120
    // number of scan codes in #buf
115
    static int count = 0;  
121
    static int count = 0;  
116
 
122
 
-
 
123
    /*
117
    // Preserve for detecting scan codes. 
124
    // Preserve for detecting scan codes.
118
    // keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
125
    keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
119
    // keybuffer_push(keybuffer, to_hex(scan_code&0xf));
126
    keybuffer_push(keybuffer, to_hex(scan_code&0xf));
120
    // keybuffer_push(keybuffer, 'X');
127
    keybuffer_push(keybuffer, 'X');
121
    // keybuffer_push(keybuffer, 'Y');
128
    keybuffer_push(keybuffer, 'Y');
122
    // return 1;
129
    return 1;
-
 
130
    */
123
 
131
 
124
    if (scan_code == '\r')
132
    if (scan_code == '\r') {
125
        scan_code = '\n';
133
        scan_code = '\n';
-
 
134
    }
126
 
135
   
127
    if(scan_code == 0x7e) {
136
    if (scan_code == GXEMUL_KEY_F5_F12_START_CODE) {
128
        switch (buf) {
137
        switch (buf) {
129
        case GXEMUL_KEY_F5:
138
        case GXEMUL_KEY_F5:
130
            keybuffer_push(keybuffer,FUNCTION_KEYS | 5);
139
            keybuffer_push(keybuffer,FUNCTION_KEYS | 5);
131
            buf = count = 0;
140
            buf = count = 0;
132
            return 1;
141
            return 1;
Line 158... Line 167...
158
            keybuffer_push(keybuffer,FUNCTION_KEYS | 12);
167
            keybuffer_push(keybuffer,FUNCTION_KEYS | 12);
159
            buf = count = 0;
168
            buf = count = 0;
160
            return 1;
169
            return 1;
161
        default:
170
        default:
162
            keybuffer_push(keybuffer, buf & 0xff);
171
            keybuffer_push(keybuffer, buf & 0xff);
163
            keybuffer_push(keybuffer, (buf >> 8) &0xff);
172
            keybuffer_push(keybuffer, (buf >> 8)  & 0xff);
164
            keybuffer_push(keybuffer, (buf >> 16) &0xff);
173
            keybuffer_push(keybuffer, (buf >> 16) & 0xff);
165
            keybuffer_push(keybuffer, (buf >> 24) &0xff);
174
            keybuffer_push(keybuffer, (buf >> 24) & 0xff);
166
            keybuffer_push(keybuffer, scan_code);
175
            keybuffer_push(keybuffer, scan_code);
167
            buf = count = 0;
176
            buf = count = 0;
168
            return 1;
177
            return 1;
169
        }
178
        }
170
    }
179
    }
171
 
180
 
-
 
181
    // add to buffer
172
    buf |= ((unsigned long) scan_code)<<(8*(count++));
182
    buf |= ((unsigned long) scan_code) << (8 * (count++));
173
   
183
   
174
    if((buf & 0xff) != (GXEMUL_KEY_F1 & 0xff)) {
184
    if ((buf & 0xff) != (GXEMUL_KEY_F1 & 0xff)) {
175
        keybuffer_push(keybuffer, buf);
185
        keybuffer_push(keybuffer, buf);
176
        buf = count = 0;
186
        buf = count = 0;
177
        return 1;
187
        return 1;
178
    }
188
    }
179
 
189
 
180
    if (count <= 1)
190
    if (count <= 1) {
181
        return 1;
191
        return 1;
-
 
192
    }
182
 
193
 
183
    if ((buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)
194
    if ((buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)
184
        && (buf & 0xffff) != (GXEMUL_KEY_F5 & 0xffff) ) {
195
        && (buf & 0xffff) != (GXEMUL_KEY_F5 & 0xffff) ) {
185
 
196
 
186
        keybuffer_push(keybuffer, buf & 0xff);
197
        keybuffer_push(keybuffer, buf & 0xff);
187
        keybuffer_push(keybuffer, (buf >> 8) &0xff);
198
        keybuffer_push(keybuffer, (buf >> 8) &0xff);
188
        buf = count = 0;
199
        buf = count = 0;
189
        return 1;
200
        return 1;
190
    }
201
    }
191
 
202
 
192
    if (count <= 2)
203
    if (count <= 2) {
193
        return 1;
204
        return 1;
-
 
205
    }
194
 
206
 
195
    switch (buf) {
207
    switch (buf) {
196
    case GXEMUL_KEY_F1:
208
    case GXEMUL_KEY_F1:
197
        keybuffer_push(keybuffer,FUNCTION_KEYS | 1);
209
        keybuffer_push(keybuffer,FUNCTION_KEYS | 1);
198
        buf = count = 0;
210
        buf = count = 0;
Line 210... Line 222...
210
        buf = count = 0;
222
        buf = count = 0;
211
        return 1;
223
        return 1;
212
    }
224
    }
213
 
225
 
214
 
226
 
215
    if((buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
227
    if ((buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
216
        && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff)) {
228
        && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff)) {
217
 
229
 
218
        keybuffer_push(keybuffer, buf & 0xff);
230
        keybuffer_push(keybuffer, buf & 0xff);
219
        keybuffer_push(keybuffer, (buf >> 8) & 0xff);
231
        keybuffer_push(keybuffer, (buf >> 8) & 0xff);
220
        keybuffer_push(keybuffer, (buf >> 16) & 0xff);
232
        keybuffer_push(keybuffer, (buf >> 16) & 0xff);
221
        buf=count=0;
233
        buf = count = 0;
222
        return 1;
234
        return 1;
223
    }
235
    }
224
 
236
 
225
    if (count <= 3)
237
    if (count <= 3) {
226
        return 1;
238
        return 1;
-
 
239
    }
227
   
240
   
228
    switch (buf) {
241
    switch (buf) {
229
    case GXEMUL_KEY_F5:
242
    case GXEMUL_KEY_F5:
230
    case GXEMUL_KEY_F6:
243
    case GXEMUL_KEY_F6:
231
    case GXEMUL_KEY_F7:
244
    case GXEMUL_KEY_F7:
Line 235... Line 248...
235
    case GXEMUL_KEY_F11:
248
    case GXEMUL_KEY_F11:
236
    case GXEMUL_KEY_F12:
249
    case GXEMUL_KEY_F12:
237
        return 1;
250
        return 1;
238
    default:
251
    default:
239
        keybuffer_push(keybuffer, buf & 0xff);
252
        keybuffer_push(keybuffer, buf & 0xff);
240
        keybuffer_push(keybuffer, (buf >> 8) &0xff);
253
        keybuffer_push(keybuffer, (buf >> 8)  & 0xff);
241
        keybuffer_push(keybuffer, (buf >> 16) &0xff);
254
        keybuffer_push(keybuffer, (buf >> 16) & 0xff);
242
        keybuffer_push(keybuffer, (buf >> 24) &0xff);
255
        keybuffer_push(keybuffer, (buf >> 24) & 0xff);
243
        buf = count = 0;
256
        buf = count = 0;
244
        return 1;
257
        return 1;
245
    }
258
    }
-
 
259
 
246
    return 1;
260
    return 1;
247
}
261
}
248
 
262
 
249
 
263
 
250
/** Process data sent when a key is pressed (in framebuffer mode).
264
/** Process data sent when a key is pressed (in framebuffer mode).
251
 *  
265
 *  
252
 *  @param keybuffer Buffer of scan codes.
266
 *  @param keybuffer Buffer of pressed keys.
253
 *  @param scan_code Scan code.
267
 *  @param scan_code Scan code.
254
 *
268
 *
255
 *  @return Code of the pressed key.
269
 *  @return Always 1.
256
 */
270
 */
257
static int gxemul_process_fb(keybuffer_t *keybuffer, int scan_code)
271
static int gxemul_kbd_process_fb(keybuffer_t *keybuffer, int scan_code)
258
{
272
{
-
 
273
    // holds at most 4 latest scan codes
259
    static unsigned long buf = 0;
274
    static unsigned long buf = 0;
260
    static int count = 0;
-
 
261
 
275
 
262
    /* Please preserve this code (it can be used to determine scancodes)
276
    // number of scan codes in #buf
-
 
277
    static int count = 0;  
263
   
278
 
-
 
279
    /*
-
 
280
    // Please preserve this code (it can be used to determine scancodes)
264
    keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
281
    keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
265
    keybuffer_push(keybuffer, to_hex(scan_code&0xf));
282
    keybuffer_push(keybuffer, to_hex(scan_code&0xf));
266
    keybuffer_push(keybuffer, ' ');
283
    keybuffer_push(keybuffer, ' ');
267
    keybuffer_push(keybuffer, ' ');
284
    keybuffer_push(keybuffer, ' ');
268
   
-
 
269
    return 1;
285
    return 1;
270
    */
286
    */
271
   
287
   
272
    if (scan_code == '\r')
288
    if (scan_code == '\r') {
273
        scan_code = '\n';
289
        scan_code = '\n';
-
 
290
    }
274
   
291
   
-
 
292
    // add to buffer
275
    buf |= ((unsigned long) scan_code)<<(8*(count++));
293
    buf |= ((unsigned long) scan_code) << (8*(count++));
276
   
294
   
277
   
295
   
278
    if ((buf & 0xff) != (GXEMUL_FB_KEY_F1 & 0xff)) {
296
    if ((buf & 0xff) != (GXEMUL_FB_KEY_F1 & 0xff)) {
279
        keybuffer_push(keybuffer, buf);
297
        keybuffer_push(keybuffer, buf);
280
        buf = count = 0;
298
        buf = count = 0;
281
        return 1;
299
        return 1;
282
    }
300
    }
283
 
301
 
284
    if (count <= 1)
302
    if (count <= 1) {
285
        return 1;
303
        return 1;
-
 
304
    }
286
 
305
 
287
    if ((buf & 0xffff) != (GXEMUL_FB_KEY_F1 & 0xffff)) {
306
    if ((buf & 0xffff) != (GXEMUL_FB_KEY_F1 & 0xffff)) {
288
        keybuffer_push(keybuffer, buf & 0xff);
307
        keybuffer_push(keybuffer, buf & 0xff);
289
        keybuffer_push(keybuffer, (buf >> 8) &0xff);
308
        keybuffer_push(keybuffer, (buf >> 8) &0xff);
290
        buf = count = 0;
309
        buf = count = 0;
291
        return 1;
310
        return 1;
292
    }
311
    }
293
 
312
 
294
    if (count <= 2)
313
    if (count <= 2) {
295
        return 1;
314
        return 1;
296
 
315
    }
297
 
316
 
298
    if ((buf & 0xffffff) != (GXEMUL_FB_KEY_F1 & 0xffffff)
317
    if ((buf & 0xffffff) != (GXEMUL_FB_KEY_F1 & 0xffffff)
299
        && (buf & 0xffffff) != (GXEMUL_FB_KEY_F5 & 0xffffff)
318
        && (buf & 0xffffff) != (GXEMUL_FB_KEY_F5 & 0xffffff)
300
        && (buf & 0xffffff) != (GXEMUL_FB_KEY_F9 & 0xffffff)) {
319
        && (buf & 0xffffff) != (GXEMUL_FB_KEY_F9 & 0xffffff)) {
301
 
320
 
Line 304... Line 323...
304
        keybuffer_push(keybuffer, (buf >> 16) & 0xff);
323
        keybuffer_push(keybuffer, (buf >> 16) & 0xff);
305
        buf = count = 0;
324
        buf = count = 0;
306
        return 1;
325
        return 1;
307
    }
326
    }
308
 
327
 
309
    if ( count <= 3 )
328
    if (count <= 3) {
310
        return 1;
329
        return 1;
311
   
330
    }
312
 
331
 
313
    switch (buf) {
332
    switch (buf) {
314
    case GXEMUL_FB_KEY_F1:
333
    case GXEMUL_FB_KEY_F1:
315
        keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
334
        keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
316
        buf=count=0;
335
        buf = count = 0;
317
        return 1;
336
        return 1;
318
    case GXEMUL_FB_KEY_F2:
337
    case GXEMUL_FB_KEY_F2:
319
        keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
338
        keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
320
        buf=count=0;
339
        buf = count = 0;
321
        return 1;
340
        return 1;
322
    case GXEMUL_FB_KEY_F3:
341
    case GXEMUL_FB_KEY_F3:
323
        keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
342
        keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
324
        buf=count=0;
343
        buf = count = 0;
325
        return 1;
344
        return 1;
326
    case GXEMUL_FB_KEY_F4:
345
    case GXEMUL_FB_KEY_F4:
327
        keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
346
        keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
328
        buf=count=0;
347
        buf = count = 0;
329
        return 1;
348
        return 1;
330
    case GXEMUL_FB_KEY_F5:
349
    case GXEMUL_FB_KEY_F5:
331
        keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
350
        keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
332
        buf=count=0;
351
        buf = count = 0;
333
        return 1;
352
        return 1;
334
    case GXEMUL_FB_KEY_F6:
353
    case GXEMUL_FB_KEY_F6:
335
        keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
354
        keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
336
        buf=count=0;
355
        buf = count = 0;
337
        return 1;
356
        return 1;
338
    case GXEMUL_FB_KEY_F7:
357
    case GXEMUL_FB_KEY_F7:
339
        keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
358
        keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
340
        buf=count=0;
359
        buf = count = 0;
341
        return 1;
360
        return 1;
342
    case GXEMUL_FB_KEY_F8:
361
    case GXEMUL_FB_KEY_F8:
343
        keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
362
        keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
344
        buf=count=0;
363
        buf = count = 0;
345
        return 1;
364
        return 1;
346
    case GXEMUL_FB_KEY_F9:
365
    case GXEMUL_FB_KEY_F9:
347
        keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
366
        keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
348
        buf=count=0;
367
        buf = count = 0;
349
        return 1;
368
        return 1;
350
    case GXEMUL_FB_KEY_F10:
369
    case GXEMUL_FB_KEY_F10:
351
        keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
370
        keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
352
        buf=count=0;
371
        buf = count = 0;
353
        return 1;
372
        return 1;
354
    case GXEMUL_FB_KEY_F11:
373
    case GXEMUL_FB_KEY_F11:
355
        keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
374
        keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
356
        buf=count=0;
375
        buf = count = 0;
357
        return 1;
376
        return 1;
358
    case GXEMUL_FB_KEY_F12:
377
    case GXEMUL_FB_KEY_F12:
359
        keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
378
        keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
360
        buf=count=0;
379
        buf = count = 0;
361
        return 1;
380
        return 1;
362
    default:
381
    default:
363
        keybuffer_push(keybuffer, buf & 0xff );
382
        keybuffer_push(keybuffer, buf & 0xff );
364
        keybuffer_push(keybuffer, (buf >> 8) &0xff );
383
        keybuffer_push(keybuffer, (buf >> 8)  & 0xff);
365
        keybuffer_push(keybuffer, (buf >> 16) &0xff );
384
        keybuffer_push(keybuffer, (buf >> 16) & 0xff);
366
        keybuffer_push(keybuffer, (buf >> 24) &0xff );
385
        keybuffer_push(keybuffer, (buf >> 24) & 0xff);
367
        buf=count=0;
386
        buf = count = 0;
368
        return 1;
387
        return 1;
369
    }
388
    }
-
 
389
 
370
    return 1;
390
    return 1;
371
}
391
}
372
 
392
 
373
 
393
 
374
/** Initializes keyboard handler. */
394
/** Initializes keyboard handler. */
Line 381... Line 401...
381
}
401
}
382
 
402
 
383
 
403
 
384
/** Process data sent when a key is pressed.
404
/** Process data sent when a key is pressed.
385
 *  
405
 *  
386
 *  @param keybuffer Buffer of scan codes.
406
 *  @param keybuffer Buffer of pressed keys.
387
 *  @param call      IPC call.
407
 *  @param call      IPC call.
388
 *
408
 *
389
 *  @return Code of the pressed key.
409
 *  @return Always 1.
390
 */
410
 */
391
int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
411
int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
392
{
412
{
393
    int scan_code = IPC_GET_ARG2(*call);
413
    int scan_code = IPC_GET_ARG2(*call);
394
    static int esc_count = 0;
-
 
395
 
-
 
396
    if (scan_code == 0x1b) {
-
 
397
        esc_count++;
-
 
398
        if (esc_count == 3) {
-
 
399
            __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
-
 
400
        }
-
 
401
    } else {
-
 
402
        esc_count = 0;
-
 
403
    }
-
 
404
 
414
 
405
    if (fb) {
415
    if (fb) {
406
        return gxemul_process_fb(keybuffer, scan_code);
416
        return gxemul_kbd_process_fb(keybuffer, scan_code);
407
    } else {
417
    } else {
408
        return gxemul_process_no_fb(keybuffer, scan_code);
418
        return gxemul_kbd_process_no_fb(keybuffer, scan_code);
409
    }
419
    }
410
 
420
 
411
}
421
}
412
 
422
 
413
/** @}
423
/** @}