Rev 3593 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3593 | Rev 3742 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 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 Key processing. |
34 | * @brief Key processing. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <genarch/kbd/key.h> |
37 | #include <genarch/kbd/key.h> |
38 | #include <genarch/kbd/scanc.h> |
38 | #include <genarch/kbd/scanc.h> |
39 | #ifdef CONFIG_I8042 |
39 | #ifdef CONFIG_I8042 |
40 | #include <genarch/kbd/scanc_pc.h> |
40 | #include <genarch/kbd/scanc_pc.h> |
41 | #endif |
41 | #endif |
42 | 42 | ||
43 | #if (defined(sparc64)) |
43 | #if (defined(sparc64)) |
44 | #if (defined(CONFIG_Z8530) || defined(CONFIG_NS16550)) |
- | |
45 | #include <genarch/kbd/scanc_sun.h> |
44 | #include <genarch/kbd/scanc_sun.h> |
46 | #endif |
45 | #endif |
47 | #endif |
- | |
48 | 46 | ||
49 | #include <synch/spinlock.h> |
47 | #include <synch/spinlock.h> |
50 | #include <console/chardev.h> |
48 | #include <console/chardev.h> |
51 | #include <macros.h> |
49 | #include <macros.h> |
52 | 50 | ||
53 | #define PRESSED_SHIFT (1<<0) |
51 | #define PRESSED_SHIFT (1<<0) |
54 | #define PRESSED_CAPSLOCK (1<<1) |
52 | #define PRESSED_CAPSLOCK (1<<1) |
55 | #define LOCKED_CAPSLOCK (1<<0) |
53 | #define LOCKED_CAPSLOCK (1<<0) |
56 | 54 | ||
57 | #define ACTIVE_READ_BUFF_SIZE 16 /* Must be power of 2 */ |
55 | #define ACTIVE_READ_BUFF_SIZE 16 /* Must be power of 2 */ |
58 | 56 | ||
59 | chardev_t kbrd; |
57 | chardev_t kbrd; |
60 | 58 | ||
61 | static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE]; |
59 | static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE]; |
62 | 60 | ||
63 | SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */ |
61 | SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */ |
64 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
62 | static volatile int keyflags; /**< Tracking of multiple keypresses. */ |
65 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
63 | static volatile int lockflags; /**< Tracking of multiple keys lockings. */ |
66 | 64 | ||
67 | /** Process release of key. |
65 | /** Process release of key. |
68 | * |
66 | * |
69 | * @param sc Scancode of the key being released. |
67 | * @param sc Scancode of the key being released. |
70 | */ |
68 | */ |
71 | void key_released(uint8_t sc) |
69 | void key_released(uint8_t sc) |
72 | { |
70 | { |
73 | spinlock_lock(&keylock); |
71 | spinlock_lock(&keylock); |
74 | switch (sc) { |
72 | switch (sc) { |
75 | case SC_LSHIFT: |
73 | case SC_LSHIFT: |
76 | case SC_RSHIFT: |
74 | case SC_RSHIFT: |
77 | keyflags &= ~PRESSED_SHIFT; |
75 | keyflags &= ~PRESSED_SHIFT; |
78 | break; |
76 | break; |
79 | case SC_CAPSLOCK: |
77 | case SC_CAPSLOCK: |
80 | keyflags &= ~PRESSED_CAPSLOCK; |
78 | keyflags &= ~PRESSED_CAPSLOCK; |
81 | if (lockflags & LOCKED_CAPSLOCK) |
79 | if (lockflags & LOCKED_CAPSLOCK) |
82 | lockflags &= ~LOCKED_CAPSLOCK; |
80 | lockflags &= ~LOCKED_CAPSLOCK; |
83 | else |
81 | else |
84 | lockflags |= LOCKED_CAPSLOCK; |
82 | lockflags |= LOCKED_CAPSLOCK; |
85 | break; |
83 | break; |
86 | default: |
84 | default: |
87 | break; |
85 | break; |
88 | } |
86 | } |
89 | spinlock_unlock(&keylock); |
87 | spinlock_unlock(&keylock); |
90 | } |
88 | } |
91 | 89 | ||
92 | /** Process keypress. |
90 | /** Process keypress. |
93 | * |
91 | * |
94 | * @param sc Scancode of the key being pressed. |
92 | * @param sc Scancode of the key being pressed. |
95 | */ |
93 | */ |
96 | void key_pressed(uint8_t sc) |
94 | void key_pressed(uint8_t sc) |
97 | { |
95 | { |
98 | char *map = sc_primary_map; |
96 | char *map = sc_primary_map; |
99 | char ascii = sc_primary_map[sc]; |
97 | char ascii = sc_primary_map[sc]; |
100 | bool shift, capslock; |
98 | bool shift, capslock; |
101 | bool letter = false; |
99 | bool letter = false; |
102 | 100 | ||
103 | spinlock_lock(&keylock); |
101 | spinlock_lock(&keylock); |
104 | switch (sc) { |
102 | switch (sc) { |
105 | case SC_LSHIFT: |
103 | case SC_LSHIFT: |
106 | case SC_RSHIFT: |
104 | case SC_RSHIFT: |
107 | keyflags |= PRESSED_SHIFT; |
105 | keyflags |= PRESSED_SHIFT; |
108 | break; |
106 | break; |
109 | case SC_CAPSLOCK: |
107 | case SC_CAPSLOCK: |
110 | keyflags |= PRESSED_CAPSLOCK; |
108 | keyflags |= PRESSED_CAPSLOCK; |
111 | break; |
109 | break; |
112 | case SC_SPEC_ESCAPE: |
110 | case SC_SPEC_ESCAPE: |
113 | break; |
111 | break; |
114 | case SC_LEFTARR: |
112 | case SC_LEFTARR: |
115 | chardev_push_character(&kbrd, 0x1b); |
113 | chardev_push_character(&kbrd, 0x1b); |
116 | chardev_push_character(&kbrd, 0x5b); |
114 | chardev_push_character(&kbrd, 0x5b); |
117 | chardev_push_character(&kbrd, 0x44); |
115 | chardev_push_character(&kbrd, 0x44); |
118 | break; |
116 | break; |
119 | case SC_RIGHTARR: |
117 | case SC_RIGHTARR: |
120 | chardev_push_character(&kbrd, 0x1b); |
118 | chardev_push_character(&kbrd, 0x1b); |
121 | chardev_push_character(&kbrd, 0x5b); |
119 | chardev_push_character(&kbrd, 0x5b); |
122 | chardev_push_character(&kbrd, 0x43); |
120 | chardev_push_character(&kbrd, 0x43); |
123 | break; |
121 | break; |
124 | case SC_UPARR: |
122 | case SC_UPARR: |
125 | chardev_push_character(&kbrd, 0x1b); |
123 | chardev_push_character(&kbrd, 0x1b); |
126 | chardev_push_character(&kbrd, 0x5b); |
124 | chardev_push_character(&kbrd, 0x5b); |
127 | chardev_push_character(&kbrd, 0x41); |
125 | chardev_push_character(&kbrd, 0x41); |
128 | break; |
126 | break; |
129 | case SC_DOWNARR: |
127 | case SC_DOWNARR: |
130 | chardev_push_character(&kbrd, 0x1b); |
128 | chardev_push_character(&kbrd, 0x1b); |
131 | chardev_push_character(&kbrd, 0x5b); |
129 | chardev_push_character(&kbrd, 0x5b); |
132 | chardev_push_character(&kbrd, 0x42); |
130 | chardev_push_character(&kbrd, 0x42); |
133 | break; |
131 | break; |
134 | case SC_HOME: |
132 | case SC_HOME: |
135 | chardev_push_character(&kbrd, 0x1b); |
133 | chardev_push_character(&kbrd, 0x1b); |
136 | chardev_push_character(&kbrd, 0x4f); |
134 | chardev_push_character(&kbrd, 0x4f); |
137 | chardev_push_character(&kbrd, 0x48); |
135 | chardev_push_character(&kbrd, 0x48); |
138 | break; |
136 | break; |
139 | case SC_END: |
137 | case SC_END: |
140 | chardev_push_character(&kbrd, 0x1b); |
138 | chardev_push_character(&kbrd, 0x1b); |
141 | chardev_push_character(&kbrd, 0x4f); |
139 | chardev_push_character(&kbrd, 0x4f); |
142 | chardev_push_character(&kbrd, 0x46); |
140 | chardev_push_character(&kbrd, 0x46); |
143 | break; |
141 | break; |
144 | case SC_DELETE: |
142 | case SC_DELETE: |
145 | chardev_push_character(&kbrd, 0x1b); |
143 | chardev_push_character(&kbrd, 0x1b); |
146 | chardev_push_character(&kbrd, 0x5b); |
144 | chardev_push_character(&kbrd, 0x5b); |
147 | chardev_push_character(&kbrd, 0x33); |
145 | chardev_push_character(&kbrd, 0x33); |
148 | chardev_push_character(&kbrd, 0x7e); |
146 | chardev_push_character(&kbrd, 0x7e); |
149 | break; |
147 | break; |
150 | default: |
148 | default: |
151 | letter = islower(ascii); |
149 | letter = islower(ascii); |
152 | capslock = (keyflags & PRESSED_CAPSLOCK) || |
150 | capslock = (keyflags & PRESSED_CAPSLOCK) || |
153 | (lockflags & LOCKED_CAPSLOCK); |
151 | (lockflags & LOCKED_CAPSLOCK); |
154 | shift = keyflags & PRESSED_SHIFT; |
152 | shift = keyflags & PRESSED_SHIFT; |
155 | if (letter && capslock) |
153 | if (letter && capslock) |
156 | shift = !shift; |
154 | shift = !shift; |
157 | if (shift) |
155 | if (shift) |
158 | map = sc_secondary_map; |
156 | map = sc_secondary_map; |
159 | chardev_push_character(&kbrd, map[sc]); |
157 | chardev_push_character(&kbrd, map[sc]); |
160 | break; |
158 | break; |
161 | } |
159 | } |
162 | spinlock_unlock(&keylock); |
160 | spinlock_unlock(&keylock); |
163 | } |
161 | } |
164 | 162 | ||
165 | uint8_t active_read_buff_read(void) |
163 | uint8_t active_read_buff_read(void) |
166 | { |
164 | { |
167 | static int i=0; |
165 | static int i=0; |
168 | i &= (ACTIVE_READ_BUFF_SIZE-1); |
166 | i &= (ACTIVE_READ_BUFF_SIZE-1); |
169 | if(!active_read_buff[i]) { |
167 | if(!active_read_buff[i]) { |
170 | return 0; |
168 | return 0; |
171 | } |
169 | } |
172 | return active_read_buff[i++]; |
170 | return active_read_buff[i++]; |
173 | } |
171 | } |
174 | 172 | ||
175 | void active_read_buff_write(uint8_t ch) |
173 | void active_read_buff_write(uint8_t ch) |
176 | { |
174 | { |
177 | static int i=0; |
175 | static int i=0; |
178 | active_read_buff[i] = ch; |
176 | active_read_buff[i] = ch; |
179 | i++; |
177 | i++; |
180 | i &= (ACTIVE_READ_BUFF_SIZE-1); |
178 | i &= (ACTIVE_READ_BUFF_SIZE-1); |
181 | active_read_buff[i]=0; |
179 | active_read_buff[i]=0; |
182 | } |
180 | } |
183 | 181 | ||
184 | 182 | ||
185 | void active_read_key_pressed(uint8_t sc) |
183 | void active_read_key_pressed(uint8_t sc) |
186 | { |
184 | { |
187 | char *map = sc_primary_map; |
185 | char *map = sc_primary_map; |
188 | char ascii = sc_primary_map[sc]; |
186 | char ascii = sc_primary_map[sc]; |
189 | bool shift, capslock; |
187 | bool shift, capslock; |
190 | bool letter = false; |
188 | bool letter = false; |
191 | 189 | ||
192 | /*spinlock_lock(&keylock);*/ |
190 | /*spinlock_lock(&keylock);*/ |
193 | switch (sc) { |
191 | switch (sc) { |
194 | case SC_LSHIFT: |
192 | case SC_LSHIFT: |
195 | case SC_RSHIFT: |
193 | case SC_RSHIFT: |
196 | keyflags |= PRESSED_SHIFT; |
194 | keyflags |= PRESSED_SHIFT; |
197 | break; |
195 | break; |
198 | case SC_CAPSLOCK: |
196 | case SC_CAPSLOCK: |
199 | keyflags |= PRESSED_CAPSLOCK; |
197 | keyflags |= PRESSED_CAPSLOCK; |
200 | break; |
198 | break; |
201 | case SC_SPEC_ESCAPE: |
199 | case SC_SPEC_ESCAPE: |
202 | break; |
200 | break; |
203 | case SC_LEFTARR: |
201 | case SC_LEFTARR: |
204 | active_read_buff_write(0x1b); |
202 | active_read_buff_write(0x1b); |
205 | active_read_buff_write(0x5b); |
203 | active_read_buff_write(0x5b); |
206 | active_read_buff_write(0x44); |
204 | active_read_buff_write(0x44); |
207 | break; |
205 | break; |
208 | case SC_RIGHTARR: |
206 | case SC_RIGHTARR: |
209 | active_read_buff_write(0x1b); |
207 | active_read_buff_write(0x1b); |
210 | active_read_buff_write(0x5b); |
208 | active_read_buff_write(0x5b); |
211 | active_read_buff_write(0x43); |
209 | active_read_buff_write(0x43); |
212 | break; |
210 | break; |
213 | case SC_UPARR: |
211 | case SC_UPARR: |
214 | active_read_buff_write(0x1b); |
212 | active_read_buff_write(0x1b); |
215 | active_read_buff_write(0x5b); |
213 | active_read_buff_write(0x5b); |
216 | active_read_buff_write(0x41); |
214 | active_read_buff_write(0x41); |
217 | break; |
215 | break; |
218 | case SC_DOWNARR: |
216 | case SC_DOWNARR: |
219 | active_read_buff_write(0x1b); |
217 | active_read_buff_write(0x1b); |
220 | active_read_buff_write(0x5b); |
218 | active_read_buff_write(0x5b); |
221 | active_read_buff_write(0x42); |
219 | active_read_buff_write(0x42); |
222 | break; |
220 | break; |
223 | case SC_HOME: |
221 | case SC_HOME: |
224 | active_read_buff_write(0x1b); |
222 | active_read_buff_write(0x1b); |
225 | active_read_buff_write(0x4f); |
223 | active_read_buff_write(0x4f); |
226 | active_read_buff_write(0x48); |
224 | active_read_buff_write(0x48); |
227 | break; |
225 | break; |
228 | case SC_END: |
226 | case SC_END: |
229 | active_read_buff_write(0x1b); |
227 | active_read_buff_write(0x1b); |
230 | active_read_buff_write(0x4f); |
228 | active_read_buff_write(0x4f); |
231 | active_read_buff_write(0x46); |
229 | active_read_buff_write(0x46); |
232 | break; |
230 | break; |
233 | case SC_DELETE: |
231 | case SC_DELETE: |
234 | active_read_buff_write(0x1b); |
232 | active_read_buff_write(0x1b); |
235 | active_read_buff_write(0x5b); |
233 | active_read_buff_write(0x5b); |
236 | active_read_buff_write(0x33); |
234 | active_read_buff_write(0x33); |
237 | active_read_buff_write(0x7e); |
235 | active_read_buff_write(0x7e); |
238 | break; |
236 | break; |
239 | default: |
237 | default: |
240 | letter = islower(ascii); |
238 | letter = islower(ascii); |
241 | capslock = (keyflags & PRESSED_CAPSLOCK) || |
239 | capslock = (keyflags & PRESSED_CAPSLOCK) || |
242 | (lockflags & LOCKED_CAPSLOCK); |
240 | (lockflags & LOCKED_CAPSLOCK); |
243 | shift = keyflags & PRESSED_SHIFT; |
241 | shift = keyflags & PRESSED_SHIFT; |
244 | if (letter && capslock) |
242 | if (letter && capslock) |
245 | shift = !shift; |
243 | shift = !shift; |
246 | if (shift) |
244 | if (shift) |
247 | map = sc_secondary_map; |
245 | map = sc_secondary_map; |
248 | active_read_buff_write(map[sc]); |
246 | active_read_buff_write(map[sc]); |
249 | break; |
247 | break; |
250 | } |
248 | } |
251 | /*spinlock_unlock(&keylock);*/ |
249 | /*spinlock_unlock(&keylock);*/ |
252 | 250 | ||
253 | } |
251 | } |
254 | 252 | ||
255 | /** @} |
253 | /** @} |
256 | */ |
254 | */ |
257 | 255 |