Changes in uspace/drv/bus/usb/usbhid/kbd/kbddev.c [2a5b62b:5da7199] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r2a5b62b r5da7199 174 174 { 175 175 sysarg_t method = IPC_GET_IMETHOD(*icall); 176 176 177 177 usb_kbd_t *kbd_dev = (usb_kbd_t *) fun->driver_data; 178 178 if (kbd_dev == NULL) { … … 182 182 return; 183 183 } 184 184 185 185 async_sess_t *sess = 186 186 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); … … 240 240 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 241 241 USB_HID_REPORT_TYPE_OUTPUT); 242 242 243 243 while (field != NULL) { 244 244 … … 263 263 USB_HID_REPORT_TYPE_OUTPUT); 264 264 } 265 265 266 266 // TODO: what about the Report ID? 267 267 int rc = usb_hid_report_output_translate(hid_dev->report, 0, 268 268 kbd_dev->output_buffer, kbd_dev->output_size); 269 269 270 270 if (rc != EOK) { 271 271 usb_log_warning("Error translating LED output to output report" … … 273 273 return; 274 274 } 275 275 276 276 usb_log_debug("Output report buffer: %s\n", 277 277 usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size, 278 278 0)); 279 279 280 280 usbhid_req_set_report(&hid_dev->usb_dev->ctrl_pipe, 281 281 hid_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, … … 300 300 return; 301 301 } 302 302 303 303 async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess); 304 304 async_msg_2(exch, KBDEV_EVENT, type, key); … … 347 347 unsigned int key; 348 348 size_t i; 349 349 350 350 /* 351 351 * First of all, check if the kbd have reported phantom state. … … 362 362 return; 363 363 } 364 364 365 365 /* 366 366 * Key releases … … 382 382 } 383 383 } 384 384 385 385 /* 386 386 * Key presses … … 402 402 } 403 403 } 404 404 405 405 memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4); 406 406 407 407 char key_buffer[512]; 408 408 ddf_dump_buffer(key_buffer, 512, … … 435 435 assert(hid_dev != NULL); 436 436 assert(kbd_dev != NULL); 437 437 438 438 usb_hid_report_path_t *path = usb_hid_report_path(); 439 439 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 440 440 441 441 usb_hid_report_path_set_report_id (path, hid_dev->report_id); 442 442 443 443 // fill in the currently pressed keys 444 444 445 445 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 446 446 hid_dev->report, NULL, path, … … 448 448 USB_HID_REPORT_TYPE_INPUT); 449 449 unsigned i = 0; 450 450 451 451 while (field != NULL) { 452 452 usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n", … … 470 470 USB_HID_REPORT_TYPE_INPUT); 471 471 } 472 472 473 473 usb_hid_report_path_free(path); 474 474 475 475 usb_kbd_check_key_changes(hid_dev, kbd_dev); 476 476 } … … 502 502 503 503 if (kbd_dev == NULL) { 504 usb_log_ error("No memory!\n");504 usb_log_fatal("No memory!\n"); 505 505 return NULL; 506 506 } 507 507 508 508 kbd_dev->console_sess = NULL; 509 509 kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED; 510 510 511 511 return kbd_dev; 512 512 } … … 514 514 /*----------------------------------------------------------------------------*/ 515 515 516 static int usb_kbd_create_function(usb_kbd_t *kbd_dev) 517 { 516 static int usb_kbd_create_function(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev) 517 { 518 assert(hid_dev != NULL); 519 assert(hid_dev->usb_dev != NULL); 518 520 assert(kbd_dev != NULL); 519 assert(kbd_dev->hid_dev != NULL); 520 assert(kbd_dev->hid_dev->usb_dev != NULL); 521 521 522 522 /* Create the exposed function. */ 523 523 usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME); 524 ddf_fun_t *fun = ddf_fun_create( kbd_dev->hid_dev->usb_dev->ddf_dev,525 fun_exposed,HID_KBD_FUN_NAME);524 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 525 HID_KBD_FUN_NAME); 526 526 if (fun == NULL) { 527 527 usb_log_error("Could not create DDF function node.\n"); 528 528 return ENOMEM; 529 529 } 530 530 531 531 /* 532 532 * Store the initialized HID device and HID ops … … 540 540 usb_log_error("Could not bind DDF function: %s.\n", 541 541 str_error(rc)); 542 fun->driver_data = NULL; /* We need this later */543 542 ddf_fun_destroy(fun); 544 543 return rc; 545 544 } 546 545 547 546 usb_log_debug("%s function created. Handle: %" PRIun "\n", 548 547 HID_KBD_FUN_NAME, fun->handle); 549 548 550 549 usb_log_debug("Adding DDF function to category %s...\n", 551 550 HID_KBD_CLASS_NAME); … … 555 554 "Could not add DDF function to category %s: %s.\n", 556 555 HID_KBD_CLASS_NAME, str_error(rc)); 557 fun->driver_data = NULL; /* We need this later */558 556 ddf_fun_destroy(fun); 559 557 return rc; 560 558 } 561 kbd_dev->fun = fun; 562 559 563 560 return EOK; 564 561 } … … 590 587 { 591 588 usb_log_debug("Initializing HID/KBD structure...\n"); 592 589 593 590 if (hid_dev == NULL) { 594 591 usb_log_error("Failed to init keyboard structure: no structure" … … 596 593 return EINVAL; 597 594 } 598 595 599 596 usb_kbd_t *kbd_dev = usb_kbd_new(); 600 597 if (kbd_dev == NULL) { … … 606 603 /* Store link to HID device */ 607 604 kbd_dev->hid_dev = hid_dev; 608 605 609 606 /* 610 607 * TODO: make more general … … 612 609 usb_hid_report_path_t *path = usb_hid_report_path(); 613 610 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 614 611 615 612 usb_hid_report_path_set_report_id(path, 0); 616 613 617 614 kbd_dev->key_count = usb_hid_report_size( 618 615 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 619 616 usb_hid_report_path_free(path); 620 617 621 618 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 622 619 623 620 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 624 621 625 622 if (kbd_dev->keys == NULL) { 626 usb_log_ error("No memory!\n");623 usb_log_fatal("No memory!\n"); 627 624 free(kbd_dev); 628 625 return ENOMEM; 629 626 } 630 627 631 628 kbd_dev->keys_old = 632 629 (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 633 630 634 631 if (kbd_dev->keys_old == NULL) { 635 usb_log_ error("No memory!\n");632 usb_log_fatal("No memory!\n"); 636 633 free(kbd_dev->keys); 637 634 free(kbd_dev); 638 635 return ENOMEM; 639 636 } 640 637 641 638 /* 642 639 * Output report … … 650 647 return ENOMEM; 651 648 } 652 649 653 650 usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size); 654 651 655 652 kbd_dev->led_path = usb_hid_report_path(); 656 653 usb_hid_report_path_append_item( 657 654 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 658 655 659 656 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 660 657 0, USB_HID_REPORT_TYPE_OUTPUT); 661 658 662 659 usb_log_debug("Output report size (in items): %zu\n", 663 660 kbd_dev->led_output_size); 664 661 665 662 kbd_dev->led_data = (int32_t *)calloc( 666 663 kbd_dev->led_output_size, sizeof(int32_t)); 667 664 668 665 if (kbd_dev->led_data == NULL) { 669 666 usb_log_warning("Error creating buffer for LED output report." … … 674 671 return ENOMEM; 675 672 } 676 673 677 674 /* 678 675 * Modifiers and locks … … 681 678 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 682 679 kbd_dev->lock_keys = 0; 683 680 684 681 /* 685 682 * Autorepeat … … 689 686 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT; 690 687 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY; 691 692 fibril_mutex_initialize(&kbd_dev->repeat_mtx); 693 688 689 kbd_dev->repeat_mtx = (fibril_mutex_t *)( 690 malloc(sizeof(fibril_mutex_t))); 691 if (kbd_dev->repeat_mtx == NULL) { 692 usb_log_fatal("No memory!\n"); 693 free(kbd_dev->keys); 694 usb_hid_report_output_free(kbd_dev->output_buffer); 695 free(kbd_dev); 696 return ENOMEM; 697 } 698 699 fibril_mutex_initialize(kbd_dev->repeat_mtx); 700 694 701 // save the KBD device structure into the HID device structure 695 702 *data = kbd_dev; 696 703 697 704 // set handler for incoming calls 698 705 kbd_dev->ops.default_handler = default_connection_handler; 699 706 700 707 /* 701 708 * Set LEDs according to initial setup. … … 703 710 */ 704 711 usb_kbd_set_led(hid_dev, kbd_dev); 705 712 706 713 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 707 714 hid_dev->usb_dev->interface_no, IDLE_RATE); 708 715 709 716 /* 710 717 * Create new fibril for auto-repeat … … 716 723 } 717 724 fibril_add_ready(fid); 718 725 719 726 kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED; 720 727 usb_log_debug("HID/KBD device structure initialized.\n"); 721 728 722 729 usb_log_debug("Creating KBD function...\n"); 723 int rc = usb_kbd_create_function( kbd_dev);730 int rc = usb_kbd_create_function(hid_dev, kbd_dev); 724 731 if (rc != EOK) { 725 732 usb_kbd_destroy(kbd_dev); 726 733 return rc; 727 734 } 728 735 729 736 return EOK; 730 737 } … … 738 745 return false; 739 746 } 740 747 741 748 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 742 749 assert(kbd_dev != NULL); 743 750 744 751 // TODO: add return value from this function 745 752 usb_kbd_process_data(hid_dev, kbd_dev); 746 753 747 754 return true; 748 755 } … … 773 780 return; 774 781 } 775 782 776 783 // hangup session to the console 777 784 async_hangup(kbd_dev->console_sess); 778 779 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); 780 // FIXME - the fibril_mutex_is_locked may not cause 781 // fibril scheduling 782 while (fibril_mutex_is_locked(&kbd_dev->repeat_mtx)) {} 783 785 786 if (kbd_dev->repeat_mtx != NULL) { 787 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); 788 // FIXME - the fibril_mutex_is_locked may not cause 789 // fibril scheduling 790 while (fibril_mutex_is_locked(kbd_dev->repeat_mtx)) {} 791 free(kbd_dev->repeat_mtx); 792 } 793 784 794 // free all buffers 785 free(kbd_dev->keys); 786 free(kbd_dev->keys_old); 787 free(kbd_dev->led_data); 788 795 if (kbd_dev->keys != NULL) { 796 free(kbd_dev->keys); 797 } 798 if (kbd_dev->keys_old != NULL) { 799 free(kbd_dev->keys_old); 800 } 801 if (kbd_dev->led_data != NULL) { 802 free(kbd_dev->led_data); 803 } 789 804 if (kbd_dev->led_path != NULL) { 790 805 usb_hid_report_path_free(kbd_dev->led_path); … … 793 808 usb_hid_report_output_free(kbd_dev->output_buffer); 794 809 } 795 796 if (ddf_fun_unbind(kbd_dev->fun) != EOK) {797 usb_log_warning("Failed to unbind kbd function.\n");798 } else {799 usb_log_debug2("%s unbound.\n", kbd_dev->fun->name);800 kbd_dev->fun->driver_data = NULL;801 ddf_fun_destroy(kbd_dev->fun);802 }803 810 } 804 811 … … 810 817 return; 811 818 } 812 819 813 820 if (data != NULL) { 814 usb_kbd_t *kbd_dev = data;821 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 815 822 if (usb_kbd_is_initialized(kbd_dev)) { 816 823 usb_kbd_mark_unusable(kbd_dev); 817 /* wait for autorepeat */ 818 async_usleep(CHECK_DELAY); 824 } else { 819 825 usb_kbd_destroy(kbd_dev); 820 826 } … … 829 835 USB_KBD_BOOT_REPORT_DESCRIPTOR, 830 836 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); 831 837 832 838 if (rc != EOK) { 833 839 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 835 841 return rc; 836 842 } 837 843 838 844 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 839 845 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 840 846 841 847 if (rc != EOK) { 842 848 usb_log_warning("Failed to set boot protocol to the device: " … … 844 850 return rc; 845 851 } 846 852 847 853 return EOK; 848 854 }
Note:
See TracChangeset
for help on using the changeset viewer.