[3a2f8aa] | 1 | /*
|
---|
[9be360ee] | 2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[3a2f8aa] | 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 | /**
|
---|
| 30 | * @file
|
---|
[a2afd8f] | 31 | * @brief Apple ADB keyboard controller
|
---|
[3a2f8aa] | 32 | */
|
---|
| 33 |
|
---|
[a2afd8f] | 34 | #include <errno.h>
|
---|
[a635535] | 35 | #include <io/kbd_event.h>
|
---|
[3a2f8aa] | 36 | #include <io/keycode.h>
|
---|
[56ad818] | 37 |
|
---|
[a2afd8f] | 38 | #include "ctl.h"
|
---|
[56ad818] | 39 |
|
---|
[c072a29] | 40 | #define KBD_KEY_RELEASE 0x80
|
---|
[3a2f8aa] | 41 |
|
---|
[c072a29] | 42 | static unsigned int scanmap[] = {
|
---|
[3a2f8aa] | 43 | [0x00] = KC_A,
|
---|
| 44 | [0x01] = KC_S,
|
---|
| 45 | [0x02] = KC_D,
|
---|
| 46 | [0x03] = KC_F,
|
---|
| 47 | [0x04] = KC_H,
|
---|
| 48 | [0x05] = KC_G,
|
---|
| 49 | [0x06] = KC_Z,
|
---|
| 50 | [0x07] = KC_X,
|
---|
| 51 | [0x08] = KC_C,
|
---|
| 52 | [0x09] = KC_V,
|
---|
| 53 | [0x0a] = KC_BACKSLASH,
|
---|
| 54 | [0x0b] = KC_B,
|
---|
| 55 | [0x0c] = KC_Q,
|
---|
| 56 | [0x0d] = KC_W,
|
---|
| 57 | [0x0e] = KC_E,
|
---|
| 58 | [0x0f] = KC_R,
|
---|
| 59 | [0x10] = KC_Y,
|
---|
| 60 | [0x11] = KC_T,
|
---|
| 61 | [0x12] = KC_1,
|
---|
| 62 | [0x13] = KC_2,
|
---|
| 63 | [0x14] = KC_3,
|
---|
| 64 | [0x15] = KC_4,
|
---|
| 65 | [0x16] = KC_6,
|
---|
| 66 | [0x17] = KC_5,
|
---|
| 67 | [0x18] = KC_EQUALS,
|
---|
| 68 | [0x19] = KC_9,
|
---|
| 69 | [0x1a] = KC_7,
|
---|
| 70 | [0x1b] = KC_MINUS,
|
---|
| 71 | [0x1c] = KC_8,
|
---|
| 72 | [0x1d] = KC_0,
|
---|
| 73 | [0x1e] = KC_RBRACKET,
|
---|
| 74 | [0x1f] = KC_O,
|
---|
| 75 | [0x20] = KC_U,
|
---|
| 76 | [0x21] = KC_LBRACKET,
|
---|
| 77 | [0x22] = KC_I,
|
---|
| 78 | [0x23] = KC_P,
|
---|
| 79 | [0x24] = KC_ENTER,
|
---|
| 80 | [0x25] = KC_L,
|
---|
| 81 | [0x26] = KC_J,
|
---|
| 82 | [0x27] = KC_QUOTE,
|
---|
| 83 | [0x28] = KC_K,
|
---|
| 84 | [0x29] = KC_SEMICOLON,
|
---|
| 85 | [0x2a] = KC_BACKSLASH,
|
---|
| 86 | [0x2b] = KC_COMMA,
|
---|
| 87 | [0x2c] = KC_SLASH,
|
---|
| 88 | [0x2d] = KC_N,
|
---|
| 89 | [0x2e] = KC_M,
|
---|
| 90 | [0x2f] = KC_PERIOD,
|
---|
| 91 | [0x30] = KC_TAB,
|
---|
| 92 | [0x31] = KC_SPACE,
|
---|
| 93 | [0x32] = KC_BACKTICK,
|
---|
| 94 | [0x33] = KC_BACKSPACE,
|
---|
| 95 | [0x34] = 0,
|
---|
| 96 | [0x35] = KC_ESCAPE,
|
---|
| 97 | [0x36] = KC_LCTRL,
|
---|
| 98 | [0x37] = 0,
|
---|
| 99 | [0x38] = KC_LSHIFT,
|
---|
| 100 | [0x39] = KC_CAPS_LOCK,
|
---|
| 101 | [0x3a] = KC_LALT,
|
---|
| 102 | [0x3b] = KC_LEFT,
|
---|
| 103 | [0x3c] = KC_RIGHT,
|
---|
| 104 | [0x3d] = KC_DOWN,
|
---|
| 105 | [0x3e] = KC_UP,
|
---|
| 106 | [0x3f] = 0,
|
---|
| 107 | [0x40] = 0,
|
---|
| 108 | [0x41] = KC_NPERIOD,
|
---|
| 109 | [0x42] = 0,
|
---|
| 110 | [0x43] = KC_NTIMES,
|
---|
| 111 | [0x44] = 0,
|
---|
| 112 | [0x45] = KC_NPLUS,
|
---|
| 113 | [0x46] = 0,
|
---|
| 114 | [0x47] = KC_NUM_LOCK,
|
---|
| 115 | [0x48] = 0,
|
---|
| 116 | [0x49] = 0,
|
---|
| 117 | [0x4a] = 0,
|
---|
| 118 | [0x4b] = KC_NSLASH,
|
---|
| 119 | [0x4c] = KC_NENTER,
|
---|
| 120 | [0x4d] = 0,
|
---|
| 121 | [0x4e] = KC_NMINUS,
|
---|
| 122 | [0x4f] = 0,
|
---|
| 123 | [0x50] = 0,
|
---|
| 124 | [0x51] = 0,
|
---|
| 125 | [0x52] = KC_N0,
|
---|
| 126 | [0x53] = KC_N1,
|
---|
| 127 | [0x54] = KC_N2,
|
---|
| 128 | [0x55] = KC_N3,
|
---|
| 129 | [0x56] = KC_N4,
|
---|
| 130 | [0x57] = KC_N5,
|
---|
| 131 | [0x58] = KC_N6,
|
---|
| 132 | [0x59] = KC_N7,
|
---|
| 133 | [0x5a] = 0,
|
---|
| 134 | [0x5b] = KC_N8,
|
---|
| 135 | [0x5c] = KC_N9,
|
---|
| 136 | [0x5d] = 0,
|
---|
| 137 | [0x5e] = 0,
|
---|
| 138 | [0x5f] = 0,
|
---|
| 139 | [0x60] = KC_F5,
|
---|
| 140 | [0x61] = KC_F6,
|
---|
| 141 | [0x62] = KC_F7,
|
---|
| 142 | [0x63] = KC_F3,
|
---|
| 143 | [0x64] = KC_F8,
|
---|
| 144 | [0x65] = KC_F9,
|
---|
| 145 | [0x66] = 0,
|
---|
| 146 | [0x67] = KC_F11,
|
---|
| 147 | [0x68] = 0,
|
---|
[c072a29] | 148 | [0x69] = KC_SYSREQ,
|
---|
[3a2f8aa] | 149 | [0x6a] = 0,
|
---|
| 150 | [0x6b] = KC_SCROLL_LOCK,
|
---|
| 151 | [0x6c] = 0,
|
---|
| 152 | [0x6d] = KC_F10,
|
---|
| 153 | [0x6e] = 0,
|
---|
| 154 | [0x6f] = KC_F12,
|
---|
| 155 | [0x70] = 0,
|
---|
[c072a29] | 156 | [0x71] = KC_PAUSE,
|
---|
[3a2f8aa] | 157 | [0x72] = KC_INSERT,
|
---|
| 158 | [0x73] = KC_HOME,
|
---|
| 159 | [0x74] = KC_PAGE_UP,
|
---|
| 160 | [0x75] = KC_DELETE,
|
---|
| 161 | [0x76] = KC_F4,
|
---|
| 162 | [0x77] = KC_END,
|
---|
| 163 | [0x78] = KC_F2,
|
---|
| 164 | [0x79] = KC_PAGE_DOWN,
|
---|
| 165 | [0x7a] = KC_F1,
|
---|
| 166 | [0x7b] = KC_RSHIFT,
|
---|
| 167 | [0x7c] = KC_RALT,
|
---|
| 168 | [0x7d] = KC_RCTRL,
|
---|
| 169 | [0x7e] = 0,
|
---|
| 170 | [0x7f] = 0
|
---|
| 171 | };
|
---|
| 172 |
|
---|
[a2afd8f] | 173 | /** Translate ADB keyboard scancode into keyboard event.
|
---|
| 174 | *
|
---|
| 175 | * @param scancode Scancode
|
---|
| 176 | * @param rtype Place to store type of keyboard event (press or release)
|
---|
| 177 | * @param rkey Place to store key code
|
---|
| 178 | *
|
---|
| 179 | * @return EOK on success, ENOENT if no translation exists
|
---|
| 180 | */
|
---|
[b7fd2a0] | 181 | errno_t adb_kbd_key_translate(sysarg_t scancode, kbd_event_type_t *rtype,
|
---|
[a2afd8f] | 182 | unsigned int *rkey)
|
---|
[c072a29] | 183 | {
|
---|
[a2afd8f] | 184 | kbd_event_type_t etype;
|
---|
| 185 | unsigned int key;
|
---|
[c072a29] | 186 |
|
---|
| 187 | if (scancode & KBD_KEY_RELEASE) {
|
---|
| 188 | scancode &= ~KBD_KEY_RELEASE;
|
---|
[a2afd8f] | 189 | etype = KEY_RELEASE;
|
---|
| 190 | } else {
|
---|
| 191 | etype = KEY_PRESS;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[c072a29] | 194 | if (scancode >= sizeof(scanmap) / sizeof(unsigned int))
|
---|
[a2afd8f] | 195 | return ENOENT;
|
---|
[c072a29] | 196 |
|
---|
[a2afd8f] | 197 | key = scanmap[scancode];
|
---|
| 198 | if (key == 0)
|
---|
| 199 | return ENOENT;
|
---|
| 200 |
|
---|
| 201 | *rtype = etype;
|
---|
| 202 | *rkey = key;
|
---|
| 203 | return EOK;
|
---|
[c072a29] | 204 | }
|
---|
| 205 |
|
---|
[3a2f8aa] | 206 | /** @}
|
---|
| 207 | */
|
---|