Rev 3924 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3923 | svoboda | 1 | /* |
2 | * Copyright (c) 2009 Jiri Svoboda |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | /** @addtogroup kbd |
||
30 | * @brief Serial TTY-like keyboard controller driver. |
||
31 | * @{ |
||
32 | */ |
||
33 | |||
34 | #include <kbd.h> |
||
35 | #include <kbd/kbd.h> |
||
36 | #include <kbd/keycode.h> |
||
37 | #include <kbd_ctl.h> |
||
38 | |||
39 | static void parse_ds_start(int scancode); |
||
40 | static void parse_ds_e(int scancode); |
||
41 | static void parse_ds_e1(int scancode); |
||
42 | static void parse_ds_e2(int scancode); |
||
43 | static void parse_ds_e2a(int scancode); |
||
44 | static void parse_ds_e2b(int scancode); |
||
45 | |||
46 | static void parse_leaf(int scancode, int *map, size_t map_length); |
||
47 | |||
48 | enum dec_state { |
||
49 | ds_start, |
||
50 | ds_e, |
||
51 | ds_e1, |
||
52 | ds_e2, |
||
53 | ds_e2a, |
||
54 | ds_e2b |
||
55 | }; |
||
56 | |||
57 | static int map_start[] = { |
||
58 | |||
59 | [0x60] = KC_BACKTICK, |
||
60 | |||
61 | [0x31] = KC_1, |
||
62 | [0x32] = KC_2, |
||
63 | [0x33] = KC_3, |
||
64 | [0x34] = KC_4, |
||
65 | [0x35] = KC_5, |
||
66 | [0x36] = KC_6, |
||
67 | [0x37] = KC_7, |
||
68 | [0x38] = KC_8, |
||
69 | [0x39] = KC_9, |
||
70 | [0x30] = KC_0, |
||
71 | |||
72 | [0x2d] = KC_MINUS, |
||
73 | [0x3d] = KC_EQUALS, |
||
74 | [0x08] = KC_BACKSPACE, |
||
75 | |||
76 | [0x0f] = KC_TAB, |
||
77 | |||
78 | [0x71] = KC_Q, |
||
79 | [0x77] = KC_W, |
||
80 | [0x65] = KC_E, |
||
81 | [0x72] = KC_R, |
||
82 | [0x74] = KC_T, |
||
83 | [0x79] = KC_Y, |
||
84 | [0x75] = KC_U, |
||
85 | [0x69] = KC_I, |
||
86 | [0x6f] = KC_O, |
||
87 | [0x70] = KC_P, |
||
88 | |||
89 | [0x5b] = KC_LBRACKET, |
||
90 | [0x5d] = KC_RBRACKET, |
||
91 | |||
92 | // [0x3a] = KC_CAPS_LOCK, |
||
93 | |||
94 | [0x61] = KC_A, |
||
95 | [0x73] = KC_S, |
||
96 | [0x64] = KC_D, |
||
97 | [0x66] = KC_F, |
||
98 | [0x67] = KC_G, |
||
99 | [0x68] = KC_H, |
||
100 | [0x6a] = KC_J, |
||
101 | [0x6b] = KC_K, |
||
102 | [0x6c] = KC_L, |
||
103 | |||
104 | [0x3b] = KC_SEMICOLON, |
||
105 | [0x27] = KC_QUOTE, |
||
106 | [0x5c] = KC_BACKSLASH, |
||
107 | |||
108 | // [0x2a] = KC_LSHIFT, |
||
109 | |||
110 | [0x7a] = KC_Z, |
||
111 | [0x78] = KC_X, |
||
112 | [0x63] = KC_C, |
||
113 | [0x76] = KC_V, |
||
114 | [0x62] = KC_B, |
||
115 | [0x6e] = KC_N, |
||
116 | [0x6d] = KC_M, |
||
117 | |||
118 | [0x2c] = KC_COMMA, |
||
119 | [0x2e] = KC_PERIOD, |
||
120 | [0x2f] = KC_SLASH, |
||
121 | |||
122 | // [0x36] = KC_RSHIFT, |
||
123 | |||
124 | // [0x1d] = KC_LCTRL, |
||
125 | // [0x38] = KC_LALT, |
||
126 | [0x20] = KC_SPACE, |
||
127 | |||
128 | [0x1b] = KC_ESCAPE, |
||
129 | |||
130 | [0x0a] = KC_ENTER, |
||
131 | [0x0d] = KC_ENTER |
||
132 | |||
133 | /* |
||
134 | [0x1] = KC_PRNSCR, |
||
135 | [0x1] = KC_SCROLL_LOCK, |
||
136 | [0x1] = KC_PAUSE, |
||
137 | */ |
||
138 | }; |
||
139 | |||
140 | static int map_e1[] = |
||
141 | { |
||
142 | [0x50] = KC_F1, |
||
143 | [0x51] = KC_F2, |
||
144 | [0x52] = KC_F3, |
||
145 | [0x53] = KC_F4, |
||
146 | }; |
||
147 | |||
148 | static int map_e2[] = |
||
149 | { |
||
150 | [0x41] = KC_UP, |
||
151 | [0x42] = KC_DOWN, |
||
152 | [0x44] = KC_LEFT, |
||
153 | [0x43] = KC_RIGHT, |
||
154 | }; |
||
155 | |||
156 | static int map_e2a[] = |
||
157 | { |
||
158 | [0x35] = KC_F5, |
||
159 | [0x37] = KC_F6, |
||
160 | [0x38] = KC_F7, |
||
161 | [0x39] = KC_F8, |
||
162 | }; |
||
163 | |||
164 | static int map_e2b[] = |
||
165 | { |
||
166 | [0x30] = KC_F9, |
||
167 | [0x31] = KC_F10, |
||
168 | [0x32] = KC_F11, |
||
169 | [0x33] = KC_F12, |
||
170 | }; |
||
171 | |||
172 | |||
173 | static enum dec_state ds; |
||
174 | |||
175 | void kbd_ctl_parse_scancode(int scancode) |
||
176 | { |
||
177 | switch (ds) { |
||
178 | case ds_start: parse_ds_start(scancode); break; |
||
179 | case ds_e: parse_ds_e(scancode); break; |
||
180 | case ds_e1: parse_ds_e1(scancode); break; |
||
181 | case ds_e2: parse_ds_e2(scancode); break; |
||
182 | case ds_e2a: parse_ds_e2a(scancode); break; |
||
183 | case ds_e2b: parse_ds_e2b(scancode); break; |
||
184 | } |
||
185 | } |
||
186 | |||
187 | static void parse_ds_start(int scancode) |
||
188 | { |
||
189 | if (scancode < 0 || scancode >= sizeof(map_start) / sizeof(int)) |
||
190 | return; |
||
191 | |||
192 | if (scancode == 0x1b) { |
||
193 | ds = ds_e; |
||
194 | return; |
||
195 | } |
||
196 | |||
197 | parse_leaf(scancode, map_start, sizeof(map_start) / sizeof(int)); |
||
198 | } |
||
199 | |||
200 | static void parse_ds_e(int scancode) |
||
201 | { |
||
202 | if (scancode < 0 || scancode >= 0x80) return; |
||
203 | |||
204 | switch (scancode) { |
||
205 | case 0x4f: ds = ds_e1; return; |
||
206 | case 0x5b: ds = ds_e2; return; |
||
207 | case 0x1b: ds = ds_start; break; |
||
208 | default: ds = ds_start; return; |
||
209 | } |
||
210 | |||
211 | kbd_push_ev(KE_PRESS, KC_ESCAPE, 0); |
||
212 | } |
||
213 | |||
214 | static void parse_ds_e1(int scancode) |
||
215 | { |
||
216 | parse_leaf(scancode, map_e1, sizeof(map_e1) / sizeof(int)); |
||
217 | } |
||
218 | |||
219 | static void parse_ds_e2(int scancode) |
||
220 | { |
||
221 | switch (scancode) { |
||
222 | case 0x31: ds = ds_e2a; break; |
||
223 | case 0x32: ds = ds_e2b; break; |
||
224 | default: ds = ds_start; break; |
||
225 | } |
||
226 | |||
227 | parse_leaf(scancode, map_e2, sizeof(map_e2) / sizeof(int)); |
||
228 | } |
||
229 | |||
230 | static void parse_ds_e2a(int scancode) |
||
231 | { |
||
232 | parse_leaf(scancode, map_e2a, sizeof(map_e2a) / sizeof(int)); |
||
233 | } |
||
234 | |||
235 | static void parse_ds_e2b(int scancode) |
||
236 | { |
||
237 | parse_leaf(scancode, map_e2b, sizeof(map_e2b) / sizeof(int)); |
||
238 | } |
||
239 | |||
240 | static void parse_leaf(int scancode, int *map, size_t map_length) |
||
241 | { |
||
242 | unsigned int key; |
||
243 | |||
244 | ds = ds_start; |
||
245 | |||
246 | if (scancode < 0 || scancode >= map_length) |
||
247 | return; |
||
248 | |||
249 | key = map[scancode]; |
||
250 | if (key != 0) |
||
251 | kbd_push_ev(KE_PRESS, key, 0); |
||
252 | } |
||
253 | |||
254 | |||
255 | /** |
||
256 | * @} |
||
257 | */ |