Ignore:
File:
1 edited

Legend:

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

    rbe01eb3 rb7fd2a0  
    5858static errno_t usb_hid_device_add(usb_device_t *dev)
    5959{
    60         usb_log_debug("%s", __FUNCTION__);
     60        usb_log_debug("%s\n", __FUNCTION__);
    6161
    6262        if (dev == NULL) {
    63                 usb_log_error("Wrong parameter given for add_device().");
     63                usb_log_error("Wrong parameter given for add_device().\n");
    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.");
     75                usb_log_error("Failed to create USB/HID device structure.\n");
    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.");
     81                usb_log_error("Failed to initialize USB/HID device.\n");
    8282                usb_hid_deinit(hid_dev);
    8383                return rc;
    8484        }
    8585
    86         usb_log_debug("USB/HID device structure initialized.");
     86        usb_log_debug("USB/HID device structure initialized.\n");
    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_polling_start(&hid_dev->polling);
     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);
    92104
    93105        if (rc != EOK) {
    94                 usb_log_error("Failed to start polling fibril for `%s'.",
     106                usb_log_error("Failed to start polling fibril for `%s'.\n",
    95107                    usb_device_get_name(dev));
    96108                usb_hid_deinit(hid_dev);
     
    99111        hid_dev->running = true;
    100112
    101         usb_log_info("HID device `%s' ready.", usb_device_get_name(dev));
    102 
    103         return EOK;
    104 }
    105 
    106 static 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));
     113        usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev));
    118114
    119115        return EOK;
     
    126122 * @return Error code.
    127123 */
    128 static errno_t usb_hid_device_remove(usb_device_t *dev)
     124static errno_t usb_hid_device_rem(usb_device_t *dev)
    129125{
    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);
     126        // TODO: Stop device polling
     127        // TODO: Call deinit (stops autorepeat too)
     128        return ENOTSUP;
    136129}
    137130
     
    147140        usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
    148141        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        }
    149151
    150         usb_log_info("Device %s gone.", usb_device_get_name(dev));
    151         return join_and_clean(dev);
     152        usb_hid_deinit(hid_dev);
     153        usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev));
     154        return EOK;
    152155}
    153156
     
    155158static const usb_driver_ops_t usb_hid_driver_ops = {
    156159        .device_add = usb_hid_device_add,
    157         .device_remove = usb_hid_device_remove,
     160        .device_rem = usb_hid_device_rem,
    158161        .device_gone = usb_hid_device_gone,
    159162};
Note: See TracChangeset for help on using the changeset viewer.