Changeset 252e30c in mainline
- Timestamp:
- 2011-03-24T22:55:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0d92638
- Parents:
- 476b71ff
- Location:
- uspace
- Files:
-
- 2 added
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/conv.h
r476b71ff r252e30c 34 34 */ 35 35 36 #ifndef USB HID_CONV_H_37 #define USB HID_CONV_H_36 #ifndef USB_KBD_CONV_H_ 37 #define USB_KBD_CONV_H_ 38 38 39 39 unsigned int usbhid_parse_scancode(int scancode); 40 40 41 #endif /* USB HID_CONV_H_ */41 #endif /* USB_KBD_CONV_H_ */ 42 42 43 43 /** -
uspace/drv/usbkbd/kbddev.c
r476b71ff r252e30c 55 55 #include <usb/classes/hidut.h> 56 56 #include <usb/classes/hidreq.h> 57 #include <usb/classes/hidreport.h> 57 58 58 59 #include <usb/devdrv.h> … … 88 89 /** Delay between two repeats of a pressed key when auto-repeating. */ 89 90 static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000; 91 92 /*----------------------------------------------------------------------------*/ 90 93 91 94 /** Keyboard polling endpoint description for boot protocol class. */ … … 99 102 }; 100 103 101 /** General keyboard polling endpoint description. */102 //static usb_endpoint_description_t general_poll_endpoint_description = {103 // .transfer_type = USB_TRANSFER_INTERRUPT,104 // .direction = USB_DIRECTION_IN,105 // .interface_class = USB_CLASS_HID,106 // .flags = 0107 //};108 109 104 /* Array of endpoints expected on the device, NULL terminated. */ 110 105 usb_endpoint_description_t 111 *usb hid_kbd_endpoints[USBHID_KBD_POLL_EP_COUNT + 1] = {106 *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1] = { 112 107 &boot_poll_endpoint_description, 113 // &general_poll_endpoint_description,114 108 NULL 115 109 }; 116 110 117 118 typedef enum usbhid_kbd_flags { 119 USBHID_KBD_STATUS_UNINITIALIZED = 0, 120 USBHID_KBD_STATUS_INITIALIZED = 1, 121 USBHID_KBD_STATUS_TO_DESTROY = -1 122 } usbhid_kbd_flags; 111 /*----------------------------------------------------------------------------*/ 112 113 enum { 114 BOOT_REPORT_DESCRIPTOR_SIZE = 0 115 }; 116 117 static const uint8_t BOOT_REPORT_DESCRIPTOR[BOOT_REPORT_DESCRIPTOR_SIZE] = {}; 118 119 /*----------------------------------------------------------------------------*/ 120 121 typedef enum usb_kbd_flags { 122 USB_KBD_STATUS_UNINITIALIZED = 0, 123 USB_KBD_STATUS_INITIALIZED = 1, 124 USB_KBD_STATUS_TO_DESTROY = -1 125 } usb_kbd_flags; 123 126 124 127 /*----------------------------------------------------------------------------*/ … … 153 156 154 157 typedef enum usbhid_lock_code { 155 USB HID_LOCK_NUM = 0x53,156 USB HID_LOCK_CAPS = 0x39,157 USB HID_LOCK_SCROLL = 0x47,158 USB HID_LOCK_COUNT = 3158 USB_KBD_LOCK_NUM = 0x53, 159 USB_KBD_LOCK_CAPS = 0x39, 160 USB_KBD_LOCK_SCROLL = 0x47, 161 USB_KBD_LOCK_COUNT = 3 159 162 } usbhid_lock_code; 160 163 161 static const usbhid_lock_code usbhid_lock_codes[USB HID_LOCK_COUNT] = {162 USB HID_LOCK_NUM,163 USB HID_LOCK_CAPS,164 USB HID_LOCK_SCROLL164 static const usbhid_lock_code usbhid_lock_codes[USB_KBD_LOCK_COUNT] = { 165 USB_KBD_LOCK_NUM, 166 USB_KBD_LOCK_CAPS, 167 USB_KBD_LOCK_SCROLL 165 168 }; 166 169 … … 190 193 sysarg_t method = IPC_GET_IMETHOD(*icall); 191 194 192 usb hid_kbd_t *kbd_dev = (usbhid_kbd_t *)fun->driver_data;195 usb_kbd_t *kbd_dev = (usb_kbd_t *)fun->driver_data; 193 196 assert(kbd_dev != NULL); 194 197 … … 224 227 * @param kbd_dev Keyboard device structure. 225 228 */ 226 static void usb hid_kbd_set_led(usbhid_kbd_t *kbd_dev)229 static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 227 230 { 228 231 uint8_t buffer[BOOTP_BUFFER_OUT_SIZE]; … … 282 285 * @param key Key code of the key according to HID Usage Tables. 283 286 */ 284 void usb hid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key)287 void usb_kbd_push_ev(usb_kbd_t *kbd_dev, int type, unsigned int key) 285 288 { 286 289 console_event_t ev; … … 332 335 /* Update keyboard lock indicator lights. */ 333 336 if (kbd_dev->lock_keys != locks_old) { 334 usb hid_kbd_set_led(kbd_dev);337 usb_kbd_set_led(kbd_dev); 335 338 } 336 339 } else { … … 380 383 381 384 /*----------------------------------------------------------------------------*/ 382 /** 383 * Checks if modifiers were pressed or released and generates key events. 384 * 385 * @param kbd_dev Keyboard device structure. 386 * @param modifiers Bitmap of modifiers. 387 * 388 * @sa usbhid_kbd_push_ev() 389 */ 390 //static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev, 391 // const uint8_t *key_codes, size_t count) 392 //{ 393 // /* 394 // * why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK 395 // * both as modifiers and as keyUSB_HID_LOCK_COUNTs with their own scancodes??? 396 // * 397 // * modifiers should be sent as normal keys to usbhid_parse_scancode()!! 398 // * so maybe it would be better if I received it from report parser in 399 // * that way 400 // */ 401 402 // int i; 403 // for (i = 0; i < count; ++i) { 404 // if ((modifiers & usb_hid_modifiers_consts[i]) && 405 // !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) { 406 // // modifier pressed 407 // if (usbhid_modifiers_keycodes[i] != 0) { 408 // usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, 409 // usbhid_modifiers_keycodes[i]); 410 // } 411 // } else if (!(modifiers & usb_hid_modifiers_consts[i]) && 412 // (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) { 413 // // modifier released 414 // if (usbhid_modifiers_keycodes[i] != 0) { 415 // usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, 416 // usbhid_modifiers_keycodes[i]); 417 // } 418 // } // no change 419 // } 420 421 // kbd_dev->modifiers = modifiers; 422 //} 423 424 /*----------------------------------------------------------------------------*/ 425 426 static inline int usbhid_kbd_is_lock(unsigned int key_code) 385 386 static inline int usb_kbd_is_lock(unsigned int key_code) 427 387 { 428 388 return (key_code == KC_NUM_LOCK … … 436 396 * 437 397 * An event is created only when key is pressed or released. Besides handling 438 * the events (usb hid_kbd_push_ev()), the auto-repeat fibril is notified about439 * key presses and releases (see usb hid_kbd_repeat_start() and440 * usb hid_kbd_repeat_stop()).398 * the events (usb_kbd_push_ev()), the auto-repeat fibril is notified about 399 * key presses and releases (see usb_kbd_repeat_start() and 400 * usb_kbd_repeat_stop()). 441 401 * 442 402 * @param kbd_dev Keyboard device structure. … … 445 405 * @param count Number of key codes in report (size of the report). 446 406 * 447 * @sa usb hid_kbd_push_ev(), usbhid_kbd_repeat_start(), usbhid_kbd_repeat_stop()448 */ 449 static void usb hid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev,407 * @sa usb_kbd_push_ev(), usb_kbd_repeat_start(), usb_kbd_repeat_stop() 408 */ 409 static void usb_kbd_check_key_changes(usb_kbd_t *kbd_dev, 450 410 const uint8_t *key_codes, size_t count) 451 411 { … … 488 448 // not found, i.e. the key was released 489 449 key = usbhid_parse_scancode(kbd_dev->keys[j]); 490 if (!usb hid_kbd_is_lock(key)) {491 usb hid_kbd_repeat_stop(kbd_dev, key);450 if (!usb_kbd_is_lock(key)) { 451 usb_kbd_repeat_stop(kbd_dev, key); 492 452 } 493 usb hid_kbd_push_ev(kbd_dev, KEY_RELEASE, key);453 usb_kbd_push_ev(kbd_dev, KEY_RELEASE, key); 494 454 usb_log_debug2("Key released: %d\n", key); 495 455 } else { … … 513 473 usb_log_debug2("Key pressed: %d (keycode: %d)\n", key, 514 474 key_codes[i]); 515 usb hid_kbd_push_ev(kbd_dev, KEY_PRESS, key);516 if (!usb hid_kbd_is_lock(key)) {517 usb hid_kbd_repeat_start(kbd_dev, key);475 usb_kbd_push_ev(kbd_dev, KEY_PRESS, key); 476 if (!usb_kbd_is_lock(key)) { 477 usb_kbd_repeat_start(kbd_dev, key); 518 478 } 519 479 } else { … … 545 505 * structure representing the keyboard. 546 506 * 547 * @sa usb hid_kbd_check_key_changes(), usbhid_kbd_check_modifier_changes()548 */ 549 static void usb hid_kbd_process_keycodes(const uint8_t *key_codes, size_t count,507 * @sa usb_kbd_check_key_changes(), usb_kbd_check_modifier_changes() 508 */ 509 static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 550 510 uint8_t modifiers, void *arg) 551 511 { … … 556 516 } 557 517 558 usb hid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg;518 usb_kbd_t *kbd_dev = (usb_kbd_t *)arg; 559 519 assert(kbd_dev != NULL); 560 520 … … 568 528 } 569 529 570 ///usb hid_kbd_check_modifier_changes(kbd_dev, key_codes, count);571 usb hid_kbd_check_key_changes(kbd_dev, key_codes, count);530 ///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count); 531 usb_kbd_check_key_changes(kbd_dev, key_codes, count); 572 532 } 573 533 … … 580 540 * This function uses the HID report parser to translate the data received from 581 541 * the device into generic USB HID key codes and into generic modifiers bitmap. 582 * The parser then calls the given callback (usb hid_kbd_process_keycodes()).542 * The parser then calls the given callback (usb_kbd_process_keycodes()). 583 543 * 584 544 * @note Currently, only the boot protocol is supported. … … 588 548 * @param actual_size Size of the data from keyboard (report size) in bytes. 589 549 * 590 * @sa usb hid_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report(),550 * @sa usb_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report(), 591 551 * usb_hid_parse_report(). 592 552 */ 593 static void usb hid_kbd_process_data(usbhid_kbd_t *kbd_dev,553 static void usb_kbd_process_data(usb_kbd_t *kbd_dev, 594 554 uint8_t *buffer, size_t actual_size) 595 555 { 596 assert(kbd_dev->initialized == USB HID_KBD_STATUS_INITIALIZED);556 assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); 597 557 assert(kbd_dev->parser != NULL); 598 558 … … 601 561 sizeof(usb_hid_report_in_callbacks_t)); 602 562 603 callbacks->keyboard = usb hid_kbd_process_keycodes;563 callbacks->keyboard = usb_kbd_process_keycodes; 604 564 605 565 usb_log_debug("Calling usb_hid_parse_report() with " … … 621 581 /*----------------------------------------------------------------------------*/ 622 582 623 static void usbhid_kbd_mark_unusable(usbhid_kbd_t *kbd_dev) 624 { 625 kbd_dev->initialized = USBHID_KBD_STATUS_TO_DESTROY; 626 } 627 628 /*----------------------------------------------------------------------------*/ 629 /* HID/KBD polling */ 630 /*----------------------------------------------------------------------------*/ 631 /** 632 * Main keyboard polling function. 633 * 634 * This function uses the Interrupt In pipe of the keyboard to poll for events. 635 * The keyboard is initialized in a way that it reports only when a key is 636 * pressed or released, so there is no actual need for any sleeping between 637 * polls (see usbhid_kbd_try_add_device() or usbhid_kbd_init()). 638 * 639 * @param kbd_dev Initialized keyboard structure representing the device to 640 * poll. 641 * 642 * @sa usbhid_kbd_process_data() 643 */ 644 //static void usbhid_kbd_poll(usbhid_kbd_t *kbd_dev) 645 //{ 646 // int rc, sess_rc; 647 // uint8_t buffer[BOOTP_BUFFER_SIZE]; 648 // size_t actual_size; 649 650 // usb_log_debug("Polling keyboard...\n"); 651 652 // if (!kbd_dev->initialized) { 653 // usb_log_error("HID/KBD device not initialized!\n"); 654 // return; 655 // } 656 657 // assert(kbd_dev->hid_dev != NULL); 658 // assert(kbd_dev->hid_dev->initialized); 659 660 // while (true) { 661 // sess_rc = usb_pipe_start_session( 662 // &kbd_dev->hid_dev->poll_pipe); 663 // if (sess_rc != EOK) { 664 // usb_log_warning("Failed to start a session: %s.\n", 665 // str_error(sess_rc)); 666 // break; 667 // } 668 669 // rc = usb_pipe_read(&kbd_dev->hid_dev->poll_pipe, 670 // buffer, BOOTP_BUFFER_SIZE, &actual_size); 671 672 // sess_rc = usb_pipe_end_session( 673 // &kbd_dev->hid_dev->poll_pipe); 674 675 // if (rc != EOK) { 676 // usb_log_warning("Error polling the keyboard: %s.\n", 677 // str_error(rc)); 678 // break; 679 // } 680 681 // if (sess_rc != EOK) { 682 // usb_log_warning("Error closing session: %s.\n", 683 // str_error(sess_rc)); 684 // break; 685 // } 686 687 // /* 688 // * If the keyboard answered with NAK, it returned no data. 689 // * This implies that no change happened since last query. 690 // */ 691 // if (actual_size == 0) { 692 // usb_log_debug("Keyboard returned NAK\n"); 693 // continue; 694 // } 695 696 // /* 697 // * TODO: Process pressed keys. 698 // */ 699 // usb_log_debug("Calling usbhid_kbd_process_data()\n"); 700 // usbhid_kbd_process_data(kbd_dev, buffer, actual_size); 701 702 // // disabled for now, no reason to sleep 703 // //async_usleep(kbd_dev->hid_dev->poll_interval); 704 // } 705 //} 706 707 /*----------------------------------------------------------------------------*/ 708 /** 709 * Function executed by the main driver fibril. 710 * 711 * Just starts polling the keyboard for events. 712 * 713 * @param arg Initialized keyboard device structure (of type usbhid_kbd_t) 714 * representing the device. 715 * 716 * @retval EOK if the fibril finished polling the device. 717 * @retval EINVAL if no device was given in the argument. 718 * 719 * @sa usbhid_kbd_poll() 720 * 721 * @todo Change return value - only case when the fibril finishes is in case 722 * of some error, so the error should probably be propagated from function 723 * usbhid_kbd_poll() to here and up. 724 */ 725 //static int usbhid_kbd_fibril(void *arg) 726 //{ 727 // if (arg == NULL) { 728 // usb_log_error("No device!\n"); 729 // return EINVAL; 730 // } 731 732 // usbhid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg; 733 734 // usbhid_kbd_poll(kbd_dev); 735 736 // // as there is another fibril using this device, so we must leave the 737 // // structure to it, but mark it for destroying. 738 // usbhid_kbd_mark_unusable(kbd_dev); 739 // // at the end, properly destroy the KBD structure 740 //// usbhid_kbd_free(&kbd_dev); 741 //// assert(kbd_dev == NULL); 742 743 // return EOK; 744 //} 745 746 static int usbhid_dev_get_report_descriptor(usbhid_kbd_t *kbd_dev) 747 { 748 assert(kbd_dev != NULL); 749 assert(kbd_dev->usb_dev != NULL); 750 assert(kbd_dev->usb_dev->interface_no >= 0); 751 752 usb_dp_parser_t parser = { 753 .nesting = usb_dp_standard_descriptor_nesting 754 }; 755 756 usb_dp_parser_data_t parser_data = { 757 .data = kbd_dev->usb_dev->descriptors.configuration, 758 .size = kbd_dev->usb_dev->descriptors.configuration_size, 759 .arg = NULL 760 }; 761 762 /* 763 * First nested descriptor of the configuration descriptor. 764 */ 765 uint8_t *d = 766 usb_dp_get_nested_descriptor(&parser, &parser_data, 767 kbd_dev->usb_dev->descriptors.configuration); 768 769 /* 770 * Find the interface descriptor corresponding to our interface number. 771 */ 772 int i = 0; 773 while (d != NULL && i < kbd_dev->usb_dev->interface_no) { 774 d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 775 kbd_dev->usb_dev->descriptors.configuration, d); 776 } 777 778 if (d == NULL) { 779 usb_log_fatal("The %. interface descriptor not found!\n", 780 kbd_dev->usb_dev->interface_no); 781 return ENOENT; 782 } 783 784 /* 785 * First nested descriptor of the interface descriptor. 786 */ 787 uint8_t *iface_desc = d; 788 d = usb_dp_get_nested_descriptor(&parser, &parser_data, iface_desc); 789 790 /* 791 * Search through siblings until the HID descriptor is found. 792 */ 793 while (d != NULL && *(d + 1) != USB_DESCTYPE_HID) { 794 d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 795 iface_desc, d); 796 } 797 798 if (d == NULL) { 799 usb_log_fatal("No HID descriptor found!\n"); 800 return ENOENT; 801 } 802 803 if (*d != sizeof(usb_standard_hid_descriptor_t)) { 804 usb_log_fatal("HID descriptor hass wrong size (%u, expected %u" 805 ")\n", *d, sizeof(usb_standard_hid_descriptor_t)); 806 return EINVAL; 807 } 808 809 usb_standard_hid_descriptor_t *hid_desc = 810 (usb_standard_hid_descriptor_t *)d; 811 812 uint16_t length = hid_desc->report_desc_info.length; 813 size_t actual_size = 0; 814 815 /* 816 * Start session for the control transfer. 817 */ 818 int sess_rc = usb_pipe_start_session(&kbd_dev->usb_dev->ctrl_pipe); 819 if (sess_rc != EOK) { 820 usb_log_warning("Failed to start a session: %s.\n", 821 str_error(sess_rc)); 822 return sess_rc; 823 } 824 825 /* 826 * Allocate space for the report descriptor. 827 */ 828 kbd_dev->report_desc = (uint8_t *)malloc(length); 829 if (kbd_dev->report_desc == NULL) { 830 usb_log_fatal("Failed to allocate space for Report descriptor." 831 "\n"); 832 return ENOMEM; 833 } 834 835 usb_log_debug("Getting Report descriptor, expected size: %u\n", length); 836 837 /* 838 * Get the descriptor from the device. 839 */ 840 int rc = usb_request_get_descriptor(&kbd_dev->usb_dev->ctrl_pipe, 841 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 842 USB_DESCTYPE_HID_REPORT, 0, kbd_dev->usb_dev->interface_no, 843 kbd_dev->report_desc, length, &actual_size); 844 845 if (rc != EOK) { 846 free(kbd_dev->report_desc); 847 kbd_dev->report_desc = NULL; 848 return rc; 849 } 850 851 if (actual_size != length) { 852 free(kbd_dev->report_desc); 853 kbd_dev->report_desc = NULL; 854 usb_log_fatal("Report descriptor has wrong size (%u, expected " 855 "%u)\n", actual_size, length); 856 return EINVAL; 857 } 858 859 /* 860 * End session for the control transfer. 861 */ 862 sess_rc = usb_pipe_end_session(&kbd_dev->usb_dev->ctrl_pipe); 863 if (sess_rc != EOK) { 864 usb_log_warning("Failed to end a session: %s.\n", 865 str_error(sess_rc)); 866 free(kbd_dev->report_desc); 867 kbd_dev->report_desc = NULL; 868 return sess_rc; 869 } 870 871 kbd_dev->report_desc_size = length; 872 873 usb_log_debug("Done.\n"); 874 875 return EOK; 876 } 877 878 /*----------------------------------------------------------------------------*/ 879 880 static int usbhid_kbd_process_report_descriptor(usbhid_kbd_t *kbd_dev) 881 { 882 int rc = usbhid_dev_get_report_descriptor(kbd_dev); 883 884 if (rc != EOK) { 885 usb_log_warning("Problem with getting Report descriptor: %s.\n", 886 str_error(rc)); 887 return rc; 888 } 889 890 rc = usb_hid_parse_report_descriptor(kbd_dev->parser, 891 kbd_dev->report_desc, kbd_dev->report_desc_size); 892 if (rc != EOK) { 893 usb_log_warning("Problem parsing Report descriptor: %s.\n", 894 str_error(rc)); 895 return rc; 896 } 897 898 usb_hid_descriptor_print(kbd_dev->parser); 899 900 /* 901 * TODO: if failed, try to parse the boot report descriptor. 902 */ 903 904 return EOK; 905 } 583 static void usb_kbd_mark_unusable(usb_kbd_t *kbd_dev) 584 { 585 kbd_dev->initialized = USB_KBD_STATUS_TO_DESTROY; 586 } 587 906 588 907 589 /*----------------------------------------------------------------------------*/ … … 912 594 * 913 595 * The structure returned by this function is not initialized. Use 914 * usb hid_kbd_init() to initialize it prior to polling.596 * usb_kbd_init() to initialize it prior to polling. 915 597 * 916 598 * @return New uninitialized structure for representing a USB/HID keyboard or 917 599 * NULL if not successful (memory error). 918 600 */ 919 usb hid_kbd_t *usbhid_kbd_new(void)920 { 921 usb hid_kbd_t *kbd_dev =922 (usb hid_kbd_t *)malloc(sizeof(usbhid_kbd_t));601 usb_kbd_t *usb_kbd_new(void) 602 { 603 usb_kbd_t *kbd_dev = 604 (usb_kbd_t *)malloc(sizeof(usb_kbd_t)); 923 605 924 606 if (kbd_dev == NULL) { … … 927 609 } 928 610 929 memset(kbd_dev, 0, sizeof(usb hid_kbd_t));611 memset(kbd_dev, 0, sizeof(usb_kbd_t)); 930 612 931 613 kbd_dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof( … … 938 620 939 621 kbd_dev->console_phone = -1; 940 kbd_dev->initialized = USB HID_KBD_STATUS_UNINITIALIZED;622 kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED; 941 623 942 624 return kbd_dev; … … 964 646 * @return Other value inherited from function usbhid_dev_init(). 965 647 */ 966 int usb hid_kbd_init(usbhid_kbd_t *kbd_dev, usb_device_t *dev)648 int usb_kbd_init(usb_kbd_t *kbd_dev, usb_device_t *dev) 967 649 { 968 650 int rc; … … 982 664 } 983 665 984 if (kbd_dev->initialized == USB HID_KBD_STATUS_INITIALIZED) {666 if (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED) { 985 667 usb_log_warning("Keyboard structure already initialized.\n"); 986 668 return EINVAL; … … 996 678 // } 997 679 998 // assert(kbd_dev->hid_dev->initialized == USB HID_KBD_STATUS_INITIALIZED);680 // assert(kbd_dev->hid_dev->initialized == USB_KBD_STATUS_INITIALIZED); 999 681 1000 682 // save the size of the report (boot protocol report by default) … … 1012 694 1013 695 /* Get the report descriptor and parse it. */ 1014 rc = usbhid_kbd_process_report_descriptor(kbd_dev); 696 rc = usb_hid_process_report_descriptor(kbd_dev->usb_dev, 697 kbd_dev->parser); 1015 698 if (rc != EOK) { 1016 usb_log_warning("Could not process report descriptor.\n"); 1017 return rc; 699 usb_log_warning("Could not process report descriptor, " 700 "falling back to boot protocol.\n"); 701 rc = usb_hid_parse_report_descriptor(kbd_dev->parser, 702 BOOT_REPORT_DESCRIPTOR, BOOT_REPORT_DESCRIPTOR_SIZE); 703 if (rc != EOK) { 704 usb_log_error("Failed to parse boot report descriptor:" 705 " %s.\n", str_error(rc)); 706 return rc; 707 } 708 709 rc = usbhid_req_set_protocol(&kbd_dev->usb_dev->ctrl_pipe, 710 kbd_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 711 712 if (rc != EOK) { 713 usb_log_warning("Failed to set boot protocol to the " 714 "device: %s\n", str_error(rc)); 715 return rc; 716 } 1018 717 } 1019 718 … … 1056 755 1057 756 /* 1058 * Set boot protocol.1059 757 * Set LEDs according to initial setup. 1060 758 * Set Idle rate 1061 759 */ 1062 //assert(kbd_dev->hid_dev != NULL); 1063 //assert(kbd_dev->hid_dev->initialized); 1064 //usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT); 1065 1066 usbhid_kbd_set_led(kbd_dev); 760 usb_kbd_set_led(kbd_dev); 1067 761 1068 762 usbhid_req_set_idle(&kbd_dev->usb_dev->ctrl_pipe, 1069 763 kbd_dev->usb_dev->interface_no, IDLE_RATE); 1070 764 1071 kbd_dev->initialized = USB HID_KBD_STATUS_INITIALIZED;765 kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED; 1072 766 usb_log_debug("HID/KBD device structure initialized.\n"); 1073 767 … … 1077 771 /*----------------------------------------------------------------------------*/ 1078 772 1079 bool usb hid_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,773 bool usb_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer, 1080 774 size_t buffer_size, void *arg) 1081 775 { … … 1085 779 } 1086 780 1087 usb hid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg;781 usb_kbd_t *kbd_dev = (usb_kbd_t *)arg; 1088 782 1089 783 // TODO: add return value from this function 1090 usb hid_kbd_process_data(kbd_dev, buffer, buffer_size);784 usb_kbd_process_data(kbd_dev, buffer, buffer_size); 1091 785 1092 786 return true; … … 1095 789 /*----------------------------------------------------------------------------*/ 1096 790 1097 void usb hid_kbd_polling_ended_callback(usb_device_t *dev, bool reason,791 void usb_kbd_polling_ended_callback(usb_device_t *dev, bool reason, 1098 792 void *arg) 1099 793 { … … 1102 796 } 1103 797 1104 usb hid_kbd_t *kbd = (usbhid_kbd_t *)arg;1105 1106 usb hid_kbd_mark_unusable(kbd);1107 } 1108 1109 /*----------------------------------------------------------------------------*/ 1110 1111 int usb hid_kbd_is_initialized(const usbhid_kbd_t *kbd_dev)1112 { 1113 return (kbd_dev->initialized == USB HID_KBD_STATUS_INITIALIZED);1114 } 1115 1116 /*----------------------------------------------------------------------------*/ 1117 1118 int usb hid_kbd_is_ready_to_destroy(const usbhid_kbd_t *kbd_dev)1119 { 1120 return (kbd_dev->initialized == USB HID_KBD_STATUS_TO_DESTROY);798 usb_kbd_t *kbd = (usb_kbd_t *)arg; 799 800 usb_kbd_mark_unusable(kbd); 801 } 802 803 /*----------------------------------------------------------------------------*/ 804 805 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev) 806 { 807 return (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); 808 } 809 810 /*----------------------------------------------------------------------------*/ 811 812 int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev) 813 { 814 return (kbd_dev->initialized == USB_KBD_STATUS_TO_DESTROY); 1121 815 } 1122 816 … … 1127 821 * @param kbd_dev Pointer to the structure to be destroyed. 1128 822 */ 1129 void usb hid_kbd_free(usbhid_kbd_t **kbd_dev)823 void usb_kbd_free(usb_kbd_t **kbd_dev) 1130 824 { 1131 825 if (kbd_dev == NULL || *kbd_dev == NULL) { -
uspace/drv/usbkbd/kbddev.h
r476b71ff r252e30c 34 34 */ 35 35 36 #ifndef USB HID_KBDDEV_H_37 #define USB HID_KBDDEV_H_36 #ifndef USB_KBDDEV_H_ 37 #define USB_KBDDEV_H_ 38 38 39 39 #include <stdint.h> … … 62 62 * being device-specific. 63 63 */ 64 typedef struct usb hid_kbd_t {64 typedef struct usb_kbd_t { 65 65 /** Structure holding generic USB device information. */ 66 66 //usbhid_dev_t *hid_dev; … … 84 84 85 85 /** Information for auto-repeat of keys. */ 86 usb hid_kbd_repeat_t repeat;86 usb_kbd_repeat_t repeat; 87 87 88 88 /** Mutex for accessing the information about auto-repeat. */ … … 105 105 */ 106 106 int initialized; 107 } usb hid_kbd_t;107 } usb_kbd_t; 108 108 109 109 /*----------------------------------------------------------------------------*/ 110 110 111 111 enum { 112 USB HID_KBD_POLL_EP_NO = 0,113 USB HID_KBD_POLL_EP_COUNT = 1112 USB_KBD_POLL_EP_NO = 0, 113 USB_KBD_POLL_EP_COUNT = 1 114 114 }; 115 115 116 usb_endpoint_description_t *usb hid_kbd_endpoints[USBHID_KBD_POLL_EP_COUNT + 1];116 usb_endpoint_description_t *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1]; 117 117 118 118 ddf_dev_ops_t keyboard_ops; … … 120 120 /*----------------------------------------------------------------------------*/ 121 121 122 usb hid_kbd_t *usbhid_kbd_new(void);122 usb_kbd_t *usb_kbd_new(void); 123 123 124 int usb hid_kbd_init(usbhid_kbd_t *kbd_dev, usb_device_t *dev);124 int usb_kbd_init(usb_kbd_t *kbd_dev, usb_device_t *dev); 125 125 126 bool usb hid_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,126 bool usb_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer, 127 127 size_t buffer_size, void *arg); 128 128 129 void usb hid_kbd_polling_ended_callback(usb_device_t *dev, bool reason,129 void usb_kbd_polling_ended_callback(usb_device_t *dev, bool reason, 130 130 void *arg); 131 131 132 int usb hid_kbd_is_initialized(const usbhid_kbd_t *kbd_dev);132 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev); 133 133 134 int usb hid_kbd_is_ready_to_destroy(const usbhid_kbd_t *kbd_dev);134 int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev); 135 135 136 void usb hid_kbd_free(usbhid_kbd_t **kbd_dev);136 void usb_kbd_free(usb_kbd_t **kbd_dev); 137 137 138 void usb hid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key);138 void usb_kbd_push_ev(usb_kbd_t *kbd_dev, int type, unsigned int key); 139 139 140 #endif /* USB HID_KBDDEV_H_ */140 #endif /* USB_KBDDEV_H_ */ 141 141 142 142 /** -
uspace/drv/usbkbd/kbdrepeat.c
r476b71ff r252e30c 62 62 * 63 63 * If the currently repeated key is not pressed any more ( 64 * usb hid_kbd_repeat_stop() was called), it stops repeating it and starts64 * usb_kbd_repeat_stop() was called), it stops repeating it and starts 65 65 * checking again. 66 66 * … … 70 70 * @param kbd Keyboard device structure. 71 71 */ 72 static void usb hid_kbd_repeat_loop(usbhid_kbd_t *kbd)72 static void usb_kbd_repeat_loop(usb_kbd_t *kbd) 73 73 { 74 74 unsigned int delay = 0; … … 78 78 while (true) { 79 79 // check if the kbd structure is usable 80 if (!usb hid_kbd_is_initialized(kbd)) {81 if (usb hid_kbd_is_ready_to_destroy(kbd)) {82 usb hid_kbd_free(&kbd);80 if (!usb_kbd_is_initialized(kbd)) { 81 if (usb_kbd_is_ready_to_destroy(kbd)) { 82 usb_kbd_free(&kbd); 83 83 assert(kbd == NULL); 84 84 } … … 92 92 usb_log_debug2("Repeating key: %u.\n", 93 93 kbd->repeat.key_repeated); 94 usb hid_kbd_push_ev(kbd, KEY_PRESS,94 usb_kbd_push_ev(kbd, KEY_PRESS, 95 95 kbd->repeat.key_repeated); 96 96 delay = kbd->repeat.delay_between; … … 127 127 * @retval EINVAL if no argument is supplied. 128 128 */ 129 int usb hid_kbd_repeat_fibril(void *arg)129 int usb_kbd_repeat_fibril(void *arg) 130 130 { 131 131 usb_log_debug("Autorepeat fibril spawned.\n"); … … 136 136 } 137 137 138 usb hid_kbd_t *kbd = (usbhid_kbd_t *)arg;138 usb_kbd_t *kbd = (usb_kbd_t *)arg; 139 139 140 usb hid_kbd_repeat_loop(kbd);140 usb_kbd_repeat_loop(kbd); 141 141 142 142 return EOK; … … 154 154 * @param key Key to start repeating. 155 155 */ 156 void usb hid_kbd_repeat_start(usbhid_kbd_t *kbd, unsigned int key)156 void usb_kbd_repeat_start(usb_kbd_t *kbd, unsigned int key) 157 157 { 158 158 fibril_mutex_lock(kbd->repeat_mtx); … … 172 172 * @param key Key to stop repeating. 173 173 */ 174 void usb hid_kbd_repeat_stop(usbhid_kbd_t *kbd, unsigned int key)174 void usb_kbd_repeat_stop(usb_kbd_t *kbd, unsigned int key) 175 175 { 176 176 fibril_mutex_lock(kbd->repeat_mtx); -
uspace/drv/usbkbd/kbdrepeat.h
r476b71ff r252e30c 34 34 */ 35 35 36 #ifndef USB HID_KBDREPEAT_H_37 #define USB HID_KBDREPEAT_H_36 #ifndef USB_KBDREPEAT_H_ 37 #define USB_KBDREPEAT_H_ 38 38 39 struct usb hid_kbd_t;39 struct usb_kbd_t; 40 40 41 41 /*----------------------------------------------------------------------------*/ … … 52 52 /** Delay between repeats in microseconds. */ 53 53 unsigned int delay_between; 54 } usb hid_kbd_repeat_t;54 } usb_kbd_repeat_t; 55 55 56 56 /*----------------------------------------------------------------------------*/ 57 57 58 int usb hid_kbd_repeat_fibril(void *arg);58 int usb_kbd_repeat_fibril(void *arg); 59 59 60 void usb hid_kbd_repeat_start(struct usbhid_kbd_t *kbd, unsigned int key);60 void usb_kbd_repeat_start(struct usb_kbd_t *kbd, unsigned int key); 61 61 62 void usb hid_kbd_repeat_stop(struct usbhid_kbd_t *kbd, unsigned int key);62 void usb_kbd_repeat_stop(struct usb_kbd_t *kbd, unsigned int key); 63 63 64 #endif /* USB HID_KBDREPEAT_H_ */64 #endif /* USB_KBDREPEAT_H_ */ 65 65 66 66 /** -
uspace/drv/usbkbd/layout.h
r476b71ff r252e30c 36 36 */ 37 37 38 #ifndef USB HID_LAYOUT_H_39 #define USB HID_LAYOUT_H_38 #ifndef USB_KBD_LAYOUT_H_ 39 #define USB_KBD_LAYOUT_H_ 40 40 41 41 #include <sys/types.h> -
uspace/drv/usbkbd/main.c
r476b71ff r252e30c 70 70 * @retval EOK if successful. 71 71 * @retval ENOMEM if there 72 * @return Other error code inherited from one of functions usb hid_kbd_init(),72 * @return Other error code inherited from one of functions usb_kbd_init(), 73 73 * ddf_fun_bind() and ddf_fun_add_to_class(). 74 74 * 75 * @sa usb hid_kbd_fibril(), usbhid_kbd_repeat_fibril()75 * @sa usb_kbd_fibril(), usb_kbd_repeat_fibril() 76 76 */ 77 77 static int usbhid_try_add_device(usb_device_t *dev) … … 90 90 usb_log_debug("Initializing USB/HID KBD device...\n"); 91 91 92 usb hid_kbd_t *kbd_dev = usbhid_kbd_new();92 usb_kbd_t *kbd_dev = usb_kbd_new(); 93 93 if (kbd_dev == NULL) { 94 94 usb_log_error("Error while creating USB/HID KBD device " … … 98 98 } 99 99 100 int rc = usb hid_kbd_init(kbd_dev, dev);100 int rc = usb_kbd_init(kbd_dev, dev); 101 101 102 102 if (rc != EOK) { 103 103 usb_log_error("Failed to initialize USB/HID KBD device.\n"); 104 104 ddf_fun_destroy(kbd_fun); 105 usb hid_kbd_free(&kbd_dev);105 usb_kbd_free(&kbd_dev); 106 106 return rc; 107 107 } … … 122 122 // TODO: Can / should I destroy the DDF function? 123 123 ddf_fun_destroy(kbd_fun); 124 usb hid_kbd_free(&kbd_dev);124 usb_kbd_free(&kbd_dev); 125 125 return rc; 126 126 } … … 133 133 // TODO: Can / should I destroy the DDF function? 134 134 ddf_fun_destroy(kbd_fun); 135 usb hid_kbd_free(&kbd_dev);135 usb_kbd_free(&kbd_dev); 136 136 return rc; 137 137 } … … 140 140 * Create new fibril for handling this keyboard 141 141 */ 142 //fid_t fid = fibril_create(usb hid_kbd_fibril, kbd_dev);142 //fid_t fid = fibril_create(usb_kbd_fibril, kbd_dev); 143 143 144 144 /* Start automated polling function. … … 148 148 rc = usb_device_auto_poll(dev, 149 149 /* Index of the polling pipe. */ 150 USB HID_KBD_POLL_EP_NO,150 USB_KBD_POLL_EP_NO, 151 151 /* Callback when data arrives. */ 152 usb hid_kbd_polling_callback,152 usb_kbd_polling_callback, 153 153 /* How much data to request. */ 154 dev->pipes[USB HID_KBD_POLL_EP_NO].pipe->max_packet_size,154 dev->pipes[USB_KBD_POLL_EP_NO].pipe->max_packet_size, 155 155 /* Callback when the polling ends. */ 156 usb hid_kbd_polling_ended_callback,156 usb_kbd_polling_ended_callback, 157 157 /* Custom argument. */ 158 158 kbd_dev); … … 169 169 * Create new fibril for auto-repeat 170 170 */ 171 fid_t fid = fibril_create(usb hid_kbd_repeat_fibril, kbd_dev);171 fid_t fid = fibril_create(usb_kbd_repeat_fibril, kbd_dev); 172 172 if (fid == 0) { 173 173 usb_log_error("Failed to start fibril for KBD auto-repeat"); … … 233 233 .name = NAME, 234 234 .ops = &usbhid_driver_ops, 235 .endpoints = usb hid_kbd_endpoints235 .endpoints = usb_kbd_endpoints 236 236 }; 237 237 -
uspace/lib/usb/Makefile
r476b71ff r252e30c 51 51 src/usbdevice.c \ 52 52 src/hidreq.c \ 53 src/hidreport.c \ 53 54 src/host/device_keeper.c \ 54 55 src/host/batch.c -
uspace/lib/usb/include/usb/classes/hidreq.h
r476b71ff r252e30c 27 27 */ 28 28 29 /** @addtogroup drvusbhid29 /** @addtogroup libusb 30 30 * @{ 31 31 */ … … 34 34 */ 35 35 36 #ifndef USB HID_HIDREQ_H_37 #define USB HID_HIDREQ_H_36 #ifndef USB_KBD_HIDREQ_H_ 37 #define USB_KBD_HIDREQ_H_ 38 38 39 39 #include <stdint.h> … … 63 63 /*----------------------------------------------------------------------------*/ 64 64 65 #endif /* USB HID_HIDREQ_H_ */65 #endif /* USB_KBD_HIDREQ_H_ */ 66 66 67 67 /**
Note:
See TracChangeset
for help on using the changeset viewer.