OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [drivers/] [kbd_ttyscan.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
3
 *
4
 * Microwindows /dev/tty console scancode keyboard driver for Linux
5
 */
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <unistd.h>
10
#include <sys/types.h>
11
#include <fcntl.h>
12
#include <errno.h>
13
#include <termios.h>
14
#include <sys/ioctl.h>
15
#include <linux/keyboard.h>
16
#include <linux/kd.h>
17
#include <linux/vt.h>
18
#include "device.h"
19
#include "fb.h"
20
 
21
#define KEYBOARD        "/dev/tty"      /* console kbd to open*/
22
 
23
static int  TTY_Open(KBDDEVICE *pkd);
24
static void TTY_Close(void);
25
static void TTY_GetModifierInfo(MWKEYMOD *modifiers, MWKEYMOD *curmodifiers);
26
static int  TTY_Read(MWKEY *kbuf, MWKEYMOD *modifiers, MWSCANCODE *scancode);
27
 
28
KBDDEVICE kbddev = {
29
        TTY_Open,
30
        TTY_Close,
31
        TTY_GetModifierInfo,
32
        TTY_Read,
33
        NULL
34
};
35
 
36
#define RELEASED        0
37
#define PRESSED         1
38
 
39
static  int             fd;             /* file descriptor for keyboard */
40
static  struct termios  old;            /* original terminal modes */
41
static  int             old_kbd_mode;
42
static unsigned char    key_state[MWKEY_LAST];  /* FIXME - make sparse array */
43
static MWKEYMOD         key_modstate;
44
 
45
/* kernel unicode tables per shiftstate and scancode*/
46
#define NUM_VGAKEYMAPS  (1<<KG_CAPSSHIFT)       /* kernel key maps*/
47
static unsigned short   os_keymap[NUM_VGAKEYMAPS][NR_KEYS];
48
 
49
/* PC scancode -> Microwindows key value mapping for non-Linux kernel values*/
50
static MWKEY            keymap[128] = {
51
MWKEY_UNKNOWN, MWKEY_ESCAPE, '1', '2', '3',                             /* 0*/
52
'4', '5', '6', '7', '8',                                                /* 5*/
53
'9', '0', '-', '=', MWKEY_BACKSPACE,                                    /* 10*/
54
MWKEY_TAB, 'q', 'w', 'e', 'r',                                          /* 15*/
55
't', 'y', 'u', 'i', 'o',                                                /* 20*/
56
'o', '[', ']', MWKEY_ENTER, MWKEY_LCTRL,                                /* 25*/
57
'a', 's', 'd', 'f', 'g',                                                /* 30*/
58
'h', 'j', 'k', 'l', ';',                                                /* 35*/
59
'\'', '`', MWKEY_LSHIFT, '\\', 'z',                                     /* 40*/
60
'x', 'c', 'v', 'b', 'n',                                                /* 45*/
61
'm', ',', '.', '/', MWKEY_RSHIFT,                                       /* 50*/
62
MWKEY_KP_MULTIPLY, MWKEY_LALT, ' ', MWKEY_CAPSLOCK, MWKEY_F1,           /* 55*/
63
MWKEY_F2, MWKEY_F3, MWKEY_F4, MWKEY_F5, MWKEY_F6,                       /* 60*/
64
MWKEY_F7, MWKEY_F8, MWKEY_F9, MWKEY_F10, MWKEY_NUMLOCK,                 /* 65*/
65
MWKEY_SCROLLOCK, MWKEY_KP7, MWKEY_KP8, MWKEY_KP9, MWKEY_KP_MINUS,       /* 70*/
66
MWKEY_KP4, MWKEY_KP5, MWKEY_KP6, MWKEY_KP_PLUS, MWKEY_KP1,              /* 75*/
67
MWKEY_KP2, MWKEY_KP3, MWKEY_KP0, MWKEY_KP_PERIOD, MWKEY_UNKNOWN,        /* 80*/
68
MWKEY_UNKNOWN, MWKEY_UNKNOWN, MWKEY_F11, MWKEY_F12, MWKEY_UNKNOWN,      /* 85*/
69
MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,  /* 90*/
70
MWKEY_UNKNOWN, MWKEY_KP_ENTER, MWKEY_RCTRL, MWKEY_KP_DIVIDE,MWKEY_PRINT,/* 95*/
71
MWKEY_RALT, MWKEY_BREAK, MWKEY_HOME, MWKEY_UP, MWKEY_PAGEUP,            /* 100*/
72
MWKEY_LEFT, MWKEY_RIGHT, MWKEY_END, MWKEY_DOWN, MWKEY_PAGEDOWN,         /* 105*/
73
MWKEY_INSERT, MWKEY_DELETE, MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,  /* 110*/
74
MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_PAUSE,    /* 115*/
75
MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,MWKEY_UNKNOWN,  /* 120*/
76
MWKEY_LMETA, MWKEY_RMETA, MWKEY_MENU                                    /* 125*/
77
};
78
 
79
static MWBOOL   UpdateKeyState(int pressed, MWKEY mwkey);
80
static void     UpdateLEDState(MWKEYMOD modstate);
81
static MWKEY    TranslateScancode(int scancode, MWKEYMOD modstate);
82
static void     LoadKernelKeymaps(int fd);
83
static MWBOOL   switch_vt(unsigned short which);
84
 
85
/*
86
 * Open the keyboard.
87
 * This is real simple, we just use a special file handle
88
 * that allows non-blocking I/O, and put the terminal into
89
 * character mode.
90
 */
91
static int
92
TTY_Open(KBDDEVICE *pkd)
93
{
94
  char *env;
95
 
96
        int             i;
97
        int             ledstate = 0;
98
        struct termios  new;
99
 
100
        /* Open "CONSOLE" or /dev/tty device*/
101
        if(!(env = getenv("CONSOLE")))
102
                fd = open(KEYBOARD, O_NONBLOCK);
103
        else
104
                fd = open(env, O_NONBLOCK);
105 716 simons
 
106 673 markom
        if (fd < 0)
107
                return -1;
108
 
109
        /* Save previous settings*/
110
        if (ioctl(fd, KDGKBMODE, &old_kbd_mode) < 0) {
111
                perror("KDGKMODE");
112
                goto err;
113
        }
114
        if (tcgetattr(fd, &old) < 0)
115
                goto err;
116
 
117
        /* Set medium-raw keyboard mode */
118
        new = old;
119
        /* ISIG and BRKINT must be set otherwise '2' is ^C (scancode 3)!!*/
120
        new.c_lflag &= ~(ICANON | ECHO | ISIG);
121
        new.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON
122
                        | BRKINT);
123
        new.c_cc[VMIN] = 0;
124
        new.c_cc[VTIME] = 0;
125
 
126
        if (tcsetattr(fd, TCSAFLUSH, &new) < 0) {
127
                TTY_Close();
128
                return -1;
129
        }
130
        if (ioctl(fd, KDSKBMODE, K_MEDIUMRAW) < 0) {
131
                TTY_Close();
132
                return -1;
133
        }
134
 
135
        /* Load OS keymappings*/
136
        LoadKernelKeymaps(fd);
137
 
138
        /* Initialize keyboard state*/
139
        key_modstate = MWKMOD_NONE;
140
        for (i=0; i<MWKEY_LAST; ++i)
141
                key_state[i] = RELEASED;
142
 
143
        /* preset CAPSLOCK and NUMLOCK from startup LED state*/
144
        if (ioctl(fd, KDGETLED, &ledstate) == 0) {
145
                if (ledstate & LED_CAP) {
146
                        key_modstate |= MWKMOD_CAPS;
147
                        key_state[MWKEY_CAPSLOCK] = PRESSED;
148
                }
149
                if (ledstate & LED_NUM) {
150
                        key_modstate |= MWKMOD_NUM;
151
                        key_state[MWKEY_NUMLOCK] = PRESSED;
152
                }
153
        }
154
        UpdateLEDState(key_modstate);
155
 
156
        return fd;
157
 
158
err:
159
        close(fd);
160
        fd = -1;
161
        return -1;
162
}
163
 
