Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/hid/usbhid/main.c

    rb7fd2a0 rbe01eb3  
    5858static errno_t usb_hid_device_add(usb_device_t *dev)
    5959{
    60         usb_log_debug("%s\n", __FUNCTION__);
     60        usb_log_debug("%s", __FUNCTION__);
    6161
    6262        if (dev == NULL) {
    63                 usb_log_error("Wrong parameter given for add_device().\n");
     63                usb_log_error("Wrong parameter given for add_device().");
    6464                return EINVAL;
    6565        }
     
    7373            usb_device_data_alloc(dev, sizeof(usb_hid_dev_t));
    7474        if (hid_dev == NULL) {
    75                 usb_log_error("Failed to create USB/HID device structure.\n");
     75                usb_log_error("Failed to create USB/HID device structure.");
    7676                return ENOMEM;
    7777        }
     
    7979        errno_t rc = usb_hid_init(hid_dev, dev);
    8080        if (rc != EOK) {
    81                 usb_log_error("Failed to initialize USB/HID device.\n");
     81                usb_log_error("Failed to initialize USB/HID device.");
    8282                usb_hid_deinit(hid_dev);
    8383                return rc;
    8484        }
    8585
    86         usb_log_debug("USB/HID device structure initialized.\n");
     86        usb_log_debug("USB/HID device structure initialized.");
    8787
    8888        /* Start automated polling function.
    8989         * This will create a separate fibril that will query the device
    9090         * for the data continuously. */
    91         rc = usb_device_auto_poll_desc(dev,
    92            /* Index of the polling pipe. */
    93            hid_dev->poll_pipe_mapping->description,
    94            /* Callback when data arrives. */
    95            usb_hid_polling_callback,
    96            /* How much data to request. */
    97            hid_dev->poll_pipe_mapping->pipe.max_packet_size,
    98            /* Delay */
    99            -1,
    100            /* Callback when the polling ends. */
    101            usb_hid_polling_ended_callback,
    102            /* Custom argument. */
    103            hid_dev);
     91        rc = usb_polling_start(&hid_dev->polling);
    10492
    10593        if (rc != EOK) {
    106                 usb_log_error("Failed to start polling fibril for `%s'.\n",
     94                usb_log_error("Failed to start polling fibril for `%s'.",
    10795                    usb_device_get_name(dev));
    10896                usb_hid_deinit(hid_dev);
     
    11199        hid_dev->running = true;
    112100
    113         usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev));
     101        usb_log_info("HID device `%s' ready.", usb_device_get_name(dev));
     102
     103        return EOK;
     104}
     105
     106static errno_t join_and_clean(usb_device_t *dev)
     107{
     108        assert(dev);
     109        usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
     110        assert(hid_dev);
     111
     112        /* Join polling fibril (ignoring error code). */
     113        usb_polling_join(&hid_dev->polling);
     114
     115        /* Clean up. */
     116        usb_hid_deinit(hid_dev);
     117        usb_log_info("%s destruction complete.", usb_device_get_name(dev));
    114118
    115119        return EOK;
     
    122126 * @return Error code.
    123127 */
    124 static errno_t usb_hid_device_rem(usb_device_t *dev)
     128static errno_t usb_hid_device_remove(usb_device_t *dev)
    125129{
    126         // TODO: Stop device polling
    127         // TODO: Call deinit (stops autorepeat too)
    128         return ENOTSUP;
     130        assert(dev);
     131        usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
     132        assert(hid_dev);
     133
     134        usb_log_info("Device %s removed.", usb_device_get_name(dev));
     135        return join_and_clean(dev);
    129136}
    130137
     
    140147        usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
    141148        assert(hid_dev);
    142         unsigned tries = 100;
    143         /* Wait for fail. */
    144         while (hid_dev->running && tries--) {
    145                 async_usleep(100000);
    146         }
    147         if (hid_dev->running) {
    148                 usb_log_error("Can't remove hid, still running.\n");
    149                 return EBUSY;
    150         }
    151149
    152         usb_hid_deinit(hid_dev);
    153         usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev));
    154         return EOK;
     150        usb_log_info("Device %s gone.", usb_device_get_name(dev));
     151        return join_and_clean(dev);
    155152}
    156153
     
    158155static const usb_driver_ops_t usb_hid_driver_ops = {
    159156        .device_add = usb_hid_device_add,
    160         .device_rem = usb_hid_device_rem,
     157        .device_remove = usb_hid_device_remove,
    161158        .device_gone = usb_hid_device_gone,
    162159};
Note: See TracChangeset for help on using the changeset viewer.