| 1 | /*
|
|---|
| 2 | * Copyright (c) 2009 Vineeth Pillai
|
|---|
| 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 | /** @addtogroup kbd_ctl
|
|---|
| 30 | * @ingroup kbd
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /**
|
|---|
| 34 | * @file
|
|---|
| 35 | * @brief PL050 keyboard controller driver.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <kbd.h>
|
|---|
| 39 | #include <io/console.h>
|
|---|
| 40 | #include <io/keycode.h>
|
|---|
| 41 | #include <kbd_ctl.h>
|
|---|
| 42 | #include <gsp.h>
|
|---|
| 43 | #include <stdio.h>
|
|---|
| 44 |
|
|---|
| 45 | #define PL050_CAPS_SCAN_CODE 0x58
|
|---|
| 46 | #define PL050_NUM_SCAN_CODE 0x77
|
|---|
| 47 | #define PL050_SCROLL_SCAN_CODE 0x7E
|
|---|
| 48 |
|
|---|
| 49 | static bool is_lock_key(int);
|
|---|
| 50 | enum dec_state {
|
|---|
| 51 | ds_s,
|
|---|
| 52 | ds_e
|
|---|
| 53 | };
|
|---|
| 54 |
|
|---|
| 55 | static enum dec_state ds;
|
|---|
| 56 |
|
|---|
| 57 | static int scanmap_simple[] = {
|
|---|
| 58 |
|
|---|
| 59 | [0x0e] = KC_BACKTICK,
|
|---|
| 60 |
|
|---|
| 61 | [0x16] = KC_1,
|
|---|
| 62 | [0x1e] = KC_2,
|
|---|
| 63 | [0x26] = KC_3,
|
|---|
| 64 | [0x25] = KC_4,
|
|---|
| 65 | [0x2e] = KC_5,
|
|---|
| 66 | [0x36] = KC_6,
|
|---|
| 67 | [0x3d] = KC_7,
|
|---|
| 68 | [0x3e] = KC_8,
|
|---|
| 69 | [0x46] = KC_9,
|
|---|
| 70 | [0x45] = KC_0,
|
|---|
| 71 |
|
|---|
| 72 | [0x4e] = KC_MINUS,
|
|---|
| 73 | [0x55] = KC_EQUALS,
|
|---|
| 74 | [0x66] = KC_BACKSPACE,
|
|---|
| 75 |
|
|---|
| 76 | [0x0d] = KC_TAB,
|
|---|
| 77 |
|
|---|
| 78 | [0x15] = KC_Q,
|
|---|
| 79 | [0x1d] = KC_W,
|
|---|
| 80 | [0x24] = KC_E,
|
|---|
| 81 | [0x2d] = KC_R,
|
|---|
| 82 | [0x2c] = KC_T,
|
|---|
| 83 | [0x35] = KC_Y,
|
|---|
| 84 | [0x3c] = KC_U,
|
|---|
| 85 | [0x43] = KC_I,
|
|---|
| 86 | [0x44] = KC_O,
|
|---|
| 87 | [0x4d] = KC_P,
|
|---|
| 88 |
|
|---|
| 89 | [0x54] = KC_LBRACKET,
|
|---|
| 90 | [0x5b] = KC_RBRACKET,
|
|---|
| 91 |
|
|---|
| 92 | [0x58] = KC_CAPS_LOCK,
|
|---|
| 93 |
|
|---|
| 94 | [0x1c] = KC_A,
|
|---|
| 95 | [0x1b] = KC_S,
|
|---|
| 96 | [0x23] = KC_D,
|
|---|
| 97 | [0x2b] = KC_F,
|
|---|
| 98 | [0x34] = KC_G,
|
|---|
| 99 | [0x33] = KC_H,
|
|---|
| 100 | [0x3b] = KC_J,
|
|---|
| 101 | [0x42] = KC_K,
|
|---|
| 102 | [0x4b] = KC_L,
|
|---|
| 103 |
|
|---|
| 104 | [0x4c] = KC_SEMICOLON,
|
|---|
| 105 | [0x52] = KC_QUOTE,
|
|---|
| 106 | [0x5d] = KC_BACKSLASH,
|
|---|
| 107 |
|
|---|
| 108 | [0x12] = KC_LSHIFT,
|
|---|
| 109 |
|
|---|
| 110 | [0x1a] = KC_Z,
|
|---|
| 111 | [0x22] = KC_X,
|
|---|
| 112 | [0x21] = KC_C,
|
|---|
| 113 | [0x2a] = KC_V,
|
|---|
| 114 | [0x32] = KC_B,
|
|---|
| 115 | [0x31] = KC_N,
|
|---|
| 116 | [0x3a] = KC_M,
|
|---|
| 117 |
|
|---|
| 118 | [0x41] = KC_COMMA,
|
|---|
| 119 | [0x49] = KC_PERIOD,
|
|---|
| 120 | [0x4a] = KC_SLASH,
|
|---|
| 121 |
|
|---|
| 122 | [0x59] = KC_RSHIFT,
|
|---|
| 123 |
|
|---|
| 124 | [0x14] = KC_LCTRL,
|
|---|
| 125 | [0x11] = KC_LALT,
|
|---|
| 126 | [0x29] = KC_SPACE,
|
|---|
| 127 |
|
|---|
| 128 | [0x76] = KC_ESCAPE,
|
|---|
| 129 |
|
|---|
| 130 | [0x05] = KC_F1,
|
|---|
| 131 | [0x06] = KC_F2,
|
|---|
| 132 | [0x04] = KC_F3,
|
|---|
| 133 | [0x0c] = KC_F4,
|
|---|
| 134 | [0x03] = KC_F5,
|
|---|
| 135 | [0x0b] = KC_F6,
|
|---|
| 136 | [0x02] = KC_F7,
|
|---|
| 137 |
|
|---|
| 138 | [0x0a] = KC_F8,
|
|---|
| 139 | [0x01] = KC_F9,
|
|---|
| 140 | [0x09] = KC_F10,
|
|---|
| 141 |
|
|---|
| 142 | [0x78] = KC_F11,
|
|---|
| 143 | [0x07] = KC_F12,
|
|---|
| 144 |
|
|---|
| 145 | [0x60] = KC_SCROLL_LOCK,
|
|---|
| 146 |
|
|---|
| 147 | [0x5a] = KC_ENTER,
|
|---|
| 148 |
|
|---|
| 149 | [0x77] = KC_NUM_LOCK,
|
|---|
| 150 | [0x7c] = KC_NTIMES,
|
|---|
| 151 | [0x7b] = KC_NMINUS,
|
|---|
| 152 | [0x79] = KC_NPLUS,
|
|---|
| 153 | [0x6c] = KC_N7,
|
|---|
| 154 | [0x75] = KC_N8,
|
|---|
| 155 | [0x7d] = KC_N9,
|
|---|
| 156 | [0x6b] = KC_N4,
|
|---|
| 157 | [0x73] = KC_N5,
|
|---|
| 158 | [0x74] = KC_N6,
|
|---|
| 159 | [0x69] = KC_N1,
|
|---|
| 160 | [0x72] = KC_N2,
|
|---|
| 161 | [0x7a] = KC_N3,
|
|---|
| 162 | [0x70] = KC_N0,
|
|---|
| 163 | [0x71] = KC_NPERIOD
|
|---|
| 164 | };
|
|---|
| 165 |
|
|---|
| 166 | static int scanmap_e0[] = {
|
|---|
| 167 | [0x65] = KC_RALT,
|
|---|
| 168 | [0x59] = KC_RSHIFT,
|
|---|
| 169 |
|
|---|
| 170 | [0x64] = KC_PRTSCR,
|
|---|
| 171 |
|
|---|
| 172 | [0x70] = KC_INSERT,
|
|---|
| 173 | [0x6c] = KC_HOME,
|
|---|
| 174 | [0x7d] = KC_PAGE_UP,
|
|---|
| 175 |
|
|---|
| 176 | [0x71] = KC_DELETE,
|
|---|
| 177 | [0x69] = KC_END,
|
|---|
| 178 | [0x7a] = KC_PAGE_DOWN,
|
|---|
| 179 |
|
|---|
| 180 | [0x75] = KC_UP,
|
|---|
| 181 | [0x6b] = KC_LEFT,
|
|---|
| 182 | [0x72] = KC_DOWN,
|
|---|
| 183 | [0x74] = KC_RIGHT,
|
|---|
| 184 |
|
|---|
| 185 | [0x4a] = KC_NSLASH,
|
|---|
| 186 | [0x5a] = KC_NENTER
|
|---|
| 187 | };
|
|---|
| 188 |
|
|---|
| 189 | int kbd_ctl_init(void)
|
|---|
| 190 | {
|
|---|
| 191 | ds = ds_s;
|
|---|
| 192 | return 0;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | void kbd_ctl_parse_scancode(int scancode)
|
|---|
| 196 | {
|
|---|
| 197 | static int key_release_flag = 0;
|
|---|
| 198 | static int is_locked = 0;
|
|---|
| 199 | console_ev_type_t type;
|
|---|
| 200 | unsigned int key;
|
|---|
| 201 | int *map;
|
|---|
| 202 | size_t map_length;
|
|---|
| 203 |
|
|---|
| 204 | if (scancode == 0xe0) {
|
|---|
| 205 | ds = ds_e;
|
|---|
| 206 | return;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | switch (ds) {
|
|---|
| 210 | case ds_s:
|
|---|
| 211 | map = scanmap_simple;
|
|---|
| 212 | map_length = sizeof(scanmap_simple) / sizeof(int);
|
|---|
| 213 | break;
|
|---|
| 214 | case ds_e:
|
|---|
| 215 | map = scanmap_e0;
|
|---|
| 216 | map_length = sizeof(scanmap_e0) / sizeof(int);
|
|---|
| 217 | break;
|
|---|
| 218 | default:
|
|---|
| 219 | map = NULL;
|
|---|
| 220 | map_length = 0;
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | ds = ds_s;
|
|---|
| 224 | if (scancode == 0xf0) {
|
|---|
| 225 | key_release_flag = 1;
|
|---|
| 226 | return;
|
|---|
| 227 | } else {
|
|---|
| 228 | if (key_release_flag) {
|
|---|
| 229 | type = KEY_RELEASE;
|
|---|
| 230 | key_release_flag = 0;
|
|---|
| 231 | if (is_lock_key(scancode)) {
|
|---|
| 232 | if (!is_locked) {
|
|---|
| 233 | is_locked = 1;
|
|---|
| 234 | } else {
|
|---|
| 235 | is_locked = 0;
|
|---|
| 236 | return;
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 | } else {
|
|---|
| 240 | if (is_lock_key(scancode) && is_locked)
|
|---|
| 241 | return;
|
|---|
| 242 | type = KEY_PRESS;
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | if (scancode < 0)
|
|---|
| 247 | return;
|
|---|
| 248 |
|
|---|
| 249 | key = map[scancode];
|
|---|
| 250 | if (key != 0)
|
|---|
| 251 | kbd_push_ev(type, key);
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | static bool is_lock_key(int sc)
|
|---|
| 255 | {
|
|---|
| 256 | return ((sc == PL050_CAPS_SCAN_CODE) || (sc == PL050_NUM_SCAN_CODE) ||
|
|---|
| 257 | (sc == PL050_SCROLL_SCAN_CODE));
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | void kbd_ctl_set_ind(unsigned mods)
|
|---|
| 261 | {
|
|---|
| 262 | (void) mods;
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | /**
|
|---|
| 266 | * @}
|
|---|
| 267 | */
|
|---|