Selaa lähdekoodia

remove auto device descriptor

Application should declare its own device descriptor
hathach 7 vuotta sitten
vanhempi
sitoutus
72575534f8

+ 0 - 6
examples/device/cdc_msc_hid/src/tusb_config.h

@@ -78,12 +78,6 @@
  */
 #define CFG_TUD_DESC_AUTO           1
 
-/* If USB VID/PID is not defined, tinyusb will use default value
- * Note: different class combination e.g CDC and (CDC + MSC) should have different
- * PID since Host OS will "remembered" device driver after the first plug */
-// #define CFG_TUD_DESC_VID          0xCAFE
-// #define CFG_TUD_DESC_PID          0x0001
-
 // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
 // Therefore we need to force endpoint number to correct type on lpc17xx
 #if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX

+ 48 - 5
examples/device/cdc_msc_hid/src/tusb_descriptors.c

@@ -26,10 +26,53 @@
 
 #include "tusb.h"
 
-//--------------------------------------------------------------------+
-// STRING DESCRIPTORS
-//--------------------------------------------------------------------+
+// If HID Generic interface is generated
+#define AUTO_DESC_HID_GENERIC    (CFG_TUD_HID && ((CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT) || \
+                                                (CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT)) )
 
+/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
+ * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
+ *
+ * Auto ProductID layout's Bitmap:
+ *   [MSB]         HID Generic | Boot Mouse | Boot Keyboard | MSC | CDC          [LSB]
+ */
+#define _PID_MAP(itf, n)      ( (CFG_TUD_##itf) << (n) )
+#define CFG_TUD_DESC_PID      (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | \
+                               _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (AUTO_DESC_HID_GENERIC << 4) )
+
+//------------- Device Descriptors -------------//
+tusb_desc_device_t const desc_device =
+{
+    .bLength            = sizeof(tusb_desc_device_t),
+    .bDescriptorType    = TUSB_DESC_DEVICE,
+    .bcdUSB             = 0x0200,
+
+  #if CFG_TUD_CDC
+    // Use Interface Association Descriptor (IAD) for CDC
+    // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
+    .bDeviceClass       = TUSB_CLASS_MISC,
+    .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
+    .bDeviceProtocol    = MISC_PROTOCOL_IAD,
+  #else
+    .bDeviceClass       = 0x00,
+    .bDeviceSubClass    = 0x00,
+    .bDeviceProtocol    = 0x00,
+  #endif
+
+    .bMaxPacketSize0    = CFG_TUD_ENDOINT0_SIZE,
+
+    .idVendor           = 0xCafe,
+    .idProduct          = CFG_TUD_DESC_PID,
+    .bcdDevice          = 0x0100,
+
+    .iManufacturer      = 0x01,
+    .iProduct           = 0x02,
+    .iSerialNumber      = 0x03,
+
+    .bNumConfigurations = 0x01
+};
+
+//------------- String Descriptors -------------//
 // array of pointer to string descriptors
 uint16_t const * const string_desc_arr [] =
 {
@@ -42,7 +85,7 @@ uint16_t const * const string_desc_arr [] =
     // 2: Product
     TUD_DESC_STRCONV('t', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'd', 'e', 'v', 'i', 'c', 'e'),
 
-    // 3: Serials TODO use chip ID
+    // 3: Serials, should use chip ID
     TUD_DESC_STRCONV('1', '2', '3', '4', '5', '6'),
 
 #if CFG_TUD_CDC
@@ -71,7 +114,7 @@ uint16_t const * const string_desc_arr [] =
 // since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr 
 tud_desc_set_t tud_desc_set =
 {
-    .device     = NULL,
+    .device     = &desc_device,
     .config     = NULL,
 
     .string_arr   = (uint8_t const **) string_desc_arr,

+ 1 - 7
examples/device/cdc_msc_hid_freertos/src/tusb_config.h

@@ -74,14 +74,8 @@
  */
 #define CFG_TUD_DESC_AUTO           1
 
-/* If USB VID/PID is not defined, tinyusb will use default value
- * Note: different class combination e.g CDC and (CDC + MSC) should have different
- * PID since Host OS will "remembered" device driver after the first plug */
-// #define CFG_TUD_DESC_VID          0xCAFE
-// #define CFG_TUD_DESC_PID          0x0001
-
 // LPC175x_6x's endpoint type (bulk/interrupt/iso) are fixed by its number
-// Therefor we need to force endpoint number to correct type on lpc17xx
+// Therefore we need to force endpoint number to correct type on lpc17xx
 #if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X
 #define CFG_TUD_DESC_CDC_EPNUM_NOTIF      1
 #define CFG_TUD_DESC_CDC_EPNUM            2

+ 49 - 5
examples/device/cdc_msc_hid_freertos/src/tusb_descriptors.c

@@ -26,10 +26,53 @@
 
 #include "tusb.h"
 
-//--------------------------------------------------------------------+
-// STRING DESCRIPTORS
-//--------------------------------------------------------------------+
+// If HID Generic interface is generated
+#define AUTO_DESC_HID_GENERIC    (CFG_TUD_HID && ((CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT) || \
+                                                (CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT)) )
 
