Changeset cc29622 in mainline
- 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
- Location:
- uspace/drv/bus/usb/usbhid
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/generic/hiddev.c
r3002434 rcc29622 92 92 usb_log_debug2("Generic HID: Get event length (fun: %p, " 93 93 "fun->driver_data: %p.\n", fun, fun->driver_data); 94 94 95 95 if (fun == NULL || fun->driver_data == NULL) { 96 96 return 0; … … 98 98 99 99 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 100 100 101 101 usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n", 102 102 hid_dev, hid_dev->max_input_report_size); 103 103 104 104 return hid_dev->max_input_report_size; 105 105 } … … 111 111 { 112 112 usb_log_debug2("Generic HID: Get event.\n"); 113 113 114 114 if (fun == NULL || fun->driver_data == NULL || buffer == NULL 115 115 || act_size == NULL || event_nr == NULL) { … … 119 119 120 120 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 121 121 122 122 if (hid_dev->input_report_size > size) { 123 123 usb_log_debug("input_report_size > size (%zu, %zu)\n", … … 125 125 return EINVAL; // TODO: other error code 126 126 } 127 127 128 128 /*! @todo This should probably be somehow atomic. */ 129 129 memcpy(buffer, hid_dev->input_report, … … 131 131 *act_size = hid_dev->input_report_size; 132 132 *event_nr = usb_hid_report_number(hid_dev); 133 133 134 134 usb_log_debug2("OK\n"); 135 135 136 136 return EOK; 137 137 } … … 142 142 { 143 143 usb_log_debug("Generic HID: Get report descriptor length.\n"); 144 144 145 145 if (fun == NULL || fun->driver_data == NULL) { 146 146 usb_log_debug("No function"); 147 147 return EINVAL; 148 148 } 149 150 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 151 149 150 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 151 152 152 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 153 153 hid_dev->report_desc_size); 154 154 155 155 return hid_dev->report_desc_size; 156 156 } … … 162 162 { 163 163 usb_log_debug2("Generic HID: Get report descriptor.\n"); 164 164 165 165 if (fun == NULL || fun->driver_data == NULL) { 166 166 usb_log_debug("No function"); 167 167 return EINVAL; 168 168 } 169 170 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 171 169 170 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 171 172 172 if (hid_dev->report_desc_size > size) { 173 173 return EINVAL; 174 174 } 175 175 176 176 memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size); 177 177 *actual_size = hid_dev->report_desc_size; 178 178 179 179 return EOK; 180 180 } … … 201 201 return ENOMEM; 202 202 } 203 203 204 204 fun->ops = &usb_generic_hid_ops; 205 205 fun->driver_data = hid_dev; … … 212 212 return rc; 213 213 } 214 214 215 215 usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle); 216 216 217 217 return EOK; 218 218 } … … 225 225 return EINVAL; 226 226 } 227 227 228 228 return usb_generic_hid_create_function(hid_dev); 229 229 } -
uspace/drv/bus/usb/usbhid/kbd/conv.c
r3002434 rcc29622 87 87 [0x26] = KC_9, 88 88 [0x27] = KC_0, 89 89 90 90 [0x28] = KC_ENTER, 91 91 [0x29] = KC_ESCAPE, … … 109 109 110 110 [0x39] = KC_CAPS_LOCK, 111 111 112 112 [0x3a] = KC_F1, 113 113 [0x3b] = KC_F2, … … 122 122 [0x44] = KC_F11, 123 123 [0x45] = KC_F12, 124 124 125 125 [0x46] = KC_PRTSCR, 126 126 [0x47] = KC_SCROLL_LOCK, … … 136 136 [0x51] = KC_DOWN, 137 137 [0x52] = KC_UP, 138 138 139 139 //[0x64] = // some funny key 140 140 141 141 [0xe0] = KC_LCTRL, 142 142 [0xe1] = KC_LSHIFT, … … 147 147 [0xe6] = KC_RALT, 148 148 //[0xe7] = KC_R // TODO: right GUI 149 149 150 150 [0x53] = KC_NUM_LOCK, 151 151 [0x54] = KC_NSLASH, … … 165 165 [0x62] = KC_N0, 166 166 [0x63] = KC_NPERIOD 167 167 168 168 }; 169 169 … … 186 186 187 187 key = map[scancode]; 188 188 189 189 return key; 190 190 } -
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 } -
uspace/drv/bus/usb/usbhid/kbd/kbddev.h
r3002434 rcc29622 75 75 /** Currently pressed modifiers (bitmap). */ 76 76 uint8_t modifiers; 77 77 78 78 /** Currently active modifiers including locks. Sent to the console. */ 79 79 unsigned mods; 80 80 81 81 /** Currently active lock keys. */ 82 82 unsigned lock_keys; 83 83 84 84 /** IPC session to the console device (for sending key events). */ 85 85 async_sess_t *console_sess; 86 86 87 87 /** @todo What is this actually? */ 88 88 ddf_dev_ops_t ops; 89 89 90 90 /** Information for auto-repeat of keys. */ 91 91 usb_kbd_repeat_t repeat; 92 92 93 93 /** Mutex for accessing the information about auto-repeat. */ 94 94 fibril_mutex_t *repeat_mtx; 95 95 96 96 uint8_t *output_buffer; 97 97 98 98 size_t output_size; 99 99 100 100 size_t led_output_size; 101 101 102 102 usb_hid_report_path_t *led_path; 103 103 104 104 int32_t *led_data; 105 105 106 106 /** State of the structure (for checking before use). 107 107 * -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.c
r3002434 rcc29622 73 73 { 74 74 unsigned int delay = 0; 75 75 76 76 usb_log_debug("Starting autorepeat loop.\n"); 77 77 … … 130 130 { 131 131 usb_log_debug("Autorepeat fibril spawned.\n"); 132 132 133 133 if (arg == NULL) { 134 134 usb_log_error("No device!\n"); 135 135 return EINVAL; 136 136 } 137 137 138 138 usb_kbd_t *kbd = (usb_kbd_t *)arg; 139 139 140 140 usb_kbd_repeat_loop(kbd); 141 141 142 142 return EOK; 143 143 } -
uspace/drv/bus/usb/usbhid/main.c
r3002434 rcc29622 76 76 { 77 77 assert(dev != NULL); 78 78 79 79 /* 80 80 * Initialize device (get and process descriptors, get address, etc.) 81 81 */ 82 82 usb_log_debug("Initializing USB/HID device...\n"); 83 83 84 84 usb_hid_dev_t *hid_dev = usb_hid_new(); 85 85 if (hid_dev == NULL) { … … 88 88 return ENOMEM; 89 89 } 90 90 91 91 int rc = usb_hid_init(hid_dev, dev); 92 92 93 93 if (rc != EOK) { 94 94 usb_log_error("Failed to initialize USB/HID device.\n"); … … 96 96 return rc; 97 97 } 98 98 99 99 usb_log_debug("USB/HID device structure initialized.\n"); 100 100 101 101 /* 102 102 * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da … … 109 109 * pouzit usb/classes/hid/iface.h - prvy int je telefon 110 110 */ 111 111 112 112 /* Start automated polling function. 113 113 * This will create a separate fibril that will query the device … … 125 125 /* Custom argument. */ 126 126 hid_dev); 127 128 127 128 129 129 if (rc != EOK) { 130 130 usb_log_error("Failed to start polling fibril for `%s'.\n", … … 153 153 { 154 154 usb_log_debug("usb_hid_device_add()\n"); 155 155 156 156 if (dev == NULL) { 157 157 usb_log_warning("Wrong parameter given for add_device().\n"); 158 158 return EINVAL; 159 159 } 160 160 161 161 if (dev->interface_no < 0) { 162 162 usb_log_warning("Device is not a supported HID device.\n"); … … 165 165 return ENOTSUP; 166 166 } 167 167 168 168 int rc = usb_hid_try_add_device(dev); 169 169 170 170 if (rc != EOK) { 171 171 usb_log_warning("Device is not a supported HID device.\n"); … … 174 174 return rc; 175 175 } 176 176 177 177 usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name); 178 178 -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r3002434 rcc29622 124 124 { 125 125 usb_mouse_t *mouse_dev = (usb_mouse_t *) fun->driver_data; 126 126 127 127 if (mouse_dev == NULL) { 128 128 usb_log_debug("default_connection_handler: Missing " … … 131 131 return; 132 132 } 133 133 134 134 usb_log_debug("default_connection_handler: fun->name: %s\n", 135 135 fun->name); 136 136 usb_log_debug("default_connection_handler: mouse_sess: %p, " 137 137 "wheel_sess: %p\n", mouse_dev->mouse_sess, mouse_dev->wheel_sess); 138 138 139 139 async_sess_t **sess_ptr = 140 140 (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) ? 141 141 &mouse_dev->mouse_sess : &mouse_dev->wheel_sess; 142 142 143 143 async_sess_t *sess = 144 144 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); … … 170 170 mouse->mouse_sess = NULL; 171 171 mouse->wheel_sess = NULL; 172 172 173 173 return mouse; 174 174 } … … 179 179 { 180 180 assert(mouse_dev != NULL); 181 181 182 182 // hangup session to the console 183 183 if (mouse_dev->mouse_sess != NULL) 184 184 async_hangup(mouse_dev->mouse_sess); 185 185 186 186 if (mouse_dev->wheel_sess != NULL) 187 187 async_hangup(mouse_dev->wheel_sess); … … 199 199 return; 200 200 } 201 201 202 202 int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 203 203 int i; 204 204 205 205 for (i = 0; i < count; i++) { 206 206 /* Send arrow press and release. */ … … 246 246 { 247 247 assert(mouse_dev != NULL); 248 248 249 249 if (mouse_dev->mouse_sess == NULL) { 250 250 usb_log_warning(NAME " No console session.\n"); … … 264 264 async_exchange_end(exch); 265 265 } 266 266 267 267 if (wheel != 0) 268 268 usb_mouse_send_wheel(mouse_dev, wheel); 269 269 270 270 /* 271 271 * Buttons … … 274 274 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 275 275 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 276 276 277 277 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 278 278 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END … … 309 309 USB_HID_REPORT_TYPE_INPUT); 310 310 } 311 311 312 312 usb_hid_report_path_free(path); 313 313 … … 321 321 assert(hid_dev != NULL); 322 322 assert(mouse != NULL); 323 323 324 324 /* Create the exposed function. */ 325 325 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); … … 330 330 return ENOMEM; 331 331 } 332 332 333 333 fun->ops = &mouse->ops; 334 334 fun->driver_data = mouse; … … 341 341 return rc; 342 342 } 343 343 344 344 usb_log_debug("Adding DDF function to category %s...\n", 345 345 HID_MOUSE_CATEGORY); … … 352 352 return rc; 353 353 } 354 354 355 355 /* 356 356 * Special function for acting as keyboard (wheel) … … 364 364 return ENOMEM; 365 365 } 366 366 367 367 /* 368 368 * Store the initialized HID device and HID ops … … 379 379 return rc; 380 380 } 381 381 382 382 usb_log_debug("Adding DDF function to category %s...\n", 383 383 HID_MOUSE_WHEEL_CATEGORY); … … 390 390 return rc; 391 391 } 392 392 393 393 return EOK; 394 394 } … … 441 441 { 442 442 usb_log_debug("Initializing HID/Mouse structure...\n"); 443 443 444 444 if (hid_dev == NULL) { 445 445 usb_log_error("Failed to init keyboard structure: no structure" … … 447 447 return EINVAL; 448 448 } 449 449 450 450 usb_mouse_t *mouse_dev = usb_mouse_new(); 451 451 if (mouse_dev == NULL) { … … 454 454 return ENOMEM; 455 455 } 456 456 457 457 // FIXME: This may not be optimal since stupid hardware vendor may 458 458 // use buttons 1, 2, 3 and 6000 and we would allocate array of … … 464 464 hid_dev->report_id) + 1; 465 465 mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t)); 466 466 467 467 if (mouse_dev->buttons == NULL) { 468 468 usb_log_error(NAME ": out of memory, giving up on device!\n"); … … 474 474 // save the Mouse device structure into the HID device structure 475 475 *data = mouse_dev; 476 476 477 477 // set handler for incoming calls 478 478 mouse_dev->ops.default_handler = default_connection_handler; 479 479 480 480 // TODO: how to know if the device supports the request??? 481 481 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 482 482 hid_dev->usb_dev->interface_no, IDLE_RATE); 483 483 484 484 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 485 485 if (rc != EOK) { … … 487 487 return rc; 488 488 } 489 489 490 490 return EOK; 491 491 } … … 500 500 return false; 501 501 } 502 502 503 503 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 504 504 … … 522 522 USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 523 523 USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE); 524 524 525 525 if (rc != EOK) { 526 526 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 528 528 return rc; 529 529 } 530 530 531 531 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 532 532 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 533 533 534 534 if (rc != EOK) { 535 535 usb_log_warning("Failed to set boot protocol to the device: " … … 537 537 return rc; 538 538 } 539 539 540 540 return EOK; 541 541 } -
uspace/drv/bus/usb/usbhid/mouse/mousedev.h
r3002434 rcc29622 49 49 async_sess_t *mouse_sess; 50 50 async_sess_t *wheel_sess; 51 51 52 52 /* Mouse buttons statuses. */ 53 53 int32_t *buttons; 54 54 size_t buttons_count; 55 55 56 56 ddf_dev_ops_t ops; 57 57 } usb_mouse_t; -
uspace/drv/bus/usb/usbhid/subdrivers.h
r3002434 rcc29622 64 64 */ 65 65 const usb_hid_subdriver_usage_t *usage_path; 66 66 67 67 /** Report ID for which the path should apply. */ 68 68 int report_id; 69 69 70 70 /** Compare type for the Usage path. */ 71 71 int compare; 72 72 73 73 /** Vendor ID (set to -1 if not specified). */ 74 74 int vendor_id; 75 75 76 76 /** Product ID (set to -1 if not specified). */ 77 77 int product_id; 78 78 79 79 /** Subdriver for controlling this device. */ 80 80 usb_hid_subdriver_t subdriver; -
uspace/drv/bus/usb/usbhid/usbhid.c
r3002434 rcc29622 68 68 { 69 69 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 70 70 71 71 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 72 72 sizeof(usb_hid_subdriver_t)); … … 74 74 return ENOMEM; 75 75 } 76 76 77 77 assert(hid_dev->subdriver_count >= 0); 78 78 79 79 // set the init callback 80 80 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init; 81 81 82 82 // set the polling callback 83 83 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 84 84 usb_kbd_polling_callback; 85 85 86 86 // set the polling ended callback 87 87 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 88 88 89 89 // set the deinit callback 90 90 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit; 91 91 92 92 // set subdriver count 93 93 ++hid_dev->subdriver_count; 94 94 95 95 return EOK; 96 96 } … … 101 101 { 102 102 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 103 103 104 104 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 105 105 sizeof(usb_hid_subdriver_t)); … … 107 107 return ENOMEM; 108 108 } 109 109 110 110 assert(hid_dev->subdriver_count >= 0); 111 111 112 112 // set the init callback 113 113 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init; 114 114 115 115 // set the polling callback 116 116 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 117 117 usb_mouse_polling_callback; 118 118 119 119 // set the polling ended callback 120 120 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 121 121 122 122 // set the deinit callback 123 123 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit; 124 124 125 125 // set subdriver count 126 126 ++hid_dev->subdriver_count; 127 127 128 128 return EOK; 129 129 } … … 134 134 { 135 135 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 136 136 137 137 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 138 138 sizeof(usb_hid_subdriver_t)); … … 140 140 return ENOMEM; 141 141 } 142 142 143 143 assert(hid_dev->subdriver_count >= 0); 144 144 145 145 // set the init callback 146 146 hid_dev->subdrivers[hid_dev->subdriver_count].init = 147 147 usb_generic_hid_init; 148 148 149 149 // set the polling callback 150 150 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 151 151 usb_generic_hid_polling_callback; 152 152 153 153 // set the polling ended callback 154 154 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 155 155 156 156 // set the deinit callback 157 157 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = NULL; 158 158 159 159 // set subdriver count 160 160 ++hid_dev->subdriver_count; 161 161 162 162 return EOK; 163 163 } … … 170 170 assert(hid_dev != NULL); 171 171 assert(hid_dev->usb_dev != NULL); 172 172 173 173 return (hid_dev->usb_dev->descriptors.device.vendor_id 174 174 == mapping->vendor_id … … 184 184 assert(hid_dev != NULL); 185 185 assert(mapping != NULL); 186 186 187 187 usb_hid_report_path_t *usage_path = usb_hid_report_path(); 188 188 if (usage_path == NULL) { … … 202 202 ++i; 203 203 } 204 204 205 205 assert(hid_dev->report != NULL); 206 206 207 207 usb_log_debug("Compare flags: %d\n", mapping->compare); 208 208 209 209 bool matches = false; 210 210 uint8_t report_id = mapping->report_id; … … 234 234 USB_HID_REPORT_TYPE_INPUT); 235 235 } while (!matches && report_id != 0); 236 236 237 237 usb_hid_report_path_free(usage_path); 238 238 239 239 return matches; 240 240 } … … 246 246 { 247 247 int i; 248 248 249 249 if (count <= 0) { 250 250 hid_dev->subdriver_count = 0; … … 252 252 return EOK; 253 253 } 254 254 255 255 // add one generic HID subdriver per device 256 256 257 257 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 258 258 sizeof(usb_hid_subdriver_t)); … … 260 260 return ENOMEM; 261 261 } 262 262 263 263 for (i = 0; i < count; ++i) { 264 264 hid_dev->subdrivers[i].init = subdrivers[i]->init; … … 267 267 hid_dev->subdrivers[i].poll_end = subdrivers[i]->poll_end; 268 268 } 269 269 270 270 hid_dev->subdrivers[count].init = usb_generic_hid_init; 271 271 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; 272 272 hid_dev->subdrivers[count].deinit = NULL; 273 273 hid_dev->subdrivers[count].poll_end = NULL; 274 274 275 275 hid_dev->subdriver_count = count + 1; 276 276 277 277 return EOK; 278 278 } … … 283 283 { 284 284 assert(hid_dev != NULL); 285 285 286 286 const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS]; 287 287 288 288 int i = 0, count = 0; 289 289 const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i]; … … 291 291 bool ids_matched; 292 292 bool matched; 293 293 294 294 while (count < USB_HID_MAX_SUBDRIVERS && 295 295 (mapping->usage_path != NULL … … 339 339 mapping = &usb_hid_subdrivers[++i]; 340 340 } 341 341 342 342 // we have all subdrivers determined, save them into the hid device 343 343 return usb_hid_save_subdrivers(hid_dev, subdrivers, count); … … 349 349 { 350 350 assert(hid_dev != NULL && dev != NULL); 351 351 352 352 int rc = EOK; 353 353 354 354 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) { 355 355 usb_log_debug("Found keyboard endpoint.\n"); … … 369 369 rc = ENOTSUP; 370 370 } 371 371 372 372 return rc; 373 373 } … … 378 378 { 379 379 assert(hid_dev != NULL && hid_dev->report != NULL); 380 380 381 381 uint8_t report_id = 0; 382 382 size_t size; 383 383 384 384 size_t max_size = 0; 385 385 386 386 do { 387 387 usb_log_debug("Getting size of the report.\n"); … … 394 394 report_id, USB_HID_REPORT_TYPE_INPUT); 395 395 } while (report_id != 0); 396 396 397 397 usb_log_debug("Max size of input report: %zu\n", max_size); 398 398 399 399 hid_dev->max_input_report_size = max_size; 400 400 assert(hid_dev->input_report == NULL); 401 401 402 402 hid_dev->input_report = malloc(max_size); 403 403 if (hid_dev->input_report == NULL) { … … 405 405 } 406 406 memset(hid_dev->input_report, 0, max_size); 407 407 408 408 return EOK; 409 409 } … … 415 415 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)calloc(1, 416 416 sizeof(usb_hid_dev_t)); 417 417 418 418 if (hid_dev == NULL) { 419 419 usb_log_fatal("No memory!\n"); 420 420 return NULL; 421 421 } 422 422 423 423 hid_dev->report = (usb_hid_report_t *)(malloc(sizeof( 424 424 usb_hid_report_t))); … … 428 428 return NULL; 429 429 } 430 430 431 431 hid_dev->poll_pipe_index = -1; 432 432 433 433 return hid_dev; 434 434 } … … 439 439 { 440 440 int rc, i; 441 441 442 442 usb_log_debug("Initializing HID structure...\n"); 443 443 444 444 if (hid_dev == NULL) { 445 445 usb_log_error("Failed to init HID structure: no structure given" … … 447 447 return EINVAL; 448 448 } 449 449 450 450 if (dev == NULL) { 451 451 usb_log_error("Failed to init HID structure: no USB device" … … 453 453 return EINVAL; 454 454 } 455 455 456 456 /* The USB device should already be initialized, save it in structure */ 457 457 hid_dev->usb_dev = dev; 458 458 459 459 rc = usb_hid_check_pipes(hid_dev, dev); 460 460 if (rc != EOK) { … … 465 465 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 466 466 hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size); 467 467 468 468 bool fallback = false; 469 469 470 470 if (rc == EOK) { 471 471 // try to find subdrivers that may want to handle this device … … 484 484 fallback = true; 485 485 } 486 486 487 487 if (fallback) { 488 488 // fall back to boot protocol … … 510 510 } 511 511 } 512 512 513 513 if (rc != EOK) { 514 514 usb_log_error("No subdriver for handling this device could be" … … 542 542 rc = (ok) ? EOK : -1; // what error to report 543 543 } 544 545 544 545 546 546 if (rc == EOK) { 547 547 // save max input report size and allocate space for the report … … 552 552 } 553 553 } 554 555 554 555 556 556 return rc; 557 557 } … … 563 563 { 564 564 int i; 565 565 566 566 if (dev == NULL || arg == NULL || buffer == NULL) { 567 567 usb_log_error("Missing arguments to polling callback.\n"); 568 568 return false; 569 569 } 570 570 571 571 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 572 572 573 573 assert(hid_dev->input_report != NULL); 574 574 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size, … … 582 582 usb_hid_new_report(hid_dev); 583 583 } 584 584 585 585 // parse the input report 586 586 587 587 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 588 588 &hid_dev->report_id); 589 589 590 590 if (rc != EOK) { 591 591 usb_log_warning("Error in usb_hid_parse_report():" 592 592 "%s\n", str_error(rc)); 593 593 } 594 594 595 595 bool cont = false; 596 596 597 597 // continue if at least one of the subdrivers want to continue 598 598 for (i = 0; i < hid_dev->subdriver_count; ++i) { … … 603 603 } 604 604 } 605 605 606 606 return cont; 607 607 } … … 613 613 { 614 614 int i; 615 615 616 616 if (dev == NULL || arg == NULL) { 617 617 return; 618 618 } 619 619 620 620 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 621 621 622 622 for (i = 0; i < hid_dev->subdriver_count; ++i) { 623 623 if (hid_dev->subdrivers[i].poll_end != NULL) { … … 626 626 } 627 627 } 628 628 629 629 usb_hid_destroy(hid_dev); 630 630 } … … 649 649 { 650 650 int i; 651 651 652 652 if (hid_dev == NULL) { 653 653 return; 654 654 } 655 655 656 656 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 657 657 hid_dev->subdrivers, hid_dev->subdriver_count); 658 658 659 659 assert(hid_dev->subdrivers != NULL 660 660 || hid_dev->subdriver_count == 0); 661 661 662 662 for (i = 0; i < hid_dev->subdriver_count; ++i) { 663 663 if (hid_dev->subdrivers[i].deinit != NULL) { … … 666 666 } 667 667 } 668 668 669 669 // free the subdrivers info 670 670 if (hid_dev->subdrivers != NULL) { -
uspace/drv/bus/usb/usbhid/usbhid.h
r3002434 rcc29622 102 102 /** Structure holding generic USB device information. */ 103 103 usb_device_t *usb_dev; 104 104 105 105 /** Index of the polling pipe in usb_hid_endpoints array. */ 106 106 int poll_pipe_index; 107 107 108 108 /** Subdrivers. */ 109 109 usb_hid_subdriver_t *subdrivers; 110 110 111 111 /** Number of subdrivers. */ 112 112 int subdriver_count; 113 113 114 114 /** Report descriptor. */ 115 115 uint8_t *report_desc; … … 117 117 /** Report descriptor size. */ 118 118 size_t report_desc_size; 119 119 120 120 /** HID Report parser. */ 121 121 usb_hid_report_t *report; 122 122 123 123 uint8_t report_id; 124 124 125 125 uint8_t *input_report; 126 126 127 127 size_t input_report_size; 128 128 size_t max_input_report_size; 129 129 130 130 int report_nr; 131 131 };
Note:
See TracChangeset
for help on using the changeset viewer.