164
/*
165
 * Close the keyboard.
166
 * This resets the terminal modes.
167
 */
168
static void
169
TTY_Close(void)
170
{
171
        int     ledstate = 0x80000000L;
172
 
173
        if (fd >= 0) {
174
                /* revert LEDs to follow key modifiers*/
175
                if (ioctl(fd, KDSETLED, ledstate) < 0)
176
                        perror("KDSETLED");
177
 
178
                /* reset terminal mode*/
179
                if (ioctl(fd, KDSKBMODE, old_kbd_mode) < 0)
180
                        perror("KDSKBMODE");
181
                tcsetattr(fd, TCSAFLUSH, &old);
182
 
183
                close(fd);
184
        }
185
        fd = -1;
186
}
187
 
188
/*
189
 * Return the possible modifiers and current modifiers for the keyboard.
190
 */
191
static  void
192
TTY_GetModifierInfo(MWKEYMOD *modifiers, MWKEYMOD *curmodifiers)
193
{
194
        if (modifiers)
195
                *modifiers = MWKMOD_CTRL | MWKMOD_SHIFT | MWKMOD_ALT |
196
                        MWKMOD_META | MWKMOD_ALTGR | MWKMOD_CAPS | MWKMOD_NUM;
197
        if (curmodifiers)
198
                *curmodifiers = key_modstate;
199
}
200
 
