Changeset 38b4a25 in mainline
- Timestamp:
- 2012-12-22T19:25:56Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 56a07e0
- Parents:
- 1e2af6a9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r1e2af6a9 r38b4a25 34 34 * USB Mouse driver API. 35 35 */ 36 37 /* XXX Fix this */38 #define _DDF_DATA_IMPLANT39 36 40 37 #include <usb/debug.h> … … 259 256 } else (void)0 260 257 261 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)262 {263 assert(hid_dev != NULL);264 assert(mouse != NULL);265 266 /* Create the exposed function. */267 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);268 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,269 HID_MOUSE_FUN_NAME);270 if (fun == NULL) {271 usb_log_error("Could not create DDF function node `%s'.\n",272 HID_MOUSE_FUN_NAME);273 return ENOMEM;274 }275 276 ddf_fun_set_ops(fun, &ops);277 ddf_fun_data_implant(fun, mouse);278 279 int rc = ddf_fun_bind(fun);280 if (rc != EOK) {281 usb_log_error("Could not bind DDF function `%s': %s.\n",282 ddf_fun_get_name(fun), str_error(rc));283 ddf_fun_destroy(fun);284 return rc;285 }286 287 usb_log_debug("Adding DDF function `%s' to category %s...\n",288 ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);289 rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);290 if (rc != EOK) {291 usb_log_error(292 "Could not add DDF function to category %s: %s.\n",293 HID_MOUSE_CATEGORY, str_error(rc));294 FUN_UNBIND_DESTROY(fun);295 return rc;296 }297 mouse->mouse_fun = fun;298 return EOK;299 }300 301 258 /** Get highest index of a button mentioned in given report. 302 259 * … … 339 296 } 340 297 341 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data) 342 { 343 usb_log_debug("Initializing HID/Mouse structure...\n"); 344 345 if (hid_dev == NULL) { 346 usb_log_error("Failed to init keyboard structure: no structure" 347 " given.\n"); 348 return EINVAL; 349 } 350 351 usb_mouse_t *mouse_dev = calloc(1, sizeof(usb_mouse_t)); 352 if (mouse_dev == NULL) { 353 usb_log_error("Error while creating USB/HID Mouse device " 354 "structure.\n"); 355 return ENOMEM; 356 } 357 298 static int mouse_dev_init(usb_mouse_t *mouse_dev, usb_hid_dev_t *hid_dev) 299 { 358 300 // FIXME: This may not be optimal since stupid hardware vendor may 359 301 // use buttons 1, 2, 3 and 6000 and we would allocate array of … … 375 317 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 376 318 hid_dev->usb_dev->interface_no, IDLE_RATE); 377 378 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 379 if (rc != EOK) { 380 free(mouse_dev->buttons); 381 free(mouse_dev); 382 return rc; 383 } 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 keyboard 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 = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 335 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) { 359 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 } 364 365 usb_log_debug("Adding DDF function `%s' to category %s...\n", 366 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 } 375 mouse_dev->mouse_fun = fun; 384 376 385 377 /* Save the Mouse device structure into the HID device structure. */ … … 417 409 } 418 410 411 free(mouse_dev->buttons); 419 412 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun); 420 421 free(mouse_dev->buttons);422 413 } 423 414
Note:
See TracChangeset
for help on using the changeset viewer.