Changeset cc29622 in mainline for uspace/drv/bus/usb/usbhid/kbd/kbddev.c
- Timestamp:
- 2011-10-14T12:40:31Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e5024111
- Parents:
- 3002434
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r3002434 rcc29622 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 } … … 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 } … … 519 519 assert(hid_dev->usb_dev != NULL); 520 520 assert(kbd_dev != NULL); 521 521 522 522 /* Create the exposed function. */ 523 523 usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME); … … 528 528 return ENOMEM; 529 529 } 530 530 531 531 /* 532 532 * Store the initialized HID device and HID ops … … 543 543 return rc; 544 544 } 545 545 546 546 usb_log_debug("%s function created. Handle: %" PRIun "\n", 547 547 HID_KBD_FUN_NAME, fun->handle); 548 548 549 549 usb_log_debug("Adding DDF function to category %s...\n", 550 550 HID_KBD_CLASS_NAME); … … 557 557 return rc; 558 558 } 559 559 560 560 return EOK; 561 561 } … … 587 587 { 588 588 usb_log_debug("Initializing HID/KBD structure...\n"); 589 589 590 590 if (hid_dev == NULL) { 591 591 usb_log_error("Failed to init keyboard structure: no structure" … … 593 593 return EINVAL; 594 594 } 595 595 596 596 usb_kbd_t *kbd_dev = usb_kbd_new(); 597 597 if (kbd_dev == NULL) { … … 603 603 /* Store link to HID device */ 604 604 kbd_dev->hid_dev = hid_dev; 605 605 606 606 /* 607 607 * TODO: make more general … … 609 609 usb_hid_report_path_t *path = usb_hid_report_path(); 610 610 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 611 611 612 612 usb_hid_report_path_set_report_id(path, 0); 613 613 614 614 kbd_dev->key_count = usb_hid_report_size( 615 615 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 616 616 usb_hid_report_path_free(path); 617 617 618 618 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 619 619 620 620 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 621 621 622 622 if (kbd_dev->keys == NULL) { 623 623 usb_log_fatal("No memory!\n"); … … 625 625 return ENOMEM; 626 626 } 627 627 628 628 kbd_dev->keys_old = 629 629 (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 630 630 631 631 if (kbd_dev->keys_old == NULL) { 632 632 usb_log_fatal("No memory!\n"); … … 635 635 return ENOMEM; 636 636 } 637 637 638 638 /* 639 639 * Output report … … 647 647 return ENOMEM; 648 648 } 649 649 650 650 usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size); 651 651 652 652 kbd_dev->led_path = usb_hid_report_path(); 653 653 usb_hid_report_path_append_item( 654 654 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 655 655 656 656 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 657 657 0, USB_HID_REPORT_TYPE_OUTPUT); 658 658 659 659 usb_log_debug("Output report size (in items): %zu\n", 660 660 kbd_dev->led_output_size); 661 661 662 662 kbd_dev->led_data = (int32_t *)calloc( 663 663 kbd_dev->led_output_size, sizeof(int32_t)); 664 664 665 665 if (kbd_dev->led_data == NULL) { 666 666 usb_log_warning("Error creating buffer for LED output report." … … 671 671 return ENOMEM; 672 672 } 673 673 674 674 /* 675 675 * Modifiers and locks … … 678 678 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 679 679 kbd_dev->lock_keys = 0; 680 680 681 681 /* 682 682 * Autorepeat … … 686 686 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT; 687 687 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY; 688 688 689 689 kbd_dev->repeat_mtx = (fibril_mutex_t *)( 690 690 malloc(sizeof(fibril_mutex_t))); … … 696 696 return ENOMEM; 697 697 } 698 698 699 699 fibril_mutex_initialize(kbd_dev->repeat_mtx); 700 700 701 701 // save the KBD device structure into the HID device structure 702 702 *data = kbd_dev; 703 703 704 704 // set handler for incoming calls 705 705 kbd_dev->ops.default_handler = default_connection_handler; 706 706 707 707 /* 708 708 * Set LEDs according to initial setup. … … 710 710 */ 711 711 usb_kbd_set_led(hid_dev, kbd_dev); 712 712 713 713 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 714 714 hid_dev->usb_dev->interface_no, IDLE_RATE); 715 715 716 716 /* 717 717 * Create new fibril for auto-repeat … … 723 723 } 724 724 fibril_add_ready(fid); 725 725 726 726 kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED; 727 727 usb_log_debug("HID/KBD device structure initialized.\n"); 728 728 729 729 usb_log_debug("Creating KBD function...\n"); 730 730 int rc = usb_kbd_create_function(hid_dev, kbd_dev); … … 733 733 return rc; 734 734 } 735 735 736 736 return EOK; 737 737 } … … 745 745 return false; 746 746 } 747 747 748 748 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 749 749 assert(kbd_dev != NULL); 750 750 751 751 // TODO: add return value from this function 752 752 usb_kbd_process_data(hid_dev, kbd_dev); 753 753 754 754 return true; 755 755 } … … 780 780 return; 781 781 } 782 782 783 783 // hangup session to the console 784 784 async_hangup(kbd_dev->console_sess); 785 785 786 786 if (kbd_dev->repeat_mtx != NULL) { 787 787 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); … … 791 791 free(kbd_dev->repeat_mtx); 792 792 } 793 793 794 794 // free all buffers 795 795 if (kbd_dev->keys != NULL) { … … 817 817 return; 818 818 } 819 819 820 820 if (data != NULL) { 821 821 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; … … 835 835 USB_KBD_BOOT_REPORT_DESCRIPTOR, 836 836 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); 837 837 838 838 if (rc != EOK) { 839 839 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 841 841 return rc; 842 842 } 843 843 844 844 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 845 845 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 846 846 847 847 if (rc != EOK) { 848 848 usb_log_warning("Failed to set boot protocol to the device: " … … 850 850 return rc; 851 851 } 852 852 853 853 return EOK; 854 854 }
Note:
See TracChangeset
for help on using the changeset viewer.