Changeset 97bfba1 in mainline


Ignore:
Timestamp:
2011-01-07T16:25:51Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9b95dbcf
Parents:
692c0d3e
Message:

Add generic function for GET_DESCRIPTOR request

Location:
uspace/lib/usb
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/devreq.h

    r692c0d3e r97bfba1  
    9292int usb_drv_req_get_full_configuration_descriptor(int, usb_address_t, int,
    9393    void *, size_t, size_t *);
     94int usb_drv_req_get_descriptor(int, usb_address_t, usb_request_type_t,
     95    uint8_t, uint8_t, uint16_t, void *, size_t, size_t *);
    9496
    9597
  • uspace/lib/usb/include/usb/usb.h

    r692c0d3e r97bfba1  
    5454        USB_DIRECTION_OUT
    5555} usb_direction_t;
     56
     57/** USB request type target. */
     58typedef enum {
     59        USB_REQUEST_TYPE_STANDARD = 0,
     60        USB_REQUEST_TYPE_CLASS = 1,
     61        USB_REQUEST_TYPE_VENDOR = 2
     62} usb_request_type_t;
    5663
    5764/** USB transaction outcome. */
  • uspace/lib/usb/src/usbdrvreq.c

    r692c0d3e r97bfba1  
    7373}
    7474
     75/** Retrieve USB descriptor of connected USB device.
     76 *
     77 * @param[in] hc_phone Open phone to HC driver.
     78 * @param[in] address Device USB address.
     79 * @param[in] request_type Request type (standard/class/vendor).
     80 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
     81 * @param[in] descriptor_index Descriptor index.
     82 * @param[in] langauge Language index.
     83 * @param[out] buffer Buffer where to store the retrieved descriptor.
     84 * @param[in] size Size of the @p buffer.
     85 * @param[out] actual_size Number of bytes actually transferred.
     86 * @return Error code.
     87 */
     88int usb_drv_req_get_descriptor(int hc_phone, usb_address_t address,
     89    usb_request_type_t request_type,
     90    uint8_t descriptor_type, uint8_t descriptor_index,
     91    uint16_t language,
     92    void *buffer, size_t size, size_t *actual_size)
     93{
     94        /* Prepare the target. */
     95        usb_target_t target = {
     96                .address = address,
     97                .endpoint = 0
     98        };
     99
     100        /* Prepare the setup packet. */
     101        usb_device_request_setup_packet_t setup_packet = {
     102                .request_type = 128 | (request_type << 5),
     103                .request = USB_DEVREQ_GET_DESCRIPTOR,
     104                .index = language,
     105                .length = (uint16_t) size,
     106        };
     107        setup_packet.value_high = descriptor_type;
     108        setup_packet.value_low = descriptor_index;
     109       
     110        /* Perform CONTROL READ */
     111        int rc = usb_drv_psync_control_read(hc_phone, target,
     112            &setup_packet, sizeof(setup_packet),
     113            buffer, size, actual_size);
     114       
     115        return rc;
     116}
     117
    75118/** Retrieve device descriptor of connected USB device.
    76119 *
Note: See TracChangeset for help on using the changeset viewer.