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) 2001-2004 Jakub Jermar |
3 | * Copyright (c) 2006 Josef Cejka |
||
1339 | cejka | 4 | * All rights reserved. |
5 | * |
||
6 | * Redistribution and use in source and binary forms, with or without |
||
7 | * modification, are permitted provided that the following conditions |
||
8 | * are met: |
||
9 | * |
||
10 | * - Redistributions of source code must retain the above copyright |
||
11 | * notice, this list of conditions and the following disclaimer. |
||
12 | * - Redistributions in binary form must reproduce the above copyright |
||
13 | * notice, this list of conditions and the following disclaimer in the |
||
14 | * documentation and/or other materials provided with the distribution. |
||
15 | * - The name of the author may not be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
1873 | jermar | 30 | /** @addtogroup kbd |
31 | * @brief Handling of keyboard IRQ notifications for several architectures. |
||
1649 | cejka | 32 | * @ingroup kbd |
33 | * @{ |
||
34 | */ |
||
35 | /** @file |
||
36 | */ |
||
37 | |||
1873 | jermar | 38 | #include <key_buffer.h> |
39 | #include <arch/scanc.h> |
||
40 | #include <genarch/scanc.h> |
||
41 | #include <genarch/kbd.h> |
||
42 | #include <libc.h> |
||
1339 | cejka | 43 | |
44 | #define PRESSED_SHIFT (1<<0) |
||
45 | #define PRESSED_CAPSLOCK (1<<1) |
||
46 | #define LOCKED_CAPSLOCK (1<<0) |
||
47 | |||
48 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
||
49 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
||
50 | |||
1873 | jermar | 51 | void key_released(keybuffer_t *keybuffer, unsigned char key) |
1339 | cejka | 52 | { |
53 | switch (key) { |
||
1873 | jermar | 54 | case SC_LSHIFT: |
55 | case SC_RSHIFT: |
||
56 | keyflags &= ~PRESSED_SHIFT; |
||
57 | break; |
||
58 | case SC_CAPSLOCK: |
||
59 | keyflags &= ~PRESSED_CAPSLOCK; |
||
60 | if (lockflags & LOCKED_CAPSLOCK) |
||
61 | lockflags &= ~LOCKED_CAPSLOCK; |
||
62 | else |
||
63 | lockflags |= LOCKED_CAPSLOCK; |
||
64 | break; |
||
65 | default: |
||
66 | break; |
||
1339 | cejka | 67 | } |
68 | } |
||
69 | |||
1873 | jermar | 70 | void key_pressed(keybuffer_t *keybuffer, unsigned char key) |
1339 | cejka | 71 | { |
1560 | vana | 72 | int *map = sc_primary_map; |
73 | int ascii = sc_primary_map[key]; |
||
74 | int shift, capslock; |
||
75 | int letter = 0; |
||
1339 | cejka | 76 | |
1873 | jermar | 77 | static int esc_count = 0; |
1644 | vana | 78 | |
1873 | jermar | 79 | if (key == SC_ESC) { |
1644 | vana | 80 | esc_count++; |
1873 | jermar | 81 | if (esc_count == 3) |
1644 | vana | 82 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
83 | } else { |
||
1873 | jermar | 84 | esc_count = 0; |
1644 | vana | 85 | } |
86 | |||
1339 | cejka | 87 | switch (key) { |
1873 | jermar | 88 | case SC_LSHIFT: |
89 | case SC_RSHIFT: |
||
90 | keyflags |= PRESSED_SHIFT; |
||
91 | break; |
||
92 | case SC_CAPSLOCK: |
||
93 | keyflags |= PRESSED_CAPSLOCK; |
||
94 | break; |
||
95 | case SC_SPEC_ESCAPE: |
||
96 | break; |
||
97 | default: |
||
98 | letter = ((ascii >= 'a') && (ascii <= 'z')); |
||
99 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
||
100 | shift = keyflags & PRESSED_SHIFT; |
||
101 | if (letter && capslock) |
||
102 | shift = !shift; |
||
103 | if (shift) |
||
104 | map = sc_secondary_map; |
||
105 | if (map[key] != SPECIAL) |
||
106 | keybuffer_push(keybuffer, map[key]); |
||
107 | break; |
||
1339 | cejka | 108 | } |
109 | } |
||
110 | |||
1649 | cejka | 111 | /** |
112 | * @} |
||
113 | */ |