diff options
Diffstat (limited to 'examples')
4 files changed, 98 insertions, 23 deletions
diff --git a/examples/device/cdc_msc_hid/src/tusb_config.h b/examples/device/cdc_msc_hid/src/tusb_config.h index 98a214d52..a4df1d2e8 100644 --- a/examples/device/cdc_msc_hid/src/tusb_config.h +++ b/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 diff --git a/examples/device/cdc_msc_hid/src/tusb_descriptors.c b/examples/device/cdc_msc_hid/src/tusb_descriptors.c index 866005e3f..3dc2a09b2 100644 --- a/examples/device/cdc_msc_hid/src/tusb_descriptors.c +++ b/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, diff --git a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h b/examples/device/cdc_msc_hid_freertos/src/tusb_config.h index 6004caf8c..d288bf296 100644 --- a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h +++ b/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 diff --git a/examples/device/cdc_msc_hid_freertos/src/tusb_descriptors.c b/examples/device/cdc_msc_hid_freertos/src/tusb_descriptors.c index 866005e3f..5f6d9e032 100644 --- a/examples/device/cdc_msc_hid_freertos/src/tusb_descriptors.c +++ b/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 } }; + |
