Changes in uspace/drv/bus/usb/usbhid/mouse/mousedev.c [4093b14:f2964e45] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r4093b14 rf2964e45 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); 188 int ret = ddf_fun_unbind(mouse_dev->mouse_fun); 189 if (ret != EOK) { 190 usb_log_error("Failed to unbind mouse function.\n"); 191 } else { 192 ddf_fun_destroy(mouse_dev->mouse_fun); 193 /* Prevent double free */ 194 mouse_dev->wheel_fun->driver_data = NULL; 195 } 196 197 ret = ddf_fun_unbind(mouse_dev->wheel_fun); 198 if (ret != EOK) { 199 usb_log_error("Failed to unbind wheel function.\n"); 200 } else { 201 ddf_fun_destroy(mouse_dev->wheel_fun); 202 } 188 203 } 189 204 … … 199 214 return; 200 215 } 201 216 202 217 int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 203 218 int i; 204 219 205 220 for (i = 0; i < count; i++) { 206 221 /* Send arrow press and release. */ … … 246 261 { 247 262 assert(mouse_dev != NULL); 248 263 249 264 if (mouse_dev->mouse_sess == NULL) { 250 265 usb_log_warning(NAME " No console session.\n"); … … 264 279 async_exchange_end(exch); 265 280 } 266 281 267 282 if (wheel != 0) 268 283 usb_mouse_send_wheel(mouse_dev, wheel); 269 284 270 285 /* 271 286 * Buttons … … 274 289 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 275 290 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 276 291 277 292 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 278 293 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END … … 309 324 USB_HID_REPORT_TYPE_INPUT); 310 325 } 311 326 312 327 usb_hid_report_path_free(path); 313 328 … … 321 336 assert(hid_dev != NULL); 322 337 assert(mouse != NULL); 323 338 324 339 /* Create the exposed function. */ 325 340 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); … … 330 345 return ENOMEM; 331 346 } 332 347 333 348 fun->ops = &mouse->ops; 334 349 fun->driver_data = mouse; … … 338 353 usb_log_error("Could not bind DDF function: %s.\n", 339 354 str_error(rc)); 340 ddf_fun_destroy(fun); 341 return rc; 342 } 343 355 return rc; 356 } 357 344 358 usb_log_debug("Adding DDF function to category %s...\n", 345 359 HID_MOUSE_CATEGORY); … … 349 363 "Could not add DDF function to category %s: %s.\n", 350 364 HID_MOUSE_CATEGORY, str_error(rc)); 351 ddf_fun_destroy(fun);352 return rc;353 }354 365 return rc; 366 } 367 mouse->mouse_fun = fun; 368 355 369 /* 356 370 * Special function for acting as keyboard (wheel) … … 364 378 return ENOMEM; 365 379 } 366 380 367 381 /* 368 382 * Store the initialized HID device and HID ops … … 376 390 usb_log_error("Could not bind DDF function: %s.\n", 377 391 str_error(rc)); 378 ddf_fun_destroy(fun); 379 return rc; 380 } 381 392 return rc; 393 } 394 382 395 usb_log_debug("Adding DDF function to category %s...\n", 383 396 HID_MOUSE_WHEEL_CATEGORY); … … 387 400 "Could not add DDF function to category %s: %s.\n", 388 401 HID_MOUSE_WHEEL_CATEGORY, str_error(rc)); 389 ddf_fun_destroy(fun);390 return rc;391 }392 402 return rc; 403 } 404 mouse->wheel_fun = fun; 405 393 406 return EOK; 394 407 } … … 441 454 { 442 455 usb_log_debug("Initializing HID/Mouse structure...\n"); 443 456 444 457 if (hid_dev == NULL) { 445 458 usb_log_error("Failed to init keyboard structure: no structure" … … 447 460 return EINVAL; 448 461 } 449 462 450 463 usb_mouse_t *mouse_dev = usb_mouse_new(); 451 464 if (mouse_dev == NULL) { … … 454 467 return ENOMEM; 455 468 } 456 469 457 470 // FIXME: This may not be optimal since stupid hardware vendor may 458 471 // use buttons 1, 2, 3 and 6000 and we would allocate array of … … 464 477 hid_dev->report_id) + 1; 465 478 mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t)); 466 479 467 480 if (mouse_dev->buttons == NULL) { 468 481 usb_log_error(NAME ": out of memory, giving up on device!\n"); … … 474 487 // save the Mouse device structure into the HID device structure 475 488 *data = mouse_dev; 476 489 477 490 // set handler for incoming calls 478 491 mouse_dev->ops.default_handler = default_connection_handler; 479 492 480 493 // TODO: how to know if the device supports the request??? 481 494 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 482 495 hid_dev->usb_dev->interface_no, IDLE_RATE); 483 496 484 497 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 485 498 if (rc != EOK) { … … 487 500 return rc; 488 501 } 489 502 490 503 return EOK; 491 504 } … … 500 513 return false; 501 514 } 502 515 503 516 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 504 517 … … 511 524 { 512 525 if (data != NULL) { 513 usb_mouse_destroy( (usb_mouse_t *)data);526 usb_mouse_destroy(data); 514 527 } 515 528 } … … 522 535 USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 523 536 USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE); 524 537 525 538 if (rc != EOK) { 526 539 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 528 541 return rc; 529 542 } 530 543 531 544 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 532 545 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 533 546 534 547 if (rc != EOK) { 535 548 usb_log_warning("Failed to set boot protocol to the device: " … … 537 550 return rc; 538 551 } 539 552 540 553 return EOK; 541 554 }
Note:
See TracChangeset
for help on using the changeset viewer.