Rev 4669 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4669 | Rev 4678 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Vineeth Pillai |
2 | * Copyright (c) 2009 Vineeth Pillai |
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 kbd_ctl |
29 | /** @addtogroup kbd_ctl |
30 | * @ingroup kbd |
30 | * @ingroup kbd |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | * @brief PL050 keyboard controller driver. |
35 | * @brief PL050 keyboard controller driver. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <kbd.h> |
38 | #include <kbd.h> |
39 | #include <io/console.h> |
39 | #include <io/console.h> |
40 | #include <io/keycode.h> |
40 | #include <io/keycode.h> |
41 | #include <kbd_ctl.h> |
41 | #include <kbd_ctl.h> |
42 | #include <gsp.h> |
42 | #include <gsp.h> |
43 | #include <stdio.h> |
43 | #include <stdio.h> |
44 | 44 | ||
45 | #define PL050_CAPS_SCAN_CODE 0x58 |
45 | #define PL050_CAPS_SCAN_CODE 0x58 |
46 | #define PL050_NUM_SCAN_CODE 0x77 |
46 | #define PL050_NUM_SCAN_CODE 0x77 |
47 | #define PL050_SCROLL_SCAN_CODE 0x7E |
47 | #define PL050_SCROLL_SCAN_CODE 0x7E |
48 | 48 | ||
49 | static bool is_lock_key(int); |
49 | static bool is_lock_key(int); |
50 | enum dec_state { |
50 | enum dec_state { |
51 | ds_s, |
51 | ds_s, |
52 | ds_e |
52 | ds_e |
53 | }; |
53 | }; |
54 | 54 | ||
55 | static enum dec_state ds; |
55 | static enum dec_state ds; |
56 | 56 | ||
57 | static int scanmap_simple[] = { |
57 | static int scanmap_simple[] = { |
58 | 58 | ||
59 | [0x0e] = KC_BACKTICK, |
59 | [0x0e] = KC_BACKTICK, |
60 | 60 | ||
61 | [0x16] = KC_1, |
61 | [0x16] = KC_1, |
62 | [0x1e] = KC_2, |
62 | [0x1e] = KC_2, |
63 | [0x26] = KC_3, |
63 | [0x26] = KC_3, |
64 | [0x25] = KC_4, |
64 | [0x25] = KC_4, |
65 | [0x2e] = KC_5, |
65 | [0x2e] = KC_5, |
66 | [0x36] = KC_6, |
66 | [0x36] = KC_6, |
67 | [0x3d] = KC_7, |
67 | [0x3d] = KC_7, |
68 | [0x3e] = KC_8, |
68 | [0x3e] = KC_8, |
69 | [0x46] = KC_9, |
69 | [0x46] = KC_9, |
70 | [0x45] = KC_0, |
70 | [0x45] = KC_0, |
71 | 71 | ||
72 | [0x4e] = KC_MINUS, |
72 | [0x4e] = KC_MINUS, |
73 | [0x55] = KC_EQUALS, |
73 | [0x55] = KC_EQUALS, |
74 | [0x66] = KC_BACKSPACE, |
74 | [0x66] = KC_BACKSPACE, |
75 | 75 | ||
76 | [0x0d] = KC_TAB, |
76 | [0x0d] = KC_TAB, |
77 | 77 | ||
78 | [0x15] = KC_Q, |
78 | [0x15] = KC_Q, |
79 | [0x1d] = KC_W, |
79 | [0x1d] = KC_W, |
80 | [0x24] = KC_E, |
80 | [0x24] = KC_E, |
81 | [0x2d] = KC_R, |
81 | [0x2d] = KC_R, |
82 | [0x2c] = KC_T, |
82 | [0x2c] = KC_T, |
83 | [0x35] = KC_Y, |
83 | [0x35] = KC_Y, |
84 | [0x3c] = KC_U, |
84 | [0x3c] = KC_U, |
85 | [0x43] = KC_I, |
85 | [0x43] = KC_I, |
86 | [0x44] = KC_O, |
86 | [0x44] = KC_O, |
87 | [0x4d] = KC_P, |
87 | [0x4d] = KC_P, |
88 | 88 | ||
89 | [0x54] = KC_LBRACKET, |
89 | [0x54] = KC_LBRACKET, |
90 | [0x5b] = KC_RBRACKET, |
90 | [0x5b] = KC_RBRACKET, |
91 | 91 | ||
92 | [0x58] = KC_CAPS_LOCK, |
92 | [0x58] = KC_CAPS_LOCK, |
93 | 93 | ||
94 | [0x1c] = KC_A, |
94 | [0x1c] = KC_A, |
95 | [0x1b] = KC_S, |
95 | [0x1b] = KC_S, |
96 | [0x23] = KC_D, |
96 | [0x23] = KC_D, |
97 | [0x2b] = KC_F, |
97 | [0x2b] = KC_F, |
98 | [0x34] = KC_G, |
98 | [0x34] = KC_G, |
99 | [0x33] = KC_H, |
99 | [0x33] = KC_H, |
100 | [0x3b] = KC_J, |
100 | [0x3b] = KC_J, |
101 | [0x42] = KC_K, |
101 | [0x42] = KC_K, |
102 | [0x4b] = KC_L, |
102 | [0x4b] = KC_L, |
103 | 103 | ||
104 | [0x4c] = KC_SEMICOLON, |
104 | [0x4c] = KC_SEMICOLON, |
105 | [0x52] = KC_QUOTE, |
105 | [0x52] = KC_QUOTE, |
106 | [0x5d] = KC_BACKSLASH, |
106 | [0x5d] = KC_BACKSLASH, |
107 | 107 | ||
108 | [0x12] = KC_LSHIFT, |
108 | [0x12] = KC_LSHIFT, |
109 | 109 | ||
110 | [0x1a] = KC_Z, |
110 | [0x1a] = KC_Z, |
111 | [0x22] = KC_X, |
111 | [0x22] = KC_X, |
112 | [0x21] = KC_C, |
112 | [0x21] = KC_C, |
113 | [0x2a] = KC_V, |
113 | [0x2a] = KC_V, |
114 | [0x32] = KC_B, |
114 | [0x32] = KC_B, |
115 | [0x31] = KC_N, |
115 | [0x31] = KC_N, |
116 | [0x3a] = KC_M, |
116 | [0x3a] = KC_M, |
117 | 117 | ||
118 | [0x41] = KC_COMMA, |
118 | [0x41] = KC_COMMA, |
119 | [0x49] = KC_PERIOD, |
119 | [0x49] = KC_PERIOD, |
120 | [0x4a] = KC_SLASH, |
120 | [0x4a] = KC_SLASH, |
121 | 121 | ||
122 | [0x59] = KC_RSHIFT, |
122 | [0x59] = KC_RSHIFT, |
123 | 123 | ||
124 | [0x14] = KC_LCTRL, |
124 | [0x14] = KC_LCTRL, |
125 | [0x11] = KC_LALT, |
125 | [0x11] = KC_LALT, |
126 | [0x29] = KC_SPACE, |
126 | [0x29] = KC_SPACE, |
127 | 127 | ||
128 | [0x76] = KC_ESCAPE, |
128 | [0x76] = KC_ESCAPE, |
129 | 129 | ||
130 | [0x05] = KC_F1, |
130 | [0x05] = KC_F1, |
131 | [0x06] = KC_F2, |
131 | [0x06] = KC_F2, |
132 | [0x04] = KC_F3, |
132 | [0x04] = KC_F3, |
133 | [0x0c] = KC_F4, |
133 | [0x0c] = KC_F4, |
134 | [0x03] = KC_F5, |
134 | [0x03] = KC_F5, |
135 | [0x0b] = KC_F6, |
135 | [0x0b] = KC_F6, |
136 | [0x02] = KC_F7, |
136 | [0x02] = KC_F7, |
137 | 137 | ||
138 | [0x0a] = KC_F8, |
138 | [0x0a] = KC_F8, |
139 | [0x01] = KC_F9, |
139 | [0x01] = KC_F9, |
140 | [0x09] = KC_F10, |
140 | [0x09] = KC_F10, |
141 | 141 | ||
142 | [0x78] = KC_F11, |
142 | [0x78] = KC_F11, |
143 | [0x07] = KC_F12, |
143 | [0x07] = KC_F12, |
144 | 144 | ||
145 | [0x60] = KC_SCROLL_LOCK, |
145 | [0x60] = KC_SCROLL_LOCK, |
146 | 146 | ||
147 | [0x5a] = KC_ENTER, |
147 | [0x5a] = KC_ENTER, |
148 | 148 | ||
149 | [0x77] = KC_NUM_LOCK, |
149 | [0x77] = KC_NUM_LOCK, |
150 | [0x7c] = KC_NTIMES, |
150 | [0x7c] = KC_NTIMES, |
151 | [0x7b] = KC_NMINUS, |
151 | [0x7b] = KC_NMINUS, |
152 | [0x79] = KC_NPLUS, |
152 | [0x79] = KC_NPLUS, |
153 | [0x6c] = KC_N7, |
153 | [0x6c] = KC_N7, |
154 | [0x75] = KC_N8, |
154 | [0x75] = KC_N8, |
155 | [0x7d] = KC_N9, |
155 | [0x7d] = KC_N9, |
156 | [0x6b] = KC_N4, |
156 | [0x6b] = KC_N4, |
157 | [0x73] = KC_N5, |
157 | [0x73] = KC_N5, |
158 | [0x74] = KC_N6, |
158 | [0x74] = KC_N6, |
159 | [0x69] = KC_N1, |
159 | [0x69] = KC_N1, |
160 | [0x72] = KC_N2, |
160 | [0x72] = KC_N2, |
161 | [0x7a] = KC_N3, |
161 | [0x7a] = KC_N3, |
162 | [0x70] = KC_N0, |
162 | [0x70] = KC_N0, |
163 | [0x71] = KC_NPERIOD |
163 | [0x71] = KC_NPERIOD |
164 | }; |
164 | }; |
165 | 165 | ||
166 | static int scanmap_e0[] = { |
166 | static int scanmap_e0[] = { |
167 | [0x65] = KC_RALT, |
167 | [0x65] = KC_RALT, |
168 | [0x59] = KC_RSHIFT, |
168 | [0x59] = KC_RSHIFT, |
169 | 169 | ||
170 | [0x64] = KC_PRTSCR, |
170 | [0x64] = KC_PRTSCR, |
171 | 171 | ||
172 | [0x70] = KC_INSERT, |
172 | [0x70] = KC_INSERT, |
173 | [0x6c] = KC_HOME, |
173 | [0x6c] = KC_HOME, |
174 | [0x7d] = KC_PAGE_UP, |
174 | [0x7d] = KC_PAGE_UP, |
175 | 175 | ||
176 | [0x71] = KC_DELETE, |
176 | [0x71] = KC_DELETE, |
177 | [0x69] = KC_END, |
177 | [0x69] = KC_END, |
178 | [0x7a] = KC_PAGE_DOWN, |
178 | [0x7a] = KC_PAGE_DOWN, |
179 | 179 | ||
180 | [0x75] = KC_UP, |
180 | [0x75] = KC_UP, |
181 | [0x6b] = KC_LEFT, |
181 | [0x6b] = KC_LEFT, |
182 | [0x72] = KC_DOWN, |
182 | [0x72] = KC_DOWN, |
183 | [0x74] = KC_RIGHT, |
183 | [0x74] = KC_RIGHT, |
184 | 184 | ||
185 | [0x4a] = KC_NSLASH, |
185 | [0x4a] = KC_NSLASH, |
186 | [0x5a] = KC_NENTER |
186 | [0x5a] = KC_NENTER |
187 | }; |
187 | }; |
188 | 188 | ||
189 | int kbd_ctl_init(void) |
189 | int kbd_ctl_init(void) |
190 | { |
190 | { |
191 | ds = ds_s; |
191 | ds = ds_s; |
192 | return 0; |
192 | return 0; |
193 | } |
193 | } |
194 | 194 | ||
195 | void kbd_ctl_parse_scancode(int scancode) |
195 | void kbd_ctl_parse_scancode(int scancode) |
196 | { |
196 | { |
197 | static int key_release_flag = 0; |
197 | static int key_release_flag = 0; |
198 | static int is_locked = 0; |
198 | static int is_locked = 0; |
199 | console_ev_type_t type; |
199 | console_ev_type_t type; |
200 | unsigned int key; |
200 | unsigned int key; |
201 | int *map; |
201 | int *map; |
202 | size_t map_length; |
202 | size_t map_length; |
203 | 203 | ||
204 | if (scancode == 0xe0) { |
204 | if (scancode == 0xe0) { |
205 | ds = ds_e; |
205 | ds = ds_e; |
206 | return; |
206 | return; |
207 | } |
207 | } |
208 | 208 | ||
209 | switch (ds) { |
209 | switch (ds) { |
210 | case ds_s: |
210 | case ds_s: |
211 | map = scanmap_simple; |
211 | map = scanmap_simple; |
212 | map_length = sizeof(scanmap_simple) / sizeof(int); |
212 | map_length = sizeof(scanmap_simple) / sizeof(int); |
213 | break; |
213 | break; |
214 | case ds_e: |
214 | case ds_e: |
215 | map = scanmap_e0; |
215 | map = scanmap_e0; |
216 | map_length = sizeof(scanmap_e0) / sizeof(int); |
216 | map_length = sizeof(scanmap_e0) / sizeof(int); |
217 | break; |
217 | break; |
218 | default: |
218 | default: |
219 | map = NULL; |
219 | map = NULL; |
220 | map_length = 0; |
220 | map_length = 0; |
221 | } |
221 | } |
222 | 222 | ||
223 | ds = ds_s; |
223 | ds = ds_s; |
224 | if (scancode == 0xf0) { |
224 | if (scancode == 0xf0) { |
225 | key_release_flag = 1; |
225 | key_release_flag = 1; |
226 | return; |
226 | return; |
227 | } else { |
227 | } else { |
228 | if (key_release_flag) { |
228 | if (key_release_flag) { |
229 | type = KEY_RELEASE; |
229 | type = KEY_RELEASE; |
230 | key_release_flag = 0; |
230 | key_release_flag = 0; |
231 | if (is_lock_key(scancode)) { |
231 | if (is_lock_key(scancode)) { |
232 | if (!is_locked) { |
232 | if (!is_locked) { |
233 | is_locked = 1; |
233 | is_locked = 1; |
234 | } else { |
234 | } else { |
235 | is_locked = 0; |
235 | is_locked = 0; |
236 | return; |
236 | return; |
237 | } |
237 | } |
238 | } |
238 | } |
239 | } else { |
239 | } else { |
240 | if (is_lock_key(scancode) && is_locked) |
240 | if (is_lock_key(scancode) && is_locked) |
241 | return; |
241 | return; |
242 | type = KEY_PRESS; |
242 | type = KEY_PRESS; |
243 | } |
243 | } |
244 | } |
244 | } |
245 | 245 | ||
246 | if (scancode < 0) |
246 | if (scancode < 0) |
247 | return; |
247 | return; |
248 | 248 | ||
249 | key = map[scancode]; |
249 | key = map[scancode]; |
250 | if (key != 0) |
250 | if (key != 0) |
251 | kbd_push_ev(type, key); |
251 | kbd_push_ev(type, key); |
252 | } |
252 | } |
253 | 253 | ||
254 | static bool is_lock_key(int sc) |
254 | static bool is_lock_key(int sc) |
255 | { |
255 | { |
256 | return ((sc == PL050_CAPS_SCAN_CODE) || (sc == PL050_NUM_SCAN_CODE) || |
256 | return ((sc == PL050_CAPS_SCAN_CODE) || (sc == PL050_NUM_SCAN_CODE) || |
257 | (sc == PL050_SCROLL_SCAN_CODE)); |
257 | (sc == PL050_SCROLL_SCAN_CODE)); |
258 | } |
258 | } |
259 | 259 | ||
260 | /** |
260 | /** |
261 | * @} |
261 | * @} |
262 | */ |
262 | */ |
263 | 263 |