201
/*
202
 * This reads one keystroke from the keyboard, and the current state of
203
 * the modifier keys (ALT, SHIFT, etc).  Returns -1 on error, 0 if no data
204
 * is ready, 1 on a keypress, and 2 on keyrelease.
205
 * This is a non-blocking call.
206
 */
207
static int
208
TTY_Read(MWKEY *kbuf, MWKEYMOD *modifiers, MWSCANCODE *pscancode)
209
{
210
        int     cc;                     /* characters read */
211
        int     pressed;
212
        int     scancode;
213
        MWKEY   mwkey;
214
        unsigned char buf[128];
215
 
216
        cc = read(fd, buf, 1);
217
        if (cc > 0) {
218
                pressed = (*buf & 0x80) ? RELEASED: PRESSED;
219
                scancode = *buf & 0x7f;
220
                mwkey = keymap[scancode];
221
 
222
                /**if(pressed) {
223
                        printf("scan %02x really: %08x\n", *buf&0x7F, *buf);
224
                        printf("mwkey: %02x (%c)\n", mwkey, mwkey);
225
                }**/
226
 
227
                /* Handle Alt-FN for vt switch */
228
                switch (mwkey) {
229
                case MWKEY_F1:
230
                case MWKEY_F2:
231
                case MWKEY_F3:
232
                case MWKEY_F4:
233
                case MWKEY_F5:
234
                case MWKEY_F6:
235
                case MWKEY_F7:
236
                case MWKEY_F8:
237
                case MWKEY_F9:
238
                case MWKEY_F10:
239
                case MWKEY_F11:
240
                case MWKEY_F12:
241
                        if (key_modstate & MWKMOD_ALT) {
242
                                if (switch_vt(mwkey-MWKEY_F1+1)) {
243
                                        mwkey = MWKEY_REDRAW;
244
                                }
245
                        }
246
                        break;
247
                        /* Fall through to normal processing */
248
                default:
249
                        /* update internal key states*/
250
                        if (!UpdateKeyState(pressed, mwkey))
251
                                return 0;
252
 
253
                        /* mwkey is 0 if only a modifier is hit */
254
                        if(mwkey != MWKEY_LCTRL &&
255
                           mwkey != MWKEY_RCTRL &&
256
                           mwkey != MWKEY_LALT &&
257
                           mwkey != MWKEY_RALT &&
258
                           mwkey != MWKEY_RSHIFT &&
259
                           mwkey != MWKEY_LSHIFT) {
260
                                /* translate scancode to key value*/
261
                                mwkey = TranslateScancode(scancode, key_modstate);
262
                        } else {
263
                                //printf("Modifier only\n");
264
                                //mwkey = 0;
265
                        }
266
 
267
                        /* XXX Hack to get scancodes to come out the same as
268
                           everything else */
269
                        switch(scancode) {
270
                                case 0x1:           /* esc              */
271
 
272
                                case 0x29:          /* `                */
273
                                case 0x2  ... 0xe:  /* 1 - BackSpace    */
274
 
275
                                case 0xf  ... 0x1b: /* TAB - ]          */
276
                                case 0x2b:          /* \                */
277
 
278
                                case 0x3a:          /* Caps-Lock        */
279
                                case 0x1e ... 0x28: /* a - '            */
280
                                case 0x1c:          /* Enter            */
281
 
282
                                case 0x2a:          /* LShift           */
283
                                case 0x2c ... 0x35: /* z - /            */
284
                                case 0x36:          /* RShift           */
285
 
286
                                case 0x1d:          /* LCtrl            */
287
                                //case 0x7d:          /* LWin           */
288
                                case 0x38:          /* LAlt             */
289
                                case 0x39:          /* Space            */
290
                                //case 0x64:          /* RAlt           */
291
                                //case 0x7e:          /* RWin           */
292
                                //case 0x7f:          /* Win-PopupMenu  */
293
                                //case 0x61:          /* RCtrl          */
294
 
295
                                //case 0x63:          /* SysReq         */
296
                                //case 0x46:          /* Scroll Lock    */
297
                                //case 0x77:          /* Pause/Break    */
298
                                        scancode += 8;
299
                                        break;
300
 
301
                                case 0x6e:            /* Insert         */
302
                                        scancode -= 0x4;
303
                                        break;
304
                                case 0x66:            /* Home           */
305
                                case 0x68:            /* Page-Up        */
306
                                        scancode -= 0x5;
307
                                        break;
308
 
309
                                case 0x6f:            /* Delete         */
310
                                case 0x6b:            /* End            */
311
                                case 0x6d:            /* Page-Down      */
312
                                        scancode -= 0x4;
313
                                        break;
314
 
315
                                case 0x67:            /* Up arrow       */
316
                                case 0x69:            /* Left arrow     */
317
                                        scancode -= 0x5;
318
                                        break;
319
 
320
                                case 0x6a:            /* Right arrow    */
321
                                case 0x6c:            /* Down arrow     */
322
                                        scancode -= 0x4;
323
                                        break;
324
 
325
                                default:
326
                                        break;
327
                        }
328
                        break;
329
                }
330
                *kbuf = mwkey;
331
                *modifiers = key_modstate;
332
                *pscancode = scancode;
333
 
334
                /**if(pressed) {
335
                        printf("Returning: mwkey: 0x%04x, mods: 0x%x,
336
                                sc:0x%04x\n\n", *kbuf, *modifiers, *pscancode);
337
                }**/
338
                return pressed ? 1 : 2;
339
        }
340
 
341
        if ((cc < 0) && (errno != EINTR) && (errno != EAGAIN))
342
                return -1;
343
        return 0;
344
}
345
 
