| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#include <keycodes.h> |
| 32 |
#include <usb/usb.h> |
| 33 |
|
| 34 |
enum { hid_subclass_none = 0, hid_subclass_boot = 1 }; |
| 35 |
typedef enum { hid_proto_boot = 0, hid_proto_report = 1 } hid_proto; |
| 36 |
enum { hid_boot_proto_none = 0, hid_boot_proto_keyboard = |
| 37 |
1, hid_boot_proto_mouse = 2 |
| 38 |
}; |
| 39 |
static const char *boot_protos[3] = { "(none)", "keyboard", "mouse" }; |
| 40 |
enum { GET_REPORT = 0x1, GET_IDLE = 0x2, GET_PROTOCOL = 0x3, SET_REPORT = |
| 41 |
0x9, SET_IDLE = 0xa, SET_PROTOCOL = 0xb |
| 42 |
}; |
| 43 |
|
| 44 |
typedef union { |
| 45 |
struct { |
| 46 |
u8 modifiers; |
| 47 |
u8 repeats; |
| 48 |
u8 keys[6]; |
| 49 |
}; |
| 50 |
u8 buffer[8]; |
| 51 |
} usb_hid_keyboard_event_t; |
| 52 |
|
| 53 |
typedef struct { |
| 54 |
void* queue; |
| 55 |
hid_descriptor_t *descriptor; |
| 56 |
|
| 57 |
usb_hid_keyboard_event_t previous; |
| 58 |
int lastkeypress; |
| 59 |
int repeat_delay; |
| 60 |
} usbhid_inst_t; |
| 61 |
|
| 62 |
#define HID_INST(dev) ((usbhid_inst_t*)(dev)->data) |
| 63 |
|
| 64 |
static void |
| 65 |
usb_hid_destroy(usbdev_t *dev) |
| 66 |
{ |
| 67 |
if (HID_INST(dev)->queue) { |
| 68 |
int i; |
| 69 |
for (i = 0; i <= dev->num_endp; i++) { |
| 70 |
if (dev->endpoints[i].endpoint == 0) |
| 71 |
continue; |
| 72 |
if (dev->endpoints[i].type != INTERRUPT) |
| 73 |
continue; |
| 74 |
if (dev->endpoints[i].direction != IN) |
| 75 |
continue; |
| 76 |
break; |
| 77 |
} |
| 78 |
dev->controller->destroy_intr_queue( |
| 79 |
&dev->endpoints[i], HID_INST(dev)->queue); |
| 80 |
HID_INST(dev)->queue = NULL; |
| 81 |
} |
| 82 |
free(HID_INST(dev)->descriptor); |
| 83 |
HID_INST(dev)->descriptor = NULL; |
| 84 |
|
| 85 |
free(dev->data); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
static int keycount; |
| 90 |
#define KEYBOARD_BUFFER_SIZE 16 |
| 91 |
static short keybuffer[KEYBOARD_BUFFER_SIZE]; |
| 92 |
static int modifiers; |
| 93 |
|
| 94 |
const char *countries[36][2] = { |
| 95 |
{ "not supported", "us" }, |
| 96 |
{ "Arabic", "ae" }, |
| 97 |
{ "Belgian", "be" }, |
| 98 |
{ "Canadian-Bilingual", "ca" }, |
| 99 |
{ "Canadian-French", "ca" }, |
| 100 |
{ "Czech Republic", "cz" }, |
| 101 |
{ "Danish", "dk" }, |
| 102 |
{ "Finnish", "fi" }, |
| 103 |
{ "French", "fr" }, |
| 104 |
{ "German", "de" }, |
| 105 |
{ "Greek", "gr" }, |
| 106 |
{ "Hebrew", "il" }, |
| 107 |
{ "Hungary", "hu" }, |
| 108 |
{ "International (ISO)", "iso" }, |
| 109 |
{ "Italian", "it" }, |
| 110 |
{ "Japan (Katakana)", "jp" }, |
| 111 |
{ "Korean", "us" }, |
| 112 |
{ "Latin American", "us" }, |
| 113 |
{ "Netherlands/Dutch", "nl" }, |
| 114 |
{ "Norwegian", "no" }, |
| 115 |
{ "Persian (Farsi)", "ir" }, |
| 116 |
{ "Poland", "pl" }, |
| 117 |
{ "Portuguese", "pt" }, |
| 118 |
{ "Russia", "ru" }, |
| 119 |
{ "Slovakia", "sl" }, |
| 120 |
{ "Spanish", "es" }, |
| 121 |
{ "Swedish", "se" }, |
| 122 |
{ "Swiss/French", "ch" }, |
| 123 |
{ "Swiss/German", "ch" }, |
| 124 |
{ "Switzerland", "ch" }, |
| 125 |
{ "Taiwan", "tw" }, |
| 126 |
{ "Turkish-Q", "tr" }, |
| 127 |
{ "UK", "uk" }, |
| 128 |
{ "US", "us" }, |
| 129 |
{ "Yugoslavia", "yu" }, |
| 130 |
{ "Turkish-F", "tr" }, |
| 131 |
|
| 132 |
}; |
| 133 |
|
| 134 |
struct layout_maps { |
| 135 |
const char *country; |
| 136 |
const short map[4][0x80]; |
| 137 |
}; |
| 138 |
|
| 139 |
static const struct layout_maps *map; |
| 140 |
|
| 141 |
static const struct layout_maps keyboard_layouts[] = { |
| 142 |
|
| 143 |
{ .country = "us", .map = { |
| 144 |
{ |
| 145 |
-1, -1, -1, -1, 'a', 'b', 'c', 'd', |
| 146 |
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', |
| 147 |
|
| 148 |
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', |
| 149 |
'u', 'v', 'w', 'x', 'y', 'z', '1', '2', |
| 150 |
|
| 151 |
'3', '4', '5', '6', '7', '8', '9', '0', |
| 152 |
'\n', '\e', '\b', '\t', ' ', '-', '=', '[', |
| 153 |
|
| 154 |
']', '\\', -1, ';', '\'', '`', ',', '.', |
| 155 |
'/', -1 , KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), |
| 156 |
|
| 157 |
KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), KEY_F(11), KEY_F(12), KEY_PRINT, -1 , |
| 158 |
KEY_BREAK, KEY_IC, KEY_HOME, KEY_PPAGE, KEY_DC, KEY_END, KEY_NPAGE, KEY_RIGHT, |
| 159 |
|
| 160 |
KEY_LEFT, KEY_DOWN, KEY_UP, -1 , '/', '*', '-' , '+', |
| 161 |
KEY_ENTER, KEY_END, KEY_DOWN, KEY_NPAGE, KEY_LEFT, -1, KEY_RIGHT, KEY_HOME, |
| 162 |
|
| 163 |
KEY_UP, KEY_PPAGE, -1, KEY_DC, -1 , -1 , -1, -1, |
| 164 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 165 |
|
| 166 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 167 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 168 |
}, |
| 169 |
{ |
| 170 |
-1, -1, -1, -1, 'A', 'B', 'C', 'D', |
| 171 |
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', |
| 172 |
|
| 173 |
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', |
| 174 |
'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', |
| 175 |
|
| 176 |
'#', '$', '%', '^', '&', '*', '(', ')', |
| 177 |
'\n', '\e', '\b', '\t', ' ', '_', '+', '[', |
| 178 |
|
| 179 |
']', '\\', -1, ':', '\'', '`', ',', '.', |
| 180 |
'/', -1 , KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), |
| 181 |
|
| 182 |
KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), KEY_F(11), KEY_F(12), KEY_PRINT, -1 , |
| 183 |
KEY_BREAK, KEY_IC, KEY_HOME, KEY_PPAGE, KEY_DC, KEY_END, KEY_NPAGE, KEY_RIGHT, |
| 184 |
|
| 185 |
KEY_LEFT, KEY_DOWN, KEY_UP, -1 , '/', '*', '-' , '+', |
| 186 |
KEY_ENTER, KEY_END, KEY_DOWN, KEY_NPAGE, KEY_LEFT, -1, KEY_RIGHT, KEY_HOME, |
| 187 |
|
| 188 |
KEY_UP, KEY_PPAGE, -1, KEY_DC, -1 , -1 , -1, -1, |
| 189 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 190 |
|
| 191 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 192 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 193 |
}, |
| 194 |
{ |
| 195 |
-1, -1, -1, -1, 'a', 'b', 'c', 'd', |
| 196 |
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', |
| 197 |
|
| 198 |
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', |
| 199 |
'u', 'v', 'w', 'x', 'y', 'z', '1', '2', |
| 200 |
|
| 201 |
'3', '4', '5', '6', '7', '8', '9', '0', |
| 202 |
'\n', '\e', '\b', '\t', ' ', '-', '=', '[', |
| 203 |
|
| 204 |
']', '\\', -1, ';', '\'', '`', ',', '.', |
| 205 |
'/', -1 , KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), |
| 206 |
|
| 207 |
KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), KEY_F(11), KEY_F(12), KEY_PRINT, -1 , |
| 208 |
KEY_BREAK, KEY_IC, KEY_HOME, KEY_PPAGE, KEY_DC, KEY_END, KEY_NPAGE, KEY_RIGHT, |
| 209 |
|
| 210 |
KEY_LEFT, KEY_DOWN, KEY_UP, -1 , '/', '*', '-' , '+', |
| 211 |
KEY_ENTER, KEY_END, KEY_DOWN, KEY_NPAGE, KEY_LEFT, -1, KEY_RIGHT, KEY_HOME, |
| 212 |
|
| 213 |
KEY_UP, KEY_PPAGE, -1, KEY_DC, -1 , -1 , -1, -1, |
| 214 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 215 |
|
| 216 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 217 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 218 |
}, |
| 219 |
{ |
| 220 |
-1, -1, -1, -1, 'A', 'B', 'C', 'D', |
| 221 |
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', |
| 222 |
|
| 223 |
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', |
| 224 |
'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', |
| 225 |
|
| 226 |
'#', '$', '%', '^', '&', '*', '(', ')', |
| 227 |
'\n', '\e', '\b', '\t', ' ', '-', '=', '[', |
| 228 |
|
| 229 |
']', '\\', -1, ':', '\'', '`', ',', '.', |
| 230 |
'/', -1 , KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), |
| 231 |
|
| 232 |
KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), KEY_F(11), KEY_F(12), KEY_PRINT, -1 , |
| 233 |
KEY_BREAK, KEY_IC, KEY_HOME, KEY_PPAGE, KEY_DC, KEY_END, KEY_NPAGE, KEY_RIGHT, |
| 234 |
|
| 235 |
KEY_LEFT, KEY_DOWN, KEY_UP, -1 , '/', '*', '-' , '+', |
| 236 |
KEY_ENTER, KEY_END, KEY_DOWN, KEY_NPAGE, KEY_LEFT, -1, KEY_RIGHT, KEY_HOME, |
| 237 |
|
| 238 |
KEY_UP, KEY_PPAGE, -1, KEY_DC, -1 , -1 , -1, -1, |
| 239 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 240 |
|
| 241 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 242 |
-1, -1, -1, -1, -1, -1, -1, -1, |
| 243 |
} |
| 244 |
}}, |
| 245 |
|
| 246 |
}; |
| 247 |
|
| 248 |
static void usb_hid_keyboard_queue(int ch) { |
| 249 |
|
| 250 |
if (keycount < KEYBOARD_BUFFER_SIZE) |
| 251 |
keybuffer[keycount++] = ch; |
| 252 |
} |
| 253 |
|
| 254 |
#define KEYBOARD_REPEAT_MS 30 |
| 255 |
#define INITIAL_REPEAT_DELAY 10 |
| 256 |
#define REPEAT_DELAY 2 |
| 257 |
|
| 258 |
static void |
| 259 |
usb_hid_process_keyboard_event(usbhid_inst_t *const inst, |
| 260 |
const usb_hid_keyboard_event_t *const current) |
| 261 |
{ |
| 262 |
const usb_hid_keyboard_event_t *const previous = &inst->previous; |
| 263 |
|
| 264 |
int i, keypress = 0; |
| 265 |
|
| 266 |
modifiers = 0; |
| 267 |
|
| 268 |
if (current->modifiers & 0x01) |
| 269 |
modifiers |= KB_MOD_CTRL; |
| 270 |
if (current->modifiers & 0x02) |
| 271 |
modifiers |= KB_MOD_SHIFT; |
| 272 |
if (current->modifiers & 0x04) |
| 273 |
modifiers |= KB_MOD_ALT; |
| 274 |
if (current->modifiers & 0x08) |
| 275 |
; |
| 276 |
if (current->modifiers & 0x10) |
| 277 |
modifiers |= KB_MOD_CTRL; |
| 278 |
if (current->modifiers & 0x20) |
| 279 |
modifiers |= KB_MOD_SHIFT; |
| 280 |
if (current->modifiers & 0x40) |
| 281 |
modifiers |= KB_MOD_ALT; |
| 282 |
if (current->modifiers & 0x80) |
| 283 |
; |
| 284 |
|
| 285 |
if ((current->modifiers & 0x05) && ((current->keys[0] == 0x4c) || |
| 286 |
(current->keys[0] == 0x63))) { |
| 287 |
|
| 288 |
if (reset_handler) |
| 289 |
reset_handler(); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
if (inst->lastkeypress && |
| 294 |
!memcmp(current, previous, sizeof(*current))) { |
| 295 |
|
| 296 |
if (inst->repeat_delay) { |
| 297 |
inst->repeat_delay--; |
| 298 |
} else { |
| 299 |
usb_hid_keyboard_queue(inst->lastkeypress); |
| 300 |
inst->repeat_delay = REPEAT_DELAY; |
| 301 |
} |
| 302 |
|
| 303 |
return; |
| 304 |
} |
| 305 |
|
| 306 |
inst->lastkeypress = 0; |
| 307 |
|
| 308 |
for (i = 0; i < 6; i++) { |
| 309 |
int j; |
| 310 |
int skip = 0; |
| 311 |
|
| 312 |
if (current->keys[i] == 0) |
| 313 |
return; |
| 314 |
|
| 315 |
for (j = 0; j < 6; j++) { |
| 316 |
if (current->keys[i] == previous->keys[j]) { |
| 317 |
skip = 1; |
| 318 |
break; |
| 319 |
} |
| 320 |
} |
| 321 |
if (skip) |
| 322 |
continue; |
| 323 |
|
| 324 |
|
| 325 |
keypress = map->map[modifiers & 0x03][current->keys[i]]; |
| 326 |
|
| 327 |
if (modifiers & KB_MOD_CTRL) { |
| 328 |
switch (keypress) { |
| 329 |
case 'a' ... 'z': |
| 330 |
keypress &= 0x1f; |
| 331 |
break; |
| 332 |
default: |
| 333 |
continue; |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
if (keypress == -1) { |
| 338 |
|
| 339 |
usb_debug("usbhid: <%x> %x [ %x %x %x %x %x %x ] %d\n", |
| 340 |
current->modifiers, current->repeats, |
| 341 |
current->keys[0], current->keys[1], |
| 342 |
current->keys[2], current->keys[3], |
| 343 |
current->keys[4], current->keys[5], i); |
| 344 |
|
| 345 |
|
| 346 |
continue; |
| 347 |
} |
| 348 |
|
| 349 |
usb_hid_keyboard_queue(keypress); |
| 350 |
|
| 351 |
|
| 352 |
inst->lastkeypress = keypress; |
| 353 |
inst->repeat_delay = INITIAL_REPEAT_DELAY; |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
static void |
| 358 |
usb_hid_poll(usbdev_t *dev) |
| 359 |
{ |
| 360 |
usb_hid_keyboard_event_t current; |
| 361 |
const u8 *buf; |
| 362 |
|
| 363 |
while ((buf = dev->controller->poll_intr_queue (HID_INST(dev)->queue))) { |
| 364 |
memcpy(¤t.buffer, buf, 8); |
| 365 |
usb_hid_process_keyboard_event(HID_INST(dev), ¤t); |
| 366 |
HID_INST(dev)->previous = current; |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
static void |
| 371 |
usb_hid_set_idle(usbdev_t *dev, interface_descriptor_t *interface, u16 duration) |
| 372 |
{ |
| 373 |
dev_req_t dr; |
| 374 |
dr.data_dir = host_to_device; |
| 375 |
dr.req_type = class_type; |
| 376 |
dr.req_recp = iface_recp; |
| 377 |
dr.bRequest = SET_IDLE; |
| 378 |
dr.wValue = (duration >> 2) << 8; |
| 379 |
dr.wIndex = interface->bInterfaceNumber; |
| 380 |
dr.wLength = 0; |
| 381 |
dev->controller->control(dev, OUT, sizeof(dev_req_t), &dr, 0, 0); |
| 382 |
} |
| 383 |
|
| 384 |
static void |
| 385 |
usb_hid_set_protocol(usbdev_t *dev, interface_descriptor_t *interface, hid_proto proto) |
| 386 |
{ |
| 387 |
dev_req_t dr; |
| 388 |
dr.data_dir = host_to_device; |
| 389 |
dr.req_type = class_type; |
| 390 |
dr.req_recp = iface_recp; |
| 391 |
dr.bRequest = SET_PROTOCOL; |
| 392 |
dr.wValue = proto; |
| 393 |
dr.wIndex = interface->bInterfaceNumber; |
| 394 |
dr.wLength = 0; |
| 395 |
dev->controller->control(dev, OUT, sizeof(dev_req_t), &dr, 0, 0); |
| 396 |
} |
| 397 |
|
| 398 |
static struct console_input_driver cons = { |
| 399 |
.havekey = usbhid_havechar, |
| 400 |
.getchar = usbhid_getchar, |
| 401 |
.input_type = CONSOLE_INPUT_TYPE_USB, |
| 402 |
}; |
| 403 |
|
| 404 |
static int usb_hid_set_layout(const char *country) |
| 405 |
{ |
| 406 |
|
| 407 |
int i; |
| 408 |
|
| 409 |
for (i = 0; i < ARRAY_SIZE(keyboard_layouts); i++) { |
| 410 |
if (strncmp(keyboard_layouts[i].country, country, |
| 411 |
strlen(keyboard_layouts[i].country))) |
| 412 |
continue; |
| 413 |
|
| 414 |
|
| 415 |
map = &keyboard_layouts[i]; |
| 416 |
usb_debug(" Keyboard layout '%s'\n", map->country); |
| 417 |
return 0; |
| 418 |
} |
| 419 |
|
| 420 |
usb_debug(" Keyboard layout '%s' not found, using '%s'\n", |
| 421 |
country, map->country); |
| 422 |
|
| 423 |
|
| 424 |
return -1; |
| 425 |
} |
| 426 |
|
| 427 |
void |
| 428 |
usb_hid_init(usbdev_t *dev) |
| 429 |
{ |
| 430 |
|
| 431 |
static int installed = 0; |
| 432 |
if (!installed) { |
| 433 |
installed = 1; |
| 434 |
console_add_input_driver(&cons); |
| 435 |
} |
| 436 |
|
| 437 |
configuration_descriptor_t *cd = (configuration_descriptor_t*)dev->configuration; |
| 438 |
interface_descriptor_t *interface = (interface_descriptor_t*)(((char *) cd) + cd->bLength); |
| 439 |
|
| 440 |
if (interface->bInterfaceSubClass == hid_subclass_boot) { |
| 441 |
u8 countrycode; |
| 442 |
usb_debug(" supports boot interface..\n"); |
| 443 |
usb_debug(" it's a %s\n", |
| 444 |
boot_protos[interface->bInterfaceProtocol]); |
| 445 |
switch (interface->bInterfaceProtocol) { |
| 446 |
case hid_boot_proto_keyboard: |
| 447 |
dev->data = xzalloc(sizeof(usbhid_inst_t)); |
| 448 |
usb_debug(" configuring...\n"); |
| 449 |
usb_hid_set_protocol(dev, interface, hid_proto_boot); |
| 450 |
usb_hid_set_idle(dev, interface, KEYBOARD_REPEAT_MS); |
| 451 |
usb_debug(" activating...\n"); |
| 452 |
|
| 453 |
hid_descriptor_t *desc = malloc(sizeof(hid_descriptor_t)); |
| 454 |
if (!desc || get_descriptor(dev, gen_bmRequestType( |
| 455 |
device_to_host, standard_type, iface_recp), |
| 456 |
0x21, 0, desc, sizeof(*desc)) != sizeof(*desc)) { |
| 457 |
usb_debug("get_descriptor(HID) failed\n"); |
| 458 |
usb_detach_device(dev->controller, dev->address); |
| 459 |
return; |
| 460 |
} |
| 461 |
HID_INST(dev)->descriptor = desc; |
| 462 |
countrycode = desc->bCountryCode; |
| 463 |
|
| 464 |
if (countrycode >= ARRAY_SIZE(countries)) |
| 465 |
countrycode = 0; |
| 466 |
usb_debug(" Keyboard has %s layout (country code %02x)\n", |
| 467 |
countries[countrycode][0], countrycode); |
| 468 |
|
| 469 |
|
| 470 |
usb_hid_set_layout(countries[countrycode][1]); |
| 471 |
|
| 472 |
|
| 473 |
dev->destroy = usb_hid_destroy; |
| 474 |
dev->poll = usb_hid_poll; |
| 475 |
int i; |
| 476 |
for (i = 1; i < dev->num_endp; i++) { |
| 477 |
if (dev->endpoints[i].type != INTERRUPT) |
| 478 |
continue; |
| 479 |
if (dev->endpoints[i].direction != IN) |
| 480 |
continue; |
| 481 |
break; |
| 482 |
} |
| 483 |
if (i >= dev->num_endp) { |
| 484 |
usb_debug("Could not find HID endpoint\n"); |
| 485 |
usb_detach_device(dev->controller, dev->address); |
| 486 |
return; |
| 487 |
} |
| 488 |
usb_debug(" found endpoint %x for interrupt-in\n", i); |
| 489 |
|
| 490 |
HID_INST(dev)->queue = dev->controller->create_intr_queue(&dev->endpoints[i], 8, 20, 10); |
| 491 |
keycount = 0; |
| 492 |
usb_debug(" configuration done.\n"); |
| 493 |
break; |
| 494 |
case hid_boot_proto_mouse: |
| 495 |
usb_debug("NOTICE: USB mice are not supported.\n"); |
| 496 |
break; |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
int usbhid_havechar (void) |
| 502 |
{ |
| 503 |
return (keycount != 0); |
| 504 |
} |
| 505 |
|
| 506 |
int usbhid_getchar (void) |
| 507 |
{ |
| 508 |
short ret; |
| 509 |
|
| 510 |
if (keycount == 0) |
| 511 |
return 0; |
| 512 |
ret = keybuffer[0]; |
| 513 |
memmove(keybuffer, keybuffer + 1, --keycount); |
| 514 |
|
| 515 |
return (int)ret; |
| 516 |
} |
| 517 |
|
| 518 |
int usbhid_getmodifiers(void) |
| 519 |
{ |
| 520 |
return modifiers; |
| 521 |
} |