+/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
+ * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
+ *
+ * Auto ProductID layout's Bitmap:
+ *   [MSB]         HID Generic | Boot Mouse | Boot Keyboard | MSC | CDC          [LSB]
+ */
+#define _PID_MAP(itf, n)      ( (CFG_TUD_##itf) << (n) )
+#define CFG_TUD_DESC_PID      (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | \
+                               _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (AUTO_DESC_HID_GENERIC << 4) )
+
+//------------- Device Descriptors -------------//
+tusb_desc_device_t const desc_device =
+{
+    .bLength            = sizeof(tusb_desc_device_t),
+    .bDescriptorType    = TUSB_DESC_DEVICE,
+    .bcdUSB             = 0x0200,
+
+  #if CFG_TUD_CDC
+    // Use Interface Association Descriptor (IAD) for CDC
+    // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
+    .bDeviceClass       = TUSB_CLASS_MISC,
+    .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
+    .bDeviceProtocol    = MISC_PROTOCOL_IAD,
+  #else
+    .bDeviceClass       = 0x00,
+    .bDeviceSubClass    = 0x00,
+    .bDeviceProtocol    = 0x00,
+  #endif
+
+    .bMaxPacketSize0    = CFG_TUD_ENDOINT0_SIZE,
+
+    .idVendor           = 0xCafe,
+    .idProduct          = CFG_TUD_DESC_PID,
+    .bcdDevice          = 0x0100,
+
+    .iManufacturer      = 0x01,
+    .iProduct           = 0x02,
+    .iSerialNumber      = 0x03,
+
+    .bNumConfigurations = 0x01
+};
+
+//------------- String Descriptors -------------//
 // array of pointer to string descriptors
 uint16_t const * const string_desc_arr [] =
 {
@@ -42,7 +85,7 @@ uint16_t const * const string_desc_arr [] =
     // 2: Product
     TUD_DESC_STRCONV('t', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'd', 'e', 'v', 'i', 'c', 'e'),
 
-    // 3: Serials TODO use chip ID
+    // 3: Serials, should use chip ID
     TUD_DESC_STRCONV('1', '2', '3', '4', '5', '6'),
 
 #if CFG_TUD_CDC
@@ -71,7 +114,7 @@ uint16_t const * const string_desc_arr [] =
 // since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr 
 tud_desc_set_t tud_desc_set =
 {
-    .device     = NULL,
+    .device     = &desc_device,
     .config     = NULL,
 
     .string_arr   = (uint8_t const **) string_desc_arr,
@@ -84,3 +127,4 @@ tud_desc_set_t tud_desc_set =
         .boot_mouse    = NULL
     }
 };
+

+ 1 - 1
src/device/usbd.c

@@ -577,7 +577,7 @@ static void const* get_descriptor(tusb_control_request_t const * p_request, uint
   switch(desc_type)
   {
     case TUSB_DESC_DEVICE:
-      desc_data = (uint8_t const *) usbd_desc_set->device;
+      desc_data = (uint8_t const *) tud_desc_set.device;
       len       = sizeof(tusb_desc_device_t);
     break;
 

+ 4 - 68
src/device/usbd_auto_desc.c

@@ -30,29 +30,10 @@
 
 #include "tusb.h"
 
-//--------------------------------------------------------------------+
-// Auto Description Default Configure & Validation
-//--------------------------------------------------------------------+
 
 // If HID Generic interface is generated
 #define AUTO_DESC_HID_GENERIC    (CFG_TUD_HID && ((CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT) || \
                                                 (CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT)) )