346
/* Update the internal keyboard state, return TRUE if changed*/
347
static MWBOOL
348
UpdateKeyState(int pressed, MWKEY mwkey)
349
{
350
        MWKEYMOD modstate = key_modstate;
351
 
352
        //printf("UpdateKeyState %02x %02x\n", pressed, mwkey);
353
        if (pressed == PRESSED) {
354
                switch (mwkey) {
355
                case MWKEY_NUMLOCK:
356
                case MWKEY_CAPSLOCK:
357
                        /* change state on release because of auto-repeat*/
358
                        return FALSE;
359
                case MWKEY_LCTRL:
360
                        modstate |= MWKMOD_LCTRL;
361
                        break;
362
                case MWKEY_RCTRL:
363
                        modstate |= MWKMOD_RCTRL;
364
                        break;
365
                case MWKEY_LSHIFT:
366
                        modstate |= MWKMOD_LSHIFT;
367
                        break;
368
                case MWKEY_RSHIFT:
369
                        modstate |= MWKMOD_RSHIFT;
370
                        break;
371
                case MWKEY_LALT:
372
                        modstate |= MWKMOD_LALT;
373
                        break;
374
                case MWKEY_RALT:
375
                        modstate |= MWKMOD_RALT;
376
                        break;
377
                case MWKEY_LMETA:
378
                        modstate |= MWKMOD_LMETA;
379
                        break;
380
                case MWKEY_RMETA:
381
                        modstate |= MWKMOD_RMETA;
382
                        break;
383
                case MWKEY_ALTGR:
384
                        modstate |= MWKMOD_ALTGR;
385
                        break;
386
                default:
387
                        break;
388
                }
389
        } else {
390
                switch (mwkey) {
391
                case MWKEY_NUMLOCK:
392
                        key_modstate ^= MWKMOD_NUM;
393
                        key_state[MWKEY_NUMLOCK] ^= PRESSED;
394
                        UpdateLEDState(key_modstate);
395
                        return TRUE;
396
                case MWKEY_CAPSLOCK:
397
                        key_modstate ^= MWKMOD_CAPS;
398
                        key_state[MWKEY_CAPSLOCK] ^= PRESSED;
399
                        UpdateLEDState(key_modstate);
400
                        return TRUE;
401
                case MWKEY_LCTRL:
402
                        modstate &= ~MWKMOD_LCTRL;
403
                        break;
404
                case MWKEY_RCTRL:
405
                        modstate &= ~MWKMOD_RCTRL;
406
                        break;
407
                case MWKEY_LSHIFT:
408
                        modstate &= ~MWKMOD_LSHIFT;
409
                        break;
410
                case MWKEY_RSHIFT:
411
                        modstate &= ~MWKMOD_RSHIFT;
412
                        break;
413
                case MWKEY_LALT:
414
                        modstate &= ~MWKMOD_LALT;
415
                        break;
416
                case MWKEY_RALT:
417
                        modstate &= ~MWKMOD_RALT;
418
                        break;
419
                case MWKEY_LMETA:
420
                        modstate &= ~MWKMOD_LMETA;
421
                        break;
422
                case MWKEY_RMETA:
423
                        modstate &= ~MWKMOD_RMETA;
424
                        break;
425
                case MWKEY_ALTGR:
426
                        modstate &= ~MWKMOD_ALTGR;
427
                        break;
428
                default:
429
                        break;
430
                }
431
        }
432
 
433
#if 0
434
        /* Drop events that don't change state */
435
        if (key_state[mwkey] == pressed)
436
                return FALSE;
437
#endif
438
        /* Update internal keyboard state */
439
        key_state[mwkey] = (unsigned char)pressed;
440
        key_modstate = modstate;
441
        return TRUE;
442
}
443
 
