Changeset 555499da in mainline


Ignore:
Timestamp:
2011-11-09T12:48:12Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e3c78efc
Parents:
8c62a71
Message:

usbhid: Merge usb_hid_device_add and usb_hid_try_add_device.

Location:
uspace/drv/bus/usb/usbhid
Files:
2 edited

Legend:

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

    r8c62a71 r555499da  
    4949
    5050/**
    51  * Function for adding a new device of type USB/HID/keyboard.
     51 * Callback for passing a new device to the driver.
    5252 *
    53  * This functions initializes required structures from the device's descriptors
    54  * and starts new fibril for polling the keyboard for events and another one for
    55  * handling auto-repeat of keys.
     53 * @note Currently, only boot-protocol keyboards are supported by this driver.
    5654 *
    57  * During initialization, the keyboard is switched into boot protocol, the idle
    58  * rate is set to 0 (infinity), resulting in the keyboard only reporting event
    59  * when a key is pressed or released. Finally, the LED lights are turned on
    60  * according to the default setup of lock keys.
    61  *
    62  * @note By default, the keyboards is initialized with Num Lock turned on and
    63  *       other locks turned off.
    64  * @note Currently supports only boot-protocol keyboards.
    65  *
    66  * @param dev Device to add.
     55 * @param dev Structure representing the new device.
    6756 * @return Error code.
    6857 */
    69 static int usb_hid_try_add_device(usb_device_t *dev)
     58static int usb_hid_device_add(usb_device_t *dev)
    7059{
    71         assert(dev != NULL);
     60        usb_log_debug("%s\n", __FUNCTION__);
    7261
    73         /* Initialize device (get and process descriptors, get address, etc.) */
    74         usb_log_debug("Initializing USB/HID device...\n");
     62        if (dev == NULL) {
     63                usb_log_error("Wrong parameter given for add_device().\n");
     64                return EINVAL;
     65        }
    7566
     67        if (dev->interface_no < 0) {
     68                usb_log_error("Failed to add HID device: endpoints not found."
     69                    "\n");
     70                return ENOTSUP;
     71        }
    7672        usb_hid_dev_t *hid_dev =
    7773            usb_device_data_alloc(dev, sizeof(usb_hid_dev_t));
     
    8379
    8480        int rc = usb_hid_init(hid_dev, dev);
    85 
    8681        if (rc != EOK) {
    8782                usb_log_error("Failed to initialize USB/HID device.\n");
     
    105100        /* Start automated polling function.
    106101         * This will create a separate fibril that will query the device
    107          * for the data continuously 
     102         * for the data continuously.
    108103         */
    109104       rc = usb_device_auto_poll(dev,
     
    126121        }
    127122        hid_dev->running = true;
    128 
    129         /*
    130          * Hurrah, device is initialized.
    131          */
    132         return EOK;
    133 }
    134 /*----------------------------------------------------------------------------*/
    135 /**
    136  * Callback for passing a new device to the driver.
    137  *
    138  * @note Currently, only boot-protocol keyboards are supported by this driver.
    139  *
    140  * @param dev Structure representing the new device.
    141  * @return Error code.
    142  */
    143 static int usb_hid_device_add(usb_device_t *dev)
    144 {
    145         usb_log_debug("usb_hid_device_add()\n");
    146 
    147         if (dev == NULL) {
    148                 usb_log_warning("Wrong parameter given for add_device().\n");
    149                 return EINVAL;
    150         }
    151 
    152         if (dev->interface_no < 0) {
    153                 usb_log_warning("Device is not a supported HID device.\n");
    154                 usb_log_error("Failed to add HID device: endpoints not found."
    155                     "\n");
    156                 return ENOTSUP;
    157         }
    158 
    159         int rc = usb_hid_try_add_device(dev);
    160 
    161         if (rc != EOK) {
    162                 usb_log_warning("Device is not a supported HID device.\n");
    163                 usb_log_error("Failed to add HID device: %s.\n",
    164                     str_error(rc));
    165                 return rc;
    166         }
    167123
    168124        usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name);
  • uspace/drv/bus/usb/usbhid/usbhid.c

    r8c62a71 r555499da  
    291291
    292292        /* We have all subdrivers determined, save them into the hid device */
    293         // TODO Dowe really need this complicated stuff if there is
     293        // TODO Do we really need this complicated stuff if there is
    294294        // max_subdrivers limitation?
    295295        return usb_hid_save_subdrivers(hid_dev, subdrivers, count);
    296296}
    297 
    298 /*----------------------------------------------------------------------------*/
    299 
     297/*----------------------------------------------------------------------------*/
    300298static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev)
    301299{
    302300        assert(hid_dev);
    303301        assert(dev);
     302
    304303
    305304        if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) {
     
    359358
    360359/*----------------------------------------------------------------------------*/
    361 
     360/*
     361 * This functions initializes required structures from the device's descriptors
     362 * and starts new fibril for polling the keyboard for events and another one for
     363 * handling auto-repeat of keys.
     364 *
     365 * During initialization, the keyboard is switched into boot protocol, the idle
     366 * rate is set to 0 (infinity), resulting in the keyboard only reporting event
     367 * when a key is pressed or released. Finally, the LED lights are turned on
     368 * according to the default setup of lock keys.
     369 *
     370 * @note By default, the keyboards is initialized with Num Lock turned on and
     371 *       other locks turned off.
     372 *
     373 * @param hid_dev Device to initialize, non-NULL.
     374 * @param dev USB device, non-NULL.
     375 * @return Error code.
     376 */
    362377int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    363378{
    364         int rc, i;
     379        assert(hid_dev);
     380        assert(dev);
    365381
    366382        usb_log_debug("Initializing HID structure...\n");
    367 
    368         if (hid_dev == NULL) {
    369                 usb_log_error("Failed to init HID structure: no structure given"
    370                     ".\n");
    371                 return EINVAL;
    372         }
    373 
    374         if (dev == NULL) {
    375                 usb_log_error("Failed to init HID structure: no USB device"
    376                     " given.\n");
    377                 return EINVAL;
    378         }
    379383
    380384        usb_hid_report_init(&hid_dev->report);
     
    384388        hid_dev->poll_pipe_index = -1;
    385389
    386         rc = usb_hid_check_pipes(hid_dev, dev);
     390        int rc = usb_hid_check_pipes(hid_dev, dev);
    387391        if (rc != EOK) {
    388392                return rc;
     
    449453                    hid_dev->subdriver_count);
    450454
    451                 for (i = 0; i < hid_dev->subdriver_count; ++i) {
     455                for (int i = 0; i < hid_dev->subdriver_count; ++i) {
    452456                        if (hid_dev->subdrivers[i].init != NULL) {
    453457                                usb_log_debug("Initializing subdriver %d.\n",i);
     
    560564
    561565/*----------------------------------------------------------------------------*/
    562 
    563566void usb_hid_deinit(usb_hid_dev_t *hid_dev)
    564567{
Note: See TracChangeset for help on using the changeset viewer.