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