Changeset 65b458c4 in mainline
- Timestamp:
- 2011-05-13T12:44:37Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 37f87fa
- Parents:
- 97cb542
- Location:
- uspace/drv/usbhid
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/generic/hiddev.c
r97cb542 r65b458c4 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
r97cb542 r65b458c4 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
r97cb542 r65b458c4 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) { … … 663 658 * usb_hid_parse_report(). 664 659 */ 665 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, 666 661 uint8_t *buffer, size_t actual_size) 667 662 { 668 663 assert(hid_dev->report != NULL); 669 664 assert(hid_dev != NULL); 670 assert(hid_dev->data != NULL); 671 672 usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data; 665 assert(kbd_dev != NULL); 673 666 674 667 usb_log_debug("Calling usb_hid_parse_report() with " … … 775 768 /*----------------------------------------------------------------------------*/ 776 769 777 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) 778 771 { 779 772 assert(hid_dev != NULL); 780 773 assert(hid_dev->usb_dev != NULL); 774 assert(kbd_dev != NULL); 781 775 782 776 /* Create the function exposed under /dev/devices. */ … … 793 787 * to the DDF function. 794 788 */ 795 fun->ops = & hid_dev->ops;796 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data789 fun->ops = &kbd_dev->ops; 790 fun->driver_data = kbd_dev; 797 791 798 792 int rc = ddf_fun_bind(fun); … … 841 835 * @return Other value inherited from function usbhid_dev_init(). 842 836 */ 843 int usb_kbd_init(usb_hid_dev_t *hid_dev )837 int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data) 844 838 { 845 839 usb_log_debug("Initializing HID/KBD structure...\n"); … … 954 948 955 949 // save the KBD device structure into the HID device structure 956 hid_dev->data = kbd_dev; 950 //hid_dev->data = kbd_dev; 951 *data = kbd_dev; 957 952 958 953 // set handler for incoming calls 959 hid_dev->ops.default_handler = default_connection_handler;954 kbd_dev->ops.default_handler = default_connection_handler; 960 955 961 956 /* … … 982 977 983 978 usb_log_debug("Creating KBD function...\n"); 984 int rc = usb_kbd_create_function(hid_dev );979 int rc = usb_kbd_create_function(hid_dev, kbd_dev); 985 980 if (rc != EOK) { 986 981 usb_kbd_free(&kbd_dev); … … 993 988 /*----------------------------------------------------------------------------*/ 994 989 995 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer,996 size_t buffer_size)997 { 998 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) { 999 994 // do not continue polling (???) 1000 995 return false; 1001 996 } 1002 997 998 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 999 assert(kbd_dev != NULL); 1000 1003 1001 // TODO: add return value from this function 1004 usb_kbd_process_data(hid_dev, buffer, buffer_size);1002 usb_kbd_process_data(hid_dev, kbd_dev, buffer, buffer_size); 1005 1003 1006 1004 return true; … … 1065 1063 /*----------------------------------------------------------------------------*/ 1066 1064 1067 void usb_kbd_deinit(usb_hid_dev_t *hid_dev )1065 void usb_kbd_deinit(usb_hid_dev_t *hid_dev, void *data) 1068 1066 { 1069 1067 if (hid_dev == NULL) { … … 1071 1069 } 1072 1070 1073 if ( hid_dev->data != NULL) {1074 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; 1075 1073 if (usb_kbd_is_initialized(kbd_dev)) { 1076 1074 usb_kbd_mark_unusable(kbd_dev); 1077 1075 } else { 1078 1076 usb_kbd_free(&kbd_dev); 1079 hid_dev->data = NULL;1080 1077 } 1081 1078 } -
uspace/drv/usbhid/kbd/kbddev.h
r97cb542 r65b458c4 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
r97cb542 r65b458c4 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;136 137 133 int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) 138 134 ? &mouse_dev->mouse_phone : &mouse_dev->wheel_phone; … … 145 141 "phone to mouse already set.\n"); 146 142 async_answer_0(icallid, ELIMIT); 147 //async_answer_0(icallid, EOK);148 143 return; 149 144 } … … 224 219 /*----------------------------------------------------------------------------*/ 225 220 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; 221 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 222 usb_mouse_t *mouse_dev, uint8_t *buffer, 223 size_t buffer_size) 224 { 225 assert(mouse_dev != NULL); 230 226 231 227 usb_log_debug2("got buffer: %s.\n", … … 378 374 /*----------------------------------------------------------------------------*/ 379 375 380 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev) 381 { 376 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse) 377 { 378 assert(hid_dev != NULL); 379 assert(mouse != NULL); 380 382 381 /* Create the function exposed under /dev/devices. */ 383 382 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); … … 389 388 } 390 389 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 390 fun->ops = &mouse->ops; 391 fun->driver_data = mouse; // TODO: maybe change to hid_dev->data 397 392 398 393 int rc = ddf_fun_bind(fun); … … 431 426 * to the DDF function. 432 427 */ 433 fun->ops = & hid_dev->ops;428 fun->ops = &mouse->ops; 434 429 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 435 430 … … 458 453 /*----------------------------------------------------------------------------*/ 459 454 460 int usb_mouse_init(usb_hid_dev_t *hid_dev )455 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data) 461 456 { 462 457 usb_log_debug("Initializing HID/Mouse structure...\n"); … … 485 480 486 481 // save the Mouse device structure into the HID device structure 487 hid_dev->data = mouse_dev;482 *data = mouse_dev; 488 483 489 484 // set handler for incoming calls 490 hid_dev->ops.default_handler = default_connection_handler; 485 // TODO: must be one for each subdriver!! 486 mouse_dev->ops.default_handler = default_connection_handler; 491 487 492 488 // TODO: how to know if the device supports the request??? … … 494 490 // hid_dev->usb_dev->interface_no, IDLE_RATE); 495 491 496 int rc = usb_mouse_create_function(hid_dev );492 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 497 493 if (rc != EOK) { 498 494 usb_mouse_free(&mouse_dev); … … 505 501 /*----------------------------------------------------------------------------*/ 506 502 507 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer,508 size_t buffer_size)503 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data, 504 uint8_t *buffer, size_t buffer_size) 509 505 { 510 506 usb_log_debug("usb_mouse_polling_callback()\n"); 511 507 usb_debug_str_buffer(buffer, buffer_size, 0); 512 508 513 if (hid_dev == NULL ) {509 if (hid_dev == NULL || data == NULL) { 514 510 usb_log_error("Missing argument to the mouse polling callback." 515 511 "\n"); … … 517 513 } 518 514 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); 515 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 516 517 return usb_mouse_process_report(hid_dev, mouse_dev, buffer, 518 buffer_size); 519 } 520 521 /*----------------------------------------------------------------------------*/ 522 523 void usb_mouse_deinit(usb_hid_dev_t *hid_dev, void *data) 524 { 525 if (data != NULL) { 526 usb_mouse_free((usb_mouse_t **)&data); 527 } 533 528 } 534 529 -
uspace/drv/usbhid/mouse/mousedev.h
r97cb542 r65b458c4 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/multimedia/multimedia.c
r97cb542 r65b458c4 87 87 sysarg_t method = IPC_GET_IMETHOD(*icall); 88 88 89 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 90 91 if (hid_dev == NULL || hid_dev->data == NULL) { 89 usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data; 90 //usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 91 92 if (multim_dev == NULL) { 92 93 async_answer_0(icallid, EINVAL); 93 94 return; 94 95 } 95 96 assert(hid_dev != NULL);97 assert(hid_dev->data != NULL);98 usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data;99 96 100 97 if (method == IPC_M_CONNECT_TO_ME) { … … 139 136 * @param key Key code of the key according to HID Usage Tables. 140 137 */ 141 static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev, int type,142 u nsigned int key)138 static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev, 139 usb_multimedia_t *multim_dev, int type, unsigned int key) 143 140 { 144 141 assert(hid_dev != NULL); 145 assert( hid_dev->data!= NULL);146 147 usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data;142 assert(multim_dev != NULL); 143 144 // usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data; 148 145 149 146 console_event_t ev; … … 190 187 /*----------------------------------------------------------------------------*/ 191 188 192 static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev) 189 static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev, 190 usb_multimedia_t *multim_dev) 193 191 { 194 192 /* Create the function exposed under /dev/devices. */ … … 200 198 } 201 199 202 /*203 * Store the initialized HID device and HID ops204 * to the DDF function.205 */206 200 fun->ops = &multimedia_ops; 207 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data201 fun->driver_data = multim_dev; // TODO: maybe change to hid_dev->data 208 202 209 203 int rc = ddf_fun_bind(fun); … … 231 225 /*----------------------------------------------------------------------------*/ 232 226 233 int usb_multimedia_init(struct usb_hid_dev *hid_dev )227 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 234 228 { 235 229 if (hid_dev == NULL || hid_dev->usb_dev == NULL) { … … 282 276 283 277 // save the KBD device structure into the HID device structure 284 hid_dev->data = multim_dev;278 *data = multim_dev; 285 279 286 280 usb_log_debug(NAME " HID/multimedia device structure initialized.\n"); 287 281 288 int rc = usb_multimedia_create_function(hid_dev );282 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 289 283 if (rc != EOK) { 290 284 usb_multimedia_free(&multim_dev); … … 299 293 /*----------------------------------------------------------------------------*/ 300 294 301 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev )295 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data) 302 296 { 303 297 if (hid_dev == NULL) { … … 305 299 } 306 300 307 if (hid_dev->data != NULL) { 308 usb_multimedia_t *multim_dev = 309 (usb_multimedia_t *)hid_dev->data; 301 if (data != NULL) { 302 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 310 303 usb_multimedia_free(&multim_dev); 311 hid_dev->data = NULL; 312 } 313 } 314 315 /*----------------------------------------------------------------------------*/ 316 317 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, 304 } 305 } 306 307 /*----------------------------------------------------------------------------*/ 308 309 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data, 318 310 uint8_t *buffer, size_t buffer_size) 319 311 { … … 322 314 usb_log_debug(NAME " usb_lgtch_polling_callback(%p, %p, %zu)\n", 323 315 hid_dev, buffer, buffer_size); 316 317 if (data == NULL) { 318 return EINVAL; // TODO: other error code? 319 } 320 321 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 324 322 325 323 usb_log_debug(NAME " Calling usb_hid_parse_report() with " … … 361 359 usb_multimedia_usage_to_str(field->usage); 362 360 usb_log_info("Pressed key: %s\n", key_str); 363 usb_multimedia_push_ev(hid_dev, KEY_PRESS, key); 361 usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS, 362 key); 364 363 } 365 364 -
uspace/drv/usbhid/multimedia/multimedia.h
r97cb542 r65b458c4 43 43 /*----------------------------------------------------------------------------*/ 44 44 45 int usb_multimedia_init(struct usb_hid_dev *hid_dev );45 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data); 46 46 47 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev );47 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data); 48 48 49 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, 49 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data, 50 50 uint8_t *buffer, size_t buffer_size); 51 51 -
uspace/drv/usbhid/subdrivers.c
r97cb542 r65b458c4 99 99 } 100 100 }, 101 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL }}101 {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL, NULL}} 102 102 }; 103 103 -
uspace/drv/usbhid/usbhid.c
r97cb542 r65b458c4 466 466 if (hid_dev->subdrivers[i].init != NULL) { 467 467 usb_log_debug("Initializing subdriver %d.\n",i); 468 rc = hid_dev->subdrivers[i].init(hid_dev); 468 rc = hid_dev->subdrivers[i].init(hid_dev, 469 &hid_dev->subdrivers[i].data); 469 470 if (rc != EOK) { 470 471 usb_log_warning("Failed to initialize" … … 531 532 for (i = 0; i < hid_dev->subdriver_count; ++i) { 532 533 if (hid_dev->subdrivers[i].poll != NULL 533 && hid_dev->subdrivers[i].poll(hid_dev, buffer,534 buffer_size)) {534 && hid_dev->subdrivers[i].poll(hid_dev, 535 hid_dev->subdrivers[i].data, buffer, buffer_size)) { 535 536 cont = true; 536 537 } … … 555 556 for (i = 0; i < hid_dev->subdriver_count; ++i) { 556 557 if (hid_dev->subdrivers[i].poll_end != NULL) { 557 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); 558 560 } 559 561 } … … 636 638 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) { 637 639 if ((*hid_dev)->subdrivers[i].deinit != NULL) { 638 (*hid_dev)->subdrivers[i].deinit(*hid_dev); 640 (*hid_dev)->subdrivers[i].deinit(*hid_dev, 641 (*hid_dev)->subdrivers[i].data); 639 642 } 640 643 } -
uspace/drv/usbhid/usbhid.h
r97cb542 r65b458c4 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
Note:
See TracChangeset
for help on using the changeset viewer.