Rev 1842 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1842 | Rev 1843 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 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 i8042 processor driver. |
34 | * @brief i8042 processor driver. |
35 | * |
35 | * |
36 | * It takes care of low-level keyboard functions. |
36 | * It takes care of low-level keyboard functions. |
37 | */ |
37 | */ |
38 | 38 | ||
39 | #include <genarch/kbd/i8042.h> |
39 | #include <genarch/kbd/i8042.h> |
- | 40 | #include <genarch/kbd/key.h> |
|
40 | #include <genarch/kbd/scanc.h> |
41 | #include <genarch/kbd/scanc.h> |
41 | #include <genarch/kbd/scanc_pc.h> |
42 | #include <genarch/kbd/scanc_pc.h> |
42 | #include <arch/drivers/i8042.h> |
43 | #include <arch/drivers/i8042.h> |
43 | #include <arch/interrupt.h> |
44 | #include <arch/interrupt.h> |
44 | #include <cpu.h> |
45 | #include <cpu.h> |
45 | #include <arch/asm.h> |
46 | #include <arch/asm.h> |
46 | #include <arch.h> |
47 | #include <arch.h> |
47 | #include <synch/spinlock.h> |
- | |
48 | #include <typedefs.h> |
48 | #include <typedefs.h> |
49 | #include <console/chardev.h> |
49 | #include <console/chardev.h> |
50 | #include <console/console.h> |
50 | #include <console/console.h> |
51 | #include <macros.h> |
- | |
52 | #include <interrupt.h> |
51 | #include <interrupt.h> |
53 | 52 | ||
54 | /* Keyboard commands. */ |
53 | /* Keyboard commands. */ |
55 | #define KBD_ENABLE 0xf4 |
54 | #define KBD_ENABLE 0xf4 |
56 | #define KBD_DISABLE 0xf5 |
55 | #define KBD_DISABLE 0xf5 |
57 | #define KBD_ACK 0xfa |
56 | #define KBD_ACK 0xfa |
58 | 57 | ||
59 | /* |
58 | /* |
60 | * 60 Write 8042 Command Byte: next data byte written to port 60h is |
59 | * 60 Write 8042 Command Byte: next data byte written to port 60h is |
61 | * placed in 8042 command register. Format: |
60 | * placed in 8042 command register. Format: |
62 | * |
61 | * |
63 | * |7|6|5|4|3|2|1|0|8042 Command Byte |
62 | * |7|6|5|4|3|2|1|0|8042 Command Byte |
64 | * | | | | | | | `---- 1=enable output register full interrupt |
63 | * | | | | | | | `---- 1=enable output register full interrupt |
65 | * | | | | | | `----- should be 0 |
64 | * | | | | | | `----- should be 0 |
66 | * | | | | | `------ 1=set status register system, 0=clear |
65 | * | | | | | `------ 1=set status register system, 0=clear |
67 | * | | | | `------- 1=override keyboard inhibit, 0=allow inhibit |
66 | * | | | | `------- 1=override keyboard inhibit, 0=allow inhibit |
68 | * | | | `-------- disable keyboard I/O by driving clock line low |
67 | * | | | `-------- disable keyboard I/O by driving clock line low |
69 | * | | `--------- disable auxiliary device, drives clock line low |
68 | * | | `--------- disable auxiliary device, drives clock line low |
70 | * | `---------- IBM scancode translation 0=AT, 1=PC/XT |
69 | * | `---------- IBM scancode translation 0=AT, 1=PC/XT |
71 | * `----------- reserved, should be 0 |
70 | * `----------- reserved, should be 0 |
72 | */ |
71 | */ |
73 | 72 | ||
74 | #define i8042_SET_COMMAND 0x60 |
73 | #define i8042_SET_COMMAND 0x60 |
75 | #define i8042_COMMAND 0x69 |
74 | #define i8042_COMMAND 0x69 |
76 | 75 | ||
77 | #define i8042_BUFFER_FULL_MASK 0x01 |
76 | #define i8042_BUFFER_FULL_MASK 0x01 |
78 | #define i8042_WAIT_MASK 0x02 |
77 | #define i8042_WAIT_MASK 0x02 |
79 | #define i8042_MOUSE_DATA 0x20 |
78 | #define i8042_MOUSE_DATA 0x20 |
80 | 79 | ||
81 | #define KEY_RELEASE 0x80 |
- | |
82 | - | ||
83 | static void key_released(uint8_t sc); |
- | |
84 | static void key_pressed(uint8_t sc); |
- | |
85 | static char key_read(chardev_t *d); |
- | |
86 | - | ||
87 | #define PRESSED_SHIFT (1<<0) |
- | |
88 | #define PRESSED_CAPSLOCK (1<<1) |
- | |
89 | #define LOCKED_CAPSLOCK (1<<0) |
- | |
90 | - | ||
91 | #define ACTIVE_READ_BUFF_SIZE 16 /* Must be power of 2 */ |
- | |
92 | - | ||
93 | static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE]; |
- | |
94 | - | ||
95 | SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */ |
- | |
96 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
- | |
97 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
- | |
98 | - | ||
99 | static void i8042_suspend(chardev_t *); |
80 | static void i8042_suspend(chardev_t *); |
100 | static void i8042_resume(chardev_t *); |
81 | static void i8042_resume(chardev_t *); |
101 | 82 | ||
102 | static chardev_t kbrd; |
83 | chardev_t kbrd; |
103 | static chardev_operations_t ops = { |
84 | static chardev_operations_t ops = { |
104 | .suspend = i8042_suspend, |
85 | .suspend = i8042_suspend, |
105 | .resume = i8042_resume, |
86 | .resume = i8042_resume, |
106 | .read = key_read |
87 | .read = key_read |
107 | }; |
88 | }; |
108 | 89 | ||
109 | static void i8042_interrupt(int n, istate_t *istate); |
90 | static void i8042_interrupt(int n, istate_t *istate); |
110 | static void i8042_wait(void); |
91 | static void i8042_wait(void); |
111 | 92 | ||
112 | static iroutine oldvector; |
93 | static iroutine oldvector; |
113 | /** Initialize keyboard and service interrupts using kernel routine */ |
94 | /** Initialize keyboard and service interrupts using kernel routine */ |
114 | void i8042_grab(void) |
95 | void i8042_grab(void) |
115 | { |
96 | { |
116 | oldvector = exc_register(VECTOR_KBD, "i8042_interrupt", (iroutine) i8042_interrupt); |
97 | oldvector = exc_register(VECTOR_KBD, "i8042_interrupt", (iroutine) i8042_interrupt); |
117 | i8042_wait(); |
98 | i8042_wait(); |
118 | i8042_command_write(i8042_SET_COMMAND); |
99 | i8042_command_write(i8042_SET_COMMAND); |
119 | i8042_wait(); |
100 | i8042_wait(); |
120 | i8042_data_write(i8042_COMMAND); |
101 | i8042_data_write(i8042_COMMAND); |
121 | i8042_wait(); |
102 | i8042_wait(); |
122 | } |
103 | } |
123 | /** Resume the former interrupt vector */ |
104 | /** Resume the former interrupt vector */ |
124 | void i8042_release(void) |
105 | void i8042_release(void) |
125 | { |
106 | { |
126 | if (oldvector) |
107 | if (oldvector) |
127 | exc_register(VECTOR_KBD, "user_interrupt", oldvector); |
108 | exc_register(VECTOR_KBD, "user_interrupt", oldvector); |
128 | } |
109 | } |
129 | 110 | ||
130 | /** Initialize i8042. */ |
111 | /** Initialize i8042. */ |
131 | void i8042_init(void) |
112 | void i8042_init(void) |
132 | { |
113 | { |
133 | int i; |
114 | int i; |
134 | 115 | ||
135 | i8042_grab(); |
116 | i8042_grab(); |
136 | /* Prevent user from accidentaly releasing calling i8042_resume |
117 | /* Prevent user from accidentaly releasing calling i8042_resume |
137 | * and disabling keyboard |
118 | * and disabling keyboard |
138 | */ |
119 | */ |
139 | oldvector = NULL; |
120 | oldvector = NULL; |
140 | 121 | ||
141 | trap_virtual_enable_irqs(1<<IRQ_KBD); |
122 | trap_virtual_enable_irqs(1<<IRQ_KBD); |
142 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
123 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
143 | stdin = &kbrd; |
124 | stdin = &kbrd; |
144 | 125 | ||
145 | /* |
126 | /* |
146 | * Clear input buffer. |
127 | * Clear input buffer. |
147 | * Number of iterations is limited to prevent infinite looping. |
128 | * Number of iterations is limited to prevent infinite looping. |
148 | */ |
129 | */ |
149 | for (i = 0; (i8042_status_read() & i8042_BUFFER_FULL_MASK) && i < 100; i++) { |
130 | for (i = 0; (i8042_status_read() & i8042_BUFFER_FULL_MASK) && i < 100; i++) { |
150 | i8042_data_read(); |
131 | i8042_data_read(); |
151 | } |
132 | } |
152 | } |
133 | } |
153 | 134 | ||
154 | /** Process i8042 interrupt. |
135 | /** Process i8042 interrupt. |
155 | * |
136 | * |
156 | * @param n Interrupt vector. |
137 | * @param n Interrupt vector. |
157 | * @param istate Interrupted state. |
138 | * @param istate Interrupted state. |
158 | */ |
139 | */ |
159 | void i8042_interrupt(int n, istate_t *istate) |
140 | void i8042_interrupt(int n, istate_t *istate) |
160 | { |
141 | { |
161 | uint8_t x; |
142 | uint8_t x; |
162 | uint8_t status; |
143 | uint8_t status; |
163 | 144 | ||
164 | while (((status=i8042_status_read()) & i8042_BUFFER_FULL_MASK)) { |
145 | while (((status=i8042_status_read()) & i8042_BUFFER_FULL_MASK)) { |
165 | x = i8042_data_read(); |
146 | x = i8042_data_read(); |
166 | 147 | ||
167 | if ((status & i8042_MOUSE_DATA)) |
148 | if ((status & i8042_MOUSE_DATA)) |
168 | continue; |
149 | continue; |
169 | 150 | ||
170 | if (x & KEY_RELEASE) |
151 | if (x & KEY_RELEASE) |
171 | key_released(x ^ KEY_RELEASE); |
152 | key_released(x ^ KEY_RELEASE); |
172 | else |
153 | else |
173 | key_pressed(x); |
154 | key_pressed(x); |
174 | } |
155 | } |
175 | trap_virtual_eoi(); |
156 | trap_virtual_eoi(); |
176 | } |
157 | } |
177 | 158 | ||
178 | /** Wait until the controller reads its data. */ |
159 | /** Wait until the controller reads its data. */ |
179 | void i8042_wait(void) { |
160 | void i8042_wait(void) { |
180 | while (i8042_status_read() & i8042_WAIT_MASK) { |
161 | while (i8042_status_read() & i8042_WAIT_MASK) { |
181 | /* wait */ |
162 | /* wait */ |
182 | } |
163 | } |
183 | } |
164 | } |
184 | 165 | ||
185 | /** Process release of key. |
- | |
186 | * |
- | |
187 | * @param sc Scancode of the key being released. |
- | |
188 | */ |
- | |
189 | void key_released(uint8_t sc) |
- | |
190 | { |
- | |
191 | spinlock_lock(&keylock); |
- | |
192 | switch (sc) { |
- | |
193 | case SC_LSHIFT: |
- | |
194 | case SC_RSHIFT: |
- | |
195 | keyflags &= ~PRESSED_SHIFT; |
- | |
196 | break; |
- | |
197 | case SC_CAPSLOCK: |
- | |
198 | keyflags &= ~PRESSED_CAPSLOCK; |
- | |
199 | if (lockflags & LOCKED_CAPSLOCK) |
- | |
200 | lockflags &= ~LOCKED_CAPSLOCK; |
- | |
201 | else |
- | |
202 | lockflags |= LOCKED_CAPSLOCK; |
- | |
203 | break; |
- | |
204 | default: |
- | |
205 | break; |
- | |
206 | } |
- | |
207 | spinlock_unlock(&keylock); |
- | |
208 | } |
- | |
209 | - | ||
210 | /** Process keypress. |
- | |
211 | * |
- | |
212 | * @param sc Scancode of the key being pressed. |
- | |
213 | */ |
- | |
214 | void key_pressed(uint8_t sc) |
- | |
215 | { |
- | |
216 | char *map = sc_primary_map; |
- | |
217 | char ascii = sc_primary_map[sc]; |
- | |
218 | bool shift, capslock; |
- | |
219 | bool letter = false; |
- | |
220 | - | ||
221 | spinlock_lock(&keylock); |
- | |
222 | switch (sc) { |
- | |
223 | case SC_LSHIFT: |
- | |
224 | case SC_RSHIFT: |
- | |
225 | keyflags |= PRESSED_SHIFT; |
- | |
226 | break; |
- | |
227 | case SC_CAPSLOCK: |
- | |
228 | keyflags |= PRESSED_CAPSLOCK; |
- | |
229 | break; |
- | |
230 | case SC_SPEC_ESCAPE: |
- | |
231 | break; |
- | |
232 | case SC_LEFTARR: |
- | |
233 | chardev_push_character(&kbrd, 0x1b); |
- | |
234 | chardev_push_character(&kbrd, 0x5b); |
- | |
235 | chardev_push_character(&kbrd, 0x44); |
- | |
236 | break; |
- | |
237 | case SC_RIGHTARR: |
- | |
238 | chardev_push_character(&kbrd, 0x1b); |
- | |
239 | chardev_push_character(&kbrd, 0x5b); |
- | |
240 | chardev_push_character(&kbrd, 0x43); |
- | |
241 | break; |
- | |
242 | case SC_UPARR: |
- | |
243 | chardev_push_character(&kbrd, 0x1b); |
- | |
244 | chardev_push_character(&kbrd, 0x5b); |
- | |
245 | chardev_push_character(&kbrd, 0x41); |
- | |
246 | break; |
- | |
247 | case SC_DOWNARR: |
- | |
248 | chardev_push_character(&kbrd, 0x1b); |
- | |
249 | chardev_push_character(&kbrd, 0x5b); |
- | |
250 | chardev_push_character(&kbrd, 0x42); |
- | |
251 | break; |
- | |
252 | case SC_HOME: |
- | |
253 | chardev_push_character(&kbrd, 0x1b); |
- | |
254 | chardev_push_character(&kbrd, 0x4f); |
- | |
255 | chardev_push_character(&kbrd, 0x48); |
- | |
256 | break; |
- | |
257 | case SC_END: |
- | |
258 | chardev_push_character(&kbrd, 0x1b); |
- | |
259 | chardev_push_character(&kbrd, 0x4f); |
- | |
260 | chardev_push_character(&kbrd, 0x46); |
- | |
261 | break; |
- | |
262 | case SC_DELETE: |
- | |
263 | chardev_push_character(&kbrd, 0x1b); |
- | |
264 | chardev_push_character(&kbrd, 0x5b); |
- | |
265 | chardev_push_character(&kbrd, 0x33); |
- | |
266 | chardev_push_character(&kbrd, 0x7e); |
- | |
267 | break; |
- | |
268 | default: |
- | |
269 | letter = is_lower(ascii); |
- | |
270 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
- | |
271 | shift = keyflags & PRESSED_SHIFT; |
- | |
272 | if (letter && capslock) |
- | |
273 | shift = !shift; |
- | |
274 | if (shift) |
- | |
275 | map = sc_secondary_map; |
- | |
276 | chardev_push_character(&kbrd, map[sc]); |
- | |
277 | break; |
- | |
278 | } |
- | |
279 | spinlock_unlock(&keylock); |
- | |
280 | } |
- | |
281 | - | ||
282 | /* Called from getc(). */ |
166 | /* Called from getc(). */ |
283 | void i8042_resume(chardev_t *d) |
167 | void i8042_resume(chardev_t *d) |
284 | { |
168 | { |
285 | } |
169 | } |
286 | 170 | ||
287 | /* Called from getc(). */ |
171 | /* Called from getc(). */ |
288 | void i8042_suspend(chardev_t *d) |
172 | void i8042_suspend(chardev_t *d) |
289 | { |
173 | { |
290 | } |
174 | } |
291 | 175 | ||
292 | static uint8_t active_read_buff_read(void) |
- | |
293 | { |
- | |
294 | static int i=0; |
- | |
295 | i &= (ACTIVE_READ_BUFF_SIZE-1); |
- | |
296 | if(!active_read_buff[i]) { |
- | |
297 | return 0; |
- | |
298 | } |
- | |
299 | return active_read_buff[i++]; |
- | |
300 | } |
- | |
301 | - | ||
302 | static void active_read_buff_write(uint8_t ch) |
- | |
303 | { |
- | |
304 | static int i=0; |
- | |
305 | active_read_buff[i] = ch; |
- | |
306 | i++; |
- | |
307 | i &= (ACTIVE_READ_BUFF_SIZE-1); |
- | |
308 | active_read_buff[i]=0; |
- | |
309 | } |
- | |
310 | - | ||
311 | - | ||
312 | static void active_read_key_pressed(uint8_t sc) |
- | |
313 | { |
- | |
314 | char *map = sc_primary_map; |
- | |
315 | char ascii = sc_primary_map[sc]; |
- | |
316 | bool shift, capslock; |
- | |
317 | bool letter = false; |
- | |
318 | - | ||
319 | /*spinlock_lock(&keylock);*/ |
- | |
320 | switch (sc) { |
- | |
321 | case SC_LSHIFT: |
- | |
322 | case SC_RSHIFT: |
- | |
323 | keyflags |= PRESSED_SHIFT; |
- | |
324 | break; |
- | |
325 | case SC_CAPSLOCK: |
- | |
326 | keyflags |= PRESSED_CAPSLOCK; |
- | |
327 | break; |
- | |
328 | case SC_SPEC_ESCAPE: |
- | |
329 | break; |
- | |
330 | case SC_LEFTARR: |
- | |
331 | active_read_buff_write(0x1b); |
- | |
332 | active_read_buff_write(0x5b); |
- | |
333 | active_read_buff_write(0x44); |
- | |
334 | break; |
- | |
335 | case SC_RIGHTARR: |
- | |
336 | active_read_buff_write(0x1b); |
- | |
337 | active_read_buff_write(0x5b); |
- | |
338 | active_read_buff_write(0x43); |
- | |
339 | break; |
- | |
340 | case SC_UPARR: |
- | |
341 | active_read_buff_write(0x1b); |
- | |
342 | active_read_buff_write(0x5b); |
- | |
343 | active_read_buff_write(0x41); |
- | |
344 | break; |
- | |
345 | case SC_DOWNARR: |
- | |
346 | active_read_buff_write(0x1b); |
- | |
347 | active_read_buff_write(0x5b); |
- | |
348 | active_read_buff_write(0x42); |
- | |
349 | break; |
- | |
350 | case SC_HOME: |
- | |
351 | active_read_buff_write(0x1b); |
- | |
352 | active_read_buff_write(0x4f); |
- | |
353 | active_read_buff_write(0x48); |
- | |
354 | break; |
- | |
355 | case SC_END: |
- | |
356 | active_read_buff_write(0x1b); |
- | |
357 | active_read_buff_write(0x4f); |
- | |
358 | active_read_buff_write(0x46); |
- | |
359 | break; |
- | |
360 | case SC_DELETE: |
- | |
361 | active_read_buff_write(0x1b); |
- | |
362 | active_read_buff_write(0x5b); |
- | |
363 | active_read_buff_write(0x33); |
- | |
364 | active_read_buff_write(0x7e); |
- | |
365 | break; |
- | |
366 | default: |
- | |
367 | letter = is_lower(ascii); |
- | |
368 | capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); |
- | |
369 | shift = keyflags & PRESSED_SHIFT; |
- | |
370 | if (letter && capslock) |
- | |
371 | shift = !shift; |
- | |
372 | if (shift) |
- | |
373 | map = sc_secondary_map; |
- | |
374 | active_read_buff_write(map[sc]); |
- | |
375 | break; |
- | |
376 | } |
- | |
377 | /*spinlock_unlock(&keylock);*/ |
- | |
378 | - | ||
379 | } |
- | |
380 | - | ||
381 | static char key_read(chardev_t *d) |
176 | char key_read(chardev_t *d) |
382 | { |
177 | { |
383 | char ch; |
178 | char ch; |
384 | 179 | ||
385 | while(!(ch = active_read_buff_read())) { |
180 | while(!(ch = active_read_buff_read())) { |
386 | uint8_t x; |
181 | uint8_t x; |
387 | while (!(i8042_status_read() & i8042_BUFFER_FULL_MASK)) |
182 | while (!(i8042_status_read() & i8042_BUFFER_FULL_MASK)) |
388 | ; |
183 | ; |
389 | x = i8042_data_read(); |
184 | x = i8042_data_read(); |
390 | if (x & KEY_RELEASE) |
185 | if (x & KEY_RELEASE) |
391 | key_released(x ^ KEY_RELEASE); |
186 | key_released(x ^ KEY_RELEASE); |
392 | else |
187 | else |
393 | active_read_key_pressed(x); |
188 | active_read_key_pressed(x); |
394 | } |
189 | } |
395 | return ch; |
190 | return ch; |
396 | } |
191 | } |
397 | 192 | ||
398 | /** Poll for key press and release events. |
193 | /** Poll for key press and release events. |
399 | * |
194 | * |
400 | * This function can be used to implement keyboard polling. |
195 | * This function can be used to implement keyboard polling. |
401 | */ |
196 | */ |
402 | void i8042_poll(void) |
197 | void i8042_poll(void) |
403 | { |
198 | { |
404 | uint8_t x; |
199 | uint8_t x; |
405 | 200 | ||
406 | while (((x = i8042_status_read() & i8042_BUFFER_FULL_MASK))) { |
201 | while (((x = i8042_status_read() & i8042_BUFFER_FULL_MASK))) { |
407 | x = i8042_data_read(); |
202 | x = i8042_data_read(); |
408 | if (x & KEY_RELEASE) |
203 | if (x & KEY_RELEASE) |
409 | key_released(x ^ KEY_RELEASE); |
204 | key_released(x ^ KEY_RELEASE); |
410 | else |
205 | else |
411 | key_pressed(x); |
206 | key_pressed(x); |
412 | } |
207 | } |
413 | } |
208 | } |
414 | 209 | ||
415 | /** @} |
210 | /** @} |
416 | */ |
211 | */ |
417 | 212 |