@@ -51,6 +51,17 @@ extern "C" {
51
51
#define USBD_HID_EP (0x83 )
52
52
#endif
53
53
54
+ #ifndef USBD_MSD_EP_OUT
55
+ #define USBD_MSD_EP_OUT (0x04 )
56
+ #endif
57
+
58
+ #ifndef USBD_MSD_EP_IN
59
+ #define USBD_MSD_EP_IN (0x84 )
60
+ #endif
61
+
62
+ #define USBD_MSD_IN_OUT_SIZE (512 )
63
+
64
+
54
65
#define USBD_CDC_CMD_MAX_SIZE (8 )
55
66
#if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE)
56
67
#define USBD_CDC_IN_OUT_MAX_SIZE (512 )
@@ -112,14 +123,18 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
112
123
void __SetupUSBDescriptor () {
113
124
if (!usbd_desc_cfg) {
114
125
115
- uint8_t interface_count = (__USBInstallSerial ? 3 : 0 ) + (__USBGetHIDReport ? 1 : 0 );
126
+ uint8_t interface_count = (__USBInstallSerial ? 3 : 0 ) + (__USBGetHIDReport ? 1 : 0 ) + (__USBInstallMSD ? 1 : 0 ) ;
116
127
117
128
uint8_t cdc_desc[TUD_CDC_DESC_LEN + TUD_DFU_RT_DESC_LEN] = {
118
129
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
119
130
TUD_CDC_DESCRIPTOR (USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),
120
131
TUD_DFU_RT_DESCRIPTOR (USBD_ITF_CDC+2 , USBD_STR_DFU_RT, 0x0d , 1000 , 4096 ),
121
132
};
122
133
134
+ /*
135
+ * ----- HID
136
+ */
137
+
123
138
size_t hid_report_len = 0 ;
124
139
if (__USBGetHIDReport) {
125
140
__USBGetHIDReport (&hid_report_len);
@@ -130,7 +145,19 @@ void __SetupUSBDescriptor() {
130
145
TUD_HID_DESCRIPTOR (hid_itf, 0 , HID_ITF_PROTOCOL_NONE, hid_report_len, USBD_HID_EP, CFG_TUD_HID_EP_BUFSIZE, 10 )
131
146
};
132
147
133
- int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof (cdc_desc) : 0 ) + (__USBGetHIDReport ? sizeof (hid_desc) : 0 );
148
+ /*
149
+ * ----- MASS STORAGE DEVICE
150
+ */
151
+
152
+ uint8_t msd_itf = (__USBInstallSerial ? 3 : 0 ) + (__USBGetHIDReport ? 1 : 0 );
153
+ uint8_t msd_desc[TUD_MSC_DESC_LEN] = {
154
+ // Interface number, string index, EP Out & EP In address, EP size
155
+ TUD_MSC_DESCRIPTOR (msd_itf, 0 , USBD_MSD_EP_OUT, USBD_MSD_EP_IN, USBD_MSD_IN_OUT_SIZE)
156
+ };
157
+
158
+
159
+
160
+ int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof (cdc_desc) : 0 ) + (__USBGetHIDReport ? sizeof (hid_desc) : 0 ) + (__USBInstallMSD ? sizeof (msd_desc) : 0 );
134
161
135
162
uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = {
136
163
// Config number, interface count, string index, total length, attribute, power in mA
@@ -152,6 +179,10 @@ void __SetupUSBDescriptor() {
152
179
memcpy (ptr, hid_desc, sizeof (hid_desc));
153
180
ptr += sizeof (hid_desc);
154
181
}
182
+ if (__USBInstallMSD) {
183
+ memcpy (ptr, msd_desc, sizeof (msd_desc));
184
+ ptr += sizeof (msd_desc);
185
+ }
155
186
}
156
187
}
157
188
}
@@ -331,7 +362,7 @@ void __USBStart() {
331
362
// Invoked when received GET_REPORT control request
332
363
// Application must fill buffer report's content and return its length.
333
364
// Return zero will cause the stack to STALL request
334
- extern " C" uint16_t tud_hid_get_report_cb (uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t * buffer, uint16_t reqlen) {
365
+ extern " C" __attribute((weak)) uint16_t tud_hid_get_report_cb (uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t * buffer, uint16_t reqlen) {
335
366
// TODO not implemented
336
367
(void ) instance;
337
368
(void ) report_id;
@@ -344,7 +375,7 @@ extern "C" uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, h
344
375
345
376
// Invoked when received SET_REPORT control request or
346
377
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
347
- extern " C" void tud_hid_set_report_cb (uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const * buffer, uint16_t bufsize) {
378
+ extern " C" __attribute((weak)) void tud_hid_set_report_cb (uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const * buffer, uint16_t bufsize) {
348
379
// TODO set LED based on CAPLOCK, NUMLOCK etc...
349
380
(void ) instance;
350
381
(void ) report_id;
@@ -353,4 +384,40 @@ extern "C" void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_r
353
384
(void ) bufsize;
354
385
}
355
386
387
+
388
+ extern " C" __attribute((weak)) int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void * buffer, uint32_t bufsize) {
389
+
390
+ return 0 ;
391
+ }
392
+
393
+
394
+ extern " C" __attribute((weak)) int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t * buffer, uint32_t bufsize) {
395
+
396
+ return 0 ;
397
+ }
398
+
399
+
400
+ extern " C" __attribute((weak)) void tud_msc_inquiry_cb (uint8_t lun, uint8_t vendor_id[8 ], uint8_t product_id[16 ], uint8_t product_rev[4 ]) {
401
+
402
+ }
403
+
404
+
405
+ extern " C" __attribute((weak)) bool tud_msc_test_unit_ready_cb (uint8_t lun) {
406
+
407
+ return false ;
408
+ }
409
+
410
+
411
+ extern " C" __attribute((weak)) void tud_msc_capacity_cb (uint8_t lun, uint32_t * block_count, uint16_t * block_size) {
412
+
413
+ }
414
+
415
+
416
+ extern " C" __attribute((weak)) int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16 ], void * buffer, uint16_t bufsize) {
417
+
418
+ return -1 ;
419
+ }
420
+
421
+
422
+
356
423
#endif
0 commit comments