-/*------------- VID/PID -------------*/
-#ifndef CFG_TUD_DESC_VID
-#define CFG_TUD_DESC_VID       0xCAFE
-#endif
-
-#ifndef CFG_TUD_DESC_PID
-/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
- * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
- *
- * Auto ProductID layout's Bitmap:
- *   [MSB]         HID Generic | Boot Mouse | Boot Keyboard | MSC | CDC          [LSB]
- */
-#define _PID_MAP(itf, n)      ( (CFG_TUD_##itf) << (n) )
-#define CFG_TUD_DESC_PID      (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
-                               _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (AUTO_DESC_HID_GENERIC << 4) )
-#endif
 
 //--------------------------------------------------------------------+
 // Interface & Endpoint mapping
@@ -61,7 +42,6 @@
 /*------------- Interface Numbering -------------*/
 /* The order as follows: CDC, MSC, Boot Keyboard, Boot Mouse, HID Generic
  * If an interface is not enabled, the later will take its place */
-
 enum
 {
 #if CFG_TUD_CDC
@@ -146,9 +126,9 @@ enum
 #endif
 
 #if TUD_OPT_HIGH_SPEED
-#define EP_MSC_SIZE 512
+  #define EP_MSC_SIZE 512
 #else
-#define EP_MSC_SIZE 64
+  #define EP_MSC_SIZE 64
 #endif
 
 
@@ -172,12 +152,10 @@ enum
 #define EP_HID_GEN              _EP_IN ( ITF_NUM_HID_GEN+1 )
 #define EP_HID_GEN_SIZE         16
 
-
 //--------------------------------------------------------------------+
 // Auto generated HID Report Descriptors
 //--------------------------------------------------------------------+
 
-
 /*------------- Boot Protocol Report Descriptor -------------*/
 #if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
 uint8_t const _desc_auto_hid_boot_kbd_report[] = { HID_REPORT_DESC_KEYBOARD() };
@@ -212,51 +190,9 @@ uint8_t const _desc_auto_hid_generic_report[] =
 
 
 /*------------------------------------------------------------------*/
-/* Auto generated Device & Configuration descriptor
+/* Auto generated Configuration descriptor
  *------------------------------------------------------------------*/
 
-// For highspeed device but currently in full speed mode
-//tusb_desc_device_qualifier_t _device_qual =
-//{
-//    .bLength = sizeof(tusb_desc_device_qualifier_t),
-//    .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
-//    .bcdUSB = 0x0200,
-//    .bDeviceClass =
-//};
-
-/*------------- Device Descriptor -------------*/
-tusb_desc_device_t const _desc_auto_device =
-{
-    .bLength            = sizeof(tusb_desc_device_t),
-    .bDescriptorType    = TUSB_DESC_DEVICE,
-    .bcdUSB             = 0x0200,
-
-  #if CFG_TUD_CDC
-    // Use Interface Association Descriptor (IAD) for CDC
-    // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
-    .bDeviceClass       = TUSB_CLASS_MISC,
-    .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
-    .bDeviceProtocol    = MISC_PROTOCOL_IAD,
-  #else
-    .bDeviceClass       = 0x00,
-    .bDeviceSubClass    = 0x00,
-    .bDeviceProtocol    = 0x00,
-  #endif
-
-    .bMaxPacketSize0    = CFG_TUD_ENDOINT0_SIZE,
-
-    .idVendor           = CFG_TUD_DESC_VID,
-    .idProduct          = CFG_TUD_DESC_PID,
-    .bcdDevice          = 0x0100,
-
-    .iManufacturer      = 0x01,
-    .iProduct           = 0x02,
-    .iSerialNumber      = 0x03,
-
-    .bNumConfigurations = 0x01
-};
-
-
 /*------------- Configuration Descriptor -------------*/
 typedef struct ATTR_PACKED
 {
@@ -623,7 +559,7 @@ uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_st
 
 tud_desc_set_t const _usbd_auto_desc_set =
 {
-    .device = &_desc_auto_device,
+    .device = NULL, // no auto device
     .config = &_desc_auto_config_struct,
 
     .hid_report =