Changes in / [2586860:ef90ffb3] in mainline
- Files:
-
- 7 added
- 15 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
r2586860 ref90ffb3 157 157 $(USPACE_PATH)/app/usbinfo/usbinfo \ 158 158 $(USPACE_PATH)/app/vuhid/vuh \ 159 $(USPACE_PATH)/app/mkbd/mkbd \ 159 160 $(USPACE_PATH)/app/websrv/websrv 160 161 -
boot/arch/amd64/Makefile.inc
r2586860 ref90ffb3 49 49 usbflbk \ 50 50 usbhub \ 51 usbkbd \52 51 usbhid \ 53 52 usbmast \ -
uspace/Makefile
r2586860 ref90ffb3 59 59 app/websrv \ 60 60 app/sysinfo \ 61 app/mkbd \ 61 62 srv/clip \ 62 63 srv/devmap \ … … 122 123 drv/uhci-rhd \ 123 124 drv/usbflbk \ 124 drv/usbkbd \125 125 drv/usbhid \ 126 126 drv/usbhub \ … … 144 144 drv/uhci-rhd \ 145 145 drv/usbflbk \ 146 drv/usbkbd \147 146 drv/usbhid \ 148 147 drv/usbhub \ -
uspace/drv/usbhid/Makefile
r2586860 ref90ffb3 57 57 generic/hiddev.c \ 58 58 mouse/mousedev.c \ 59 lgtch-ultrax/lgtch-ultrax.c \60 lgtch-ultrax/keymap.c \59 multimedia/multimedia.c \ 60 multimedia/keymap.c \ 61 61 $(STOLEN_LAYOUT_SOURCES) 62 62 -
uspace/drv/usbhid/generic/hiddev.c
r2586860 ref90ffb3 162 162 /*----------------------------------------------------------------------------*/ 163 163 164 int usb_generic_hid_init(usb_hid_dev_t *hid_dev )164 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 165 165 { 166 166 if (hid_dev == NULL) { … … 173 173 /*----------------------------------------------------------------------------*/ 174 174 175 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, 175 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data, 176 176 uint8_t *buffer, size_t buffer_size) 177 177 { -
uspace/drv/usbhid/generic/hiddev.h
r2586860 ref90ffb3 48 48 /*----------------------------------------------------------------------------*/ 49 49 50 int usb_generic_hid_init(struct usb_hid_dev *hid_dev );50 int usb_generic_hid_init(struct usb_hid_dev *hid_dev, void **data); 51 51 52 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, 52 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, void *data, 53 53 uint8_t *buffer, size_t buffer_size); 54 54 -
uspace/drv/usbhid/kbd/kbddev.c
r2586860 ref90ffb3 252 252 sysarg_t method = IPC_GET_IMETHOD(*icall); 253 253 254 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 255 256 if (hid_dev == NULL || hid_dev->data == NULL) { 254 usb_kbd_t *kbd_dev = (usb_kbd_t *)fun->driver_data; 255 if (kbd_dev == NULL) { 257 256 usb_log_debug("default_connection_handler: " 258 257 "Missing parameter.\n"); … … 260 259 return; 261 260 } 262 263 assert(hid_dev != NULL);264 assert(hid_dev->data != NULL);265 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data;266 261 267 262 if (method == IPC_M_CONNECT_TO_ME) { … … 313 308 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 314 309 hid_dev->report, NULL, kbd_dev->led_path, 315 USB_HID_PATH_COMPARE_ USAGE_PAGE_ONLY | USB_HID_PATH_COMPARE_END,310 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 316 311 USB_HID_REPORT_TYPE_OUTPUT); 317 312 318 while (field != NULL) { 319 313 while (field != NULL) { 314 320 315 if ((field->usage == USB_HID_LED_NUM_LOCK) 321 316 && (kbd_dev->mods & KM_NUM_LOCK)){ … … 334 329 335 330 field = usb_hid_report_get_sibling(hid_dev->report, field, 336 kbd_dev->led_path, USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 337 | USB_HID_PATH_COMPARE_END, USB_HID_REPORT_TYPE_OUTPUT); 331 kbd_dev->led_path, 332 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 333 USB_HID_REPORT_TYPE_OUTPUT); 338 334 } 339 335 … … 662 658 * usb_hid_parse_report(). 663 659 */ 664 static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, 660 static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev, 665 661 uint8_t *buffer, size_t actual_size) 666 662 { 667 663 assert(hid_dev->report != NULL); 668 664 assert(hid_dev != NULL); 669 assert(hid_dev->data != NULL); 670 671 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 665 assert(kbd_dev != NULL); 672 666 673 667 usb_log_debug("Calling usb_hid_parse_report() with " … … 774 768 /*----------------------------------------------------------------------------*/ 775 769 776 static int usb_kbd_create_function(usb_hid_dev_t *hid_dev )770 static int usb_kbd_create_function(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev) 777 771 { 778 772 assert(hid_dev != NULL); 779 773 assert(hid_dev->usb_dev != NULL); 774 assert(kbd_dev != NULL); 780 775 781 776 /* Create the function exposed under /dev/devices. */ … … 792 787 * to the DDF function. 793 788 */ 794 fun->ops = & hid_dev->ops;795 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data789 fun->ops = &kbd_dev->ops; 790 fun->driver_data = kbd_dev; 796 791 797 792 int rc = ddf_fun_bind(fun); … … 840 835 * @return Other value inherited from function usbhid_dev_init(). 841 836 */ 842 int usb_kbd_init(usb_hid_dev_t *hid_dev )837 int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data) 843 838 { 844 839 usb_log_debug("Initializing HID/KBD structure...\n"); … … 865 860 usb_hid_report_path_set_report_id(path, 0); 866 861 867 kbd_dev->key_count = usb_hid_report_input_length( 868 hid_dev->report, path, 869 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 862 kbd_dev->key_count = usb_hid_report_size( 863 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 870 864 usb_hid_report_path_free(path); 871 865 … … 908 902 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 909 903 910 kbd_dev->led_output_size = usb_hid_report_output_size(hid_dev->report, 911 kbd_dev->led_path, 912 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 904 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 905 0, USB_HID_REPORT_TYPE_OUTPUT); 913 906 914 907 usb_log_debug("Output report size (in items): %zu\n", … … 955 948 956 949 // save the KBD device structure into the HID device structure 957 hid_dev->data = kbd_dev; 950 //hid_dev->data = kbd_dev; 951 *data = kbd_dev; 958 952 959 953 // set handler for incoming calls 960 hid_dev->ops.default_handler = default_connection_handler;954 kbd_dev->ops.default_handler = default_connection_handler; 961 955 962 956 /* … … 983 977 984 978 usb_log_debug("Creating KBD function...\n"); 985 int rc = usb_kbd_create_function(hid_dev );979 int rc = usb_kbd_create_function(hid_dev, kbd_dev); 986 980 if (rc != EOK) { 987 981 usb_kbd_free(&kbd_dev); … … 994 988 /*----------------------------------------------------------------------------*/ 995 989 996 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer,997 size_t buffer_size)998 { 999 if (hid_dev == NULL || buffer == NULL ) {990 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data, 991 uint8_t *buffer, size_t buffer_size) 992 { 993 if (hid_dev == NULL || buffer == NULL || data == NULL) { 1000 994 // do not continue polling (???) 1001 995 return false; 1002 996 } 1003 997 998 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 999 assert(kbd_dev != NULL); 1000 1004 1001 // TODO: add return value from this function 1005 usb_kbd_process_data(hid_dev, buffer, buffer_size);1002 usb_kbd_process_data(hid_dev, kbd_dev, buffer, buffer_size); 1006 1003 1007 1004 return true; … … 1066 1063 /*----------------------------------------------------------------------------*/ 1067 1064 1068 void usb_kbd_deinit(usb_hid_dev_t *hid_dev )1065 void usb_kbd_deinit(usb_hid_dev_t *hid_dev, void *data) 1069 1066 { 1070 1067 if (hid_dev == NULL) { … … 1072 1069 } 1073 1070 1074 if ( hid_dev->data != NULL) {1075 usb_kbd_t *kbd_dev = (usb_kbd_t *) hid_dev->data;1071 if (data != NULL) { 1072 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 1076 1073 if (usb_kbd_is_initialized(kbd_dev)) { 1077 1074 usb_kbd_mark_unusable(kbd_dev); 1078 1075 } else { 1079 1076 usb_kbd_free(&kbd_dev); 1080 hid_dev->data = NULL;1081 1077 } 1082 1078 } -
uspace/drv/usbhid/kbd/kbddev.h
r2586860 ref90ffb3 83 83 int console_phone; 84 84 85 /** @todo What is this actually? */ 86 ddf_dev_ops_t ops; 87 85 88 /** Information for auto-repeat of keys. */ 86 89 usb_kbd_repeat_t repeat; … … 117 120 /*----------------------------------------------------------------------------*/ 118 121 119 int usb_kbd_init(struct usb_hid_dev *hid_dev );122 int usb_kbd_init(struct usb_hid_dev *hid_dev, void **data); 120 123 121 bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer,122 size_t buffer_size);124 bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, void *data, 125 uint8_t *buffer, size_t buffer_size); 123 126 124 127 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev); … … 131 134 int type, unsigned int key); 132 135 133 void usb_kbd_deinit(struct usb_hid_dev *hid_dev );136 void usb_kbd_deinit(struct usb_hid_dev *hid_dev, void *data); 134 137 135 138 int usb_kbd_set_boot_protocol(struct usb_hid_dev *hid_dev); -
uspace/drv/usbhid/mouse/mousedev.c
r2586860 ref90ffb3 122 122 sysarg_t method = IPC_GET_IMETHOD(*icall); 123 123 124 usb_ hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;125 126 if ( hid_dev == NULL || hid_dev->data== NULL) {124 usb_mouse_t *mouse_dev = (usb_mouse_t *)fun->driver_data; 125 126 if (mouse_dev == NULL) { 127 127 usb_log_debug("default_connection_handler: Missing " 128 128 "parameters.\n"); … … 131 131 } 132 132 133 assert(hid_dev != NULL); 134 assert(hid_dev->data != NULL); 135 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data; 133 usb_log_debug("default_connection_handler: fun->name: %s\n", 134 fun->name); 135 usb_log_debug("default_connection_handler: mouse_phone: %d, wheel " 136 "phone: %d\n", mouse_dev->mouse_phone, mouse_dev->wheel_phone); 136 137 137 138 int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) … … 145 146 "phone to mouse already set.\n"); 146 147 async_answer_0(icallid, ELIMIT); 147 //async_answer_0(icallid, EOK);148 148 return; 149 149 } 150 150 151 151 *phone = callback; 152 usb_log_debug("Console phone to mouse set ok (%d).\n", callback);152 usb_log_debug("Console phone to mouse set ok (%d).\n", *phone); 153 153 async_answer_0(icallid, EOK); 154 154 return; … … 224 224 /*----------------------------------------------------------------------------*/ 225 225 226 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, uint8_t *buffer, 227 size_t buffer_size) 228 { 229 usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data; 226 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 227 usb_mouse_t *mouse_dev, uint8_t *buffer, 228 size_t buffer_size) 229 { 230 assert(mouse_dev != NULL); 230 231 231 232 usb_log_debug2("got buffer: %s.\n", … … 378 379 /*----------------------------------------------------------------------------*/ 379 380 380 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev) 381 { 381 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse) 382 { 383 assert(hid_dev != NULL); 384 assert(mouse != NULL); 385 382 386 /* Create the function exposed under /dev/devices. */ 383 387 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); … … 389 393 } 390 394 391 /* 392 * Store the initialized HID device and HID ops 393 * to the DDF function. 394 */ 395 fun->ops = &hid_dev->ops; 396 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 395 fun->ops = &mouse->ops; 396 fun->driver_data = mouse; // TODO: maybe change to hid_dev->data 397 397 398 398 int rc = ddf_fun_bind(fun); … … 431 431 * to the DDF function. 432 432 */ 433 fun->ops = & hid_dev->ops;434 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data433 fun->ops = &mouse->ops; 434 fun->driver_data = mouse; // TODO: maybe change to hid_dev->data 435 435 436 436 rc = ddf_fun_bind(fun); … … 458 458 /*----------------------------------------------------------------------------*/ 459 459 460 int usb_mouse_init(usb_hid_dev_t *hid_dev )460 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data) 461 461 { 462 462 usb_log_debug("Initializing HID/Mouse structure...\n"); … … 485 485 486 486 // save the Mouse device structure into the HID device structure 487 hid_dev->data = mouse_dev;487 *data = mouse_dev; 488 488 489 489 // set handler for incoming calls 490 hid_dev->ops.default_handler = default_connection_handler; 490 // TODO: must be one for each subdriver!! 491 mouse_dev->ops.default_handler = default_connection_handler; 491 492 492 493 // TODO: how to know if the device supports the request??? … … 494 495 // hid_dev->usb_dev->interface_no, IDLE_RATE); 495 496 496 int rc = usb_mouse_create_function(hid_dev );497 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 497 498 if (rc != EOK) { 498 499 usb_mouse_free(&mouse_dev); … … 505 506 /*----------------------------------------------------------------------------*/ 506 507 507 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer,508 size_t buffer_size)508 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data, 509 uint8_t *buffer, size_t buffer_size) 509 510 { 510 511 usb_log_debug("usb_mouse_polling_callback()\n"); 511 512 usb_debug_str_buffer(buffer, buffer_size, 0); 512 513 513 if (hid_dev == NULL ) {514 if (hid_dev == NULL || data == NULL) { 514 515 usb_log_error("Missing argument to the mouse polling callback." 515 516 "\n"); … … 517 518 } 518 519 519 if (hid_dev->data == NULL) { 520 usb_log_error("Wrong argument to the mouse polling callback." 521 "\n"); 522 return false; 523 } 524 525 return usb_mouse_process_report(hid_dev, buffer, buffer_size); 526 } 527 528 /*----------------------------------------------------------------------------*/ 529 530 void usb_mouse_deinit(usb_hid_dev_t *hid_dev) 531 { 532 usb_mouse_free((usb_mouse_t **)&hid_dev->data); 520 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 521 522 return usb_mouse_process_report(hid_dev, mouse_dev, buffer, 523 buffer_size); 524 } 525 526 /*----------------------------------------------------------------------------*/ 527 528 void usb_mouse_deinit(usb_hid_dev_t *hid_dev, void *data) 529 { 530 if (data != NULL) { 531 usb_mouse_free((usb_mouse_t **)&data); 532 } 533 533 } 534 534 -
uspace/drv/usbhid/mouse/mousedev.h
r2586860 ref90ffb3 52 52 53 53 int32_t *buttons; 54 55 ddf_dev_ops_t ops; 54 56 } usb_mouse_t; 55 57 … … 63 65 /*----------------------------------------------------------------------------*/ 64 66 65 int usb_mouse_init(struct usb_hid_dev *hid_dev );67 int usb_mouse_init(struct usb_hid_dev *hid_dev, void **data); 66 68 67 bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer,68 size_t buffer_size);69 bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, void *data, 70 uint8_t *buffer, size_t buffer_size); 69 71 70 void usb_mouse_deinit(struct usb_hid_dev *hid_dev );72 void usb_mouse_deinit(struct usb_hid_dev *hid_dev, void *data); 71 73 72 74 int usb_mouse_set_boot_protocol(struct usb_hid_dev *hid_dev); -
uspace/drv/usbhid/subdrivers.c
r2586860 ref90ffb3 38 38 #include <usb/hid/hidpath.h> 39 39 40 #include "lgtch-ultrax/lgtch-ultrax.h" 40 //#include "lgtch-ultrax/lgtch-ultrax.h" 41 #include "multimedia/multimedia.h" 41 42 #include "mouse/mousedev.h" 42 43 43 44 static usb_hid_subdriver_usage_t path_kbd[] = { 44 {USB_HIDUT_PAGE_KEYBOARD, 0}, 45 {USB_HIDUT_PAGE_GENERIC_DESKTOP, 46 USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD}, 45 47 {0, 0} 46 48 }; 47 49 48 static usb_hid_subdriver_usage_t path_mouse 2[] = {49 {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_ X},50 static usb_hid_subdriver_usage_t path_mouse[] = { 51 {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_MOUSE}, 50 52 {0, 0} 51 53 }; 52 54 53 static usb_hid_subdriver_usage_t lgtch_path[] = {54 { 0xc, 0},55 static usb_hid_subdriver_usage_t multim_key_path[] = { 56 {USB_HIDUT_PAGE_CONSUMER, USB_HIDUT_USAGE_CONSUMER_CONSUMER_CONTROL}, 55 57 {0, 0} 56 58 }; … … 60 62 path_kbd, 61 63 -1, 62 USB_HID_PATH_COMPARE_END 63 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 64 USB_HID_PATH_COMPARE_BEGIN, 64 65 -1, 65 66 -1, … … 73 74 }, 74 75 { 75 lgtch_path,76 multim_key_path, 76 77 1, 77 USB_HID_PATH_COMPARE_END 78 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 79 0x046d, 80 0xc30e, 78 USB_HID_PATH_COMPARE_BEGIN, 79 -1, 80 -1, 81 81 { 82 .init = usb_ lgtch_init,83 .deinit = usb_ lgtch_deinit,84 .poll = usb_ lgtch_polling_callback,82 .init = usb_multimedia_init, 83 .deinit = usb_multimedia_deinit, 84 .poll = usb_multimedia_polling_callback, 85 85 .poll_end = NULL 86 86 } 87 87 }, 88 88 { 89 path_mouse 2,89 path_mouse, 90 90 -1, 91 USB_HID_PATH_COMPARE_END 92 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 91 USB_HID_PATH_COMPARE_BEGIN, 93 92 -1, 94 93 -1, … … 100 99 } 101 100 }, 102 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL }}101 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL, NULL}} 103 102 }; 104 103 -
uspace/drv/usbhid/usbhid.c
r2586860 ref90ffb3 203 203 204 204 usb_log_debug("Compare flags: %d\n", mapping->compare); 205 size_t size = usb_hid_report_input_length(hid_dev->report, usage_path, 206 mapping->compare); 205 // size_t size = usb_hid_report_size(hid_dev->report, 0, 206 // USB_HID_REPORT_TYPE_INPUT); 207 size_t size = 0; 208 usb_hid_report_field_t *field = usb_hid_report_get_sibling (hid_dev->report, 209 NULL, usage_path, mapping->compare, USB_HID_REPORT_TYPE_INPUT); 210 while(field != NULL) { 211 size++; 212 field = usb_hid_report_get_sibling (hid_dev->report, 213 field, usage_path, mapping->compare, 214 USB_HID_REPORT_TYPE_INPUT); 215 } 216 207 217 usb_log_debug("Size of the input report: %zuB\n", size); 208 209 218 usb_hid_report_path_free(usage_path); 210 219 … … 457 466 if (hid_dev->subdrivers[i].init != NULL) { 458 467 usb_log_debug("Initializing subdriver %d.\n",i); 459 rc = hid_dev->subdrivers[i].init(hid_dev); 468 rc = hid_dev->subdrivers[i].init(hid_dev, 469 &hid_dev->subdrivers[i].data); 460 470 if (rc != EOK) { 461 471 usb_log_warning("Failed to initialize" … … 522 532 for (i = 0; i < hid_dev->subdriver_count; ++i) { 523 533 if (hid_dev->subdrivers[i].poll != NULL 524 && hid_dev->subdrivers[i].poll(hid_dev, buffer,525 buffer_size)) {534 && hid_dev->subdrivers[i].poll(hid_dev, 535 hid_dev->subdrivers[i].data, buffer, buffer_size)) { 526 536 cont = true; 527 537 } … … 546 556 for (i = 0; i < hid_dev->subdriver_count; ++i) { 547 557 if (hid_dev->subdrivers[i].poll_end != NULL) { 548 hid_dev->subdrivers[i].poll_end(hid_dev, reason); 558 hid_dev->subdrivers[i].poll_end(hid_dev, 559 hid_dev->subdrivers[i].data, reason); 549 560 } 550 561 } … … 627 638 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) { 628 639 if ((*hid_dev)->subdrivers[i].deinit != NULL) { 629 (*hid_dev)->subdrivers[i].deinit(*hid_dev); 640 (*hid_dev)->subdrivers[i].deinit(*hid_dev, 641 (*hid_dev)->subdrivers[i].data); 630 642 } 631 643 } -
uspace/drv/usbhid/usbhid.h
r2586860 ref90ffb3 48 48 struct usb_hid_dev; 49 49 50 typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *); 51 typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *); 52 typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, uint8_t *, size_t); 53 typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, bool reason); 50 typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *, void **data); 51 typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *, void *data); 52 typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, void *data, uint8_t *, 53 size_t); 54 typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, void *data, 55 bool reason); 54 56 55 57 // TODO: add function and class name?? … … 63 65 /** Function to be called when polling ends. */ 64 66 usb_hid_driver_poll_ended poll_end; 67 /** Arbitrary data needed by the subdriver. */ 68 void *data; 65 69 } usb_hid_subdriver_t; 66 70 … … 72 76 /** Structure holding generic USB device information. */ 73 77 usb_device_t *usb_dev; 74 75 /** @todo What is this actually? */76 ddf_dev_ops_t ops;77 78 78 79 /** Index of the polling pipe in usb_hid_endpoints array. */ … … 97 98 98 99 size_t input_report_size; 99 100 /** Arbitrary data (e.g. a special structure for handling keyboard). */101 void *data;102 100 } usb_hid_dev_t; 103 101 -
uspace/lib/usbhid/include/usb/hid/hid_report_items.h
r2586860 ref90ffb3 46 46 #define USB_HID_ITEM_IS_LONG(data) (data == 0xFE) 47 47 48 49 /** 50 * Extended usage macros 51 */ 52 #define USB_HID_IS_EXTENDED_USAGE(usage) ((usage & 0xFFFF0000) != 0) 53 #define USB_HID_EXTENDED_USAGE_PAGE(usage) ((usage & 0xFFFF0000) >> 16) 54 #define USB_HID_EXTENDED_USAGE(usage) (usage & 0xFFFF) 48 55 49 56 /** -
uspace/lib/usbhid/include/usb/hid/hidparser.h
r2586860 ref90ffb3 51 51 size_t size, uint8_t *report_id); 52 52 53 /** */54 size_t usb_hid_report_input_length(const usb_hid_report_t *report,55 usb_hid_report_path_t *path, int flags);56 57 53 /* 58 54 * Output report parser functions … … 65 61 void usb_hid_report_output_free(uint8_t *output); 66 62 67 /** Returns size of output for given usage path*/68 size_t usb_hid_report_ output_size(usb_hid_report_t *report,69 usb_hid_report_path_t *path, int flags);63 /** Returns size of report in items */ 64 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 65 usb_hid_report_type_t type); 70 66 71 67 /** Makes the output report buffer by translated given data */ -
uspace/lib/usbhid/include/usb/hid/hidtypes.h
r2586860 ref90ffb3 39 39 #include <adt/list.h> 40 40 41 #define USB_HID_MAX_USAGES 2041 #define USB_HID_MAX_USAGES 0xffff 42 42 43 43 #define USB_HID_UINT32_TO_INT32(x, size) ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1))) … … 92 92 int32_t physical_minimum; 93 93 int32_t physical_maximum; 94 uint32_t usage_minimum;95 uint32_t usage_maximum;94 int32_t usage_minimum; 95 int32_t usage_maximum; 96 96 uint32_t unit; 97 97 uint32_t unit_exponent; 98 98 99 uint32_t *usages; 100 size_t usages_count; 99 101 100 102 int32_t value; … … 121 123 122 124 /** */ 123 uint32_t usage_minimum;124 /** */ 125 uint32_t usage_maximum;125 int32_t usage_minimum; 126 /** */ 127 int32_t usage_maximum; 126 128 /** */ 127 129 int32_t logical_minimum; -
uspace/lib/usbhid/include/usb/hid/usages/core.h
r2586860 ref90ffb3 67 67 } usb_hidut_usage_generic_desktop_t; 68 68 69 typedef enum { 70 USB_HIDUT_USAGE_CONSUMER_CONSUMER_CONTROL = 1 71 } usb_hidut_usage_consumer_t; 72 69 73 70 74 #endif -
uspace/lib/usbhid/src/hiddescriptor.c
r2586860 ref90ffb3 64 64 { 65 65 /* find or append current collection path to the list */ 66 link_t *path_it = report->collection_paths.next; 66 //link_t *path_it = report->collection_paths.next; 67 link_t *path_it = report->collection_paths.prev->next; 67 68 usb_hid_report_path_t *path = NULL; 69 70 68 71 while(path_it != &report->collection_paths) { 69 72 path = list_get_instance(path_it, usb_hid_report_path_t, link); … … 116 119 int i; 117 120 118 for(i=0; i<report_item->usages_count; i++){ 119 usb_log_debug("usages (%d) - %x\n", i, report_item->usages[i]); 120 } 121 121 uint32_t *usages; 122 int usages_used=0; 123 if(report_item->usages_count > 0){ 124 usages = malloc(sizeof(int32_t) * report_item->usages_count); 125 memcpy(usages, report_item->usages, sizeof(int32_t) * report_item->usages_count); 126 } 127 else { 128 usages = NULL; 129 } 130 122 131 usb_hid_report_path_t *path = report_item->usage_path; 123 132 for(i=0; i<report_item->count; i++){ … … 133 142 field->physical_maximum = report_item->physical_maximum; 134 143 135 field->usage_minimum = report_item->usage_minimum; 136 field->usage_maximum = report_item->usage_maximum; 137 if(report_item->extended_usage_page != 0){ 138 field->usage_page = report_item->extended_usage_page; 144 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){ 145 /* 146 Store usage array. The Correct Usage Page and Usage is depending 147 on data in report and will be filled later 148 */ 149 field->usage = 0; 150 field->usage_page = 0; //report_item->usage_page; 151 152 field->usages_count = report_item->usages_count; 153 field->usages = usages; 154 usages_used = 1; 139 155 } 140 156 else { 141 field->usage_page = report_item->usage_page; 142 } 143 144 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) { 145 uint32_t usage; 146 if(i < report_item->usages_count){ 157 158 /* Fill the correct Usage and Usage Page */ 159 int32_t usage; 160 if(i < report_item->usages_count) { 147 161 usage = report_item->usages[i]; 148 162 } … … 151 165 } 152 166 153 154 if((usage & 0xFFFF0000) != 0){ 155 field->usage_page = (usage >> 16); 156 field->usage = (usage & 0xFFFF); 167 if(USB_HID_IS_EXTENDED_USAGE(usage)){ 168 field->usage = USB_HID_EXTENDED_USAGE(usage); 169 field->usage_page = USB_HID_EXTENDED_USAGE_PAGE(usage); 157 170 } 158 171 else { 172 // should not occur 159 173 field->usage = usage; 160 } 161 162 163 } 164 165 if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) { 166 field->usage = report_item->usage_minimum + i; 174 field->usage_page = report_item->usage_page; 175 } 167 176 } 168 177 … … 209 218 } 210 219 220 // free only when not used!!! 221 if(usages && usages_used == 0) { 222 free(usages); 223 } 211 224 212 225 return EOK; … … 450 463 451 464 case USB_HID_REPORT_TAG_COLLECTION: 465 452 466 // store collection atributes 453 467 path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); … … 455 469 456 470 // set last item 457 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page); 458 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]); 471 usb_hid_report_set_last_item(usage_path, 472 USB_HID_TAG_CLASS_GLOBAL, 473 USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1])); 474 usb_hid_report_set_last_item(usage_path, 475 USB_HID_TAG_CLASS_LOCAL, 476 USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1])); 459 477 460 478 // append the new one which will be set by common … … 551 569 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path) 552 570 { 571 int32_t extended_usage; 572 553 573 switch(tag) { 554 574 case USB_HID_REPORT_TAG_USAGE: … … 560 580 report_item->in_delimiter = INSIDE_DELIMITER_SET; 561 581 case OUTSIDE_DELIMITER_SET: 562 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size); 582 extended_usage = ((report_item->usage_page) << 16); 583 extended_usage += usb_hid_report_tag_data_uint32(data,item_size); 584 report_item->usages[report_item->usages_count] = extended_usage; 563 585 report_item->usages_count++; 564 586 break; 565 587 } 566 588 break; 567 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 589 case USB_HID_REPORT_TAG_USAGE_MINIMUM: 568 590 if (item_size == 3) { 569 591 // usage extended usages … … 577 599 case USB_HID_REPORT_TAG_USAGE_MAXIMUM: 578 600 if (item_size == 3) { 601 602 if(report_item->extended_usage_page != ((usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16)) { 603 return EINVAL; 604 } 605 579 606 // usage extended usages 580 607 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; … … 584 611 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size); 585 612 } 613 614 // vlozit zaznamy do pole usages 615 int32_t i; 616 for(i=report_item->usage_minimum; i<=report_item->usage_maximum; i++) { 617 if(report_item->extended_usage_page) { 618 report_item->usages[report_item->usages_count++] = (report_item->extended_usage_page << 16) + i; 619 } 620 else { 621 622 report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i; 623 } 624 } 625 report_item->extended_usage_page = 0; 626 586 627 break; 587 628 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX: … … 663 704 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum); 664 705 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum); 706 usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count); 665 707 666 708 usb_log_debug("\t\tVALUE: %X\n", report_item->value); … … 668 710 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page); 669 711 670 //usb_hid_print_usage_path(report_item->collection_path);712 usb_hid_print_usage_path(report_item->collection_path); 671 713 672 714 usb_log_debug("\n"); … … 700 742 usb_hid_descriptor_print_list(&report_des->report_items); 701 743 702 744 /* 703 745 link_t *path_it = report->collection_paths.next; 704 746 while(path_it != &report->collection_paths) { … … 706 748 path_it = path_it->next; 707 749 } 708 750 */ 709 751 report_it = report_it->next; 710 752 } -
uspace/lib/usbhid/src/hidparser.c
r2586860 ref90ffb3 69 69 70 70 71 /** Returns size of report of specified report id and type in items 72 * 73 * @param parser Opaque report parser structure 74 * @param report_id 75 * @param type 76 * @return Number of items in specified report 77 */ 78 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id, 79 usb_hid_report_type_t type) 80 { 81 usb_hid_report_description_t *report_des; 82 83 if(report == NULL) { 84 return 0; 85 } 86 87 report_des = usb_hid_report_find_description (report, report_id, type); 88 if(report_des == NULL){ 89 return 0; 90 } 91 else { 92 return report_des->item_length; 93 } 94 } 71 95 72 96 … … 87 111 usb_hid_report_description_t *report_des; 88 112 usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT; 89 113 90 114 if(report == NULL) { 91 115 return EINVAL; … … 114 138 // array 115 139 item->value = usb_hid_translate_data(item, data); 116 item->usage = (item->value - item->physical_minimum) + item->usage_minimum; 140 141 item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]); 142 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]); 143 144 usb_hid_report_set_last_item (item->collection_path, 145 USB_HID_TAG_CLASS_GLOBAL, 146 item->usage_page); 147 usb_hid_report_set_last_item (item->collection_path, 148 USB_HID_TAG_CLASS_LOCAL, 149 item->usage); 150 117 151 } 118 152 else { … … 123 157 list_item = list_item->next; 124 158 } 125 159 126 160 return EOK; 127 161 … … 206 240 } 207 241 208 /**209 * Returns number of items in input report which are accessible by given usage path210 *211 * @param parser Opaque report descriptor structure212 * @param path Usage path specification213 * @param flags Usage path comparison flags214 * @return Number of items in input report215 */216 size_t usb_hid_report_input_length(const usb_hid_report_t *report,217 usb_hid_report_path_t *path, int flags)218 {219 220 size_t ret = 0;221 222 if(report == NULL) {223 return 0;224 }225 226 usb_hid_report_description_t *report_des;227 report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_INPUT);228 if(report_des == NULL) {229 return 0;230 }231 232 link_t *field_it = report_des->report_items.next;233 usb_hid_report_field_t *field;234 while(field_it != &report_des->report_items) {235 236 field = list_get_instance(field_it, usb_hid_report_field_t, link);237 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {238 239 usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);240 if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {241 ret++;242 }243 usb_hid_report_remove_last_item (field->collection_path);244 }245 246 field_it = field_it->next;247 }248 249 return ret;250 }251 252 242 /*** OUTPUT API **/ 253 243 … … 304 294 } 305 295 306 /** Returns size of output for given usage path307 *308 * @param parser Opaque report parser structure309 * @param path Usage path specified which items will be thought for the output310 * @param flags Flags of usage path structure comparison311 * @return Number of items matching the given usage path312 */313 size_t usb_hid_report_output_size(usb_hid_report_t *report,314 usb_hid_report_path_t *path, int flags)315 {316 size_t ret = 0;317 usb_hid_report_description_t *report_des;318 319 if(report == NULL) {320 return 0;321 }322 323 report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_OUTPUT);324 if(report_des == NULL){325 return 0;326 }327 328 link_t *field_it = report_des->report_items.next;329 usb_hid_report_field_t *field;330 while(field_it != &report_des->report_items) {331 332 field = list_get_instance(field_it, usb_hid_report_field_t, link);333 if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0){334 usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);335 if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {336 ret++;337 }338 usb_hid_report_remove_last_item (field->collection_path);339 }340 341 field_it = field_it->next;342 }343 344 return ret;345 346 }347 348 296 /** Makes the output report buffer for data given in the report structure 349 297 * … … 385 333 report_item = list_get_instance(item, usb_hid_report_field_t, link); 386 334 387 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 335 usb_log_debug("OUTPUT ITEM usage(%x), value(%x)\n", report_item->usage, report_item->value); 336 337 if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) { 388 338 389 // array 390 value = usb_hid_translate_data_reverse(report_item, report_item->value); 391 offset = report_item->offset; 392 length = report_item->size; 393 } 394 else { 395 // variable item 396 value = usb_hid_translate_data_reverse(report_item, report_item->value); 397 offset = report_item->offset; 398 length = report_item->size; 399 } 400 401 if((offset/8) == ((offset+length-1)/8)) { 402 // je to v jednom bytu 403 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 404 break; // TODO ErrorCode 339 // array 340 value = usb_hid_translate_data_reverse(report_item, report_item->value); 341 offset = report_item->offset; 342 length = report_item->size; 343 } 344 else { 345 // variable item 346 value = usb_hid_translate_data_reverse(report_item, report_item->value); 347 offset = report_item->offset; 348 length = report_item->size; 349 } 350 351 usb_log_debug("\ttranslated value: %x\n", value); 352 353 if((offset/8) == ((offset+length-1)/8)) { 354 // je to v jednom bytu 355 if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) { 356 break; // TODO ErrorCode 357 } 358 size_t shift = 8 - offset%8 - length; 359 value = value << shift; 360 value = value & (((1 << length)-1) << shift); 361 362 uint8_t mask = 0; 363 mask = 0xff - (((1 << length) - 1) << shift); 364 buffer[offset/8] = (buffer[offset/8] & mask) | value; 365 } 366 else { 367 int i = 0; 368 uint8_t mask = 0; 369 for(i = (offset/8); i <= ((offset+length-1)/8); i++) { 370 if(i == (offset/8)) { 371 tmp_value = value; 372 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 373 tmp_value = tmp_value << (offset%8); 374 375 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 376 buffer[i] = (buffer[i] & mask) | tmp_value; 405 377 } 406 407 size_t shift = 8 - offset%8 - length; 408 409 value = value << shift; 410 value = value & (((1 << length)-1) << shift); 378 else if (i == ((offset + length -1)/8)) { 379 380 value = value >> (length - ((offset + length) % 8)); 381 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 411 382 412 uint8_t mask = 0; 413 mask = 0xff - (((1 << length) - 1) << shift); 414 buffer[offset/8] = (buffer[offset/8] & mask) | value; 415 } 416 else { 417 int i = 0; 418 uint8_t mask = 0; 419 for(i = (offset/8); i <= ((offset+length-1)/8); i++) { 420 if(i == (offset/8)) { 421 tmp_value = value; 422 tmp_value = tmp_value & ((1 << (8-(offset%8)))-1); 423 tmp_value = tmp_value << (offset%8); 424 425 mask = ~(((1 << (8-(offset%8)))-1) << (offset%8)); 426 buffer[i] = (buffer[i] & mask) | tmp_value; 427 } 428 else if (i == ((offset + length -1)/8)) { 429 430 value = value >> (length - ((offset + length) % 8)); 431 value = value & ((1 << (length - ((offset + length) % 8))) - 1); 432 433 mask = (1 << (length - ((offset + length) % 8))) - 1; 434 buffer[i] = (buffer[i] & mask) | value; 435 } 436 else { 437 buffer[i] = value & (0xFF << i); 438 } 383 mask = (1 << (length - ((offset + length) % 8))) - 1; 384 buffer[i] = (buffer[i] & mask) | value; 439 385 } 440 } 441 386 else { 387 buffer[i] = value & (0xFF << i); 388 } 389 } 390 } 442 391 443 392 // reset value … … 472 421 } 473 422 474 475 if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) { 476 477 // variable item 478 if(item->physical_maximum == item->physical_minimum){ 479 resolution = 1; 480 } 481 else { 482 resolution = (item->logical_maximum - item->logical_minimum) / 483 ((item->physical_maximum - item->physical_minimum) * 484 (usb_pow(10,(item->unit_exponent)))); 485 } 486 487 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 488 } 489 else { 490 // bitmapa 491 if(value == 0) { 492 ret = 0; 493 } 494 else { 495 size_t bitmap_idx = (value - item->usage_minimum); 496 ret = 1 << bitmap_idx; 497 } 498 } 499 423 // variable item 424 if(item->physical_maximum == item->physical_minimum){ 425 resolution = 1; 426 } 427 else { 428 resolution = (item->logical_maximum - item->logical_minimum) / 429 ((item->physical_maximum - item->physical_minimum) * 430 (usb_pow(10,(item->unit_exponent)))); 431 } 432 433 ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum; 434 usb_log_debug("\tvalue(%x), resolution(%x), phymin(%x) logmin(%x), ret(%x)\n", value, resolution, item->physical_minimum, item->logical_minimum, ret); 435 500 436 if((item->logical_minimum < 0) || (item->logical_maximum < 0)){ 501 437 return USB_HID_INT32_TO_UINT32(ret, item->size); 502 438 } 503 return (int32_t) ret;439 return (int32_t)0 + ret; 504 440 } 505 441 -
uspace/lib/usbhid/src/hidpath.c
r2586860 ref90ffb3 42 42 43 43 44 #define USB_HID_SAME_USAGE(usage1, usage2) ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0)) 45 #define USB_HID_SAME_USAGE_PAGE(page1, page2) ((page1 == page2) || (page1 == 0) || (page2 == 0)) 46 44 47 /** 45 48 * Appends one item (couple of usage_path and usage) into the usage path … … 203 206 while(report_link != &report_path->head) { 204 207 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 205 if( report_item->usage_page == path_item->usage_page){208 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){ 206 209 if(only_page == 0){ 207 if( report_item->usage == path_item->usage) {210 if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) { 208 211 return EOK; 209 212 } … … 242 245 link); 243 246 244 if( (report_item->usage_page !=path_item->usage_page) ||247 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) || 245 248 ((only_page == 0) && 246 (report_item->usage !=path_item->usage))) {249 !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) { 247 250 248 251 return 1; … … 282 285 usb_hid_report_usage_path_t, 283 286 link); 284 285 if( (report_item->usage_page !=path_item->usage_page) ||287 288 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) || 286 289 ((only_page == 0) && 287 (report_item->usage !=path_item->usage))) {288 290 !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) { 291 return 1; 289 292 } else { 290 293 report_link = report_link->prev;
Note:
See TracChangeset
for help on using the changeset viewer.