Changeset 818dc00 in mainline for uspace/lib/usb


Ignore:
Timestamp:
2010-12-09T00:02:25Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
040068c
Parents:
aca85e4 (diff), 07b9203e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with vojtechhorky/

Location:
uspace/lib/usb
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/Makefile

    raca85e4 r818dc00  
    3434SOURCES = \
    3535        src/addrkeep.c \
     36        src/debug.c \
     37        src/drvpsync.c \
    3638        src/hcdhubd.c \
    3739        src/hcdrv.c \
  • uspace/lib/usb/include/usb/usb.h

    raca85e4 r818dc00  
    7171/** Default USB address. */
    7272#define USB_ADDRESS_DEFAULT 0
     73/** Maximum address number in USB 1.1. */
     74#define USB11_ADDRESS_MAX 128
    7375
    7476/** USB endpoint number type.
  • uspace/lib/usb/include/usb/usbdrv.h

    raca85e4 r818dc00  
    3838#include <usb/usb.h>
    3939#include <driver.h>
     40#include <usb/devreq.h>
     41#include <usb/descriptor.h>
    4042
    4143int usb_drv_hc_connect(device_t *, unsigned int);
     
    5456    void *, size_t, size_t *, usb_handle_t *);
    5557
     58int usb_drv_psync_interrupt_out(int, usb_target_t, void *, size_t);
     59int usb_drv_psync_interrupt_in(int, usb_target_t, void *, size_t, size_t *);
     60
     61
     62
    5663int usb_drv_async_control_write_setup(int, usb_target_t,
    5764    void *, size_t, usb_handle_t *);
     
    6067int usb_drv_async_control_write_status(int, usb_target_t,
    6168    usb_handle_t *);
     69
     70int usb_drv_psync_control_write_setup(int, usb_target_t, void *, size_t);
     71int usb_drv_psync_control_write_data(int, usb_target_t, void *, size_t);
     72int usb_drv_psync_control_write_status(int, usb_target_t);
     73
    6274
    6375int usb_drv_async_control_read_setup(int, usb_target_t,
     
    6880    usb_handle_t *);
    6981
     82int usb_drv_psync_control_read_setup(int, usb_target_t, void *, size_t);
     83int usb_drv_psync_control_read_data(int, usb_target_t, void *, size_t, size_t *);
     84int usb_drv_psync_control_read_status(int, usb_target_t);
     85
     86
    7087int usb_drv_async_wait_for(usb_handle_t);
    7188
    7289
    7390int usb_drv_req_set_address(int, usb_address_t, usb_address_t);
     91int usb_drv_req_get_device_descriptor(int, usb_address_t,
     92    usb_standard_device_descriptor_t *);
    7493
    7594#endif
  • uspace/lib/usb/src/usbdrvreq.c

    raca85e4 r818dc00  
    3434 */
    3535#include <usb/usbdrv.h>
    36 #include <usb/devreq.h>
    3736#include <errno.h>
    3837
     
    9594}
    9695
     96/** Retrieve device descriptor of connected USB device.
     97 *
     98 * @param[in] phone Open phone to HC driver.
     99 * @param[in] address Device USB address.
     100 * @param[out] descriptor Storage for the device descriptor.
     101 * @return Error code.
     102 * @retval EBADMEM @p descriptor is NULL.
     103 */
     104int usb_drv_req_get_device_descriptor(int phone, usb_address_t address,
     105    usb_standard_device_descriptor_t *descriptor)
     106{
     107        if (descriptor == NULL) {
     108                return EBADMEM;
     109        }
     110
     111        /* Prepare the target. */
     112        usb_target_t target = {
     113                .address = address,
     114                .endpoint = 0
     115        };
     116
     117        /* Prepare the setup packet. */
     118        usb_device_request_setup_packet_t setup_packet = {
     119                .request_type = 128,
     120                .request = USB_DEVREQ_GET_DESCRIPTOR,
     121                .index = 0,
     122                .length = sizeof(usb_standard_device_descriptor_t)
     123        };
     124        setup_packet.value_high = USB_DESCTYPE_DEVICE;
     125        setup_packet.value_low = 0;
     126
     127        usb_handle_t handle;
     128        int rc;
     129
     130        /* Start the control read transfer. */
     131        rc = usb_drv_async_control_read_setup(phone, target,
     132            &setup_packet, sizeof(usb_device_request_setup_packet_t), &handle);
     133        if (rc != EOK) {
     134                return rc;
     135        }
     136        rc = usb_drv_async_wait_for(handle);
     137        if (rc != EOK) {
     138                return rc;
     139        }
     140
     141        /* Retrieve the descriptor. */
     142        size_t actually_transferred = 0;
     143        usb_standard_device_descriptor_t descriptor_tmp;
     144        rc = usb_drv_async_control_read_data(phone, target,
     145            &descriptor_tmp, sizeof(usb_standard_device_descriptor_t),
     146            &actually_transferred, &handle);
     147        if (rc != EOK) {
     148                return rc;
     149        }
     150        rc = usb_drv_async_wait_for(handle);
     151        if (rc != EOK) {
     152                return rc;
     153        }
     154
     155        /* Finish the control read transfer. */
     156        rc = usb_drv_async_control_read_status(phone, target, &handle);
     157        if (rc != EOK) {
     158                return rc;
     159        }
     160        rc = usb_drv_async_wait_for(handle);
     161        if (rc != EOK) {
     162                return rc;
     163        }
     164
     165        if (actually_transferred < sizeof(usb_standard_device_descriptor_t)) {
     166                return ELIMIT;
     167        }
     168
     169        /*
     170         * Everything is okay, copy the descriptor.
     171         */
     172        memcpy(descriptor, &descriptor_tmp,
     173            sizeof(usb_standard_device_descriptor_t));
     174
     175        return EOK;
     176}
     177
     178
     179
    97180/**
    98181 * @}
Note: See TracChangeset for help on using the changeset viewer.