Rev 3924 | Rev 3944 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3924 | Rev 3933 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Jiri Svoboda |
2 | * Copyright (c) 2009 Jiri Svoboda |
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 Serial TTY-like keyboard controller driver. |
35 | * @brief Serial TTY-like keyboard controller driver. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <kbd.h> |
38 | #include <kbd.h> |
39 | #include <kbd/kbd.h> |
39 | #include <kbd/kbd.h> |
40 | #include <kbd/keycode.h> |
40 | #include <kbd/keycode.h> |
41 | #include <kbd_ctl.h> |
41 | #include <kbd_ctl.h> |
42 | 42 | ||
43 | static void parse_ds_start(int scancode); |
43 | static void parse_ds_start(int scancode); |
44 | static void parse_ds_e(int scancode); |
44 | static void parse_ds_e(int scancode); |
45 | static void parse_ds_e1(int scancode); |
45 | static void parse_ds_e1(int scancode); |
46 | static void parse_ds_e2(int scancode); |
46 | static void parse_ds_e2(int scancode); |
47 | static void parse_ds_e2a(int scancode); |
47 | static void parse_ds_e2a(int scancode); |
48 | static void parse_ds_e2b(int scancode); |
48 | static void parse_ds_e2b(int scancode); |
49 | 49 | ||
50 | static void parse_leaf(int scancode, int *map, size_t map_length); |
50 | static void parse_leaf(int scancode, int *map, size_t map_length); |
51 | 51 | ||
52 | enum dec_state { |
52 | enum dec_state { |
53 | ds_start, |
53 | ds_start, |
54 | ds_e, |
54 | ds_e, |
55 | ds_e1, |
55 | ds_e1, |
56 | ds_e2, |
56 | ds_e2, |
57 | ds_e2a, |
57 | ds_e2a, |
58 | ds_e2b |
58 | ds_e2b |
59 | }; |
59 | }; |
60 | 60 | ||
61 | static int map_start[] = { |
61 | static int map_start[] = { |
62 | 62 | ||
63 | [0x60] = KC_BACKTICK, |
63 | [0x60] = KC_BACKTICK, |
64 | 64 | ||
65 | [0x31] = KC_1, |
65 | [0x31] = KC_1, |
66 | [0x32] = KC_2, |
66 | [0x32] = KC_2, |
67 | [0x33] = KC_3, |
67 | [0x33] = KC_3, |
68 | [0x34] = KC_4, |
68 | [0x34] = KC_4, |
69 | [0x35] = KC_5, |
69 | [0x35] = KC_5, |
70 | [0x36] = KC_6, |
70 | [0x36] = KC_6, |
71 | [0x37] = KC_7, |
71 | [0x37] = KC_7, |
72 | [0x38] = KC_8, |
72 | [0x38] = KC_8, |
73 | [0x39] = KC_9, |
73 | [0x39] = KC_9, |
74 | [0x30] = KC_0, |
74 | [0x30] = KC_0, |
75 | 75 | ||
76 | [0x2d] = KC_MINUS, |
76 | [0x2d] = KC_MINUS, |
77 | [0x3d] = KC_EQUALS, |
77 | [0x3d] = KC_EQUALS, |
78 | [0x08] = KC_BACKSPACE, |
78 | [0x08] = KC_BACKSPACE, |
79 | 79 | ||
80 | [0x0f] = KC_TAB, |
80 | [0x0f] = KC_TAB, |
81 | 81 | ||
82 | [0x71] = KC_Q, |
82 | [0x71] = KC_Q, |
83 | [0x77] = KC_W, |
83 | [0x77] = KC_W, |
84 | [0x65] = KC_E, |
84 | [0x65] = KC_E, |
85 | [0x72] = KC_R, |
85 | [0x72] = KC_R, |
86 | [0x74] = KC_T, |
86 | [0x74] = KC_T, |
87 | [0x79] = KC_Y, |
87 | [0x79] = KC_Y, |
88 | [0x75] = KC_U, |
88 | [0x75] = KC_U, |
89 | [0x69] = KC_I, |
89 | [0x69] = KC_I, |
90 | [0x6f] = KC_O, |
90 | [0x6f] = KC_O, |
91 | [0x70] = KC_P, |
91 | [0x70] = KC_P, |
92 | 92 | ||
93 | [0x5b] = KC_LBRACKET, |
93 | [0x5b] = KC_LBRACKET, |
94 | [0x5d] = KC_RBRACKET, |
94 | [0x5d] = KC_RBRACKET, |
95 | 95 | ||
96 | // [0x3a] = KC_CAPS_LOCK, |
96 | // [0x3a] = KC_CAPS_LOCK, |
97 | 97 | ||
98 | [0x61] = KC_A, |
98 | [0x61] = KC_A, |
99 | [0x73] = KC_S, |
99 | [0x73] = KC_S, |
100 | [0x64] = KC_D, |
100 | [0x64] = KC_D, |
101 | [0x66] = KC_F, |
101 | [0x66] = KC_F, |
102 | [0x67] = KC_G, |
102 | [0x67] = KC_G, |
103 | [0x68] = KC_H, |
103 | [0x68] = KC_H, |
104 | [0x6a] = KC_J, |
104 | [0x6a] = KC_J, |
105 | [0x6b] = KC_K, |
105 | [0x6b] = KC_K, |
106 | [0x6c] = KC_L, |
106 | [0x6c] = KC_L, |
107 | 107 | ||
108 | [0x3b] = KC_SEMICOLON, |
108 | [0x3b] = KC_SEMICOLON, |
109 | [0x27] = KC_QUOTE, |
109 | [0x27] = KC_QUOTE, |
110 | [0x5c] = KC_BACKSLASH, |
110 | [0x5c] = KC_BACKSLASH, |
111 | 111 | ||
112 | // [0x2a] = KC_LSHIFT, |
112 | // [0x2a] = KC_LSHIFT, |
113 | 113 | ||
114 | [0x7a] = KC_Z, |
114 | [0x7a] = KC_Z, |
115 | [0x78] = KC_X, |
115 | [0x78] = KC_X, |
116 | [0x63] = KC_C, |
116 | [0x63] = KC_C, |
117 | [0x76] = KC_V, |
117 | [0x76] = KC_V, |
118 | [0x62] = KC_B, |
118 | [0x62] = KC_B, |
119 | [0x6e] = KC_N, |
119 | [0x6e] = KC_N, |
120 | [0x6d] = KC_M, |
120 | [0x6d] = KC_M, |
121 | 121 | ||
122 | [0x2c] = KC_COMMA, |
122 | [0x2c] = KC_COMMA, |
123 | [0x2e] = KC_PERIOD, |
123 | [0x2e] = KC_PERIOD, |
124 | [0x2f] = KC_SLASH, |
124 | [0x2f] = KC_SLASH, |
125 | 125 | ||
126 | // [0x36] = KC_RSHIFT, |
126 | // [0x36] = KC_RSHIFT, |
127 | 127 | ||
128 | // [0x1d] = KC_LCTRL, |
128 | // [0x1d] = KC_LCTRL, |
129 | // [0x38] = KC_LALT, |
129 | // [0x38] = KC_LALT, |
130 | [0x20] = KC_SPACE, |
130 | [0x20] = KC_SPACE, |
131 | 131 | ||
132 | [0x1b] = KC_ESCAPE, |
132 | [0x1b] = KC_ESCAPE, |
133 | 133 | ||
134 | [0x0a] = KC_ENTER, |
134 | [0x0a] = KC_ENTER, |
135 | [0x0d] = KC_ENTER |
135 | [0x0d] = KC_ENTER |
136 | 136 | ||
137 | /* |
137 | /* |
138 | [0x1] = KC_PRNSCR, |
138 | [0x1] = KC_PRNSCR, |
139 | [0x1] = KC_SCROLL_LOCK, |
139 | [0x1] = KC_SCROLL_LOCK, |
140 | [0x1] = KC_PAUSE, |
140 | [0x1] = KC_PAUSE, |
141 | */ |
141 | */ |
142 | }; |
142 | }; |
143 | 143 | ||
144 | static int map_e1[] = |
144 | static int map_e1[] = |
145 | { |
145 | { |
146 | [0x50] = KC_F1, |
146 | [0x50] = KC_F1, |
147 | [0x51] = KC_F2, |
147 | [0x51] = KC_F2, |
148 | [0x52] = KC_F3, |
148 | [0x52] = KC_F3, |
149 | [0x53] = KC_F4, |
149 | [0x53] = KC_F4, |
150 | }; |
150 | }; |
151 | 151 | ||
152 | static int map_e2[] = |
152 | static int map_e2[] = |
153 | { |
153 | { |
154 | [0x41] = KC_UP, |
154 | [0x41] = KC_UP, |
155 | [0x42] = KC_DOWN, |
155 | [0x42] = KC_DOWN, |
156 | [0x44] = KC_LEFT, |
156 | [0x44] = KC_LEFT, |
157 | [0x43] = KC_RIGHT, |
157 | [0x43] = KC_RIGHT, |
158 | }; |
158 | }; |
159 | 159 | ||
160 | static int map_e2a[] = |
160 | static int map_e2a[] = |
161 | { |
161 | { |
162 | [0x35] = KC_F5, |
162 | [0x35] = KC_F5, |
163 | [0x37] = KC_F6, |
163 | [0x37] = KC_F6, |
164 | [0x38] = KC_F7, |
164 | [0x38] = KC_F7, |
165 | [0x39] = KC_F8, |
165 | [0x39] = KC_F8, |
166 | }; |
166 | }; |
167 | 167 | ||
168 | static int map_e2b[] = |
168 | static int map_e2b[] = |
169 | { |
169 | { |
170 | [0x30] = KC_F9, |
170 | [0x30] = KC_F9, |
171 | [0x31] = KC_F10, |
171 | [0x31] = KC_F10, |
172 | [0x32] = KC_F11, |
172 | [0x32] = KC_F11, |
173 | [0x33] = KC_F12, |
173 | [0x33] = KC_F12, |
174 | }; |
174 | }; |
175 | 175 | ||
176 | 176 | ||
177 | static enum dec_state ds; |
177 | static enum dec_state ds; |
178 | 178 | ||
179 | void kbd_ctl_parse_scancode(int scancode) |
179 | void kbd_ctl_parse_scancode(int scancode) |
180 | { |
180 | { |
181 | switch (ds) { |
181 | switch (ds) { |
182 | case ds_start: parse_ds_start(scancode); break; |
182 | case ds_start: parse_ds_start(scancode); break; |
183 | case ds_e: parse_ds_e(scancode); break; |
183 | case ds_e: parse_ds_e(scancode); break; |
184 | case ds_e1: parse_ds_e1(scancode); break; |
184 | case ds_e1: parse_ds_e1(scancode); break; |
185 | case ds_e2: parse_ds_e2(scancode); break; |
185 | case ds_e2: parse_ds_e2(scancode); break; |
186 | case ds_e2a: parse_ds_e2a(scancode); break; |
186 | case ds_e2a: parse_ds_e2a(scancode); break; |
187 | case ds_e2b: parse_ds_e2b(scancode); break; |
187 | case ds_e2b: parse_ds_e2b(scancode); break; |
188 | } |
188 | } |
189 | } |
189 | } |
190 | 190 | ||
191 | static void parse_ds_start(int scancode) |
191 | static void parse_ds_start(int scancode) |
192 | { |
192 | { |
193 | if (scancode < 0 || scancode >= sizeof(map_start) / sizeof(int)) |
193 | if (scancode < 0 || scancode >= sizeof(map_start) / sizeof(int)) |
194 | return; |
194 | return; |
195 | 195 | ||
196 | if (scancode == 0x1b) { |
196 | if (scancode == 0x1b) { |
197 | ds = ds_e; |
197 | ds = ds_e; |
198 | return; |
198 | return; |
199 | } |
199 | } |
200 | 200 | ||
201 | parse_leaf(scancode, map_start, sizeof(map_start) / sizeof(int)); |
201 | parse_leaf(scancode, map_start, sizeof(map_start) / sizeof(int)); |
202 | } |
202 | } |
203 | 203 | ||
204 | static void parse_ds_e(int scancode) |
204 | static void parse_ds_e(int scancode) |
205 | { |
205 | { |
206 | if (scancode < 0 || scancode >= 0x80) return; |
206 | if (scancode < 0 || scancode >= 0x80) return; |
207 | 207 | ||
208 | switch (scancode) { |
208 | switch (scancode) { |
209 | case 0x4f: ds = ds_e1; return; |
209 | case 0x4f: ds = ds_e1; return; |
210 | case 0x5b: ds = ds_e2; return; |
210 | case 0x5b: ds = ds_e2; return; |
211 | case 0x1b: ds = ds_start; break; |
211 | case 0x1b: ds = ds_start; break; |
212 | default: ds = ds_start; return; |
212 | default: ds = ds_start; return; |
213 | } |
213 | } |
214 | 214 | ||
215 | kbd_push_ev(KE_PRESS, KC_ESCAPE, 0); |
215 | kbd_push_ev(KE_PRESS, KC_ESCAPE); |
216 | } |
216 | } |
217 | 217 | ||
218 | static void parse_ds_e1(int scancode) |
218 | static void parse_ds_e1(int scancode) |
219 | { |
219 | { |
220 | parse_leaf(scancode, map_e1, sizeof(map_e1) / sizeof(int)); |
220 | parse_leaf(scancode, map_e1, sizeof(map_e1) / sizeof(int)); |
221 | } |
221 | } |
222 | 222 | ||
223 | static void parse_ds_e2(int scancode) |
223 | static void parse_ds_e2(int scancode) |
224 | { |
224 | { |
225 | switch (scancode) { |
225 | switch (scancode) { |
226 | case 0x31: ds = ds_e2a; break; |
226 | case 0x31: ds = ds_e2a; break; |
227 | case 0x32: ds = ds_e2b; break; |
227 | case 0x32: ds = ds_e2b; break; |
228 | default: ds = ds_start; break; |
228 | default: ds = ds_start; break; |
229 | } |
229 | } |
230 | 230 | ||
231 | parse_leaf(scancode, map_e2, sizeof(map_e2) / sizeof(int)); |
231 | parse_leaf(scancode, map_e2, sizeof(map_e2) / sizeof(int)); |
232 | } |
232 | } |
233 | 233 | ||
234 | static void parse_ds_e2a(int scancode) |
234 | static void parse_ds_e2a(int scancode) |
235 | { |
235 | { |
236 | parse_leaf(scancode, map_e2a, sizeof(map_e2a) / sizeof(int)); |
236 | parse_leaf(scancode, map_e2a, sizeof(map_e2a) / sizeof(int)); |
237 | } |
237 | } |
238 | 238 | ||
239 | static void parse_ds_e2b(int scancode) |
239 | static void parse_ds_e2b(int scancode) |
240 | { |
240 | { |
241 | parse_leaf(scancode, map_e2b, sizeof(map_e2b) / sizeof(int)); |
241 | parse_leaf(scancode, map_e2b, sizeof(map_e2b) / sizeof(int)); |
242 | } |
242 | } |
243 | 243 | ||
244 | static void parse_leaf(int scancode, int *map, size_t map_length) |
244 | static void parse_leaf(int scancode, int *map, size_t map_length) |
245 | { |
245 | { |
246 | unsigned int key; |
246 | unsigned int key; |
247 | 247 | ||
248 | ds = ds_start; |
248 | ds = ds_start; |
249 | 249 | ||
250 | if (scancode < 0 || scancode >= map_length) |
250 | if (scancode < 0 || scancode >= map_length) |
251 | return; |
251 | return; |
252 | 252 | ||
253 | key = map[scancode]; |
253 | key = map[scancode]; |
254 | if (key != 0) |
254 | if (key != 0) |
255 | kbd_push_ev(KE_PRESS, key, 0); |
255 | kbd_push_ev(KE_PRESS, key); |
256 | } |
256 | } |
257 | 257 | ||
258 | 258 | ||
259 | /** |
259 | /** |
260 | * @} |
260 | * @} |
261 | */ |
261 | */ |
262 | 262 |