Changes in uspace/drv/bus/usb/usbhid/kbd/kbddev.c [5da7199:2a5b62b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r5da7199 r2a5b62b 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_ fatal("No memory!\n");504 usb_log_error("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_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev) 517 { 518 assert(hid_dev != NULL); 519 assert(hid_dev->usb_dev != NULL); 516 static int usb_kbd_create_function(usb_kbd_t *kbd_dev) 517 { 520 518 assert(kbd_dev != NULL); 521 519 assert(kbd_dev->hid_dev != NULL); 520 assert(kbd_dev->hid_dev->usb_dev != NULL); 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( hid_dev->usb_dev->ddf_dev, fun_exposed,525 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); 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 */ 542 543 ddf_fun_destroy(fun); 543 544 return rc; 544 545 } 545 546 546 547 usb_log_debug("%s function created. Handle: %" PRIun "\n", 547 548 HID_KBD_FUN_NAME, fun->handle); 548 549 549 550 usb_log_debug("Adding DDF function to category %s...\n", 550 551 HID_KBD_CLASS_NAME); … … 554 555 "Could not add DDF function to category %s: %s.\n", 555 556 HID_KBD_CLASS_NAME, str_error(rc)); 557 fun->driver_data = NULL; /* We need this later */ 556 558 ddf_fun_destroy(fun); 557 559 return rc; 558 560 } 559 561 kbd_dev->fun = fun; 562 560 563 return EOK; 561 564 } … … 587 590 { 588 591 usb_log_debug("Initializing HID/KBD structure...\n"); 589 592 590 593 if (hid_dev == NULL) { 591 594 usb_log_error("Failed to init keyboard structure: no structure" … … 593 596 return EINVAL; 594 597 } 595 598 596 599 usb_kbd_t *kbd_dev = usb_kbd_new(); 597 600 if (kbd_dev == NULL) { … … 603 606 /* Store link to HID device */ 604 607 kbd_dev->hid_dev = hid_dev; 605 608 606 609 /* 607 610 * TODO: make more general … … 609 612 usb_hid_report_path_t *path = usb_hid_report_path(); 610 613 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 611 614 612 615 usb_hid_report_path_set_report_id(path, 0); 613 616 614 617 kbd_dev->key_count = usb_hid_report_size( 615 618 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 616 619 usb_hid_report_path_free(path); 617 620 618 621 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 619 622 620 623 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 621 624 622 625 if (kbd_dev->keys == NULL) { 623 usb_log_ fatal("No memory!\n");626 usb_log_error("No memory!\n"); 624 627 free(kbd_dev); 625 628 return ENOMEM; 626 629 } 627 630 628 631 kbd_dev->keys_old = 629 632 (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 630 633 631 634 if (kbd_dev->keys_old == NULL) { 632 usb_log_ fatal("No memory!\n");635 usb_log_error("No memory!\n"); 633 636 free(kbd_dev->keys); 634 637 free(kbd_dev); 635 638 return ENOMEM; 636 639 } 637 640 638 641 /* 639 642 * Output report … … 647 650 return ENOMEM; 648 651 } 649 652 650 653 usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size); 651 654 652 655 kbd_dev->led_path = usb_hid_report_path(); 653 656 usb_hid_report_path_append_item( 654 657 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 655 658 656 659 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 657 660 0, USB_HID_REPORT_TYPE_OUTPUT); 658 661 659 662 usb_log_debug("Output report size (in items): %zu\n", 660 663 kbd_dev->led_output_size); 661 664 662 665 kbd_dev->led_data = (int32_t *)calloc( 663 666 kbd_dev->led_output_size, sizeof(int32_t)); 664 667 665 668 if (kbd_dev->led_data == NULL) { 666 669 usb_log_warning("Error creating buffer for LED output report." … … 671 674 return ENOMEM; 672 675 } 673 676 674 677 /* 675 678 * Modifiers and locks … … 678 681 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 679 682 kbd_dev->lock_keys = 0; 680 683 681 684 /* 682 685 * Autorepeat … … 686 689 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT; 687 690 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY; 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 691 692 fibril_mutex_initialize(&kbd_dev->repeat_mtx); 693 701 694 // save the KBD device structure into the HID device structure 702 695 *data = kbd_dev; 703 696 704 697 // set handler for incoming calls 705 698 kbd_dev->ops.default_handler = default_connection_handler; 706 699 707 700 /* 708 701 * Set LEDs according to initial setup. … … 710 703 */ 711 704 usb_kbd_set_led(hid_dev, kbd_dev); 712 705 713 706 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 714 707 hid_dev->usb_dev->interface_no, IDLE_RATE); 715 708 716 709 /* 717 710 * Create new fibril for auto-repeat … … 723 716 } 724 717 fibril_add_ready(fid); 725 718 726 719 kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED; 727 720 usb_log_debug("HID/KBD device structure initialized.\n"); 728 721 729 722 usb_log_debug("Creating KBD function...\n"); 730 int rc = usb_kbd_create_function( hid_dev,kbd_dev);723 int rc = usb_kbd_create_function(kbd_dev); 731 724 if (rc != EOK) { 732 725 usb_kbd_destroy(kbd_dev); 733 726 return rc; 734 727 } 735 728 736 729 return EOK; 737 730 } … … 745 738 return false; 746 739 } 747 740 748 741 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 749 742 assert(kbd_dev != NULL); 750 743 751 744 // TODO: add return value from this function 752 745 usb_kbd_process_data(hid_dev, kbd_dev); 753 746 754 747 return true; 755 748 } … … 780 773 return; 781 774 } 782 775 783 776 // hangup session to the console 784 777 async_hangup(kbd_dev->console_sess); 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 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 794 784 // free all buffers 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 } 785 free(kbd_dev->keys); 786 free(kbd_dev->keys_old); 787 free(kbd_dev->led_data); 788 804 789 if (kbd_dev->led_path != NULL) { 805 790 usb_hid_report_path_free(kbd_dev->led_path); … … 808 793 usb_hid_report_output_free(kbd_dev->output_buffer); 809 794 } 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 } 810 803 } 811 804 … … 817 810 return; 818 811 } 819 812 820 813 if (data != NULL) { 821 usb_kbd_t *kbd_dev = (usb_kbd_t *)data;814 usb_kbd_t *kbd_dev = data; 822 815 if (usb_kbd_is_initialized(kbd_dev)) { 823 816 usb_kbd_mark_unusable(kbd_dev); 824 } else { 817 /* wait for autorepeat */ 818 async_usleep(CHECK_DELAY); 825 819 usb_kbd_destroy(kbd_dev); 826 820 } … … 835 829 USB_KBD_BOOT_REPORT_DESCRIPTOR, 836 830 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); 837 831 838 832 if (rc != EOK) { 839 833 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 841 835 return rc; 842 836 } 843 837 844 838 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 845 839 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 846 840 847 841 if (rc != EOK) { 848 842 usb_log_warning("Failed to set boot protocol to the device: " … … 850 844 return rc; 851 845 } 852 846 853 847 return EOK; 854 848 }
Note:
See TracChangeset
for help on using the changeset viewer.