Beispiel #1
0
/**
 * This function will set a configuration to the usb device.
 *
 * @param uinst the usb device instance.
 * @param config the configuration number.
  *
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usb_set_configure(uinst_t uinst, int config)
{
    struct ureqest setup;
    int timeout = 100;

    /* check parameter */
    RT_ASSERT(uinst != RT_NULL);

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD |
                         USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_SET_CONFIGURATION;
    setup.index = 0;
    setup.length = 0;
    setup.value = config;

    if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, RT_NULL, 0,
                               timeout) != 0) return -RT_EIO;

    return RT_EOK;
}
Beispiel #2
0
/**
 * This function will set an interface to the usb device.
 *
 * @param uinst the usb device instance.
 * @param intf the interface number.
 *
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usb_set_interface(uinst_t uinst, int intf)
{
    struct ureqest setup;
    int timeout = 100;

    /* check parameter */
    RT_ASSERT(uinst != RT_NULL);

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD |
                         USB_REQ_TYPE_INTERFACE;
    setup.request = USB_REQ_SET_INTERFACE;
    setup.index = 0;
    setup.length = 0;
    setup.value = intf;

    if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, RT_NULL, 0,
                               timeout) != 0) return -RT_EIO;

    return RT_EOK;
}
Beispiel #3
0
/**
 * This function will clear feature for the endpoint of the usb device.
 *
 * @param uinst the usb device instance.
 * @param endpoint the endpoint number of the usb device.
 * 
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usb_clear_feature(uinst_t uinst, int endpoint, int feature)
{
    struct ureqest setup;
    int timeout = 100;

    /* check parameter */
    RT_ASSERT(uinst != RT_NULL);

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD | 
        USB_REQ_TYPE_ENDPOINT;
    setup.request = USB_REQ_CLEAR_FEATURE;
    setup.index = endpoint;
    setup.length = 0;
    setup.value = feature;

    if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, RT_NULL, 0, 
        timeout) != 0) return -RT_EIO;
    
    return RT_EOK;    
}
Beispiel #4
0
/**
 * This function will do USB_REQ_GET_STATUS request for the device instance 
 * to get usb hub status.
 *
 * @param intf the interface instance.
 * @buffer the data buffer to save usb hub status.
 * 
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usbh_hub_get_status(struct uinstance* device, rt_uint8_t* buffer)
{
    struct ureqest setup;
    int timeout = 100;
    int length = 4;
    
    /* parameter check */
    RT_ASSERT(device != RT_NULL);

    setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS | 
        USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_GET_STATUS;
    setup.index = 0;
    setup.length = length;
    setup.value = 0;

    if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, length, 
        timeout) == length) return RT_EOK;
    else return -RT_FALSE;    
}
Beispiel #5
0
/**
 * This function will do USB_REQ_GET_DESCRIPTOR request for the device instance 
 * to get usb hub descriptor.
 *
 * @param intf the interface instance.
 * @buffer the data buffer to save usb hub descriptor.
 * @param nbytes the size of buffer
 * 
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_usbh_hub_get_descriptor(struct uinstance* device, rt_uint8_t *buffer, 
    rt_size_t nbytes)
{
    struct ureqest setup;
    int timeout = 100;
        
    /* parameter check */
    RT_ASSERT(device != RT_NULL);
    
    setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS | 
        USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_GET_DESCRIPTOR;
    setup.index = 0;
    setup.length = nbytes;
    setup.value = USB_DESC_TYPE_HUB << 8;

    if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, nbytes, 
        timeout) == nbytes) return RT_EOK;
    else return -RT_FALSE;    
}
Beispiel #6
0
/**
 * This function will do USB_REQ_GET_PROTOCOL request to set idle period to the usb adk device
 *
 * @param intf the interface instance.
 * @duration the idle period of requesting data.
 * @report_id the report id
 * 
 * @return the error code, RT_EOK on successfully.
*/
static rt_err_t rt_usbh_adk_get_protocol(struct uintf* intf, rt_uint16_t *protocol)
{
    struct ureqest setup;
    uinst_t device;    
    int timeout = 100;
            
        /* parameter check */
    RT_ASSERT(intf != RT_NULL);
    RT_ASSERT(intf->device != RT_NULL);

    device = intf->device;

    setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_VENDOR | 
        USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_GET_PROTOCOL;
    setup.index = 0;
    setup.length = 2;
    setup.value = 0;

    if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, (void*)protocol, 2, 
        timeout) == 0) return RT_EOK;
    else return -RT_FALSE;    
}
Beispiel #7
0
/**
 * This function will do USB_REQ_START request to set idle period to the usb adk device
 *
 * @param intf the interface instance.
 * @duration the idle period of requesting data.
 * @report_id the report id
 * 
 * @return the error code, RT_EOK on successfully.
*/
static rt_err_t rt_usbh_adk_start(struct uintf* intf)
{
    struct ureqest setup;
    uinst_t device;    
    int timeout = 100;
            
        /* parameter check */
    RT_ASSERT(intf != RT_NULL);
    RT_ASSERT(intf->device != RT_NULL);

    device = intf->device;

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_VENDOR | 
        USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_START;
    setup.index = 0;
    setup.length = 0;
    setup.value = 0;

    if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0, 
        timeout) == 0) return RT_EOK;
    else return -RT_FALSE;   
}
/**
 * This function will do USB_REQ_START request to set idle period to the usb adk device
 *
 * @param ifinst the interface instance.
 * @duration the idle period of requesting data.
 * @report_id the report id
 *
 * @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usb_adk_start(uifinst_t ifinst)
{
    struct ureqest setup;
    uinst_t uinst;
    int timeout = 100;

    /* parameter check */
    RT_ASSERT(ifinst != RT_NULL);
    RT_ASSERT(ifinst->uinst != RT_NULL);

    uinst = ifinst->uinst;

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_VENDOR |
                         USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_START;
    setup.index = 0;
    setup.length = 0;
    setup.value = 0;

    if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, RT_NULL, 0,
                               timeout) == 0) return RT_EOK;
    else return -RT_FALSE;
}
/**
 * This function will do USB_REQ_GET_PROTOCOL request to set idle period to the usb adk device
 *
 * @param ifinst the interface instance.
 * @duration the idle period of requesting data.
 * @report_id the report id
 *
 * @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usb_adk_get_protocol(uifinst_t ifinst, rt_uint16_t *protocol)
{
    struct ureqest setup;
    uinst_t uinst;
    int timeout = 100;

    /* parameter check */
    RT_ASSERT(ifinst != RT_NULL);
    RT_ASSERT(ifinst->uinst != RT_NULL);

    uinst = ifinst->uinst;

    setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_VENDOR |
                         USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_GET_PROTOCOL;
    setup.index = 0;
    setup.length = 2;
    setup.value = 0;

    if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, (void*)protocol, 2,
                               timeout) == 0) return RT_EOK;
    else return -RT_FALSE;
}
Beispiel #10
0
/**
 * This function will do USB_REQ_SEND_STRING request to set idle period to the usb adk device
 *
 * @param intf the interface instance.
 * @duration the idle period of requesting data.
 * @report_id the report id
 * 
 * @return the error code, RT_EOK on successfully.
*/
static rt_err_t rt_usbh_adk_send_string(struct uintf* intf, rt_uint16_t index, 
    const char* str)
{
    struct ureqest setup;
    uinst_t device;    
    int timeout = 100;
            
        /* parameter check */
    RT_ASSERT(intf != RT_NULL);
    RT_ASSERT(intf->device != RT_NULL);

    device = intf->device;

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_VENDOR | 
        USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_SEND_STRING;
    setup.index = index;
    setup.length = rt_strlen(str) + 1;
    setup.value = 0;

    if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, (void*)str, 
        rt_strlen(str) + 1, timeout) == 0) return RT_EOK;
    else return -RT_FALSE;   
}