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