提交 effcee25 编写于 作者: D Dillon Min

component: driver: usb: Add usb interface string(iInterface) setting

To make compositive usb device string more reansonable, not all devices
just show same "RTT Composite Device" on windows device manager.

add a interface rt_usbd_device_set_interface_string to set respective
interface string.
Signed-off-by: NDillon Min <dillon.minfei@gmail.com>
v1 -> v2: remove all tabs to space, to match rt-thread coding style
上级 0beaeeef
...@@ -34,6 +34,10 @@ extern "C" { ...@@ -34,6 +34,10 @@ extern "C" {
#define _PRODUCT_ID 0x0001 #define _PRODUCT_ID 0x0001
#endif #endif
#ifndef MAX_INTF_STR
#define MAX_INTF_STR 20
#endif
#define USB_BCD_DEVICE 0x0200 /* USB Specification Release Number in Binary-Coded Decimal */ #define USB_BCD_DEVICE 0x0200 /* USB Specification Release Number in Binary-Coded Decimal */
#define USB_BCD_VERSION 0x0200 /* USB 2.0 */ #define USB_BCD_VERSION 0x0200 /* USB 2.0 */
#define EP0_IN_ADDR 0x80 #define EP0_IN_ADDR 0x80
...@@ -193,7 +197,7 @@ struct udevice ...@@ -193,7 +197,7 @@ struct udevice
struct usb_qualifier_descriptor * dev_qualifier; struct usb_qualifier_descriptor * dev_qualifier;
usb_os_comp_id_desc_t os_comp_id_desc; usb_os_comp_id_desc_t os_comp_id_desc;
const char** str; const char** str;
const char *str_intf[MAX_INTF_STR];
udevice_state_t state; udevice_state_t state;
rt_list_t cfg_list; rt_list_t cfg_list;
uconfig_t curr_cfg; uconfig_t curr_cfg;
...@@ -260,6 +264,7 @@ rt_err_t rt_usbd_event_signal(struct udev_msg* msg); ...@@ -260,6 +264,7 @@ rt_err_t rt_usbd_event_signal(struct udev_msg* msg);
rt_err_t rt_usbd_device_set_controller(udevice_t device, udcd_t dcd); rt_err_t rt_usbd_device_set_controller(udevice_t device, udcd_t dcd);
rt_err_t rt_usbd_device_set_descriptor(udevice_t device, udev_desc_t dev_desc); rt_err_t rt_usbd_device_set_descriptor(udevice_t device, udev_desc_t dev_desc);
rt_err_t rt_usbd_device_set_string(udevice_t device, const char** ustring); rt_err_t rt_usbd_device_set_string(udevice_t device, const char** ustring);
rt_err_t rt_usbd_device_set_interface_string(udevice_t device, int index, const char* string);
rt_err_t rt_usbd_device_set_qualifier(udevice_t device, struct usb_qualifier_descriptor* qualifier); rt_err_t rt_usbd_device_set_qualifier(udevice_t device, struct usb_qualifier_descriptor* qualifier);
rt_err_t rt_usbd_device_set_os_comp_id_desc(udevice_t device, usb_os_comp_id_desc_t os_comp_id_desc); rt_err_t rt_usbd_device_set_os_comp_id_desc(udevice_t device, usb_os_comp_id_desc_t os_comp_id_desc);
rt_err_t rt_usbd_device_add_config(udevice_t device, uconfig_t cfg); rt_err_t rt_usbd_device_add_config(udevice_t device, uconfig_t cfg);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#define EVENT_RECORD_STOP (1 << 1) #define EVENT_RECORD_STOP (1 << 1)
#define EVENT_RECORD_DATA (1 << 2) #define EVENT_RECORD_DATA (1 << 2)
#define MIC_INTF_STR_INDEX 8
/* /*
* uac mic descriptor define * uac mic descriptor define
*/ */
...@@ -128,7 +129,7 @@ const static char *_ustring[] = ...@@ -128,7 +129,7 @@ const static char *_ustring[] =
{ {
"Language", "Language",
"RT-Thread Team.", "RT-Thread Team.",
"Microphone", "RT-Thread Audio Microphone",
"32021919830108", "32021919830108",
"Configuration", "Configuration",
"Interface", "Interface",
...@@ -160,7 +161,11 @@ static struct uac_ac_descriptor ac_desc = ...@@ -160,7 +161,11 @@ static struct uac_ac_descriptor ac_desc =
USB_CLASS_AUDIO, USB_CLASS_AUDIO,
USB_SUBCLASS_AUDIOCONTROL, USB_SUBCLASS_AUDIOCONTROL,
0x00, 0x00,
#ifdef RT_USB_DEVICE_COMPOSITE
MIC_INTF_STR_INDEX,
#else
0x00, 0x00,
#endif
}, },
/* Header Descriptor */ /* Header Descriptor */
{ {
...@@ -495,9 +500,12 @@ ufunction_t rt_usbd_function_uac_mic_create(udevice_t device) ...@@ -495,9 +500,12 @@ ufunction_t rt_usbd_function_uac_mic_create(udevice_t device)
/* parameter check */ /* parameter check */
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, MIC_INTF_STR_INDEX, _ustring[2]);
#else
/* set usb device string description */ /* set usb device string description */
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a uac function */ /* create a uac function */
func = rt_usbd_function_new(device, &dev_desc, &ops); func = rt_usbd_function_new(device, &dev_desc, &ops);
//not support HS //not support HS
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#define EVENT_AUDIO_STOP (1 << 1) #define EVENT_AUDIO_STOP (1 << 1)
#define EVENT_AUDIO_DATA (1 << 2) #define EVENT_AUDIO_DATA (1 << 2)
#define SPK_INTF_STR_INDEX 9
/* /*
* uac speaker descriptor define * uac speaker descriptor define
*/ */
...@@ -128,7 +129,7 @@ const static char *_ustring[] = ...@@ -128,7 +129,7 @@ const static char *_ustring[] =
{ {
"Language", "Language",
"RT-Thread Team.", "RT-Thread Team.",
"RT-Thread Speaker", "RT-Thread Audio Speaker",
"32021919830108", "32021919830108",
"Configuration", "Configuration",
"Interface", "Interface",
...@@ -160,7 +161,11 @@ static struct uac_ac_descriptor ac_desc = ...@@ -160,7 +161,11 @@ static struct uac_ac_descriptor ac_desc =
USB_CLASS_AUDIO, USB_CLASS_AUDIO,
USB_SUBCLASS_AUDIOCONTROL, USB_SUBCLASS_AUDIOCONTROL,
0x00, 0x00,
#ifdef RT_USB_DEVICE_COMPOSITE
SPK_INTF_STR_INDEX,
#else
0x00, 0x00,
#endif
}, },
/* Header Descriptor */ /* Header Descriptor */
{ {
...@@ -496,9 +501,12 @@ ufunction_t rt_usbd_function_uac_speaker_create(udevice_t device) ...@@ -496,9 +501,12 @@ ufunction_t rt_usbd_function_uac_speaker_create(udevice_t device)
/* parameter check */ /* parameter check */
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, SPK_INTF_STR_INDEX, _ustring[2]);
#else
/* set usb device string description */ /* set usb device string description */
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a uac function */ /* create a uac function */
func = rt_usbd_function_new(device, &dev_desc, &ops); func = rt_usbd_function_new(device, &dev_desc, &ops);
//not support HS //not support HS
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifdef RT_USB_DEVICE_CDC #ifdef RT_USB_DEVICE_CDC
#define VCOM_INTF_STR_INDEX 5
#ifdef RT_VCOM_TX_TIMEOUT #ifdef RT_VCOM_TX_TIMEOUT
#define VCOM_TX_TIMEOUT RT_VCOM_TX_TIMEOUT #define VCOM_TX_TIMEOUT RT_VCOM_TX_TIMEOUT
#else /*!RT_VCOM_TX_TIMEOUT*/ #else /*!RT_VCOM_TX_TIMEOUT*/
...@@ -151,7 +152,11 @@ const static struct ucdc_comm_descriptor _comm_desc = ...@@ -151,7 +152,11 @@ const static struct ucdc_comm_descriptor _comm_desc =
USB_CDC_CLASS_COMM, USB_CDC_CLASS_COMM,
USB_CDC_SUBCLASS_ACM, USB_CDC_SUBCLASS_ACM,
USB_CDC_PROTOCOL_V25TER, USB_CDC_PROTOCOL_V25TER,
0x00, #ifdef RT_USB_DEVICE_COMPOSITE
VCOM_INTF_STR_INDEX,
#else
0,
#endif
}, },
/* Header Functional Descriptor */ /* Header Functional Descriptor */
{ {
...@@ -582,9 +587,12 @@ ufunction_t rt_usbd_function_cdc_create(udevice_t device) ...@@ -582,9 +587,12 @@ ufunction_t rt_usbd_function_cdc_create(udevice_t device)
rt_memset(serno, 0, _SER_NO_LEN + 1); rt_memset(serno, 0, _SER_NO_LEN + 1);
rt_memcpy(serno, _SER_NO, rt_strlen(_SER_NO)); rt_memcpy(serno, _SER_NO, rt_strlen(_SER_NO));
} }
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, VCOM_INTF_STR_INDEX, _ustring[2]);
#else
/* set usb device string description */ /* set usb device string description */
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a cdc function */ /* create a cdc function */
func = rt_usbd_function_new(device, &dev_desc, &ops); func = rt_usbd_function_new(device, &dev_desc, &ops);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define USB_ETH_MTU 1514 #define USB_ETH_MTU 1514
#endif #endif
#define MAX_ADDR_LEN 6 #define MAX_ADDR_LEN 6
#define ECM_INTF_STR_INDEX 10
struct rt_ecm_eth struct rt_ecm_eth
{ {
...@@ -96,7 +97,11 @@ const static struct ucdc_eth_descriptor _comm_desc = ...@@ -96,7 +97,11 @@ const static struct ucdc_eth_descriptor _comm_desc =
USB_CDC_CLASS_COMM, USB_CDC_CLASS_COMM,
USB_CDC_SUBCLASS_ETH, USB_CDC_SUBCLASS_ETH,
USB_CDC_PROTOCOL_NONE, USB_CDC_PROTOCOL_NONE,
#ifdef RT_USB_DEVICE_COMPOSITE
ECM_INTF_STR_INDEX,
#else
0x00, 0x00,
#endif
}, },
/* Header Functional Descriptor */ /* Header Functional Descriptor */
{ {
...@@ -560,8 +565,11 @@ ufunction_t rt_usbd_function_ecm_create(udevice_t device) ...@@ -560,8 +565,11 @@ ufunction_t rt_usbd_function_ecm_create(udevice_t device)
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
/* set usb device string description */ /* set usb device string description */
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, ECM_INTF_STR_INDEX, _ustring[2]);
#else
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a cdc class */ /* create a cdc class */
cdc = rt_usbd_function_new(device, &_dev_desc, &ops); cdc = rt_usbd_function_new(device, &_dev_desc, &ops);
rt_usbd_device_set_qualifier(device, &dev_qualifier); rt_usbd_device_set_qualifier(device, &dev_qualifier);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "hid.h" #include "hid.h"
#ifdef RT_USB_DEVICE_HID #ifdef RT_USB_DEVICE_HID
#define HID_INTF_STR_INDEX 7
struct hid_s struct hid_s
{ {
struct rt_device parent; struct rt_device parent;
...@@ -318,8 +318,12 @@ const static struct uhid_comm_descriptor _hid_comm_desc = ...@@ -318,8 +318,12 @@ const static struct uhid_comm_descriptor _hid_comm_desc =
#else #else
USB_HID_PROTOCOL_MOUSE, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ USB_HID_PROTOCOL_MOUSE, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
#endif #endif
0, /* iInterface: Index of string descriptor */ #ifdef RT_USB_DEVICE_COMPOSITE
}, HID_INTF_STR_INDEX, /* iInterface: Index of string descriptor */
#else
0,
#endif
},
/* HID Descriptor */ /* HID Descriptor */
{ {
...@@ -685,8 +689,11 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device) ...@@ -685,8 +689,11 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device)
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
/* set usb device string description */ /* set usb device string description */
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, HID_INTF_STR_INDEX, _ustring[2]);
#else
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a cdc function */ /* create a cdc function */
func = rt_usbd_function_new(device, &_dev_desc, &ops); func = rt_usbd_function_new(device, &_dev_desc, &ops);
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#ifdef RT_USING_DFS_MNTTABLE #ifdef RT_USING_DFS_MNTTABLE
#include "dfs_fs.h" #include "dfs_fs.h"
#endif #endif
#ifdef RT_USB_DEVICE_MSTORAGE #ifdef RT_USB_DEVICE_MSTORAGE
#define MSTRORAGE_INTF_STR_INDEX 11
enum STAT enum STAT
{ {
...@@ -131,7 +131,11 @@ const static struct umass_descriptor _mass_desc = ...@@ -131,7 +131,11 @@ const static struct umass_descriptor _mass_desc =
USB_CLASS_MASS_STORAGE, //bInterfaceClass; USB_CLASS_MASS_STORAGE, //bInterfaceClass;
0x06, //bInterfaceSubClass; 0x06, //bInterfaceSubClass;
0x50, //bInterfaceProtocol; 0x50, //bInterfaceProtocol;
#ifdef RT_USB_DEVICE_COMPOSITE
MSTRORAGE_INTF_STR_INDEX,
#else
0x00, //iInterface; 0x00, //iInterface;
#endif
}, },
{ {
...@@ -1097,8 +1101,11 @@ ufunction_t rt_usbd_function_mstorage_create(udevice_t device) ...@@ -1097,8 +1101,11 @@ ufunction_t rt_usbd_function_mstorage_create(udevice_t device)
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
/* set usb device string description */ /* set usb device string description */
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, MSTRORAGE_INTF_STR_INDEX, _ustring[2]);
#else
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a mass storage function */ /* create a mass storage function */
func = rt_usbd_function_new(device, &dev_desc, &ops); func = rt_usbd_function_new(device, &dev_desc, &ops);
device->dev_qualifier = &dev_qualifier; device->dev_qualifier = &dev_qualifier;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define DBG_SECTION_NAME "RNDIS" #define DBG_SECTION_NAME "RNDIS"
#include <rtdbg.h> #include <rtdbg.h>
#define RNDIS_INTF_STR_INDEX 12
/* RT-Thread LWIP ethernet interface */ /* RT-Thread LWIP ethernet interface */
#include <netif/ethernetif.h> #include <netif/ethernetif.h>
...@@ -123,7 +123,11 @@ const static struct ucdc_comm_descriptor _comm_desc = ...@@ -123,7 +123,11 @@ const static struct ucdc_comm_descriptor _comm_desc =
USB_CDC_CLASS_COMM, USB_CDC_CLASS_COMM,
USB_CDC_SUBCLASS_ACM, USB_CDC_SUBCLASS_ACM,
USB_CDC_PROTOCOL_VENDOR, USB_CDC_PROTOCOL_VENDOR,
#ifdef RT_USB_DEVICE_COMPOSITE
RNDIS_INTF_STR_INDEX,
#else
0x00, 0x00,
#endif
}, },
/* Header Functional Descriptor */ /* Header Functional Descriptor */
{ {
...@@ -1318,8 +1322,11 @@ ufunction_t rt_usbd_function_rndis_create(udevice_t device) ...@@ -1318,8 +1322,11 @@ ufunction_t rt_usbd_function_rndis_create(udevice_t device)
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
/* set usb device string description */ /* set usb device string description */
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, RNDIS_INTF_STR_INDEX, _ustring[2]);
#else
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a cdc class */ /* create a cdc class */
cdc = rt_usbd_function_new(device, &_dev_desc, &ops); cdc = rt_usbd_function_new(device, &_dev_desc, &ops);
rt_usbd_device_set_qualifier(device, &dev_qualifier); rt_usbd_device_set_qualifier(device, &dev_qualifier);
......
...@@ -19,7 +19,7 @@ struct winusb_device ...@@ -19,7 +19,7 @@ struct winusb_device
uep_t ep_out; uep_t ep_out;
uep_t ep_in; uep_t ep_in;
}; };
#define WINUSB_INTF_STR_INDEX 13
typedef struct winusb_device * winusb_device_t; typedef struct winusb_device * winusb_device_t;
ALIGN(4) ALIGN(4)
...@@ -82,7 +82,11 @@ struct winusb_descriptor _winusb_desc = ...@@ -82,7 +82,11 @@ struct winusb_descriptor _winusb_desc =
0xFF, //bInterfaceClass; 0xFF, //bInterfaceClass;
0x00, //bInterfaceSubClass; 0x00, //bInterfaceSubClass;
0x00, //bInterfaceProtocol; 0x00, //bInterfaceProtocol;
#ifdef RT_USB_DEVICE_COMPOSITE
WINUSB_INTF_STR_INDEX,
#else
0x00, //iInterface; 0x00, //iInterface;
#endif
}, },
/*endpoint descriptor*/ /*endpoint descriptor*/
{ {
...@@ -308,7 +312,11 @@ ufunction_t rt_usbd_function_winusb_create(udevice_t device) ...@@ -308,7 +312,11 @@ ufunction_t rt_usbd_function_winusb_create(udevice_t device)
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
/* set usb device string description */ /* set usb device string description */
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_interface_string(device, WINUSB_INTF_STR_INDEX, _ustring[2]);
#else
rt_usbd_device_set_string(device, _ustring); rt_usbd_device_set_string(device, _ustring);
#endif
/* create a cdc function */ /* create a cdc function */
func = rt_usbd_function_new(device, &dev_desc, &ops); func = rt_usbd_function_new(device, &dev_desc, &ops);
......
...@@ -123,12 +123,18 @@ static rt_err_t _get_string_descriptor(struct udevice* device, ureq_t setup) ...@@ -123,12 +123,18 @@ static rt_err_t _get_string_descriptor(struct udevice* device, ureq_t setup)
} }
else else
{ {
len = rt_strlen(device->str[index]); if(index < 5)
len = rt_strlen(device->str[index]);
else
len = rt_strlen(device->str_intf[index]);
str_desc.bLength = len*2 + 2; str_desc.bLength = len*2 + 2;
for(i=0; i<len; i++) for(i=0; i<len; i++)
{ {
str_desc.String[i*2] = device->str[index][i]; if(index < 5)
str_desc.String[i*2] = device->str[index][i];
else
str_desc.String[i*2] = device->str_intf[index][i];
str_desc.String[i*2 + 1] = 0; str_desc.String[i*2 + 1] = 0;
} }
} }
...@@ -1044,6 +1050,28 @@ rt_err_t rt_usbd_device_set_string(udevice_t device, const char** ustring) ...@@ -1044,6 +1050,28 @@ rt_err_t rt_usbd_device_set_string(udevice_t device, const char** ustring)
return RT_EOK; return RT_EOK;
} }
/**
* This function will set usb device interface string description.
*
* @param device the usb device object.
* @param index of interface string
* @param string pointer to interface string description.
*
* @return RT_EOK.
*/
rt_err_t rt_usbd_device_set_interface_string(udevice_t device, int index, const char* string)
{
/* parameter check */
RT_ASSERT(device != RT_NULL);
RT_ASSERT(string != RT_NULL);
RT_ASSERT(index < MAX_INTF_STR);
/* set string descriptor array to the device object */
device->str_intf[index] = string;
return RT_EOK;
}
rt_err_t rt_usbd_device_set_os_comp_id_desc(udevice_t device, usb_os_comp_id_desc_t os_comp_id_desc) rt_err_t rt_usbd_device_set_os_comp_id_desc(udevice_t device, usb_os_comp_id_desc_t os_comp_id_desc)
{ {
/* parameter check */ /* parameter check */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册