Changes in uspace/drv/bus/usb/usbhid/mouse/mousedev.c [350274a:58563585] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r350274a r58563585 246 246 } 247 247 248 #define FUN_UNBIND_DESTROY(fun) \ 249 if (fun) { \ 250 if (ddf_fun_unbind((fun)) == EOK) { \ 251 ddf_fun_destroy((fun)); \ 252 } else { \ 253 usb_log_error("Could not unbind function `%s', it " \ 254 "will not be destroyed.\n", ddf_fun_get_name(fun)); \ 255 } \ 256 } else (void) 0 257 248 258 /** Get highest index of a button mentioned in given report. 249 259 * … … 286 296 } 287 297 288 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data) 289 { 290 ddf_fun_t *fun = NULL; 291 usb_mouse_t *mouse_dev = NULL; 292 bool bound = false; 293 int rc; 294 295 usb_log_debug("Initializing HID/Mouse structure...\n"); 296 297 if (hid_dev == NULL) { 298 usb_log_error("Failed to init mouse structure: no structure" 299 " given.\n"); 300 rc = EINVAL; 301 goto error; 302 } 303 304 /* Create the exposed function. */ 305 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); 306 fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 307 HID_MOUSE_FUN_NAME); 308 if (fun == NULL) { 309 usb_log_error("Could not create DDF function node `%s'.\n", 310 HID_MOUSE_FUN_NAME); 311 rc = ENOMEM; 312 goto error; 313 } 314 315 ddf_fun_set_ops(fun, &ops); 316 317 mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t)); 318 if (mouse_dev == NULL) { 319 usb_log_error("Error while creating USB/HID Mouse device " 320 "structure.\n"); 321 rc = ENOMEM; 322 goto error; 323 } 324 298 static int mouse_dev_init(usb_mouse_t *mouse_dev, usb_hid_dev_t *hid_dev) 299 { 325 300 // FIXME: This may not be optimal since stupid hardware vendor may 326 301 // use buttons 1, 2, 3 and 6000 and we would allocate array of … … 335 310 if (mouse_dev->buttons == NULL) { 336 311 usb_log_error(NAME ": out of memory, giving up on device!\n"); 337 rc = ENOMEM;338 goto error;312 free(mouse_dev); 313 return ENOMEM; 339 314 } 340 315 341 316 // TODO: how to know if the device supports the request??? 342 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 343 hid_dev->usb_dev->interface_no, IDLE_RATE); 344 345 rc = ddf_fun_bind(fun); 346 if (rc != EOK) { 317 usbhid_req_set_idle(usb_device_get_default_pipe(hid_dev->usb_dev), 318 usb_device_get_iface_number(hid_dev->usb_dev), IDLE_RATE); 319 return EOK; 320 } 321 322 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data) 323 { 324 usb_log_debug("Initializing HID/Mouse structure...\n"); 325 326 if (hid_dev == NULL) { 327 usb_log_error("Failed to init mouse structure: no structure" 328 " given.\n"); 329 return EINVAL; 330 } 331 332 /* Create the exposed function. */ 333 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); 334 ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev, 335 fun_exposed, HID_MOUSE_FUN_NAME); 336 if (fun == NULL) { 337 usb_log_error("Could not create DDF function node `%s'.\n", 338 HID_MOUSE_FUN_NAME); 339 return ENOMEM; 340 } 341 342 usb_mouse_t *mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t)); 343 if (mouse_dev == NULL) { 344 usb_log_error("Failed to alloc HID mouse device structure.\n"); 345 ddf_fun_destroy(fun); 346 return ENOMEM; 347 } 348 349 int ret = mouse_dev_init(mouse_dev, hid_dev); 350 if (ret != EOK) { 351 usb_log_error("Failed to init HID mouse device structure.\n"); 352 return ret; 353 } 354 355 ddf_fun_set_ops(fun, &ops); 356 357 ret = ddf_fun_bind(fun); 358 if (ret != EOK) { 347 359 usb_log_error("Could not bind DDF function `%s': %s.\n", 348 ddf_fun_get_name(fun), str_error(rc)); 349 goto error; 350 } 351 352 bound = true; 360 ddf_fun_get_name(fun), str_error(ret)); 361 ddf_fun_destroy(fun); 362 return ret; 363 } 353 364 354 365 usb_log_debug("Adding DDF function `%s' to category %s...\n", 355 366 ddf_fun_get_name(fun), HID_MOUSE_CATEGORY); 356 rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY); 357 if (rc != EOK) { 358 usb_log_error("Could not add DDF function to category %s: " 359 "%s.\n", HID_MOUSE_CATEGORY, str_error(rc)); 360 goto error; 361 } 362 367 ret = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY); 368 if (ret != EOK) { 369 usb_log_error( 370 "Could not add DDF function to category %s: %s.\n", 371 HID_MOUSE_CATEGORY, str_error(ret)); 372 FUN_UNBIND_DESTROY(fun); 373 return ret; 374 } 363 375 mouse_dev->mouse_fun = fun; 364 376 365 377 /* Save the Mouse device structure into the HID device structure. */ 366 378 *data = mouse_dev; 379 367 380 return EOK; 368 error:369 if (bound)370 ddf_fun_unbind(fun);371 if (mouse_dev != NULL)372 free(mouse_dev->buttons);373 if (fun != NULL)374 ddf_fun_destroy(fun);375 return rc;376 381 } 377 382 … … 404 409 } 405 410 406 ddf_fun_unbind(mouse_dev->mouse_fun);407 411 free(mouse_dev->buttons); 408 ddf_fun_destroy(mouse_dev->mouse_fun);412 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun); 409 413 } 410 414 … … 421 425 } 422 426 423 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 424 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 427 rc = usbhid_req_set_protocol( 428 usb_device_get_default_pipe(hid_dev->usb_dev), 429 usb_device_get_iface_number(hid_dev->usb_dev), 430 USB_HID_PROTOCOL_BOOT); 425 431 426 432 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.