[f89979b] | 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 |
|
---|
[24ff4df] | 29 | /** @addtogroup kbd_ctl
|
---|
| 30 | * @ingroup kbd
|
---|
[f89979b] | 31 | * @{
|
---|
[24ff4df] | 32 | */
|
---|
| 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | * @brief GXEmul framebuffer-mode keyboard controller driver.
|
---|
| 36 | */
|
---|
[f89979b] | 37 |
|
---|
| 38 | #include <kbd.h>
|
---|
| 39 | #include <kbd/kbd.h>
|
---|
| 40 | #include <kbd/keycode.h>
|
---|
| 41 | #include <kbd_ctl.h>
|
---|
| 42 |
|
---|
| 43 | static void parse_ds_start(int scancode);
|
---|
| 44 | static void parse_ds_e(int scancode);
|
---|
| 45 | static void parse_ds_e1(int scancode);
|
---|
| 46 | static void parse_ds_e1a(int scancode);
|
---|
| 47 | static void parse_ds_e1b(int scancode);
|
---|
| 48 | static void parse_ds_e1c(int scancode);
|
---|
| 49 |
|
---|
[5ad8661] | 50 | static void parse_leaf(int scancode, int (*map)[2], size_t map_length);
|
---|
[f89979b] | 51 |
|
---|
| 52 | enum dec_state {
|
---|
| 53 | ds_start,
|
---|
| 54 | ds_e,
|
---|
| 55 | ds_e1,
|
---|
| 56 | ds_e1a,
|
---|
| 57 | ds_e1b,
|
---|
| 58 | ds_e1c
|
---|
| 59 | };
|
---|
| 60 |
|
---|
[5ad8661] | 61 | static int map_start[][2] = {
|
---|
| 62 |
|
---|
| 63 | [0x60] = { 0, KC_BACKTICK },
|
---|
| 64 |
|
---|
| 65 | [0x31] = { 0, KC_1 },
|
---|
| 66 | [0x32] = { 0, KC_2 },
|
---|
| 67 | [0x33] = { 0, KC_3 },
|
---|
| 68 | [0x34] = { 0, KC_4 },
|
---|
| 69 | [0x35] = { 0, KC_5 },
|
---|
| 70 | [0x36] = { 0, KC_6 },
|
---|
| 71 | [0x37] = { 0, KC_7 },
|
---|
| 72 | [0x38] = { 0, KC_8 },
|
---|
| 73 | [0x39] = { 0, KC_9 },
|
---|
| 74 | [0x30] = { 0, KC_0 },
|
---|
| 75 |
|
---|
| 76 | [0x2d] = { 0, KC_MINUS },
|
---|
| 77 | [0x3d] = { 0, KC_EQUALS },
|
---|
| 78 | [0x08] = { 0, KC_BACKSPACE },
|
---|
| 79 |
|
---|
| 80 | [0x0f] = { 0, KC_TAB },
|
---|
| 81 |
|
---|
| 82 | [0x71] = { 0, KC_Q },
|
---|
| 83 | [0x77] = { 0, KC_W },
|
---|
| 84 | [0x65] = { 0, KC_E },
|
---|
| 85 | [0x72] = { 0, KC_R },
|
---|
| 86 | [0x74] = { 0, KC_T },
|
---|
| 87 | [0x79] = { 0, KC_Y },
|
---|
| 88 | [0x75] = { 0, KC_U },
|
---|
| 89 | [0x69] = { 0, KC_I },
|
---|
| 90 | [0x6f] = { 0, KC_O },
|
---|
| 91 | [0x70] = { 0, KC_P },
|
---|
| 92 |
|
---|
| 93 | [0x5b] = { 0, KC_LBRACKET },
|
---|
| 94 | [0x5d] = { 0, KC_RBRACKET },
|
---|
| 95 |
|
---|
| 96 | [0x61] = { 0, KC_A },
|
---|
| 97 | [0x73] = { 0, KC_S },
|
---|
| 98 | [0x64] = { 0, KC_D },
|
---|
| 99 | [0x66] = { 0, KC_F },
|
---|
| 100 | [0x67] = { 0, KC_G },
|
---|
| 101 | [0x68] = { 0, KC_H },
|
---|
| 102 | [0x6a] = { 0, KC_J },
|
---|
| 103 | [0x6b] = { 0, KC_K },
|
---|
| 104 | [0x6c] = { 0, KC_L },
|
---|
| 105 |
|
---|
| 106 | [0x3b] = { 0, KC_SEMICOLON },
|
---|
| 107 | [0x27] = { 0, KC_QUOTE },
|
---|
| 108 | [0x5c] = { 0, KC_BACKSLASH },
|
---|
| 109 |
|
---|
| 110 | [0x7a] = { 0, KC_Z },
|
---|
| 111 | [0x78] = { 0, KC_X },
|
---|
| 112 | [0x63] = { 0, KC_C },
|
---|
| 113 | [0x76] = { 0, KC_V },
|
---|
| 114 | [0x62] = { 0, KC_B },
|
---|
| 115 | [0x6e] = { 0, KC_N },
|
---|
| 116 | [0x6d] = { 0, KC_M },
|
---|
| 117 |
|
---|
| 118 | [0x2c] = { 0, KC_COMMA },
|
---|
| 119 | [0x2e] = { 0, KC_PERIOD },
|
---|
| 120 | [0x2f] = { 0, KC_SLASH },
|
---|
| 121 |
|
---|
| 122 | [0x20] = { 0, KC_SPACE },
|
---|
| 123 |
|
---|
| 124 | [0x1b] = { 0, KC_ESCAPE },
|
---|
| 125 |
|
---|
| 126 | [0x0a] = { 0, KC_ENTER },
|
---|
| 127 | [0x0d] = { 0, KC_ENTER },
|
---|
| 128 |
|
---|
| 129 | /* with Shift pressed */
|
---|
| 130 |
|
---|
| 131 | [0x7e] = { KM_LSHIFT, KC_BACKTICK },
|
---|
| 132 |
|
---|
| 133 | [0x21] = { KM_LSHIFT, KC_1 },
|
---|
| 134 | [0x40] = { KM_LSHIFT, KC_2 },
|
---|
| 135 | [0x23] = { KM_LSHIFT, KC_3 },
|
---|
| 136 | [0x24] = { KM_LSHIFT, KC_4 },
|
---|
| 137 | [0x25] = { KM_LSHIFT, KC_5 },
|
---|
| 138 | [0x5e] = { KM_LSHIFT, KC_6 },
|
---|
| 139 | [0x26] = { KM_LSHIFT, KC_7 },
|
---|
| 140 | [0x2a] = { KM_LSHIFT, KC_8 },
|
---|
| 141 | [0x28] = { KM_LSHIFT, KC_9 },
|
---|
| 142 | [0x29] = { KM_LSHIFT, KC_0 },
|
---|
| 143 |
|
---|
| 144 | [0x5f] = { KM_LSHIFT, KC_MINUS },
|
---|
| 145 | [0x2b] = { KM_LSHIFT, KC_EQUALS },
|
---|
| 146 |
|
---|
| 147 | [0x51] = { KM_LSHIFT, KC_Q },
|
---|
| 148 | [0x57] = { KM_LSHIFT, KC_W },
|
---|
| 149 | [0x45] = { KM_LSHIFT, KC_E },
|
---|
| 150 | [0x52] = { KM_LSHIFT, KC_R },
|
---|
| 151 | [0x54] = { KM_LSHIFT, KC_T },
|
---|
| 152 | [0x59] = { KM_LSHIFT, KC_Y },
|
---|
| 153 | [0x55] = { KM_LSHIFT, KC_U },
|
---|
| 154 | [0x49] = { KM_LSHIFT, KC_I },
|
---|
| 155 | [0x4f] = { KM_LSHIFT, KC_O },
|
---|
| 156 | [0x50] = { KM_LSHIFT, KC_P },
|
---|
| 157 |
|
---|
| 158 | [0x7b] = { KM_LSHIFT, KC_LBRACKET },
|
---|
| 159 | [0x7d] = { KM_LSHIFT, KC_RBRACKET },
|
---|
| 160 |
|
---|
| 161 | [0x41] = { KM_LSHIFT, KC_A },
|
---|
| 162 | [0x53] = { KM_LSHIFT, KC_S },
|
---|
| 163 | [0x44] = { KM_LSHIFT, KC_D },
|
---|
| 164 | [0x46] = { KM_LSHIFT, KC_F },
|
---|
| 165 | [0x47] = { KM_LSHIFT, KC_G },
|
---|
| 166 | [0x48] = { KM_LSHIFT, KC_H },
|
---|
| 167 | [0x4a] = { KM_LSHIFT, KC_J },
|
---|
| 168 | [0x4b] = { KM_LSHIFT, KC_K },
|
---|
| 169 | [0x4c] = { KM_LSHIFT, KC_L },
|
---|
| 170 |
|
---|
| 171 | [0x3a] = { KM_LSHIFT, KC_SEMICOLON },
|
---|
| 172 | [0x22] = { KM_LSHIFT, KC_QUOTE },
|
---|
| 173 | [0x7c] = { KM_LSHIFT, KC_BACKSLASH },
|
---|
| 174 |
|
---|
| 175 | [0x5a] = { KM_LSHIFT, KC_Z },
|
---|
| 176 | [0x58] = { KM_LSHIFT, KC_X },
|
---|
| 177 | [0x43] = { KM_LSHIFT, KC_C },
|
---|
| 178 | [0x56] = { KM_LSHIFT, KC_V },
|
---|
| 179 | [0x42] = { KM_LSHIFT, KC_B },
|
---|
| 180 | [0x4e] = { KM_LSHIFT, KC_N },
|
---|
| 181 | [0x4d] = { KM_LSHIFT, KC_M },
|
---|
| 182 |
|
---|
| 183 | [0x3c] = { KM_LSHIFT, KC_COMMA },
|
---|
| 184 | [0x3e] = { KM_LSHIFT, KC_PERIOD },
|
---|
| 185 | [0x3f] = { KM_LSHIFT, KC_SLASH }
|
---|
[f89979b] | 186 | };
|
---|
| 187 |
|
---|
[5ad8661] | 188 | static int map_e1[][2] =
|
---|
[f89979b] | 189 | {
|
---|
| 190 | };
|
---|
| 191 |
|
---|
[5ad8661] | 192 | static int map_e1a[][2] =
|
---|
[f89979b] | 193 | {
|
---|
[5ad8661] | 194 | [0x50] = { 0, KC_F1 },
|
---|
| 195 | [0x51] = { 0, KC_F2 },
|
---|
| 196 | [0x52] = { 0, KC_F3 },
|
---|
| 197 | [0x53] = { 0, KC_F4 },
|
---|
[f89979b] | 198 | };
|
---|
| 199 |
|
---|
[5ad8661] | 200 | static int map_e1b[][2] =
|
---|
[f89979b] | 201 | {
|
---|
[5ad8661] | 202 | [0x33] = { 0, KC_F5 },
|
---|
| 203 | [0x37] = { 0, KC_F6 },
|
---|
| 204 | [0x38] = { 0, KC_F7 },
|
---|
| 205 | [0x39] = { 0, KC_F8 },
|
---|
[f89979b] | 206 | };
|
---|
| 207 |
|
---|
[5ad8661] | 208 | static int map_e1c[][2] =
|
---|
[f89979b] | 209 | {
|
---|
[5ad8661] | 210 | [0x38] = { 0, KC_F9 },
|
---|
| 211 | [0x39] = { 0, KC_F10 },
|
---|
| 212 | [0x33] = { 0, KC_F11 },
|
---|
| 213 | [0x34] = { 0, KC_F12 },
|
---|
[f89979b] | 214 | };
|
---|
| 215 |
|
---|
[5ad8661] | 216 | static unsigned int mods_keys[][2] = {
|
---|
| 217 | { KM_LSHIFT, KC_LSHIFT },
|
---|
| 218 | { 0, 0 }
|
---|
| 219 | };
|
---|
[f89979b] | 220 |
|
---|
| 221 | static enum dec_state ds = ds_start;
|
---|
| 222 |
|
---|
| 223 | void kbd_ctl_parse_scancode(int scancode)
|
---|
| 224 | {
|
---|
| 225 | switch (ds) {
|
---|
| 226 | case ds_start: parse_ds_start(scancode); break;
|
---|
| 227 | case ds_e: parse_ds_e(scancode); break;
|
---|
| 228 | case ds_e1: parse_ds_e1(scancode); break;
|
---|
| 229 | case ds_e1a: parse_ds_e1a(scancode); break;
|
---|
| 230 | case ds_e1b: parse_ds_e1b(scancode); break;
|
---|
| 231 | case ds_e1c: parse_ds_e1c(scancode); break;
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | static void parse_ds_start(int scancode)
|
---|
| 236 | {
|
---|
| 237 | if (scancode == 0x1b) {
|
---|
| 238 | ds = ds_e;
|
---|
| 239 | return;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[5ad8661] | 242 | parse_leaf(scancode, map_start, sizeof(map_start) / (2 * sizeof(int)));
|
---|
[f89979b] | 243 | }
|
---|
| 244 |
|
---|
| 245 | static void parse_ds_e(int scancode)
|
---|
| 246 | {
|
---|
| 247 | switch (scancode) {
|
---|
| 248 | case 0x5b: ds = ds_e1; return;
|
---|
| 249 | case 0x1b: ds = ds_start; break;
|
---|
| 250 | default: ds = ds_start; return;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[d1eece6] | 253 | kbd_push_ev(KE_PRESS, KC_ESCAPE);
|
---|
[f89979b] | 254 | }
|
---|
| 255 |
|
---|
| 256 | static void parse_ds_e1(int scancode)
|
---|
| 257 | {
|
---|
| 258 | switch (scancode) {
|
---|
| 259 | case 0x4f: ds = ds_e1a; return;
|
---|
| 260 | case 0x31: ds = ds_e1b; return;
|
---|
| 261 | case 0x32: ds = ds_e1c; return;
|
---|
| 262 | default: ds = ds_start; break;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[5ad8661] | 265 | parse_leaf(scancode, map_e1, sizeof(map_e1) / (2 * sizeof(int)));
|
---|
[f89979b] | 266 | }
|
---|
| 267 |
|
---|
| 268 | static void parse_ds_e1a(int scancode)
|
---|
| 269 | {
|
---|
[5ad8661] | 270 | parse_leaf(scancode, map_e1a, sizeof(map_e1a) / (2 * sizeof(int)));
|
---|
[f89979b] | 271 | }
|
---|
| 272 |
|
---|
| 273 | static void parse_ds_e1b(int scancode)
|
---|
| 274 | {
|
---|
[5ad8661] | 275 | parse_leaf(scancode, map_e1b, sizeof(map_e1b) / (2 * sizeof(int)));
|
---|
[f89979b] | 276 | }
|
---|
| 277 |
|
---|
| 278 | static void parse_ds_e1c(int scancode)
|
---|
| 279 | {
|
---|
[5ad8661] | 280 | parse_leaf(scancode, map_e1c, sizeof(map_e1c) / (2 * sizeof(int)));
|
---|
[f89979b] | 281 | }
|
---|
| 282 |
|
---|
[5ad8661] | 283 | static void parse_leaf(int scancode, int (*map)[2], size_t map_length)
|
---|
[f89979b] | 284 | {
|
---|
[5ad8661] | 285 | unsigned int key, mod;
|
---|
| 286 | int i;
|
---|
[f89979b] | 287 |
|
---|
| 288 | ds = ds_start;
|
---|
| 289 |
|
---|
| 290 | if (scancode < 0 || scancode >= map_length)
|
---|
| 291 | return;
|
---|
| 292 |
|
---|
[5ad8661] | 293 | mod = map[scancode][0];
|
---|
| 294 | key = map[scancode][1];
|
---|
| 295 |
|
---|
| 296 | /* Simulate modifier pressing. */
|
---|
| 297 | i = 0;
|
---|
| 298 | while (mods_keys[i][0] != 0) {
|
---|
| 299 | if (mod & mods_keys[i][0]) {
|
---|
| 300 | kbd_push_ev(KE_PRESS, mods_keys[i][1]);
|
---|
| 301 | }
|
---|
| 302 | ++i;
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | if (key != 0) {
|
---|
[5c06c1c] | 306 | kbd_push_ev(KE_PRESS, key);
|
---|
[5ad8661] | 307 | kbd_push_ev(KE_RELEASE, key);
|
---|
| 308 | }
|
---|
[f89979b] | 309 |
|
---|
[5ad8661] | 310 | /* Simulate modifier releasing. */
|
---|
| 311 | i = 0;
|
---|
| 312 | while (mods_keys[i][0] != 0) {
|
---|
| 313 | if (mod & mods_keys[i][0]) {
|
---|
| 314 | kbd_push_ev(KE_RELEASE, mods_keys[i][1]);
|
---|
| 315 | }
|
---|
| 316 | ++i;
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
[f89979b] | 319 |
|
---|
| 320 | /**
|
---|
| 321 | * @}
|
---|
| 322 | */
|
---|