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