Ignore:
Timestamp:
2016-07-22T08:24:47Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r5b18137 rb4b534ac  
    246246}
    247247
     248#define FUN_UNBIND_DESTROY(fun) \
     249if (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
    248258/** Get highest index of a button mentioned in given report.
    249259 *
     
    286296}
    287297
    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 
     298static int mouse_dev_init(usb_mouse_t *mouse_dev, usb_hid_dev_t *hid_dev)
     299{
    325300        // FIXME: This may not be optimal since stupid hardware vendor may
    326301        // use buttons 1, 2, 3 and 6000 and we would allocate array of
     
    335310        if (mouse_dev->buttons == NULL) {
    336311                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;
    339314        }
    340315
    341316        // 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
     322int 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 = 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) {
    347359                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        }
    353364
    354365        usb_log_debug("Adding DDF function `%s' to category %s...\n",
    355366            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        }
    363375        mouse_dev->mouse_fun = fun;
    364376
    365377        /* Save the Mouse device structure into the HID device structure. */
    366378        *data = mouse_dev;
     379
    367380        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;
    376381}
    377382
     
    404409        }
    405410
    406         ddf_fun_unbind(mouse_dev->mouse_fun);
    407411        free(mouse_dev->buttons);
    408         ddf_fun_destroy(mouse_dev->mouse_fun);
     412        FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
    409413}
    410414
     
    421425        }
    422426
    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);
    425431
    426432        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.