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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b1bdc7a4 was b1bdc7a4, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Control keyboard port modules through ops structures. Allows compiling in
all modules at the same time.

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