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