[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 | */
|
---|
[1c13dac] | 28 |
|
---|
| 29 | /** @addtogroup drvusbhid
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * USB scancode parser.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[e2b1548] | 36 | #include <io/keycode.h>
|
---|
| 37 | #include <stdint.h>
|
---|
[d972534] | 38 | #include <stdio.h>
|
---|
| 39 | #include <usb/debug.h>
|
---|
[e2b1548] | 40 | #include "conv.h"
|
---|
| 41 |
|
---|
[11797d5] | 42 | static int scanmap_simple[255] = {
|
---|
[e2b1548] | 43 |
|
---|
[7d540c8] | 44 | // [0x29] = KC_BACKTICK,
|
---|
| 45 |
|
---|
| 46 | // [0x02] = KC_1,
|
---|
| 47 | // [0x03] = KC_2,
|
---|
| 48 | [0x04] = KC_A,
|
---|
| 49 | [0x05] = KC_B,
|
---|
| 50 | [0x06] = KC_C,
|
---|
| 51 | [0x07] = KC_D,
|
---|
| 52 | [0x08] = KC_E,
|
---|
| 53 | [0x09] = KC_F,
|
---|
| 54 | [0x0a] = KC_G,
|
---|
| 55 | [0x0b] = KC_H,
|
---|
| 56 | [0x0c] = KC_I,
|
---|
| 57 | [0x0d] = KC_J,
|
---|
| 58 | [0x0e] = KC_K,
|
---|
| 59 | [0x0f] = KC_L,
|
---|
| 60 | [0x10] = KC_M,
|
---|
| 61 | [0x11] = KC_N,
|
---|
| 62 | [0x12] = KC_O,
|
---|
| 63 | [0x13] = KC_P,
|
---|
| 64 | [0x14] = KC_Q,
|
---|
| 65 | [0x15] = KC_R,
|
---|
| 66 | [0x16] = KC_S,
|
---|
| 67 | [0x17] = KC_T,
|
---|
[11797d5] | 68 | [0x18] = KC_U,
|
---|
[7d540c8] | 69 | [0x19] = KC_V,
|
---|
| 70 | [0x1a] = KC_W,
|
---|
| 71 | [0x1b] = KC_X,
|
---|
| 72 | [0x1c] = KC_Y,
|
---|
| 73 | [0x1d] = KC_Z,
|
---|
| 74 |
|
---|
| 75 | [0x1e] = KC_1,
|
---|
| 76 | [0x1f] = KC_2,
|
---|
| 77 | [0x20] = KC_3,
|
---|
| 78 | [0x21] = KC_4,
|
---|
| 79 | [0x22] = KC_5,
|
---|
| 80 | [0x23] = KC_6,
|
---|
| 81 | [0x24] = KC_7,
|
---|
| 82 | [0x25] = KC_8,
|
---|
| 83 | [0x26] = KC_9,
|
---|
| 84 | [0x27] = KC_0,
|
---|
| 85 |
|
---|
| 86 | [0x28] = KC_ENTER,
|
---|
| 87 | [0x29] = KC_ESCAPE,
|
---|
| 88 | [0x2a] = KC_BACKSPACE,
|
---|
| 89 | [0x2b] = KC_TAB,
|
---|
| 90 | [0x2c] = KC_SPACE,
|
---|
| 91 |
|
---|
| 92 | [0x2d] = KC_MINUS, // same as DASH? (- or _)
|
---|
| 93 | [0x2e] = KC_EQUALS,
|
---|
| 94 | [0x2f] = KC_LBRACKET,
|
---|
| 95 | [0x30] = KC_RBRACKET,
|
---|
| 96 | [0x31] = KC_BACKSLASH,
|
---|
| 97 | //[0x32] = KC_, // TODO: HASH??? maybe some as 0x31 - backslash
|
---|
| 98 | [0x33] = KC_SEMICOLON,
|
---|
| 99 | [0x34] = KC_QUOTE, // same as APOSTROPHE? (')
|
---|
| 100 | [0x35] = KC_BACKTICK, // same as GRAVE ACCENT?? (`)
|
---|
| 101 | [0x36] = KC_COMMA,
|
---|
| 102 | [0x37] = KC_PERIOD,
|
---|
| 103 | [0x38] = KC_SLASH,
|
---|
| 104 |
|
---|
| 105 | [0x39] = KC_CAPS_LOCK,
|
---|
| 106 |
|
---|
| 107 | [0x3a] = KC_F1,
|
---|
| 108 | [0x3b] = KC_F2,
|
---|
| 109 | [0x3c] = KC_F3,
|
---|
| 110 | [0x3d] = KC_F4,
|
---|
| 111 | [0x3e] = KC_F5,
|
---|
| 112 | [0x3f] = KC_F6,
|
---|
| 113 | [0x40] = KC_F7,
|
---|
| 114 | [0x41] = KC_F8,
|
---|
| 115 | [0x42] = KC_F9,
|
---|
| 116 | [0x43] = KC_F10,
|
---|
| 117 | [0x44] = KC_F11,
|
---|
| 118 | [0x45] = KC_F12,
|
---|
| 119 |
|
---|
| 120 | [0x46] = KC_PRTSCR,
|
---|
| 121 | [0x47] = KC_SCROLL_LOCK,
|
---|
| 122 | [0x48] = KC_PAUSE,
|
---|
| 123 | [0x49] = KC_INSERT,
|
---|
| 124 | [0x4a] = KC_HOME,
|
---|
| 125 | [0x4b] = KC_PAGE_UP,
|
---|
| 126 | [0x4c] = KC_DELETE,
|
---|
| 127 | [0x4d] = KC_END,
|
---|
| 128 | [0x4e] = KC_PAGE_DOWN,
|
---|
| 129 | [0x4f] = KC_RIGHT,
|
---|
| 130 | [0x50] = KC_LEFT,
|
---|
| 131 | [0x51] = KC_DOWN,
|
---|
| 132 | [0x52] = KC_UP,
|
---|
| 133 |
|
---|
| 134 | //[0x64] = // some funny key
|
---|
| 135 |
|
---|
| 136 | [0xe0] = KC_LCTRL,
|
---|
| 137 | [0xe1] = KC_LSHIFT,
|
---|
| 138 | [0xe2] = KC_LALT,
|
---|
| 139 | //[0xe3] = KC_L // TODO: left GUI
|
---|
| 140 | [0xe4] = KC_RCTRL,
|
---|
| 141 | [0xe5] = KC_RSHIFT,
|
---|
| 142 | [0xe6] = KC_RALT,
|
---|
| 143 | //[0xe7] = KC_R // TODO: right GUI
|
---|
| 144 |
|
---|
[f2ba5d9f] | 145 | [0x53] = KC_NUM_LOCK,
|
---|
| 146 | [0x54] = KC_NSLASH,
|
---|
| 147 | [0x55] = KC_NTIMES,
|
---|
| 148 | [0x56] = KC_NMINUS,
|
---|
| 149 | [0x57] = KC_NPLUS,
|
---|
| 150 | [0x58] = KC_NENTER,
|
---|
| 151 | [0x59] = KC_N1,
|
---|
| 152 | [0x5a] = KC_N2,
|
---|
| 153 | [0x5b] = KC_N3,
|
---|
| 154 | [0x5c] = KC_N4,
|
---|
| 155 | [0x5d] = KC_N5,
|
---|
| 156 | [0x5e] = KC_N6,
|
---|
| 157 | [0x5f] = KC_N7,
|
---|
| 158 | [0x60] = KC_N8,
|
---|
| 159 | [0x61] = KC_N9,
|
---|
| 160 | [0x62] = KC_N0,
|
---|
| 161 | [0x63] = KC_NPERIOD
|
---|
| 162 |
|
---|
[e2b1548] | 163 | };
|
---|
| 164 |
|
---|
[2391aaf] | 165 | unsigned int usbhid_parse_scancode(int scancode)
|
---|
[e2b1548] | 166 | {
|
---|
| 167 | unsigned int key;
|
---|
| 168 | int *map = scanmap_simple;
|
---|
| 169 | size_t map_length = sizeof(scanmap_simple) / sizeof(int);
|
---|
| 170 |
|
---|
| 171 | if ((scancode < 0) || ((size_t) scancode >= map_length))
|
---|
| 172 | return -1;
|
---|
| 173 |
|
---|
| 174 | key = map[scancode];
|
---|
[d972534] | 175 |
|
---|
[e2b1548] | 176 | return key;
|
---|
[7d540c8] | 177 | }
|
---|
[1c13dac] | 178 |
|
---|
| 179 | /**
|
---|
| 180 | * @}
|
---|
| 181 | */
|
---|