1 | /*
|
---|
2 | * Copyright (c) 2011 Lubos Slovak
|
---|
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 | #include <io/keycode.h>
|
---|
29 | #include <stdint.h>
|
---|
30 | #include "conv.h"
|
---|
31 |
|
---|
32 | static int scanmap_simple[] = {
|
---|
33 |
|
---|
34 | [0x29] = KC_BACKTICK,
|
---|
35 |
|
---|
36 | [0x02] = KC_1,
|
---|
37 | [0x03] = KC_2,
|
---|
38 | [0x04] = KC_3,
|
---|
39 | [0x05] = KC_4,
|
---|
40 | [0x06] = KC_5,
|
---|
41 | [0x07] = KC_6,
|
---|
42 | // [0x08] = KC_7,
|
---|
43 | [0x09] = KC_8,
|
---|
44 | [0x0a] = KC_9,
|
---|
45 | // [0x0b] = KC_0,
|
---|
46 |
|
---|
47 | [0x0c] = KC_MINUS,
|
---|
48 | [0x0d] = KC_EQUALS,
|
---|
49 | [0x0e] = KC_BACKSPACE,
|
---|
50 |
|
---|
51 | // [0x0f] = KC_TAB,
|
---|
52 |
|
---|
53 | [0x10] = KC_Q,
|
---|
54 | [0x11] = KC_W,
|
---|
55 | [0x08] = KC_E, // OK
|
---|
56 | [0x13] = KC_R,
|
---|
57 | [0x14] = KC_T,
|
---|
58 | [0x15] = KC_Y,
|
---|
59 | [0x16] = KC_U,
|
---|
60 | [0x17] = KC_I,
|
---|
61 | [0x12] = KC_O, // OK
|
---|
62 | [0x19] = KC_P,
|
---|
63 |
|
---|
64 | [0x1a] = KC_LBRACKET,
|
---|
65 | [0x1b] = KC_RBRACKET,
|
---|
66 |
|
---|
67 | [0x3a] = KC_CAPS_LOCK,
|
---|
68 |
|
---|
69 | [0x1e] = KC_A,
|
---|
70 | [0x1f] = KC_S,
|
---|
71 | [0x20] = KC_D,
|
---|
72 | [0x21] = KC_F,
|
---|
73 | [0x22] = KC_G,
|
---|
74 | [0x0B] = KC_H, // OK
|
---|
75 | [0x24] = KC_J,
|
---|
76 | [0x25] = KC_K,
|
---|
77 | [0x0F] = KC_L, // OK
|
---|
78 |
|
---|
79 | [0x27] = KC_SEMICOLON,
|
---|
80 | [0x28] = KC_QUOTE,
|
---|
81 | [0x2b] = KC_BACKSLASH,
|
---|
82 |
|
---|
83 | [0x2a] = KC_LSHIFT,
|
---|
84 |
|
---|
85 | [0x2c] = KC_Z,
|
---|
86 | [0x2d] = KC_X,
|
---|
87 | [0x2e] = KC_C,
|
---|
88 | [0x2f] = KC_V,
|
---|
89 | [0x30] = KC_B,
|
---|
90 | [0x31] = KC_N,
|
---|
91 | [0x32] = KC_M,
|
---|
92 |
|
---|
93 | [0x33] = KC_COMMA,
|
---|
94 | [0x34] = KC_PERIOD,
|
---|
95 | [0x35] = KC_SLASH,
|
---|
96 |
|
---|
97 | [0x36] = KC_RSHIFT,
|
---|
98 |
|
---|
99 | [0x1d] = KC_LCTRL,
|
---|
100 | [0x38] = KC_LALT,
|
---|
101 | [0x39] = KC_SPACE,
|
---|
102 |
|
---|
103 | [0x01] = KC_ESCAPE,
|
---|
104 |
|
---|
105 | [0x3b] = KC_F1,
|
---|
106 | [0x3c] = KC_F2,
|
---|
107 | [0x3d] = KC_F3,
|
---|
108 | [0x3e] = KC_F4,
|
---|
109 | [0x3f] = KC_F5,
|
---|
110 | [0x40] = KC_F6,
|
---|
111 | [0x41] = KC_F7,
|
---|
112 |
|
---|
113 | [0x42] = KC_F8,
|
---|
114 | [0x43] = KC_F9,
|
---|
115 | [0x44] = KC_F10,
|
---|
116 |
|
---|
117 | [0x57] = KC_F11,
|
---|
118 | [0x58] = KC_F12,
|
---|
119 |
|
---|
120 | [0x46] = KC_SCROLL_LOCK,
|
---|
121 |
|
---|
122 | [0x1c] = KC_ENTER,
|
---|
123 |
|
---|
124 | [0x45] = KC_NUM_LOCK,
|
---|
125 | [0x37] = KC_NTIMES,
|
---|
126 | [0x4a] = KC_NMINUS,
|
---|
127 | [0x4e] = KC_NPLUS,
|
---|
128 | [0x47] = KC_N7,
|
---|
129 | [0x48] = KC_N8,
|
---|
130 | [0x49] = KC_N9,
|
---|
131 | [0x4b] = KC_N4,
|
---|
132 | [0x4c] = KC_N5,
|
---|
133 | [0x4d] = KC_N6,
|
---|
134 | [0x4f] = KC_N1,
|
---|
135 | [0x50] = KC_N2,
|
---|
136 | [0x51] = KC_N3,
|
---|
137 | [0x52] = KC_N0,
|
---|
138 | [0x53] = KC_NPERIOD
|
---|
139 | };
|
---|
140 |
|
---|
141 | unsigned int usbkbd_parse_scancode(int scancode)
|
---|
142 | {
|
---|
143 | // console_ev_type_t type;
|
---|
144 | unsigned int key;
|
---|
145 | int *map = scanmap_simple;
|
---|
146 | size_t map_length = sizeof(scanmap_simple) / sizeof(int);
|
---|
147 |
|
---|
148 | /*
|
---|
149 | * ACK/NAK are returned as response to us sending a command.
|
---|
150 | * We are not interested in them.
|
---|
151 | */
|
---|
152 | // if (scancode == SC_ACK || scancode == SC_NAK)
|
---|
153 | // return;
|
---|
154 |
|
---|
155 | // if (scancode == 0xe0) {
|
---|
156 | // ds = ds_e;
|
---|
157 | // return;
|
---|
158 | // }
|
---|
159 |
|
---|
160 | // switch (ds) {
|
---|
161 | // case ds_s:
|
---|
162 | // map = scanmap_simple;
|
---|
163 | // map_length = sizeof(scanmap_simple) / sizeof(int);
|
---|
164 | // break;
|
---|
165 | // case ds_e:
|
---|
166 | // map = scanmap_e0;
|
---|
167 | // map_length = sizeof(scanmap_e0) / sizeof(int);
|
---|
168 | // break;
|
---|
169 | // default:
|
---|
170 | // map = NULL;
|
---|
171 | // map_length = 0;
|
---|
172 | // }
|
---|
173 |
|
---|
174 | // ds = ds_s;
|
---|
175 |
|
---|
176 | // if (scancode & 0x80) {
|
---|
177 | // scancode &= ~0x80;
|
---|
178 | // type = KEY_RELEASE;
|
---|
179 | // } else {
|
---|
180 | // type = KEY_PRESS;
|
---|
181 | // }
|
---|
182 |
|
---|
183 | if ((scancode < 0) || ((size_t) scancode >= map_length))
|
---|
184 | return -1;
|
---|
185 |
|
---|
186 | key = map[scancode];
|
---|
187 | // if (key != 0)
|
---|
188 | // kbd_push_ev(type, key);
|
---|
189 | return key;
|
---|
190 | } |
---|