未验证 提交 60b756a8 编写于 作者: lymzzyh's avatar lymzzyh 提交者: GitHub

Merge pull request #1291 from uestczyh222/master

[Components][USB Device]增加设备栈对HS设备的支持
......@@ -140,6 +140,7 @@ struct udcd
struct uendpoint ep0;
uep0_stage_t stage;
struct ep_id* ep_pool;
rt_uint8_t device_is_hs;
};
typedef struct udcd* udcd_t;
......
......@@ -114,15 +114,17 @@ static struct udevice_descriptor dev_desc =
USB_DYNAMIC, //bNumConfigurations;
};
//FS and HS needed
static struct usb_qualifier_descriptor dev_qualifier =
{
sizeof(dev_qualifier),
USB_DESC_TYPE_DEVICEQUALIFIER,
0x0200,
USB_CLASS_CDC,
0x00,
64,
0x01,
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
USB_CLASS_CDC, //bDeviceClass
0x00, //bDeviceSubClass
0x00, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
0,
};
......@@ -566,7 +568,8 @@ ufunction_t rt_usbd_function_cdc_create(udevice_t device)
/* create a cdc function */
func = rt_usbd_function_new(device, &dev_desc, &ops);
rt_usbd_device_set_qualifier(device, &dev_qualifier);
//not support HS
//rt_usbd_device_set_qualifier(device, &dev_qualifier);
/* allocate memory for cdc vcom data */
data = (struct vcom*)rt_malloc(sizeof(struct vcom));
......
......@@ -41,7 +41,7 @@ struct rt_ecm_eth
rt_uint8_t dev_addr[MAX_ADDR_LEN];
ALIGN(4)
rt_uint8_t rx_pool[64];
rt_uint8_t rx_pool[512];
ALIGN(4)
rt_size_t rx_size;
ALIGN(4)
......@@ -147,14 +147,14 @@ const static struct ucdc_data_descriptor _data_desc =
USB_DESC_TYPE_ENDPOINT,
USB_DIR_OUT | USB_DYNAMIC,
USB_EP_ATTR_BULK,
USB_CDC_BUFSIZE,
USB_DYNAMIC,
0x00,
/* endpoint, bulk in */
USB_DESC_LENGTH_ENDPOINT,
USB_DESC_TYPE_ENDPOINT,
USB_DYNAMIC | USB_DIR_IN,
USB_EP_ATTR_BULK,
USB_CDC_BUFSIZE,
USB_DYNAMIC,
0x00,
};
......@@ -170,17 +170,20 @@ const static char* _ustring[] =
};
ALIGN(4)
//FS and HS needed
static struct usb_qualifier_descriptor dev_qualifier =
{
sizeof(dev_qualifier),
USB_DESC_TYPE_DEVICEQUALIFIER,
0x0200,
USB_CLASS_CDC,
0x00,
64,
0x01,
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
USB_CLASS_CDC, //bDeviceClass
USB_CDC_SUBCLASS_ETH, //bDeviceSubClass
USB_CDC_PROTOCOL_NONE, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
0,
};
static rt_err_t _cdc_send_notifi(ufunction_t func,ucdc_notification_code_t notifi,rt_uint16_t wValue,rt_uint16_t wLength)
{
static struct ucdc_management_element_notifications _notifi;
......@@ -472,7 +475,7 @@ static struct ufunction_ops ops =
*
* @return RT_EOK on successful.
*/
static rt_err_t _cdc_descriptor_config(ucdc_comm_desc_t comm, rt_uint8_t cintf_nr, ucdc_data_desc_t data, rt_uint8_t dintf_nr)
static rt_err_t _cdc_descriptor_config(ucdc_comm_desc_t comm, rt_uint8_t cintf_nr, ucdc_data_desc_t data, rt_uint8_t dintf_nr, rt_uint8_t device_is_hs)
{
comm->call_mgmt_desc.data_interface = dintf_nr;
comm->union_desc.master_interface = cintf_nr;
......@@ -480,7 +483,8 @@ static rt_err_t _cdc_descriptor_config(ucdc_comm_desc_t comm, rt_uint8_t cintf_n
#ifdef RT_USB_DEVICE_COMPOSITE
comm->iad_desc.bFirstInterface = cintf_nr;
#endif
data->ep_out_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
data->ep_in_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
return RT_EOK;
}
......@@ -532,7 +536,7 @@ ufunction_t rt_usbd_function_ecm_create(udevice_t device)
(rt_off_t)&((ucdc_eth_desc_t)0)->intf_desc);
rt_usbd_altsetting_config_descriptor(data_setting, &_data_desc, 0);
/* configure the cdc interface descriptor */
_cdc_descriptor_config(comm_setting->desc, intf_comm->intf_num, data_setting->desc, intf_data->intf_num);
_cdc_descriptor_config(comm_setting->desc, intf_comm->intf_num, data_setting->desc, intf_data->intf_num, device->dcd->device_is_hs);
/* create a command endpoint */
comm_desc = (ucdc_eth_desc_t)comm_setting->desc;
......
......@@ -227,18 +227,21 @@ static struct udevice_descriptor _dev_desc =
USB_DYNAMIC, //bNumConfigurations;
};
static struct usb_qualifier_descriptor _dev_qualifier =
//FS and HS needed
static struct usb_qualifier_descriptor dev_qualifier =
{
sizeof(_dev_qualifier),
USB_DESC_TYPE_DEVICEQUALIFIER,
0x0200,
USB_CLASS_HID,
0x00,
64,
0x01,
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
USB_CLASS_MASS_STORAGE, //bDeviceClass
0x06, //bDeviceSubClass
0x50, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
0,
};
/* hid interface descriptor */
const static struct uhid_comm_descriptor _hid_comm_desc =
{
......@@ -631,7 +634,8 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device)
/* create a cdc function */
func = rt_usbd_function_new(device, &_dev_desc, &ops);
rt_usbd_device_set_qualifier(device, &_dev_qualifier);
//not support hs
//rt_usbd_device_set_qualifier(device, &_dev_qualifier);
/* allocate memory for cdc vcom data */
data = (struct hid_s*)rt_malloc(sizeof(struct hid_s));
......
......@@ -88,8 +88,8 @@ static struct udevice_descriptor dev_desc =
USB_DESC_TYPE_DEVICE, //type;
USB_BCD_VERSION, //bcdUSB;
USB_CLASS_MASS_STORAGE, //bDeviceClass;
0x00, //bDeviceSubClass;
0x00, //bDeviceProtocol;
0x06, //bDeviceSubClass;
0x50, //bDeviceProtocol;
0x40, //bMaxPacketSize0;
_VENDOR_ID, //idVendor;
_PRODUCT_ID, //idProduct;
......@@ -100,15 +100,17 @@ static struct udevice_descriptor dev_desc =
USB_DYNAMIC, //bNumConfigurations;
};
//FS and HS needed
static struct usb_qualifier_descriptor dev_qualifier =
{
sizeof(dev_qualifier),
USB_DESC_TYPE_DEVICEQUALIFIER,
0x0200,
USB_CLASS_MASS_STORAGE,
0x00,
64,
0x01,
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
USB_CLASS_MASS_STORAGE, //bDeviceClass
0x06, //bDeviceSubClass
0x50, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
0,
};
......@@ -141,14 +143,14 @@ const static struct umass_descriptor _mass_desc =
USB_DESC_TYPE_ENDPOINT, //type;
USB_DYNAMIC | USB_DIR_OUT, //bEndpointAddress;
USB_EP_ATTR_BULK, //bmAttributes;
0x40, //wMaxPacketSize;
USB_DYNAMIC, //wMaxPacketSize;
0x00, //bInterval;
USB_DESC_LENGTH_ENDPOINT, //bLength;
USB_DESC_TYPE_ENDPOINT, //type;
USB_DYNAMIC | USB_DIR_IN, //bEndpointAddress;
USB_EP_ATTR_BULK, //bmAttributes;
0x40, //wMaxPacketSize;
USB_DYNAMIC, //wMaxPacketSize;
0x00, //bInterval;
};
......@@ -1043,11 +1045,13 @@ static struct ufunction_ops ops =
_function_disable,
RT_NULL,
};
static rt_err_t _mstorage_descriptor_config(umass_desc_t desc, rt_uint8_t cintf_nr)
static rt_err_t _mstorage_descriptor_config(umass_desc_t desc, rt_uint8_t cintf_nr, rt_uint8_t device_is_hs)
{
#ifdef RT_USB_DEVICE_COMPOSITE
desc->iad_desc.bFirstInterface = cintf_nr;
#endif
desc->ep_out_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
desc->ep_in_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
return RT_EOK;
}
/**
......@@ -1090,7 +1094,7 @@ ufunction_t rt_usbd_function_mstorage_create(udevice_t device)
rt_usbd_altsetting_config_descriptor(setting, &_mass_desc, (rt_off_t)&((umass_desc_t)0)->intf_desc);
/* configure the msc interface descriptor */
_mstorage_descriptor_config(setting->desc, intf->intf_num);
_mstorage_descriptor_config(setting->desc, intf->intf_num, device->dcd->device_is_hs);
/* create a bulk out and a bulk in endpoint */
mass_desc = (umass_desc_t)setting->desc;
......
......@@ -58,9 +58,9 @@ struct rt_rndis_eth
#endif /* RNDIS_DELAY_LINK_UP */
ALIGN(4)
rt_uint8_t rx_pool[64];
rt_uint8_t rx_pool[512];
ALIGN(4)
rt_uint8_t tx_pool[64];
rt_uint8_t tx_pool[512];
rt_uint32_t cmd_pool[2];
ALIGN(4)
......@@ -175,14 +175,14 @@ const static struct ucdc_data_descriptor _data_desc =
USB_DESC_TYPE_ENDPOINT,
USB_DIR_OUT | USB_DYNAMIC,
USB_EP_ATTR_BULK,
USB_CDC_BUFSIZE,
USB_DYNAMIC,
0x00,
/* endpoint, bulk in */
USB_DESC_LENGTH_ENDPOINT,
USB_DESC_TYPE_ENDPOINT,
USB_DYNAMIC | USB_DIR_IN,
USB_EP_ATTR_BULK,
USB_CDC_BUFSIZE,
USB_DYNAMIC,
0x00,
};
......@@ -206,16 +206,17 @@ struct usb_os_function_comp_id_descriptor rndis_func_comp_id_desc =
.subCompatibleID = {'5', '1', '6', '2', '0', '0', '1', 0x00},
.reserved2 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
};
ALIGN(4)
//FS and HS needed
static struct usb_qualifier_descriptor dev_qualifier =
{
sizeof(dev_qualifier),
USB_DESC_TYPE_DEVICEQUALIFIER,
0x0200,
USB_CLASS_CDC,
0x00,
64,
0x01,
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
USB_CLASS_CDC, //bDeviceClass
USB_CDC_SUBCLASS_ACM, //bDeviceSubClass
USB_CDC_PROTOCOL_VENDOR, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
0,
};
......@@ -401,7 +402,7 @@ static rt_err_t _rndis_query_response(ufunction_t func,rndis_query_msg_t msg)
case OID_GEN_LINK_SPEED:
resp = _create_resp(4);
if(resp == RT_NULL) break;
_set_resp(resp, (10UL * 1000 * 1000) / 100);
_set_resp(resp, func->device->dcd->device_is_hs ? (480UL * 1000 *1000) : (12UL * 1000 * 1000) / 100);
break;
case OID_GEN_MEDIA_CONNECT_STATUS:
......@@ -1008,7 +1009,7 @@ static struct ufunction_ops ops =
*
* @return RT_EOK on successful.
*/
static rt_err_t _cdc_descriptor_config(ucdc_comm_desc_t comm, rt_uint8_t cintf_nr, ucdc_data_desc_t data, rt_uint8_t dintf_nr)
static rt_err_t _cdc_descriptor_config(ucdc_comm_desc_t comm, rt_uint8_t cintf_nr, ucdc_data_desc_t data, rt_uint8_t dintf_nr, rt_uint8_t device_is_hs)
{
comm->call_mgmt_desc.data_interface = dintf_nr;
comm->union_desc.master_interface = cintf_nr;
......@@ -1016,7 +1017,8 @@ static rt_err_t _cdc_descriptor_config(ucdc_comm_desc_t comm, rt_uint8_t cintf_n
#ifdef RT_USB_DEVICE_COMPOSITE
comm->iad_desc.bFirstInterface = cintf_nr;
#endif
data->ep_out_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
data->ep_in_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
return RT_EOK;
}
......@@ -1237,7 +1239,7 @@ ufunction_t rt_usbd_function_rndis_create(udevice_t device)
(rt_off_t)&((ucdc_comm_desc_t)0)->intf_desc);
rt_usbd_altsetting_config_descriptor(data_setting, &_data_desc, 0);
/* configure the cdc interface descriptor */
_cdc_descriptor_config(comm_setting->desc, intf_comm->intf_num, data_setting->desc, intf_data->intf_num);
_cdc_descriptor_config(comm_setting->desc, intf_comm->intf_num, data_setting->desc, intf_data->intf_num, device->dcd->device_is_hs);
/* create a command endpoint */
comm_desc = (ucdc_comm_desc_t)comm_setting->desc;
......
......@@ -43,13 +43,14 @@ static struct udevice_descriptor dev_desc =
//FS and HS needed
static struct usb_qualifier_descriptor dev_qualifier =
{
sizeof(dev_qualifier),
USB_DESC_TYPE_DEVICEQUALIFIER,
0x0200,
0x00,
0x00,
64,
0x01,
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
0xFF, //bDeviceClass
0x00, //bDeviceSubClass
0x00, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
0,
};
......@@ -81,14 +82,14 @@ struct winusb_descriptor _winusb_desc =
USB_DESC_TYPE_ENDPOINT,
USB_DYNAMIC | USB_DIR_OUT,
USB_EP_ATTR_BULK,
0x40,
USB_DYNAMIC,
0x00,
/*endpoint descriptor*/
USB_DESC_LENGTH_ENDPOINT,
USB_DESC_TYPE_ENDPOINT,
USB_DYNAMIC | USB_DIR_IN,
USB_EP_ATTR_BULK,
0x40,
USB_DYNAMIC,
0x00,
};
......@@ -197,11 +198,13 @@ static struct ufunction_ops ops =
RT_NULL,
};
static rt_err_t _winusb_descriptor_config(winusb_desc_t winusb, rt_uint8_t cintf_nr)
static rt_err_t _winusb_descriptor_config(winusb_desc_t winusb, rt_uint8_t cintf_nr, rt_uint8_t device_is_hs)
{
#ifdef RT_USB_DEVICE_COMPOSITE
winusb->iad_desc.bFirstInterface = cintf_nr;
#endif
winusb->ep_out_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
winusb->ep_in_desc.wMaxPacketSize = device_is_hs ? 512 : 64;
winusb_func_comp_id_desc.bFirstInterfaceNumber = cintf_nr;
return RT_EOK;
}
......@@ -293,7 +296,7 @@ ufunction_t rt_usbd_function_winusb_create(udevice_t device)
rt_usbd_altsetting_config_descriptor(winusb_setting, &_winusb_desc, (rt_off_t)&((winusb_desc_t)0)->intf_desc);
/* configure the hid interface descriptor */
_winusb_descriptor_config(winusb_setting->desc, winusb_intf->intf_num);
_winusb_descriptor_config(winusb_setting->desc, winusb_intf->intf_num, device->dcd->device_is_hs);
/* create endpoint */
winusb_desc = (winusb_desc_t)winusb_setting->desc;
......
......@@ -166,7 +166,7 @@ static rt_err_t _get_qualifier_descriptor(struct udevice* device, ureq_t setup)
RT_ASSERT(device != RT_NULL);
RT_ASSERT(setup != RT_NULL);
if(device->dev_qualifier)
if(device->dev_qualifier && device->dcd->device_is_hs)
{
/* send device qualifier descriptor to endpoint 0 */
rt_usbd_ep0_write(device, (rt_uint8_t*)device->dev_qualifier,
......@@ -210,6 +210,9 @@ static rt_err_t _get_descriptor(struct udevice* device, ureq_t setup)
case USB_DESC_TYPE_DEVICEQUALIFIER:
_get_qualifier_descriptor(device, setup);
break;
case USB_DESC_TYPE_OTHERSPEED:
_get_config_descriptor(device, setup);
break;
default:
rt_kprintf("unsupported descriptor request\n");
rt_usbd_ep0_set_stall(device);
......
......@@ -59,6 +59,20 @@ static struct udevice_descriptor compsit_desc =
USB_STRING_SERIAL_INDEX, //iSerialNumber;
USB_DYNAMIC, //bNumConfigurations;
};
//FS and HS needed
static struct usb_qualifier_descriptor dev_qualifier =
{
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
USB_CLASS_MISC, //bDeviceClass
0x02, //bDeviceSubClass
0x01, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
0,
};
#endif
struct usb_os_comp_id_descriptor usb_comp_id_desc =
......@@ -169,6 +183,7 @@ rt_err_t rt_usb_device_init(void)
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_descriptor(udevice, &compsit_desc);
rt_usbd_device_set_string(udevice, ustring);
rt_usbd_device_set_qualifier(device, &dev_qualifier);
#else
rt_usbd_device_set_descriptor(udevice, func->dev_desc);
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册