444
static void
445
UpdateLEDState(MWKEYMOD modstate)
446
{
447
        int     ledstate = 0;
448
 
449
        if (modstate & MWKMOD_CAPS)
450
                ledstate |= LED_CAP;
451
        if (modstate & MWKMOD_NUM)
452
                ledstate |= LED_NUM;
453
        ioctl(fd, KDSETLED, ledstate);
454
}
455
 
456
/* translate a scancode and modifier state to an MWKEY*/
457
static MWKEY
458
TranslateScancode(int scancode, MWKEYMOD modstate)
459
{
460
        unsigned short  mwkey = 0;
461
        int             map = 0;
462
 
463
        //printf("Translate: 0x%04x\n", scancode);
464
 
465
        /* determine appropriate kernel table*/
466
        if (modstate & MWKMOD_SHIFT)
467
                map |= (1<<KG_SHIFT);
468
        if (modstate & MWKMOD_CTRL)
469
                map |= (1<<KG_CTRL);
470
        if (modstate & MWKMOD_ALT)
471
                map |= (1<<KG_ALT);
472
        if (modstate & MWKMOD_ALTGR)
473
                map |= (1<<KG_ALTGR);
474
        if (KTYP(os_keymap[map][scancode]) == KT_LETTER) {
475
                if (modstate & MWKMOD_CAPS)
476
                        map |= (1<<KG_SHIFT);
477
        }
478
        if (KTYP(os_keymap[map][scancode]) == KT_PAD) {
479
                if (modstate & MWKMOD_NUM) {
480
                        switch (keymap[scancode]) {
481
                        case MWKEY_KP0:
482
                        case MWKEY_KP1:
483
                        case MWKEY_KP2:
484
                        case MWKEY_KP3:
485
                        case MWKEY_KP4:
486
                        case MWKEY_KP5:
487
                        case MWKEY_KP6:
488
                        case MWKEY_KP7:
489
                        case MWKEY_KP8:
490
                        case MWKEY_KP9:
491
                                mwkey = keymap[scancode] - MWKEY_KP0 + '0';
492
                                break;
493
                        case MWKEY_KP_PERIOD:
494
                                mwkey = '.';
495
                                break;
496
                        case MWKEY_KP_DIVIDE:
497
                                mwkey = '/';
498
                                break;
499
                        case MWKEY_KP_MULTIPLY:
500
                                mwkey = '*';
501
                                break;
502
                        case MWKEY_KP_MINUS:
503
                                mwkey = '-';
504
                                break;
505
                        case MWKEY_KP_PLUS:
506
                                mwkey = '+';
507
                                break;
508
                        case MWKEY_KP_ENTER:
509
                                mwkey = MWKEY_ENTER;
510
                                break;
511
                        case MWKEY_KP_EQUALS:
512
                                mwkey = '-';
513
                                break;
514
                        }
515
                }
516
        } else
517
                mwkey = KVAL(os_keymap[map][scancode]);
518
 
519
        if (!mwkey)
520
                mwkey = keymap[scancode];
521
 
522
        /* perform additional translations*/
523
        switch (mwkey) {
524
        case 127:
525
                mwkey = MWKEY_BACKSPACE;
526
                break;
527
        case MWKEY_BREAK:
528
        case MWKEY_PAUSE:
529
                mwkey = MWKEY_QUIT;
530
                break;
531
        case 0x1c:      /* kernel maps print key to ctrl-\ */
532
        case MWKEY_SYSREQ:
533
                mwkey = MWKEY_PRINT;
534
                break;
535
        }
536
 
537
        /* printf("TranslateScancode %02x to mwkey %d\n", scancode, mwkey); */
538
        return mwkey;
539
}
540
 
