From effcee25b7cbb2bb42d4134d37dc8a9ec4635130 Mon Sep 17 00:00:00 2001 From: Dillon Min Date: Thu, 11 Mar 2021 17:29:41 +0800 Subject: 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: Dillon Min v1 -> v2: remove all tabs to space, to match rt-thread coding style --- .../drivers/usb/usbdevice/core/usbdevice_core.c | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'components/drivers/usb/usbdevice/core') diff --git a/components/drivers/usb/usbdevice/core/usbdevice_core.c b/components/drivers/usb/usbdevice/core/usbdevice_core.c index ef569d7bf2..063d5781bc 100644 --- a/components/drivers/usb/usbdevice/core/usbdevice_core.c +++ b/components/drivers/usb/usbdevice/core/usbdevice_core.c @@ -123,12 +123,18 @@ static rt_err_t _get_string_descriptor(struct udevice* device, ureq_t setup) } 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; for(i=0; istr[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; } } @@ -1044,6 +1050,28 @@ rt_err_t rt_usbd_device_set_string(udevice_t device, const char** ustring) 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) { /* parameter check */ -- cgit v1.3.1