source: mainline/uspace/srv/hid/kbd/ctl/pc.c@ 827d73f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 827d73f was b3d513f, checked in by Martin Decky <martin@…>, 16 years ago

restructure servers into a more well-arranged hierarchy

  • Property mode set to 100644
File size: 4.9 KB
Line 
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_ctl
30 * @ingroup kbd
31 * @{
32 */
33/**
34 * @file
35 * @brief PC keyboard controller driver.
36 */
37
38#include <kbd.h>
39#include <io/console.h>
40#include <io/keycode.h>
41#include <kbd_ctl.h>
42#include <kbd_port.h>
43#include <gsp.h>
44
45enum dec_state {
46 ds_s,
47 ds_e
48};
49
50enum special_code {
51 SC_ACK = 0xfa,
52 SC_NAK = 0xfe
53};
54
55enum lock_ind_bits {
56 LI_SCROLL = 0x01,
57 LI_NUM = 0x02,
58 LI_CAPS = 0x04
59};
60
61enum kbd_command {
62 KBD_CMD_SET_LEDS = 0xed
63};
64
65static enum dec_state ds;
66
67static int scanmap_simple[] = {
68
69 [0x29] = KC_BACKTICK,
70
71 [0x02] = KC_1,
72 [0x03] = KC_2,
73 [0x04] = KC_3,
74 [0x05] = KC_4,
75 [0x06] = KC_5,
76 [0x07] = KC_6,
77 [0x08] = KC_7,
78 [0x09] = KC_8,
79 [0x0a] = KC_9,
80 [0x0b] = KC_0,
81
82 [0x0c] = KC_MINUS,
83 [0x0d] = KC_EQUALS,
84 [0x0e] = KC_BACKSPACE,
85
86 [0x0f] = KC_TAB,
87
88 [0x10] = KC_Q,
89 [0x11] = KC_W,
90 [0x12] = KC_E,
91 [0x13] = KC_R,
92 [0x14] = KC_T,
93 [0x15] = KC_Y,
94 [0x16] = KC_U,
95 [0x17] = KC_I,
96 [0x18] = KC_O,
97 [0x19] = KC_P,
98
99 [0x1a] = KC_LBRACKET,
100 [0x1b] = KC_RBRACKET,
101
102 [0x3a] = KC_CAPS_LOCK,
103
104 [0x1e] = KC_A,
105 [0x1f] = KC_S,
106 [0x20] = KC_D,
107 [0x21] = KC_F,
108 [0x22] = KC_G,
109 [0x23] = KC_H,
110 [0x24] = KC_J,
111 [0x25] = KC_K,
112 [0x26] = KC_L,
113
114 [0x27] = KC_SEMICOLON,
115 [0x28] = KC_QUOTE,
116 [0x2b] = KC_BACKSLASH,
117
118 [0x2a] = KC_LSHIFT,
119
120 [0x2c] = KC_Z,
121 [0x2d] = KC_X,
122 [0x2e] = KC_C,
123 [0x2f] = KC_V,
124 [0x30] = KC_B,
125 [0x31] = KC_N,
126 [0x32] = KC_M,
127
128 [0x33] = KC_COMMA,
129 [0x34] = KC_PERIOD,
130 [0x35] = KC_SLASH,
131
132 [0x36] = KC_RSHIFT,
133
134 [0x1d] = KC_LCTRL,
135 [0x38] = KC_LALT,
136 [0x39] = KC_SPACE,
137
138 [0x01] = KC_ESCAPE,
139
140 [0x3b] = KC_F1,
141 [0x3c] = KC_F2,
142 [0x3d] = KC_F3,
143 [0x3e] = KC_F4,
144 [0x3f] = KC_F5,
145 [0x40] = KC_F6,
146 [0x41] = KC_F7,
147
148 [0x42] = KC_F8,
149 [0x43] = KC_F9,
150 [0x44] = KC_F10,
151
152 [0x57] = KC_F11,
153 [0x58] = KC_F12,
154
155 [0x46] = KC_SCROLL_LOCK,
156
157 [0x1c] = KC_ENTER,
158
159 [0x45] = KC_NUM_LOCK,
160 [0x37] = KC_NTIMES,
161 [0x4a] = KC_NMINUS,
162 [0x4e] = KC_NPLUS,
163 [0x47] = KC_N7,
164 [0x48] = KC_N8,
165 [0x49] = KC_N9,
166 [0x4b] = KC_N4,
167 [0x4c] = KC_N5,
168 [0x4d] = KC_N6,
169 [0x4f] = KC_N1,
170 [0x50] = KC_N2,
171 [0x51] = KC_N3,
172 [0x52] = KC_N0,
173 [0x53] = KC_NPERIOD
174};
175
176static int scanmap_e0[] = {
177 [0x38] = KC_RALT,
178 [0x1d] = KC_RSHIFT,
179
180 [0x37] = KC_PRTSCR,
181
182 [0x52] = KC_INSERT,
183 [0x47] = KC_HOME,
184 [0x49] = KC_PAGE_UP,
185
186 [0x53] = KC_DELETE,
187 [0x4f] = KC_END,
188 [0x51] = KC_PAGE_DOWN,
189
190 [0x48] = KC_UP,
191 [0x4b] = KC_LEFT,
192 [0x50] = KC_DOWN,
193 [0x4d] = KC_RIGHT,
194
195 [0x35] = KC_NSLASH,
196 [0x1c] = KC_NENTER
197};
198
199int kbd_ctl_init(void)
200{
201 ds = ds_s;
202 return 0;
203}
204
205void kbd_ctl_parse_scancode(int scancode)
206{
207 console_ev_type_t type;
208 unsigned int key;
209 int *map;
210 size_t map_length;
211
212 /*
213 * ACK/NAK are returned as response to us sending a command.
214 * We are not interested in them.
215 */
216 if (scancode == SC_ACK || scancode == SC_NAK)
217 return;
218
219 if (scancode == 0xe0) {
220 ds = ds_e;
221 return;
222 }
223
224 switch (ds) {
225 case ds_s:
226 map = scanmap_simple;
227 map_length = sizeof(scanmap_simple) / sizeof(int);
228 break;
229 case ds_e:
230 map = scanmap_e0;
231 map_length = sizeof(scanmap_e0) / sizeof(int);
232 break;
233 default:
234 map = NULL;
235 map_length = 0;
236 }
237
238 ds = ds_s;
239
240 if (scancode & 0x80) {
241 scancode &= ~0x80;
242 type = KEY_RELEASE;
243 } else {
244 type = KEY_PRESS;
245 }
246
247 if ((scancode < 0) || ((size_t) scancode >= map_length))
248 return;
249
250 key = map[scancode];
251 if (key != 0)
252 kbd_push_ev(type, key);
253}
254
255void kbd_ctl_set_ind(unsigned mods)
256{
257 uint8_t b;
258
259 b = 0;
260 if ((mods & KM_CAPS_LOCK) != 0)
261 b = b | LI_CAPS;
262 if ((mods & KM_NUM_LOCK) != 0)
263 b = b | LI_NUM;
264 if ((mods & KM_SCROLL_LOCK) != 0)
265 b = b | LI_SCROLL;
266
267 kbd_port_write(KBD_CMD_SET_LEDS);
268 kbd_port_write(b);
269}
270
271/**
272 * @}
273 */
Note: See TracBrowser for help on using the repository browser.