Changes in / [173922f:8c74d15] in mainline
- Location:
- uspace/drv/usbhid
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/generic/hiddev.c
r173922f r8c74d15 126 126 } 127 127 128 /*! @todo This should probably be somehow atomic. */ 128 /*! @todo This should probably be atomic. */ 129 // if (usb_hid_report_ready()) { 130 // usb_log_debug2("Report ready, size: %zu\n", 131 // hid_dev->input_report_size); 132 133 // usb_hid_report_received(); 134 // } else { 135 // memset(buffer, 0, hid_dev->input_report_size); 136 // } 129 137 memcpy(buffer, hid_dev->input_report, 130 138 hid_dev->input_report_size); … … 132 140 *event_nr = usb_hid_report_number(hid_dev); 133 141 142 // clear the buffer so that it will not be received twice 143 //memset(hid_dev->input_report, 0, hid_dev->input_report_size); 144 145 // note that we already received this report 146 // report_received = true; 134 147 usb_log_debug2("OK\n"); 135 148 … … 171 184 172 185 if (hid_dev->report_desc_size > size) { 173 return EINVAL; 186 return EINVAL; // TODO: other error code 174 187 } 175 188 -
uspace/drv/usbhid/kbd/kbddev.c
r173922f r8c74d15 72 72 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 73 73 74 ///** Boot protocol report size (key part). */ 75 //static const size_t BOOTP_REPORT_SIZE = 6; 76 77 ///** Boot protocol total report size. */ 78 //static const size_t BOOTP_BUFFER_SIZE = 8; 79 80 ///** Boot protocol output report size. */ 81 //static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 82 83 ///** Boot protocol error key code. */ 84 //static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 74 85 static const uint8_t ERROR_ROLLOVER = 1; 75 86 … … 94 105 .flags = 0 95 106 }; 107 108 //static usb_endpoint_description_t hid_poll_endpoint_description = { 109 // .transfer_type = USB_TRANSFER_INTERRUPT, 110 // .direction = USB_DIRECTION_IN, 111 // .interface_class = USB_CLASS_HID, 112 // .flags = 0 113 //}; 114 115 ///* Array of endpoints expected on the device, NULL terminated. */ 116 //usb_endpoint_description_t 117 // *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1] = { 118 // &boot_poll_endpoint_description, 119 // &hid_poll_endpoint_description, 120 // NULL 121 //}; 96 122 97 123 const char *HID_KBD_FUN_NAME = "keyboard"; … … 150 176 151 177 /*----------------------------------------------------------------------------*/ 178 179 //static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 180 // uint8_t report_id, void *arg); 181 182 //static const usb_hid_report_in_callbacks_t usb_kbd_parser_callbacks = { 183 // .keyboard = usb_kbd_process_keycodes 184 //}; 185 186 /*----------------------------------------------------------------------------*/ 152 187 /* Keyboard layouts */ 153 188 /*----------------------------------------------------------------------------*/ … … 165 200 166 201 /*----------------------------------------------------------------------------*/ 202 /* Modifier constants */ 203 /*----------------------------------------------------------------------------*/ 204 /** Mapping of USB modifier key codes to generic modifier key codes. */ 205 //static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = { 206 // KC_LCTRL, /* USB_HID_MOD_LCTRL */ 207 // KC_LSHIFT, /* USB_HID_MOD_LSHIFT */ 208 // KC_LALT, /* USB_HID_MOD_LALT */ 209 // 0, /* USB_HID_MOD_LGUI */ 210 // KC_RCTRL, /* USB_HID_MOD_RCTRL */ 211 // KC_RSHIFT, /* USB_HID_MOD_RSHIFT */ 212 // KC_RALT, /* USB_HID_MOD_RALT */ 213 // 0, /* USB_HID_MOD_RGUI */ 214 //}; 215 216 //typedef enum usbhid_lock_code { 217 // USB_KBD_LOCK_NUM = 0x53, 218 // USB_KBD_LOCK_CAPS = 0x39, 219 // USB_KBD_LOCK_SCROLL = 0x47, 220 // USB_KBD_LOCK_COUNT = 3 221 //} usbhid_lock_code; 222 223 //static const usbhid_lock_code usbhid_lock_codes[USB_KBD_LOCK_COUNT] = { 224 // USB_KBD_LOCK_NUM, 225 // USB_KBD_LOCK_CAPS, 226 // USB_KBD_LOCK_SCROLL 227 //}; 228 229 /*----------------------------------------------------------------------------*/ 167 230 /* IPC method handler */ 168 231 /*----------------------------------------------------------------------------*/ 169 232 170 233 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 234 //ddf_dev_ops_t keyboard_ops = { 235 // .default_handler = default_connection_handler 236 //}; 171 237 172 238 /** … … 235 301 return; 236 302 } 237 303 238 304 /* Reset the LED data. */ 239 305 memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t)); … … 429 495 */ 430 496 static void usb_kbd_check_key_changes(usb_hid_dev_t *hid_dev, 431 usb_kbd_t *kbd_dev )497 usb_kbd_t *kbd_dev/*, const uint8_t *key_codes, size_t count*/) 432 498 { 433 499 unsigned int key; … … 501 567 } 502 568 569 // usb_log_debug("Old keys: "); 570 // for (i = 0; i < kbd_dev->key_count; ++i) { 571 // usb_log_debug("%d ", kbd_dev->keys_old[i]); 572 // } 573 // usb_log_debug("\n"); 574 575 576 // usb_log_debug("New keys: "); 577 // for (i = 0; i < kbd_dev->key_count; ++i) { 578 // usb_log_debug("%d ", kbd_dev->keys[i]); 579 // } 580 // usb_log_debug("\n"); 581 503 582 memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4); 504 583 … … 511 590 512 591 /*----------------------------------------------------------------------------*/ 592 /* Callbacks for parser */ 593 /*----------------------------------------------------------------------------*/ 594 /** 595 * Callback function for the HID report parser. 596 * 597 * This function is called by the HID report parser with the parsed report. 598 * The parsed report is used to check if any events occured (key was pressed or 599 * released, modifier was pressed or released). 600 * 601 * @param key_codes Parsed keyboard report - codes of currently pressed keys 602 * according to HID Usage Tables. 603 * @param count Number of key codes in report (size of the report). 604 * @param report_id 605 * @param arg User-specified argument. Expects pointer to the keyboard device 606 * structure representing the keyboard. 607 * 608 * @sa usb_kbd_check_key_changes(), usb_kbd_check_modifier_changes() 609 */ 610 //static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 611 // uint8_t report_id, void *arg) 612 //{ 613 // if (arg == NULL) { 614 // usb_log_warning("Missing argument in callback " 615 // "usbhid_process_keycodes().\n"); 616 // return; 617 // } 618 619 // usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 620 621 // if (hid_dev->data == NULL) { 622 // usb_log_warning("Missing KBD device structure in callback.\n"); 623 // return; 624 // } 625 626 // usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 627 628 // usb_log_debug("Got keys from parser (report id: %u): %s\n", 629 // report_id, usb_debug_str_buffer(key_codes, count, 0)); 630 631 // if (count != kbd_dev->key_count) { 632 // usb_log_warning("Number of received keycodes (%zu) differs from" 633 // " expected (%zu).\n", count, kbd_dev->key_count); 634 // return; 635 // } 636 637 // ///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count); 638 // usb_kbd_check_key_changes(hid_dev, kbd_dev, key_codes, count); 639 //} 640 641 /*----------------------------------------------------------------------------*/ 513 642 /* General kbd functions */ 514 643 /*----------------------------------------------------------------------------*/ … … 539 668 "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0)); 540 669 670 // int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 671 // callbacks, kbd_dev); 541 672 usb_hid_report_path_t *path = usb_hid_report_path(); 542 673 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 674 //usb_hid_report_path_set_report_id(path, 0); 543 675 544 676 uint8_t report_id; … … 566 698 567 699 assert(i < kbd_dev->key_count); 700 // if (i == kbd_dev->key_count) { 701 // break; 702 // } 568 703 569 704 // save the key usage 705 /* TODO: maybe it's not good to save value, nor usage 706 * as the value may be e.g. 1 for LEDs and usage may be 707 * value of the LED. On the other hand, in case of normal 708 * keys, the usage is more important and we must check 709 * that. One possible solution: distinguish between those 710 * two parts of the Report somehow. 711 */ 570 712 if (field->value != 0) { 571 713 kbd_dev->keys[i] = field->usage; … … 754 896 usb_log_warning("Error creating output report buffer.\n"); 755 897 free(kbd_dev->keys); 756 return ENOMEM; 898 return ENOMEM; /* TODO: other error code */ 757 899 } 758 900 … … 809 951 810 952 // save the KBD device structure into the HID device structure 953 //hid_dev->data = kbd_dev; 811 954 *data = kbd_dev; 812 955 … … 895 1038 896 1039 if ((*kbd_dev)->repeat_mtx != NULL) { 897 / /assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));898 while (fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)) {}1040 /* TODO: replace by some check and wait */ 1041 assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); 899 1042 free((*kbd_dev)->repeat_mtx); 900 1043 } -
uspace/drv/usbhid/kbd/main.c
r173922f r8c74d15 131 131 "Could not add DDF function to class 'keyboard': %s.\n", 132 132 str_error(rc)); 133 // TODO: Can / should I destroy the DDF function? 133 134 ddf_fun_destroy(kbd_fun); 134 135 usb_kbd_free(&kbd_dev); 135 136 return rc; 136 137 } 138 139 /* 140 * Create new fibril for handling this keyboard 141 */ 142 //fid_t fid = fibril_create(usb_kbd_fibril, kbd_dev); 137 143 138 144 /* Start automated polling function. … … 158 164 return rc; 159 165 } 166 //fibril_add_ready(fid); 160 167 161 168 /* -
uspace/drv/usbhid/mouse/mousedev.c
r173922f r8c74d15 394 394 395 395 fun->ops = &mouse->ops; 396 fun->driver_data = mouse; 396 fun->driver_data = mouse; // TODO: maybe change to hid_dev->data 397 397 398 398 int rc = ddf_fun_bind(fun); … … 432 432 */ 433 433 fun->ops = &mouse->ops; 434 fun->driver_data = mouse; 434 fun->driver_data = mouse; // TODO: maybe change to hid_dev->data 435 435 436 436 rc = ddf_fun_bind(fun); … … 488 488 489 489 // set handler for incoming calls 490 // TODO: must be one for each subdriver!! 490 491 mouse_dev->ops.default_handler = default_connection_handler; 491 492 492 493 // TODO: how to know if the device supports the request??? 493 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,494 hid_dev->usb_dev->interface_no, IDLE_RATE);494 // usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 495 // hid_dev->usb_dev->interface_no, IDLE_RATE); 495 496 496 497 int rc = usb_mouse_create_function(hid_dev, mouse_dev); -
uspace/drv/usbhid/mouse/mousedev.h
r173922f r8c74d15 45 45 /** Container for USB mouse device. */ 46 46 typedef struct { 47 ///** Polling interval in microseconds. */ 48 //suseconds_t poll_interval_us; 47 49 /** IPC phone to console (consumer). */ 48 50 int mouse_phone; -
uspace/drv/usbhid/multimedia/multimedia.c
r173922f r8c74d15 143 143 assert(multim_dev != NULL); 144 144 145 // usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data; 146 145 147 console_event_t ev; 146 148 … … 171 173 // hangup phone to the console 172 174 async_hangup((*multim_dev)->console_phone); 175 176 // free all buffers 177 // if ((*multim_dev)->keys != NULL) { 178 // free((*multim_dev)->keys); 179 // } 180 // if ((*multim_dev)->keys_old != NULL) { 181 // free((*multim_dev)->keys_old); 182 // } 173 183 174 184 free(*multim_dev); … … 235 245 multim_dev->console_phone = -1; 236 246 247 // usb_hid_report_path_t *path = usb_hid_report_path(); 248 // usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); 249 250 // usb_hid_report_path_set_report_id(path, 1); 251 252 // multim_dev->key_count = usb_hid_report_size( 253 // hid_dev->report, 1, USB_HID_REPORT_TYPE_INPUT); 254 255 // usb_hid_report_path_free(path); 256 257 // usb_log_debug(NAME " Size of the input report: %zu\n", 258 // multim_dev->key_count); 259 260 // multim_dev->keys = (int32_t *)calloc(multim_dev->key_count, 261 // sizeof(int32_t)); 262 263 // if (multim_dev->keys == NULL) { 264 // usb_log_fatal("No memory!\n"); 265 // free(multim_dev); 266 // return ENOMEM; 267 // } 268 269 // multim_dev->keys_old = 270 // (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t)); 271 272 // if (multim_dev->keys_old == NULL) { 273 // usb_log_fatal("No memory!\n"); 274 // free(multim_dev->keys); 275 // free(multim_dev); 276 // return ENOMEM; 277 // } 278 237 279 /*! @todo Autorepeat */ 238 280 … … 273 315 { 274 316 // TODO: checks 275 if (hid_dev == NULL || data == NULL || buffer == NULL) {276 return false;277 }278 317 279 318 usb_log_debug(NAME " usb_lgtch_polling_callback(%p, %p, %zu)\n", 280 319 hid_dev, buffer, buffer_size); 320 321 if (data == NULL) { 322 return EINVAL; // TODO: other error code? 323 } 281 324 282 325 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; … … 305 348 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 306 349 USB_HID_REPORT_TYPE_INPUT); 307 350 351 // unsigned int key; 352 308 353 /*! @todo Is this iterating OK if done multiple times? 309 354 * @todo The parsing is not OK -
uspace/drv/usbhid/subdrivers.c
r173922f r8c74d15 58 58 }; 59 59 60 //static usb_hid_subdriver_usage_t generic_hid_key_path[] = { 61 // {0, 0} 62 //}; 63 60 64 const usb_hid_subdriver_mapping_t usb_hid_subdrivers[] = { 61 65 { … … 99 103 } 100 104 }, 105 // { 106 // generic_hid_key_path, 107 // 0, 108 // USB_HID_PATH_COMPARE_ANYWHERE, 109 // -1, 110 // -1, 111 // { 112 // .init = usb_generic_hid_init, 113 // .deinit = NULL, 114 // .poll = usb_generic_hid_polling_callback, 115 // .poll_end = NULL 116 // } 117 // }, 101 118 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL, NULL}} 102 119 }; -
uspace/drv/usbhid/usbhid.c
r173922f r8c74d15 63 63 static const int USB_HID_MAX_SUBDRIVERS = 10; 64 64 65 /** @todo What happens if this is not fibril local? */ 66 //static fibril_local bool report_number; 67 65 68 /*----------------------------------------------------------------------------*/ 66 69 … … 203 206 } 204 207 208 // if (mapping->report_id >= 0) { 209 // usb_hid_report_path_set_report_id(usage_path, 210 // mapping->report_id); 211 // } 212 205 213 assert(hid_dev->report != NULL); 206 214 207 215 usb_log_debug("Compare flags: %d\n", mapping->compare); 216 // size_t size = usb_hid_report_size(hid_dev->report, 0, 217 // USB_HID_REPORT_TYPE_INPUT); 218 // size_t size = 0; 208 219 209 220 bool matches = false; 221 222 // usb_hid_report_description_t *report_des = 223 // usb_hid_report_find_description(hid_dev->report, 224 // mapping->report_id, USB_HID_REPORT_TYPE_INPUT); 210 225 uint8_t report_id = mapping->report_id; 211 226 212 do { 227 /*while(report_des != NULL)*/do { 228 229 // if((mapping->report_id) == 0 && (report_des->report_id != 0)) { 230 // usb_hid_report_path_set_report_id(usage_path, 231 // report_des->report_id); 232 // } 233 213 234 usb_log_debug("Trying report id %u\n", report_id); 214 235 … … 226 247 227 248 if (field != NULL) { 249 // size++; 250 // field = usb_hid_report_get_sibling(hid_dev->report, 251 // field, usage_path, mapping->compare, 252 // USB_HID_REPORT_TYPE_INPUT); 228 253 matches = true; 229 254 break; … … 233 258 hid_dev->report, report_id, 234 259 USB_HID_REPORT_TYPE_INPUT); 260 261 // if((mapping->report_id == 0) && (report_des->report_id != 0)) { 262 // uint8_t report_id = usb_hid_get_next_report_id( 263 // hid_dev->report, report_des->report_id, 264 // USB_HID_REPORT_TYPE_INPUT); 265 266 // if(report_id == 0) { 267 // break; 268 // } 269 270 // report_des = usb_hid_report_find_description( 271 // hid_dev->report, report_id, 272 // USB_HID_REPORT_TYPE_INPUT); 273 // } 274 // else { 275 // break; 276 // } 235 277 } while (!matches && report_id != 0); 236 278 279 // usb_log_debug("Size of the input report: %zu\n", size); 237 280 usb_hid_report_path_free(usage_path); 238 281 … … 380 423 381 424 uint8_t report_id = 0; 382 size_t size; 425 size_t size;/* = usb_hid_report_byte_size(hid_dev->report, report_id, 426 USB_HID_REPORT_TYPE_INPUT);*/ 383 427 384 428 size_t max_size = 0; … … 459 503 rc = usb_hid_check_pipes(hid_dev, dev); 460 504 if (rc != EOK) { 505 //usb_hid_free(&hid_dev); 461 506 return rc; 462 507 } … … 506 551 == USB_HID_GENERIC_POLL_EP_NO); 507 552 553 /* TODO: this has no meaning if the report descriptor 554 is not parsed */ 508 555 usb_log_info("Falling back to generic HID driver.\n"); 509 556 rc = usb_hid_set_generic_hid_subdriver(hid_dev); … … 516 563 usb_log_debug("Subdriver count: %d\n", 517 564 hid_dev->subdriver_count); 565 //usb_hid_free(&hid_dev); 518 566 519 567 } else { … … 571 619 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 572 620 621 // int allocated = (hid_dev->input_report != NULL); 573 622 assert(hid_dev->input_report != NULL); 574 623 usb_log_debug("Max input report size: %zu, buffer size: %zu\n", 575 624 hid_dev->max_input_report_size, buffer_size); 576 625 //assert(hid_dev->max_input_report_size >= buffer_size); 577 626 if (hid_dev->max_input_report_size >= buffer_size) { 578 627 /*! @todo This should probably be atomic. */ … … 621 670 /*----------------------------------------------------------------------------*/ 622 671 672 //const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev) 673 //{ 674 // switch (hid_dev->poll_pipe_index) { 675 // case USB_HID_KBD_POLL_EP_NO: 676 // return HID_KBD_FUN_NAME; 677 // break; 678 // case USB_HID_MOUSE_POLL_EP_NO: 679 // return HID_MOUSE_FUN_NAME; 680 // break; 681 // default: 682 // return HID_GENERIC_FUN_NAME; 683 // } 684 //} 685 686 /*----------------------------------------------------------------------------*/ 687 688 //const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev) 689 //{ 690 // // this means that only boot protocol keyboards will be connected 691 // // to the console; there is probably no better way to do this 692 693 // switch (hid_dev->poll_pipe_index) { 694 // case USB_HID_KBD_POLL_EP_NO: 695 // return HID_KBD_CLASS_NAME; 696 // break; 697 // case USB_HID_MOUSE_POLL_EP_NO: 698 // return HID_MOUSE_CLASS_NAME; 699 // break; 700 // default: 701 // return HID_GENERIC_CLASS_NAME; 702 // } 703 //} 704 705 /*----------------------------------------------------------------------------*/ 706 623 707 void usb_hid_new_report(usb_hid_dev_t *hid_dev) 624 708 { … … 632 716 return hid_dev->report_nr; 633 717 } 718 719 /*----------------------------------------------------------------------------*/ 720 721 //void usb_hid_report_received(void) 722 //{ 723 // ++report_number; 724 //} 725 726 /*----------------------------------------------------------------------------*/ 727 728 //bool usb_hid_report_ready(void) 729 //{ 730 // return !report_received; 731 //} 634 732 635 733 /*----------------------------------------------------------------------------*/ -
uspace/drv/usbhid/usbhid.h
r173922f r8c74d15 55 55 bool reason); 56 56 57 // TODO: add function and class name?? 57 58 typedef struct usb_hid_subdriver { 58 59 /** Function to be called when initializing HID device. */ … … 125 126 void *arg); 126 127 128 //const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev); 129 130 //const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev); 131 127 132 void usb_hid_new_report(usb_hid_dev_t *hid_dev); 128 133 129 134 int usb_hid_report_number(usb_hid_dev_t *hid_dev); 135 136 //void usb_hid_report_received(void); 137 138 //bool usb_hid_report_ready(void); 130 139 131 140 void usb_hid_free(usb_hid_dev_t **hid_dev);
Note:
See TracChangeset
for help on using the changeset viewer.