Ignore:
File:
1 edited

Legend:

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

    r065064e6 r5f6e25e  
    7676{
    7777        assert(dev != NULL);
    78 
    79         /* Initialize device (get and process descriptors, get address, etc.) */
     78       
     79        /*
     80         * Initialize device (get and process descriptors, get address, etc.)
     81         */
    8082        usb_log_debug("Initializing USB/HID device...\n");
    81 
    82         usb_hid_dev_t *hid_dev =
    83             usb_device_data_alloc(dev, sizeof(usb_hid_dev_t));
     83       
     84        usb_hid_dev_t *hid_dev = usb_hid_new();
    8485        if (hid_dev == NULL) {
    8586                usb_log_error("Error while creating USB/HID device "
     
    8788                return ENOMEM;
    8889        }
    89 
     90       
    9091        int rc = usb_hid_init(hid_dev, dev);
    91 
     92       
    9293        if (rc != EOK) {
    9394                usb_log_error("Failed to initialize USB/HID device.\n");
    9495                usb_hid_destroy(hid_dev);
    9596                return rc;
    96         }
    97 
     97        }       
     98       
    9899        usb_log_debug("USB/HID device structure initialized.\n");
    99 
     100       
    100101        /*
    101102         * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da
     
    108109         *    pouzit usb/classes/hid/iface.h - prvy int je telefon
    109110         */
    110 
     111       
    111112        /* Start automated polling function.
    112113         * This will create a separate fibril that will query the device
     
    124125           /* Custom argument. */
    125126           hid_dev);
    126 
     127       
     128       
    127129        if (rc != EOK) {
    128130                usb_log_error("Failed to start polling fibril for `%s'.\n",
    129131                    dev->ddf_dev->name);
    130                 usb_hid_destroy(hid_dev);
    131132                return rc;
    132133        }
    133         hid_dev->running = true;
    134         dev->driver_data = hid_dev;
    135134
    136135        /*
     
    151150 * @retval EREFUSED if the device is not supported.
    152151 */
    153 static int usb_hid_device_add(usb_device_t *dev)
     152static int usb_hid_add_device(usb_device_t *dev)
    154153{
    155         usb_log_debug("usb_hid_device_add()\n");
    156 
     154        usb_log_debug("usb_hid_add_device()\n");
     155       
    157156        if (dev == NULL) {
    158157                usb_log_warning("Wrong parameter given for add_device().\n");
    159158                return EINVAL;
    160159        }
    161 
     160       
    162161        if (dev->interface_no < 0) {
    163162                usb_log_warning("Device is not a supported HID device.\n");
     
    166165                return ENOTSUP;
    167166        }
    168 
     167       
    169168        int rc = usb_hid_try_add_device(dev);
    170 
     169       
    171170        if (rc != EOK) {
    172171                usb_log_warning("Device is not a supported HID device.\n");
     
    175174                return rc;
    176175        }
    177 
     176       
    178177        usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name);
    179178
     
    183182/*----------------------------------------------------------------------------*/
    184183
    185 /**
    186  * Callback for removing a device from the driver.
    187  *
    188  * @param dev Structure representing the device.
    189  *
    190  * @retval EOK if successful.
    191  * @retval EREFUSED if the device is not supported.
    192  */
    193 static int usb_hid_device_gone(usb_device_t *dev)
    194 {
    195         usb_hid_dev_t *hid_dev = dev->driver_data;
    196         unsigned tries = 10;
    197         while (hid_dev->running) {
    198                 async_usleep(100000);
    199                 if (!tries--) {
    200                         usb_log_error("Can't remove hub, still running.\n");
    201                         return EINPROGRESS;
    202                 }
    203         }
    204 
    205         assert(!hid_dev->running);
    206         usb_hid_destroy(hid_dev);
    207         usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name);
    208         return EOK;
    209 }
    210 
    211 /** USB generic driver callbacks */
     184/* Currently, the framework supports only device adding. Once the framework
     185 * supports unplug, more callbacks will be added. */
    212186static usb_driver_ops_t usb_hid_driver_ops = {
    213         .device_add = usb_hid_device_add,
    214         .device_gone = usb_hid_device_gone,
     187        .add_device = usb_hid_add_device,
    215188};
    216189
    217190
    218 /** The driver itself. */
     191/* The driver itself. */
    219192static usb_driver_t usb_hid_driver = {
    220193        .name = NAME,
Note: See TracChangeset for help on using the changeset viewer.