34#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
43#define USB_PID 0x520Fu
49tusb_desc_device_t
const desc_device =
51 .bLength =
sizeof(tusb_desc_device_t),
52 .bDescriptorType = TUSB_DESC_DEVICE,
57 .bDeviceClass = TUSB_CLASS_MISC,
58 .bDeviceSubClass = MISC_SUBCLASS_COMMON,
59 .bDeviceProtocol = MISC_PROTOCOL_IAD,
61 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
67 .iManufacturer = 0x01,
69 .iSerialNumber = 0x03,
71 .bNumConfigurations = 0x01
76uint8_t
const * tud_descriptor_device_cb(
void)
78 return (uint8_t
const *) &desc_device;
89#if CFG_TUD_DFU_RUNTIME
98#define NORDIC_DFU_TRIGGER_DESC_LEN (9 + 9)
100#if CFG_TUD_DFU_RUNTIME
101#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN \
102 + TUD_DFU_RT_DESC_LEN + NORDIC_DFU_TRIGGER_DESC_LEN)
104#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN \
105 + NORDIC_DFU_TRIGGER_DESC_LEN)
111#define NORDIC_DFU_TRIGGER_DESCRIPTOR(_itfnum, _stridx) \
113 9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, 0xFF, 0x01, 0x01, _stridx, \
117 9, 0x21, 0x09, 0xE8, 0x03, 0x00, 0x10, 0x01, 0x01
119#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
122 #define EPNUM_CDC_NOTIF 0x81
123 #define EPNUM_CDC_OUT 0x02
124 #define EPNUM_CDC_IN 0x82
126#elif CFG_TUSB_MCU == OPT_MCU_SAMG
129 #define EPNUM_CDC_NOTIF 0x81
130 #define EPNUM_CDC_OUT 0x02
131 #define EPNUM_CDC_IN 0x83
133#elif CFG_TUSB_MCU == OPT_MCU_CXD56
138 #define EPNUM_CDC_NOTIF 0x83
139 #define EPNUM_CDC_OUT 0x02
140 #define EPNUM_CDC_IN 0x81
143 #define EPNUM_CDC_NOTIF 0x81
144 #define EPNUM_CDC_OUT 0x02
145 #define EPNUM_CDC_IN 0x82
154#define DFU_RT_ATTR (DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_WILL_DETACH)
155#define DFU_RT_TIMEOUT 1000
156#define DFU_RT_XFER 4096
158uint8_t
const desc_fs_configuration[] =
161 TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
164 TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
165#if CFG_TUD_DFU_RUNTIME
166 TUD_DFU_RT_DESCRIPTOR(ITF_NUM_DFU_RT, 5, DFU_RT_ATTR, DFU_RT_TIMEOUT, DFU_RT_XFER),
168 NORDIC_DFU_TRIGGER_DESCRIPTOR(ITF_NUM_NORDIC_DFU, 6),
171#if TUD_OPT_HIGH_SPEED
172uint8_t
const desc_hs_configuration[] =
175 TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
178 TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
179#if CFG_TUD_DFU_RUNTIME
180 TUD_DFU_RT_DESCRIPTOR(ITF_NUM_DFU_RT, 5, DFU_RT_ATTR, DFU_RT_TIMEOUT, DFU_RT_XFER),
182 NORDIC_DFU_TRIGGER_DESCRIPTOR(ITF_NUM_NORDIC_DFU, 6),
190uint8_t
const * tud_descriptor_configuration_cb(uint8_t index)
194#if TUD_OPT_HIGH_SPEED
196 return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
198 return desc_fs_configuration;
207char const* string_desc_arr [] =
209 (
const char[]) { 0x09, 0x04 },
214#if CFG_TUD_DFU_RUNTIME
219 "Contiki-NG Nordic DFU",
224 string_desc_arr[1] = manufacturer;
229 string_desc_arr[2] = product;
234 string_desc_arr[3] = serial;
239 string_desc_arr[4] = cdc_interface;
242static uint16_t _desc_str[32];
246uint16_t
const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
254 memcpy(&_desc_str[1], string_desc_arr[0], 2);
261 if ( !(index <
sizeof(string_desc_arr)/
sizeof(string_desc_arr[0])) )
return NULL;
263 const char* str = string_desc_arr[index];
266 chr_count = strlen(str);
267 if ( chr_count > 31 ) chr_count = 31;
270 for(uint8_t i=0; i<chr_count; i++)
272 _desc_str[1+i] = str[i];
277 _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.