summaryrefslogtreecommitdiff
path: root/examples/device/msc_dual_lun/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-05-11 16:31:08 +0700
committerhathach <[email protected]>2019-05-11 16:31:52 +0700
commitde56a0ca8987c15c06112ece2589dab18f1d6666 (patch)
tree101bd3bf6cb994043e3347e2e473f252996fd215 /examples/device/msc_dual_lun/src
parentbfa073818c83266c2353ccf4fce580eef62e4a0c (diff)
add tud_descriptor_string_cb() for getting string descriptor from application
- remove tud_desc_set.string_arr/string_count
Diffstat (limited to 'examples/device/msc_dual_lun/src')
-rw-r--r--examples/device/msc_dual_lun/src/usb_descriptors.c62
1 files changed, 43 insertions, 19 deletions
diff --git a/examples/device/msc_dual_lun/src/usb_descriptors.c b/examples/device/msc_dual_lun/src/usb_descriptors.c
index af2b1a091..43a785024 100644
--- a/examples/device/msc_dual_lun/src/usb_descriptors.c
+++ b/examples/device/msc_dual_lun/src/usb_descriptors.c
@@ -82,29 +82,53 @@ uint8_t const desc_configuration[] =
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 0, EPNUM_MSC, 0x80 | EPNUM_MSC, 64), // highspeed 512
};
-//------------- String Descriptors -------------//
-// array of pointer to string descriptors
-uint16_t const * const string_desc_arr [] =
+
+// tud_desc_set is required by tinyusb stack
+tud_desc_set_t tud_desc_set =
{
- // 0: is supported language = English
- TUD_DESC_STRCONV(0x0409),
+ .device = &desc_device,
+ .config = desc_configuration,
- // 1: Manufacturer
- TUD_DESC_STRCONV('t', 'i', 'n', 'y', 'u', 's', 'b', '.', 'o', 'r', 'g'),
+#if CFG_TUD_HID
+ .hid_report = desc_hid_report,
+#endif
+};
- // 2: Product
- TUD_DESC_STRCONV('t', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'd', 'e', 'v', 'i', 'c', 'e'),
+//------------- String Descriptors -------------//
- // 3: Serials, should use chip ID
- TUD_DESC_STRCONV('1', '2', '3', '4', '5', '6')
+// array of pointer to string descriptors
+char const* string_desc_arr [] =
+{
+ (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
+ "TinyUSB", // 1: Manufacturer
+ "TinyUSB Device", // 2: Product
+ "123456", // 3: Serials, should use chip ID
};
-// tud_desc_set is required by tinyusb stack
-tud_desc_set_t tud_desc_set =
+// Invoked when received GET_STRING_DESC request
+// max_char is CFG_TUD_ENDOINT0_SIZE/2 -1, typically max_char = 31 if Endpoint0 size is 64
+// Return number of characters. Note usb string is in 16-bits unicode format
+uint8_t tud_descriptor_string_cb(uint8_t index, uint16_t* desc, uint8_t max_char)
{
- .device = &desc_device,
- .config = desc_configuration,
- .string_arr = (uint8_t const **) string_desc_arr,
- .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]),
- .hid_report = NULL,
-};
+ if ( index == 0)
+ {
+ memcpy(desc, string_desc_arr[0], 2);
+ return 1;
+ }else
+ {
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return 0;
+
+ const char* str = string_desc_arr[index];
+
+ // Cap at max char
+ uint8_t count = strlen(str);
+ if ( count > max_char ) count = max_char;
+
+ for(uint8_t i=0; i<count; i++)
+ {
+ *desc++ = str[i];
+ }
+
+ return count;
+ }
+}