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