Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset f4138ac in mainline


Ignore:
Timestamp:
2013-01-26T19:22:41Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
b06d35a
Parents:
2dc5a9f
Message:

libusbdev: Use alternate_interfaces.current.

It's initialized to zero if there are no alternatives.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/devdrv.c

    r2dc5a9f rf4138ac  
    7676 * @return Error code.
    7777 */
    78 int usb_device_select_interface(usb_device_t *dev, uint8_t alternate_setting,
    79     const usb_endpoint_description_t **endpoints)
    80 {
    81         if (dev->interface_no < 0) {
     78int usb_device_select_interface(usb_device_t *usb_dev,
     79    uint8_t alternate_setting, const usb_endpoint_description_t **endpoints)
     80{
     81        assert(usb_dev);
     82
     83        if (usb_dev->interface_no < 0) {
    8284                return EINVAL;
    8385        }
    8486
     87        /* Change the interface itself. */
     88        int rc = usb_request_set_interface(&usb_dev->ctrl_pipe,
     89            usb_dev->interface_no, alternate_setting);
     90        if (rc != EOK) {
     91                return rc;
     92        }
     93
     94        /* Change current alternative */
     95        usb_dev->alternate_interfaces.current = alternate_setting;
     96
    8597        /* Destroy existing pipes. */
    86         usb_device_destroy_pipes(dev);
    87 
    88         /* Change the interface itself. */
    89         int rc = usb_request_set_interface(&dev->ctrl_pipe, dev->interface_no,
    90             alternate_setting);
    91         if (rc != EOK) {
    92                 return rc;
    93         }
     98        usb_device_destroy_pipes(usb_dev);
    9499
    95100        /* Create new pipes. */
    96         rc = usb_device_create_pipes(&dev->wire, endpoints,
    97             dev->descriptors.configuration, dev->descriptors.configuration_size,
    98             dev->interface_no, (int)alternate_setting,
    99             &dev->pipes, &dev->pipes_count);
     101        rc = usb_device_create_pipes(&usb_dev->wire, endpoints,
     102            usb_dev->descriptors.configuration,
     103            usb_dev->descriptors.configuration_size,
     104            usb_dev->interface_no, usb_dev->alternate_interfaces.current,
     105            &usb_dev->pipes, &usb_dev->pipes_count);
    100106
    101107        return rc;
     
    381387            usb_dev->descriptors.configuration,
    382388            usb_dev->descriptors.configuration_size, usb_dev->interface_no);
    383         const int alternate_iface =
    384             (rc == EOK) ? usb_dev->alternate_interfaces.current : 0;
    385389
    386390        /* Create and register other pipes than default control (EP 0) */
     
    388392            usb_dev->descriptors.configuration,
    389393            usb_dev->descriptors.configuration_size,
    390             usb_dev->interface_no, (int)alternate_iface,
     394            usb_dev->interface_no, usb_dev->alternate_interfaces.current,
    391395            &usb_dev->pipes, &usb_dev->pipes_count);
    392396        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.