541
/* load Linux keyboard mappings, used as first try for scancode conversion*/
542
static void
543
LoadKernelKeymaps(int fd)
544
{
545
        int             map, i;
546
        struct kbentry  entry;
547
 
548
        /* Load all the keysym mappings */
549
        for (map=0; map<NUM_VGAKEYMAPS; ++map) {
550
                memset(os_keymap[map], 0, NR_KEYS*sizeof(unsigned short));
551
                for (i=0; i<NR_KEYS; ++i) {
552
                        entry.kb_table = map;
553
                        entry.kb_index = i;
554
                        if (ioctl(fd, KDGKBENT, &entry) == 0) {
555
                                /* change K_ENTER to \r*/
556
                                if (entry.kb_value == K_ENTER)
557
                                        entry.kb_value = K(KT_ASCII,13);
558
 
559
                                if ((KTYP(entry.kb_value) == KT_LATIN) ||
560
                                    (KTYP(entry.kb_value) == KT_ASCII) ||
561
                                    (KTYP(entry.kb_value) == KT_PAD) ||
562
                                    (KTYP(entry.kb_value) == KT_LETTER)
563
                                    )
564
                                        os_keymap[map][i] = entry.kb_value;
565
                        }
566
                }
567
        }
568
 
569
}
570
/* Handle switching to another VC, returns when our VC is back */
571
static MWBOOL
572
switch_vt(unsigned short which)
573
{
574
        struct vt_stat vtstate;
575
        unsigned short current;
576
        static unsigned short r[16], g[16], b[16];
577
 
578
        /* Figure out whether or not we're switching to a new console */
579
        if ((ioctl(fd, VT_GETSTATE, &vtstate) < 0) ||
580
            (which == vtstate.v_active)) {
581
                return FALSE;
582
        }
583
        current = vtstate.v_active;
584
 
585
        /* save palette, goto text mode*/
586
        ioctl_getpalette(0, 16, r, g, b);
587
        ioctl(fd, KDSETMODE, KD_TEXT);
588
 
589
        /* New console, switch to it */
590
        if (ioctl(fd, VT_ACTIVATE, which) == 0) {
591
                /* Wait for our console to be activated again */
592
                ioctl(fd, VT_WAITACTIVE, which);
593
                while (ioctl(fd, VT_WAITACTIVE, current) < 0) {
594
                        if ((errno != EINTR) && (errno != EAGAIN)) {
595
                                /* Unknown VT error, cancel*/
596
                                break;
597
                        }
598
                        usleep(100000);
599
                }
600
        }
601
 
602
        /* Restore graphics mode and the contents of the screen */
603
        ioctl(fd, KDSETMODE, KD_GRAPHICS);
604
        ioctl_setpalette(0, 16, r, g, b);
605
        return TRUE;
606
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.