1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "usb_descriptors.h" 16 #include "sdkconfig.h" 17 18 #define USB_TUSB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | _PID_MAP(MIDI, 3)) 19 20 /**** TinyUSB default ****/ 21 tusb_desc_device_t descriptor_tinyusb = { 22 .bLength = sizeof(descriptor_tinyusb), 23 .bDescriptorType = TUSB_DESC_DEVICE, 24 .bcdUSB = 0x0200, 25 26 #if CFG_TUD_CDC 27 // Use Interface Association Descriptor (IAD) for CDC 28 // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1) 29 .bDeviceClass = TUSB_CLASS_MISC, 30 .bDeviceSubClass = MISC_SUBCLASS_COMMON, 31 .bDeviceProtocol = MISC_PROTOCOL_IAD, 32 #else 33 .bDeviceClass = 0x00, 34 .bDeviceSubClass = 0x00, 35 .bDeviceProtocol = 0x00, 36 #endif 37 38 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, 39 40 .idVendor = 0xCafe, 41 .idProduct = USB_TUSB_PID, 42 .bcdDevice = 0x0100, 43 44 .iManufacturer = 0x01, 45 .iProduct = 0x02, 46 .iSerialNumber = 0x03, 47 48 .bNumConfigurations = 0x01 49 }; 50 51 tusb_desc_strarray_device_t descriptor_str_tinyusb = { 52 // array of pointer to string descriptors 53 (char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) 54 "TinyUSB", // 1: Manufacturer 55 "TinyUSB Device", // 2: Product 56 "123456", // 3: Serials, should use chip ID 57 "TinyUSB CDC", // 4: CDC Interface 58 "TinyUSB MSC", // 5: MSC Interface 59 "TinyUSB HID" // 6: HID 60 }; 61 /* End of TinyUSB default */ 62 63 /**** Kconfig driven Descriptor ****/ 64 tusb_desc_device_t descriptor_kconfig = { 65 .bLength = sizeof(descriptor_kconfig), 66 .bDescriptorType = TUSB_DESC_DEVICE, 67 .bcdUSB = 0x0200, 68 69 #if CFG_TUD_CDC 70 // Use Interface Association Descriptor (IAD) for CDC 71 // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1) 72 .bDeviceClass = TUSB_CLASS_MISC, 73 .bDeviceSubClass = MISC_SUBCLASS_COMMON, 74 .bDeviceProtocol = MISC_PROTOCOL_IAD, 75 #else 76 .bDeviceClass = 0x00, 77 .bDeviceSubClass = 0x00, 78 .bDeviceProtocol = 0x00, 79 #endif 80 81 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, 82 83 #if CONFIG_TINYUSB_DESC_USE_ESPRESSIF_VID 84 .idVendor = USB_ESPRESSIF_VID, 85 #else 86 .idVendor = CONFIG_TINYUSB_DESC_CUSTOM_VID, 87 #endif 88 89 #if CONFIG_TINYUSB_DESC_USE_DEFAULT_PID 90 .idProduct = USB_TUSB_PID, 91 #else 92 .idProduct = CONFIG_TINYUSB_DESC_CUSTOM_PID, 93 #endif 94 95 .bcdDevice = CONFIG_TINYUSB_DESC_BCD_DEVICE, 96 97 .iManufacturer = 0x01, 98 .iProduct = 0x02, 99 .iSerialNumber = 0x03, 100 101 .bNumConfigurations = 0x01 102 }; 103 104 tusb_desc_strarray_device_t descriptor_str_kconfig = { 105 // array of pointer to string descriptors 106 (char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) 107 CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, // 1: Manufacturer 108 CONFIG_TINYUSB_DESC_PRODUCT_STRING, // 2: Product 109 CONFIG_TINYUSB_DESC_SERIAL_STRING, // 3: Serials, should use chip ID 110 111 #if CONFIG_TINYUSB_CDC_ENABLED 112 CONFIG_TINYUSB_DESC_CDC_STRING, // 4: CDC Interface 113 #else 114 "", 115 #endif 116 117 #if CONFIG_TINYUSB_MSC_ENABLED 118 CONFIG_TINYUSB_DESC_MSC_STRING, // 5: MSC Interface 119 #else 120 "", 121 #endif 122 123 #if CONFIG_TINYUSB_HID_ENABLED 124 CONFIG_TINYUSB_DESC_HID_STRING // 6: HIDs 125 #else 126 "", 127 #endif 128 129 }; 130 /* End of Kconfig driven Descriptor */ 131