Changes in / [92574f4:a80849c] in mainline
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/hid.h
r92574f4 ra80849c 37 37 #define USBHID_HID_H_ 38 38 39 #include <stdint.h>40 41 39 #include <usb/classes/hid.h> 42 40 #include <ddf/driver.h> … … 76 74 usb_endpoint_pipe_t ctrl_pipe; 77 75 usb_endpoint_pipe_t poll_pipe; 78 79 uint8_t *keycodes;80 size_t keycode_count;81 uint8_t modifiers;82 76 } usb_hid_dev_kbd_t; 83 77 -
uspace/drv/usbhid/main.c
r92574f4 ra80849c 51 51 #include <usb/descriptor.h> 52 52 #include <io/console.h> 53 #include <stdint.h>54 53 #include "hid.h" 55 54 #include "descparser.h" … … 62 61 63 62 #define GUESSED_POLL_ENDPOINT 1 64 #define BOOTP_REPORT_SIZE 665 63 66 64 /** Keyboard polling endpoint description for boot protocol class. */ … … 209 207 } 210 208 /* 211 usb_log_debug2("type: %d\n", type);212 usb_log_debug2("mods: 0x%x\n", mods);213 usb_log_debug2("keycode: %u\n", key);209 printf("type: %d\n", type); 210 printf("mods: 0x%x\n", mods); 211 printf("keycode: %u\n", key); 214 212 */ 215 213 … … 241 239 ev.c = layout[active_layout]->parse_ev(&ev); 242 240 243 usb_log_debug("Sending key %d to the console\n", ev.key);241 printf("Sending key %d to the console\n", ev.key); 244 242 assert(console_callback_phone != -1); 245 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, 246 ev.mods, ev.c); 243 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); 247 244 } 248 245 /* … … 252 249 /* 253 250 * TODO: 254 * 1) key press / key release - how does the keyboard notify about 255 * release? 251 * 1) key press / key release - how does the keyboard notify about release? 256 252 * 2) layouts (use the already defined), not important now 257 253 * 3) 258 254 */ 259 255 260 static const keycode_t usb_hid_modifiers_boot_keycodes[5] = {261 KC_NUM_LOCK, /* USB_HID_MOD_BOOT_NUM_LOCK */262 KC_CAPS_LOCK, /* USB_HID_MOD_BOOT_CAPS_LOCK */263 KC_SCROLL_LOCK, /* USB_HID_MOD_BOOT_SCROLL_LOCK */264 0, /* USB_HID_MOD_BOOT_COMPOSE */265 0 /* USB_HID_MOD_BOOT_KANA */266 };267 268 static void usbkbd_check_modifier_changes(usb_hid_dev_kbd_t *kbd_dev,269 uint8_t modifiers)270 {271 /*272 * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK273 * both as modifiers and as keys with their own scancodes???274 *275 * modifiers should be sent as normal keys to usbkbd_parse_scancode()!!276 * so maybe it would be better if I received it from report parser in277 * that way278 */279 280 int i;281 for (i = 0; i < USB_HID_MOD_BOOT_COUNT; ++i) {282 if ((modifiers & usb_hid_modifiers_boot_consts[i]) &&283 !(kbd_dev->modifiers & usb_hid_modifiers_boot_consts[i])) {284 // modifier pressed285 if (usb_hid_modifiers_boot_keycodes[i] != 0) {286 kbd_push_ev(KEY_PRESS,287 usb_hid_modifiers_boot_keycodes[i]);288 }289 } else if (!(modifiers & usb_hid_modifiers_boot_consts[i]) &&290 (kbd_dev->modifiers & usb_hid_modifiers_boot_consts[i])) {291 // modifier released292 if (usb_hid_modifiers_boot_keycodes[i] != 0) {293 kbd_push_ev(KEY_RELEASE,294 usb_hid_modifiers_boot_keycodes[i]);295 }296 } // no change297 }298 }299 300 static void usbkbd_check_key_changes(usb_hid_dev_kbd_t *kbd_dev,301 const uint8_t *key_codes)302 {303 // TODO: phantom state!!304 305 unsigned int key;306 unsigned int i, j;307 308 // TODO: quite dummy right now, think of better implementation309 310 // key releases311 for (j = 0; j < kbd_dev->keycode_count; ++j) {312 // try to find the old key in the new key list313 i = 0;314 while (i < kbd_dev->keycode_count315 && key_codes[i] != kbd_dev->keycodes[j]) {316 ++j;317 }318 319 if (j == kbd_dev->keycode_count) {320 // not found, i.e. the key was released321 key = usbkbd_parse_scancode(kbd_dev->keycodes[j]);322 kbd_push_ev(KEY_RELEASE, key);323 } else {324 // found, nothing happens325 }326 }327 328 // key presses329 for (i = 0; i < kbd_dev->keycode_count; ++i) {330 // try to find the new key in the old key list331 j = 0;332 while (j < kbd_dev->keycode_count333 && kbd_dev->keycodes[j] != key_codes[i]) {334 ++j;335 }336 337 assert(kbd_dev->keycode_count <= kbd_dev->keycode_count);338 339 if (j == kbd_dev->keycode_count) {340 // not found, i.e. new key pressed341 key = usbkbd_parse_scancode(key_codes[i]);342 kbd_push_ev(KEY_PRESS, key);343 } else {344 // found, nothing happens345 }346 }347 }348 349 256 /* 350 257 * Callbacks for parser … … 353 260 uint8_t modifiers, void *arg) 354 261 { 355 if (arg == NULL) { 356 usb_log_warning("Missing argument in callback " 357 "usbkbd_process_keycodes().\n"); 358 return; 359 } 360 361 usb_log_debug2("Got keys from parser: "); 262 printf("Got keys: "); 362 263 unsigned i; 363 264 for (i = 0; i < count; ++i) { 364 usb_log_debug2("%d ", key_codes[i]); 365 } 366 usb_log_debug2("\n"); 367 368 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg; 369 370 if (count != kbd_dev->keycode_count) { 371 usb_log_warning("Number of received keycodes (%d) differs from" 372 " expected number (%d).\n", count, kbd_dev->keycode_count); 373 return; 374 } 375 376 usbkbd_check_modifier_changes(kbd_dev, modifiers); 377 usbkbd_check_key_changes(kbd_dev, key_codes); 265 printf("%d ", key_codes[i]); 266 } 267 printf("\n"); 268 269 for (i = 0; i < count; ++i) { 270 // TODO: Key press / release 271 272 // TODO: NOT WORKING 273 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 274 275 if (key == 0) { 276 continue; 277 } 278 kbd_push_ev(KEY_PRESS, key); 279 } 280 printf("\n"); 378 281 } 379 282 … … 388 291 for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) { 389 292 // TODO: endianness 390 uint16_t length = kbd_dev->conf->interfaces[i].hid_desc.391 report_desc_info.length;293 uint16_t length = 294 kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length; 392 295 size_t actual_size = 0; 393 296 394 297 // allocate space for the report descriptor 395 kbd_dev->conf->interfaces[i].report_desc = 396 (uint8_t *)malloc(length); 298 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length); 397 299 398 300 // get the descriptor from the device … … 415 317 return EOK; 416 318 } 417 418 319 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev) 419 320 { … … 487 388 free(descriptors); 488 389 if (rc != EOK) { 489 usb_log_warning("Problem with parsing standard descriptors.\n");390 printf("Problem with parsing standard descriptors.\n"); 490 391 return rc; 491 392 } … … 494 395 rc = usbkbd_get_report_descriptor(kbd_dev); 495 396 if (rc != EOK) { 496 usb_log_warning("Problem with parsingREPORT descriptor.\n");397 printf("Problem with parsing HID REPORT descriptor.\n"); 497 398 return rc; 498 399 } … … 504 405 * 1) select one configuration (lets say the first) 505 406 * 2) how many interfaces?? how to select one?? 506 * ("The default setting for an interface is always alternate 507 * setting zero.") 407 * ("The default setting for an interface is always alternate setting zero.") 508 408 * 3) find endpoint which is IN and INTERRUPT (parse), save its number 509 409 * as the endpoint for polling 510 410 */ 511 411 … … 521 421 522 422 if (kbd_dev == NULL) { 523 usb_log_fatal("No memory!\n");423 fprintf(stderr, NAME ": No memory!\n"); 524 424 return NULL; 525 425 } … … 576 476 usb_hid_report_in_callbacks_t *callbacks = 577 477 (usb_hid_report_in_callbacks_t *)malloc( 578 478 sizeof(usb_hid_report_in_callbacks_t)); 579 479 callbacks->keyboard = usbkbd_process_keycodes; 580 480 581 481 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 582 482 // NULL); 583 /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size"584 " %zu\n", actual_size);*/483 printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n", 484 actual_size); 585 485 //dump_buffer("bufffer: ", buffer, actual_size); 586 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 587 callbacks, kbd_dev); 588 589 if (rc != EOK) { 590 usb_log_warning("Error in usb_hid_boot_keyboard_input_report():" 591 "%s\n", str_error(rc)); 486 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 487 NULL); 488 if (rc != EOK) { 489 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc); 592 490 } 593 491 } … … 599 497 size_t actual_size; 600 498 601 usb_log_info("Polling keyboard...\n");499 printf("Polling keyboard...\n"); 602 500 603 501 while (true) { … … 606 504 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe); 607 505 if (sess_rc != EOK) { 608 usb_log_warning("Failed to start a session: %s.\n",506 printf("Failed to start a session: %s.\n", 609 507 str_error(sess_rc)); 610 508 continue; … … 616 514 617 515 if (rc != EOK) { 618 usb_log_warning("Error polling the keyboard: %s.\n",516 printf("Error polling the keyboard: %s.\n", 619 517 str_error(rc)); 620 518 continue; … … 622 520 623 521 if (sess_rc != EOK) { 624 usb_log_warning("Error closing session: %s.\n",522 printf("Error closing session: %s.\n", 625 523 str_error(sess_rc)); 626 524 continue; … … 632 530 */ 633 531 if (actual_size == 0) { 634 usb_log_debug("Keyboard returned NAK\n");532 printf("Keyboard returned NAK\n"); 635 533 continue; 636 534 } … … 639 537 * TODO: Process pressed keys. 640 538 */ 641 usb_log_debug("Calling usbkbd_process_interrupt_in()\n");539 printf("Calling usbkbd_process_interrupt_in()\n"); 642 540 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 643 541 } … … 649 547 static int usbkbd_fibril_device(void *arg) 650 548 { 549 printf("!!! USB device fibril\n"); 550 651 551 if (arg == NULL) { 652 usb_log_error("No device!\n");552 printf("No device!\n"); 653 553 return -1; 654 554 } … … 659 559 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 660 560 if (kbd_dev == NULL) { 661 usb_log_error("Error while initializing device.\n");561 printf("Error while initializing device.\n"); 662 562 return -1; 663 563 } … … 707 607 fid_t fid = fibril_create(usbkbd_fibril_device, dev); 708 608 if (fid == 0) { 709 usb_log_error("Failed to start fibril for HID device\n");609 printf("%s: failed to start fibril for HID device\n", NAME); 710 610 return ENOMEM; 711 611 } … … 734 634 int main(int argc, char *argv[]) 735 635 { 736 usb_log_enable(USB_LOG_LEVEL_ MAX, NAME);636 usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid"); 737 637 return ddf_driver_main(&kbd_driver); 738 638 } -
uspace/lib/usb/include/usb/classes/hidparser.h
r92574f4 ra80849c 70 70 } usb_hid_report_in_callbacks_t; 71 71 72 73 typedef enum { 74 USB_HID_MOD_BOOT_NUM_LOCK = 0x01, 75 USB_HID_MOD_BOOT_CAPS_LOCK = 0x02, 76 USB_HID_MOD_BOOT_SCROLL_LOCK = 0x04, 77 USB_HID_MOD_BOOT_COMPOSE = 0x08, 78 USB_HID_MOD_BOOT_KANA = 0x10, 79 USB_HID_MOD_BOOT_COUNT = 5 80 } usb_hid_modifiers_boot_t; 81 82 static const usb_hid_modifiers_boot_t usb_hid_modifiers_boot_consts[5] = { 83 USB_HID_MOD_BOOT_NUM_LOCK, 84 USB_HID_MOD_BOOT_CAPS_LOCK, 85 USB_HID_MOD_BOOT_SCROLL_LOCK, 86 USB_HID_MOD_BOOT_COMPOSE, 87 USB_HID_MOD_BOOT_KANA 88 }; 89 90 //#define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x01 91 //#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK 0x02 92 //#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK 0x04 93 //#define USB_HID_BOOT_KEYBOARD_COMPOSE 0x08 94 //#define USB_HID_BOOT_KEYBOARD_KANA 0x10 72 #define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x01 73 #define USB_HID_BOOT_KEYBOARD_CAPS_LOCK 0x02 74 #define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK 0x04 75 #define USB_HID_BOOT_KEYBOARD_COMPOSE 0x08 76 #define USB_HID_BOOT_KEYBOARD_KANA 0x10 95 77 96 78 /*
Note:
See TracChangeset
for help on using the changeset viewer.