Changes in uspace/drv/bus/usb/usbhid/mouse/mousedev.c [58563585:350274a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r58563585 r350274a 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) 0257 258 248 /** Get highest index of a button mentioned in given report. 259 249 * … … 296 286 } 297 287 298 static int mouse_dev_init(usb_mouse_t *mouse_dev, usb_hid_dev_t *hid_dev) 299 { 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 300 325 // FIXME: This may not be optimal since stupid hardware vendor may 301 326 // use buttons 1, 2, 3 and 6000 and we would allocate array of … … 310 335 if (mouse_dev->buttons == NULL) { 311 336 usb_log_error(NAME ": out of memory, giving up on device!\n"); 312 free(mouse_dev);313 return ENOMEM;337 rc = ENOMEM; 338 goto error; 314 339 } 315 340 316 341 // TODO: how to know if the device supports the request??? 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) { 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) { 359 347 usb_log_error("Could not bind DDF function `%s': %s.\n", 360 ddf_fun_get_name(fun), str_error(ret)); 361 ddf_fun_destroy(fun); 362 return ret; 363 } 348 ddf_fun_get_name(fun), str_error(rc)); 349 goto error; 350 } 351 352 bound = true; 364 353 365 354 usb_log_debug("Adding DDF function `%s' to category %s...\n", 366 355 ddf_fun_get_name(fun), HID_MOUSE_CATEGORY); 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 } 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 375 363 mouse_dev->mouse_fun = fun; 376 364 377 365 /* Save the Mouse device structure into the HID device structure. */ 378 366 *data = mouse_dev; 379 380 367 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; 381 376 } 382 377 … … 409 404 } 410 405 406 ddf_fun_unbind(mouse_dev->mouse_fun); 411 407 free(mouse_dev->buttons); 412 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);408 ddf_fun_destroy(mouse_dev->mouse_fun); 413 409 } 414 410 … … 425 421 } 426 422 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); 423 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 424 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 431 425 432 426 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.