34#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
35#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
36 _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
41tusb_desc_device_t
const desc_device =
43 .bLength =
sizeof(tusb_desc_device_t),
44 .bDescriptorType = TUSB_DESC_DEVICE,
49 .bDeviceClass = TUSB_CLASS_MISC,
50 .bDeviceSubClass = MISC_SUBCLASS_COMMON,
51 .bDeviceProtocol = MISC_PROTOCOL_IAD,
53 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
59 .iManufacturer = 0x01,
61 .iSerialNumber = 0x03,
63 .bNumConfigurations = 0x01
68uint8_t
const * tud_descriptor_device_cb(
void)
70 return (uint8_t
const *) &desc_device;
84#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
86#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
89 #define EPNUM_CDC_NOTIF 0x81
90 #define EPNUM_CDC_OUT 0x02
91 #define EPNUM_CDC_IN 0x82
93#elif CFG_TUSB_MCU == OPT_MCU_SAMG
96 #define EPNUM_CDC_NOTIF 0x81
97 #define EPNUM_CDC_OUT 0x02
98 #define EPNUM_CDC_IN 0x83
100#elif CFG_TUSB_MCU == OPT_MCU_CXD56
105 #define EPNUM_CDC_NOTIF 0x83
106 #define EPNUM_CDC_OUT 0x02
107 #define EPNUM_CDC_IN 0x81
110 #define EPNUM_CDC_NOTIF 0x81
111 #define EPNUM_CDC_OUT 0x02
112 #define EPNUM_CDC_IN 0x82
116uint8_t
const desc_fs_configuration[] =
119 TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
122 TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
125#if TUD_OPT_HIGH_SPEED
126uint8_t
const desc_hs_configuration[] =
129 TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
132 TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
140uint8_t
const * tud_descriptor_configuration_cb(uint8_t index)
144#if TUD_OPT_HIGH_SPEED
146 return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
148 return desc_fs_configuration;
157char const* string_desc_arr [] =
159 (
const char[]) { 0x09, 0x04 },
168 string_desc_arr[1] = manufacturer;
173 string_desc_arr[2] = product;
178 string_desc_arr[3] = serial;
183 string_desc_arr[4] = cdc_interface;
186static uint16_t _desc_str[32];
190uint16_t
const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
198 memcpy(&_desc_str[1], string_desc_arr[0], 2);
205 if ( !(index <
sizeof(string_desc_arr)/
sizeof(string_desc_arr[0])) )
return NULL;
207 const char* str = string_desc_arr[index];
210 chr_count = strlen(str);
211 if ( chr_count > 31 ) chr_count = 31;
214 for(uint8_t i=0; i<chr_count; i++)
216 _desc_str[1+i] = str[i];
221 _desc_str[0] = (TUSB_DESC_STRING << 8 ) | (2*chr_count + 2);
void usb_descriptor_set_serial(char *serial)
Set the serial.
void usb_descriptor_set_manufacturer(char *manufacturer)
Set the manufactorer.
void usb_descriptor_set_cdc_interface(char *cdc_interface)
Set the cdc interface.
void usb_descriptor_set_product(char *product)
Set the product.