Changes in uspace/drv/bus/usb/usbhid/kbd/kbddev.c [8e10ef4:56fd7cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r8e10ef4 r56fd7cf 34 34 * USB HID keyboard device structure and API. 35 35 */ 36 37 /* XXX Fix this */ 38 #define _DDF_DATA_IMPLANT 36 39 37 40 #include <errno.h> … … 261 264 262 265 if (rc != EOK) { 263 usb_log_warning(" Could not translate LED output to output"264 " report.\n");266 usb_log_warning("Error translating LED output to output report" 267 ".\n"); 265 268 return; 266 269 } … … 270 273 0)); 271 274 272 rc = usbhid_req_set_report( 273 usb_device_get_default_pipe(hid_dev->usb_dev), 274 usb_device_get_iface_number(hid_dev->usb_dev), 275 USB_HID_REPORT_TYPE_OUTPUT, 275 rc = usbhid_req_set_report(&hid_dev->usb_dev->ctrl_pipe, 276 hid_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, 276 277 kbd_dev->output_buffer, kbd_dev->output_size); 277 278 if (rc != EOK) { … … 480 481 /* HID/KBD structure manipulation */ 481 482 482 static int kbd_dev_init(usb_kbd_t *kbd_dev, usb_hid_dev_t *hid_dev) 483 { 484 assert(kbd_dev); 485 assert(hid_dev); 486 483 static int usb_kbd_create_function(usb_kbd_t *kbd_dev) 484 { 485 assert(kbd_dev != NULL); 486 assert(kbd_dev->hid_dev != NULL); 487 assert(kbd_dev->hid_dev->usb_dev != NULL); 488 489 /* Create the exposed function. */ 490 usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME); 491 ddf_fun_t *fun = ddf_fun_create(kbd_dev->hid_dev->usb_dev->ddf_dev, 492 fun_exposed, HID_KBD_FUN_NAME); 493 if (fun == NULL) { 494 usb_log_error("Could not create DDF function node.\n"); 495 return ENOMEM; 496 } 497 498 /* Store the initialized HID device and HID ops 499 * to the DDF function. */ 500 ddf_fun_set_ops(fun, &kbdops); 501 ddf_fun_data_implant(fun, kbd_dev); 502 503 int rc = ddf_fun_bind(fun); 504 if (rc != EOK) { 505 usb_log_error("Could not bind DDF function: %s.\n", 506 str_error(rc)); 507 ddf_fun_destroy(fun); 508 return rc; 509 } 510 511 usb_log_debug("%s function created. Handle: %" PRIun "\n", 512 HID_KBD_FUN_NAME, ddf_fun_get_handle(fun)); 513 514 usb_log_debug("Adding DDF function to category %s...\n", 515 HID_KBD_CLASS_NAME); 516 rc = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME); 517 if (rc != EOK) { 518 usb_log_error( 519 "Could not add DDF function to category %s: %s.\n", 520 HID_KBD_CLASS_NAME, str_error(rc)); 521 if (ddf_fun_unbind(fun) == EOK) { 522 ddf_fun_destroy(fun); 523 } else { 524 usb_log_error( 525 "Failed to unbind `%s', will not destroy.\n", 526 ddf_fun_get_name(fun)); 527 } 528 return rc; 529 } 530 kbd_dev->fun = fun; 531 532 return EOK; 533 } 534 535 /* API functions */ 536 537 /** 538 * Initialization of the USB/HID keyboard structure. 539 * 540 * This functions initializes required structures from the device's descriptors. 541 * 542 * During initialization, the keyboard is switched into boot protocol, the idle 543 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 544 * when a key is pressed or released. Finally, the LED lights are turned on 545 * according to the default setup of lock keys. 546 * 547 * @note By default, the keyboards is initialized with Num Lock turned on and 548 * other locks turned off. 549 * 550 * @param kbd_dev Keyboard device structure to be initialized. 551 * @param dev DDF device structure of the keyboard. 552 * 553 * @retval EOK if successful. 554 * @retval EINVAL if some parameter is not given. 555 * @return Other value inherited from function usbhid_dev_init(). 556 */ 557 int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data) 558 { 559 usb_log_debug("Initializing HID/KBD structure...\n"); 560 561 if (hid_dev == NULL) { 562 usb_log_error( 563 "Failed to init keyboard structure: no structure given.\n"); 564 return EINVAL; 565 } 566 567 usb_kbd_t *kbd_dev = calloc(1, sizeof(usb_kbd_t)); 568 if (kbd_dev == NULL) { 569 usb_log_error("Failed to allocate KBD device structure.\n"); 570 return ENOMEM; 571 } 487 572 /* Default values */ 488 573 fibril_mutex_initialize(&kbd_dev->repeat_mtx); … … 498 583 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT; 499 584 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY; 585 500 586 501 587 // TODO: make more general … … 583 669 usb_kbd_set_led(hid_dev, kbd_dev); 584 670 585 usbhid_req_set_idle(usb_device_get_default_pipe(hid_dev->usb_dev), 586 usb_device_get_iface_number(hid_dev->usb_dev), IDLE_RATE); 587 671 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 672 hid_dev->usb_dev->interface_no, IDLE_RATE); 673 674 /* Save the KBD device structure into the HID device structure. */ 675 *data = kbd_dev; 588 676 589 677 kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED; 590 678 usb_log_debug("HID/KBD device structure initialized.\n"); 591 679 592 return EOK; 593 } 594 595 596 /* API functions */ 597 598 /** 599 * Initialization of the USB/HID keyboard structure. 600 * 601 * This functions initializes required structures from the device's descriptors. 602 * 603 * During initialization, the keyboard is switched into boot protocol, the idle 604 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 605 * when a key is pressed or released. Finally, the LED lights are turned on 606 * according to the default setup of lock keys. 607 * 608 * @note By default, the keyboards is initialized with Num Lock turned on and 609 * other locks turned off. 610 * 611 * @param kbd_dev Keyboard device structure to be initialized. 612 * @param dev DDF device structure of the keyboard. 613 * 614 * @retval EOK if successful. 615 * @retval EINVAL if some parameter is not given. 616 * @return Other value inherited from function usbhid_dev_init(). 617 */ 618 int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data) 619 { 620 usb_log_debug("Initializing HID/KBD structure...\n"); 621 622 if (hid_dev == NULL) { 623 usb_log_error( 624 "Failed to init keyboard structure: no structure given.\n"); 625 return EINVAL; 626 } 627 628 /* Create the exposed function. */ 629 usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME); 630 ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev, 631 fun_exposed, HID_KBD_FUN_NAME); 632 if (fun == NULL) { 633 usb_log_error("Could not create DDF function node.\n"); 634 return ENOMEM; 635 } 636 637 usb_kbd_t *kbd_dev = ddf_fun_data_alloc(fun, sizeof(usb_kbd_t)); 638 if (kbd_dev == NULL) { 639 usb_log_error("Failed to allocate KBD device structure.\n"); 640 ddf_fun_destroy(fun); 641 return ENOMEM; 642 } 643 644 int ret = kbd_dev_init(kbd_dev, hid_dev); 680 usb_log_debug("Creating KBD function...\n"); 681 ret = usb_kbd_create_function(kbd_dev); 645 682 if (ret != EOK) { 646 usb_log_error("Failed to initialize KBD device structure.\n"); 647 ddf_fun_destroy(fun); 648 return ret; 649 } 650 651 /* Store the initialized HID device and HID ops 652 * to the DDF function. */ 653 ddf_fun_set_ops(fun, &kbdops); 654 655 ret = ddf_fun_bind(fun); 656 if (ret != EOK) { 657 usb_log_error("Could not bind DDF function: %s.\n", 658 str_error(ret)); 659 usb_kbd_destroy(kbd_dev); 660 ddf_fun_destroy(fun); 661 return ret; 662 } 663 664 usb_log_debug("%s function created. Handle: %" PRIun "\n", 665 HID_KBD_FUN_NAME, ddf_fun_get_handle(fun)); 666 667 usb_log_debug("Adding DDF function to category %s...\n", 668 HID_KBD_CLASS_NAME); 669 ret = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME); 670 if (ret != EOK) { 671 usb_log_error( 672 "Could not add DDF function to category %s: %s.\n", 673 HID_KBD_CLASS_NAME, str_error(ret)); 674 usb_kbd_destroy(kbd_dev); 675 if (ddf_fun_unbind(fun) == EOK) { 676 ddf_fun_destroy(fun); 677 } else { 678 usb_log_error( 679 "Failed to unbind `%s', will not destroy.\n", 680 ddf_fun_get_name(fun)); 681 } 683 usb_kbd_destroy(kbd_dev); 682 684 return ret; 683 685 } … … 691 693 } 692 694 fibril_add_ready(fid); 693 kbd_dev->fun = fun;694 /* Save the KBD device structure into the HID device structure. */695 *data = kbd_dev;696 695 697 696 return EOK; … … 788 787 } 789 788 790 rc = usbhid_req_set_protocol( 791 usb_device_get_default_pipe(hid_dev->usb_dev), 792 usb_device_get_iface_number(hid_dev->usb_dev), 793 USB_HID_PROTOCOL_BOOT); 789 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 790 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 794 791 795 792 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.