Rev 4348 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4348 | Rev 4691 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Jakub Jermar |
2 | * Copyright (c) 2009 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup genarch |
29 | /** @addtogroup genarch |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief Keyboard processing. |
34 | * @brief Keyboard processing. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <genarch/kbrd/kbrd.h> |
37 | #include <genarch/kbrd/kbrd.h> |
38 | #include <genarch/kbrd/scanc.h> |
38 | #include <genarch/kbrd/scanc.h> |
39 | 39 | ||
40 | #ifdef CONFIG_PC_KBD |
40 | #ifdef CONFIG_PC_KBD |
41 | #include <genarch/kbrd/scanc_pc.h> |
41 | #include <genarch/kbrd/scanc_pc.h> |
42 | #endif |
42 | #endif |
43 | 43 | ||
44 | #ifdef CONFIG_SUN_KBD |
44 | #ifdef CONFIG_SUN_KBD |
45 | #include <genarch/kbrd/scanc_sun.h> |
45 | #include <genarch/kbrd/scanc_sun.h> |
46 | #endif |
46 | #endif |
47 | 47 | ||
- | 48 | #ifdef CONFIG_MAC_KBD |
|
- | 49 | #include <genarch/kbrd/scanc_mac.h> |
|
- | 50 | #endif |
|
- | 51 | ||
48 | #include <synch/spinlock.h> |
52 | #include <synch/spinlock.h> |
49 | #include <console/chardev.h> |
53 | #include <console/chardev.h> |
50 | #include <console/console.h> |
54 | #include <console/console.h> |
51 | #include <proc/thread.h> |
55 | #include <proc/thread.h> |
52 | #include <arch.h> |
56 | #include <arch.h> |
53 | #include <macros.h> |
57 | #include <macros.h> |
54 | 58 | ||
55 | #define IGNORE_CODE 0x7f |
59 | #define IGNORE_CODE 0x7f |
56 | #define KEY_RELEASE 0x80 |
60 | #define KEY_RELEASE 0x80 |
57 | 61 | ||
58 | #define PRESSED_SHIFT (1 << 0) |
62 | #define PRESSED_SHIFT (1 << 0) |
59 | #define PRESSED_CAPSLOCK (1 << 1) |
63 | #define PRESSED_CAPSLOCK (1 << 1) |
60 | #define LOCKED_CAPSLOCK (1 << 0) |
64 | #define LOCKED_CAPSLOCK (1 << 0) |
61 | 65 | ||
62 | static indev_operations_t kbrd_raw_ops = { |
66 | static indev_operations_t kbrd_raw_ops = { |
63 | .poll = NULL |
67 | .poll = NULL |
64 | }; |
68 | }; |
65 | 69 | ||
66 | /** Process release of key. |
70 | /** Process release of key. |
67 | * |
71 | * |
68 | * @param sc Scancode of the key being released. |
72 | * @param sc Scancode of the key being released. |
69 | */ |
73 | */ |
70 | static void key_released(kbrd_instance_t *instance, wchar_t sc) |
74 | static void key_released(kbrd_instance_t *instance, wchar_t sc) |
71 | { |
75 | { |
72 | spinlock_lock(&instance->keylock); |
76 | spinlock_lock(&instance->keylock); |
73 | 77 | ||
74 | switch (sc) { |
78 | switch (sc) { |
75 | case SC_LSHIFT: |
79 | case SC_LSHIFT: |
76 | case SC_RSHIFT: |
80 | case SC_RSHIFT: |
77 | instance->keyflags &= ~PRESSED_SHIFT; |
81 | instance->keyflags &= ~PRESSED_SHIFT; |
78 | break; |
82 | break; |
79 | case SC_CAPSLOCK: |
83 | case SC_CAPSLOCK: |
80 | instance->keyflags &= ~PRESSED_CAPSLOCK; |
84 | instance->keyflags &= ~PRESSED_CAPSLOCK; |
81 | if (instance->lockflags & LOCKED_CAPSLOCK) |
85 | if (instance->lockflags & LOCKED_CAPSLOCK) |
82 | instance->lockflags &= ~LOCKED_CAPSLOCK; |
86 | instance->lockflags &= ~LOCKED_CAPSLOCK; |
83 | else |
87 | else |
84 | instance->lockflags |= LOCKED_CAPSLOCK; |
88 | instance->lockflags |= LOCKED_CAPSLOCK; |
85 | break; |
89 | break; |
86 | default: |
90 | default: |
87 | break; |
91 | break; |
88 | } |
92 | } |
89 | 93 | ||
90 | spinlock_unlock(&instance->keylock); |
94 | spinlock_unlock(&instance->keylock); |
91 | } |
95 | } |
92 | 96 | ||
93 | /** Process keypress. |
97 | /** Process keypress. |
94 | * |
98 | * |
95 | * @param sc Scancode of the key being pressed. |
99 | * @param sc Scancode of the key being pressed. |
96 | */ |
100 | */ |
97 | static void key_pressed(kbrd_instance_t *instance, wchar_t sc) |
101 | static void key_pressed(kbrd_instance_t *instance, wchar_t sc) |
98 | { |
102 | { |
99 | bool letter; |
103 | bool letter; |
100 | bool shift; |
104 | bool shift; |
101 | bool capslock; |
105 | bool capslock; |
102 | 106 | ||
103 | spinlock_lock(&instance->keylock); |
107 | spinlock_lock(&instance->keylock); |
104 | 108 | ||
105 | switch (sc) { |
109 | switch (sc) { |
106 | case SC_LSHIFT: |
110 | case SC_LSHIFT: |
107 | case SC_RSHIFT: |
111 | case SC_RSHIFT: |
108 | instance->keyflags |= PRESSED_SHIFT; |
112 | instance->keyflags |= PRESSED_SHIFT; |
109 | break; |
113 | break; |
110 | case SC_CAPSLOCK: |
114 | case SC_CAPSLOCK: |
111 | instance->keyflags |= PRESSED_CAPSLOCK; |
115 | instance->keyflags |= PRESSED_CAPSLOCK; |
112 | break; |
116 | break; |
113 | case SC_SCAN_ESCAPE: |
117 | case SC_SCAN_ESCAPE: |
114 | break; |
118 | break; |
115 | default: |
119 | default: |
116 | letter = islower(sc_primary_map[sc]); |
120 | letter = islower(sc_primary_map[sc]); |
117 | shift = instance->keyflags & PRESSED_SHIFT; |
121 | shift = instance->keyflags & PRESSED_SHIFT; |
118 | capslock = (instance->keyflags & PRESSED_CAPSLOCK) || |
122 | capslock = (instance->keyflags & PRESSED_CAPSLOCK) || |
119 | (instance->lockflags & LOCKED_CAPSLOCK); |
123 | (instance->lockflags & LOCKED_CAPSLOCK); |
120 | 124 | ||
121 | if ((letter) && (capslock)) |
125 | if ((letter) && (capslock)) |
122 | shift = !shift; |
126 | shift = !shift; |
123 | 127 | ||
124 | if (shift) |
128 | if (shift) |
125 | indev_push_character(instance->sink, sc_secondary_map[sc]); |
129 | indev_push_character(instance->sink, sc_secondary_map[sc]); |
126 | else |
130 | else |
127 | indev_push_character(instance->sink, sc_primary_map[sc]); |
131 | indev_push_character(instance->sink, sc_primary_map[sc]); |
128 | break; |
132 | break; |
129 | } |
133 | } |
130 | 134 | ||
131 | spinlock_unlock(&instance->keylock); |
135 | spinlock_unlock(&instance->keylock); |
132 | } |
136 | } |
133 | 137 | ||
134 | static void kkbrd(void *arg) |
138 | static void kkbrd(void *arg) |
135 | { |
139 | { |
136 | kbrd_instance_t *instance = (kbrd_instance_t *) arg; |
140 | kbrd_instance_t *instance = (kbrd_instance_t *) arg; |
137 | 141 | ||
138 | while (true) { |
142 | while (true) { |
139 | wchar_t sc = indev_pop_character(&instance->raw); |
143 | wchar_t sc = indev_pop_character(&instance->raw); |
140 | 144 | ||
141 | if (sc == IGNORE_CODE) |
145 | if (sc == IGNORE_CODE) |
142 | continue; |
146 | continue; |
143 | 147 | ||
144 | if (sc & KEY_RELEASE) |
148 | if (sc & KEY_RELEASE) |
145 | key_released(instance, (sc ^ KEY_RELEASE) & 0x7f); |
149 | key_released(instance, (sc ^ KEY_RELEASE) & 0x7f); |
146 | else |
150 | else |
147 | key_pressed(instance, sc & 0x7f); |
151 | key_pressed(instance, sc & 0x7f); |
148 | } |
152 | } |
149 | } |
153 | } |
150 | 154 | ||
151 | kbrd_instance_t *kbrd_init(void) |
155 | kbrd_instance_t *kbrd_init(void) |
152 | { |
156 | { |
153 | kbrd_instance_t *instance |
157 | kbrd_instance_t *instance |
154 | = malloc(sizeof(kbrd_instance_t), FRAME_ATOMIC); |
158 | = malloc(sizeof(kbrd_instance_t), FRAME_ATOMIC); |
155 | if (instance) { |
159 | if (instance) { |
156 | instance->thread |
160 | instance->thread |
157 | = thread_create(kkbrd, (void *) instance, TASK, 0, "kkbrd", false); |
161 | = thread_create(kkbrd, (void *) instance, TASK, 0, "kkbrd", false); |
158 | 162 | ||
159 | if (!instance->thread) { |
163 | if (!instance->thread) { |
160 | free(instance); |
164 | free(instance); |
161 | return NULL; |
165 | return NULL; |
162 | } |
166 | } |
163 | 167 | ||
164 | instance->sink = NULL; |
168 | instance->sink = NULL; |
165 | indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops); |
169 | indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops); |
166 | 170 | ||
167 | spinlock_initialize(&instance->keylock, "instance_keylock"); |
171 | spinlock_initialize(&instance->keylock, "instance_keylock"); |
168 | instance->keyflags = 0; |
172 | instance->keyflags = 0; |
169 | instance->lockflags = 0; |
173 | instance->lockflags = 0; |
170 | } |
174 | } |
171 | 175 | ||
172 | return instance; |
176 | return instance; |
173 | } |
177 | } |
174 | 178 | ||
175 | indev_t *kbrd_wire(kbrd_instance_t *instance, indev_t *sink) |
179 | indev_t *kbrd_wire(kbrd_instance_t *instance, indev_t *sink) |
176 | { |
180 | { |
177 | ASSERT(instance); |
181 | ASSERT(instance); |
178 | ASSERT(sink); |
182 | ASSERT(sink); |
179 | 183 | ||
180 | instance->sink = sink; |
184 | instance->sink = sink; |
181 | thread_ready(instance->thread); |
185 | thread_ready(instance->thread); |
182 | 186 | ||
183 | return &instance->raw; |
187 | return &instance->raw; |
184 | } |
188 | } |
185 | 189 | ||
186 | /** @} |
190 | /** @} |
187 | */ |
191 | */ |
188 | 192 |