Use USB product field in the descriptor.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
7805131d92
commit
585a6d77e3
2 changed files with 35 additions and 13 deletions
10
src/main.c
10
src/main.c
|
|
@ -323,6 +323,16 @@ int main(void) {
|
|||
gpio_pulldown_dis(BOOT_PIN);
|
||||
|
||||
tusb_cfg.string_descriptor[3] = pico_serial_str;
|
||||
if (phy_data.usb_product_present) {
|
||||
tusb_cfg.string_descriptor[2] = phy_data.usb_product;
|
||||
}
|
||||
static char tmps[4][32];
|
||||
for (int i = 4; i < tusb_cfg.string_descriptor_count; i++) {
|
||||
strlcpy(tmps[i-4], tusb_cfg.string_descriptor[2], sizeof(tmps[0]));
|
||||
strlcat(tmps[i-4], " ", sizeof(tmps[0]));
|
||||
strlcat(tmps[i-4], tusb_cfg.string_descriptor[i], sizeof(tmps[0]));
|
||||
tusb_cfg.string_descriptor[i] = tmps[i-4];
|
||||
}
|
||||
tusb_cfg.configuration_descriptor = desc_config;
|
||||
|
||||
tinyusb_driver_install(&tusb_cfg);
|
||||
|
|
|
|||
|
|
@ -266,14 +266,14 @@ char const *string_desc_arr [] = {
|
|||
"Pol Henarejos", // 1: Manufacturer
|
||||
"Pico Key", // 2: Product
|
||||
"11223344", // 3: Serials, should use chip ID
|
||||
"Pico Key Config" // 4: Vendor Interface
|
||||
"Config" // 4: Vendor Interface
|
||||
#ifdef USB_ITF_HID
|
||||
, "Pico Key HID Interface"
|
||||
, "Pico Key HID Keyboard Interface"
|
||||
, "HID Interface"
|
||||
, "HID Keyboard Interface"
|
||||
#endif
|
||||
#ifdef USB_ITF_CCID
|
||||
, "Pico Key CCID Interface"
|
||||
, "Pico Key WebCCID Interface"
|
||||
, "CCID OTP FIDO Interface"
|
||||
, "WebCCID Interface"
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ static uint16_t _desc_str[32];
|
|||
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
(void) langid;
|
||||
|
||||
uint8_t chr_count;
|
||||
uint8_t chr_count = 0;
|
||||
|
||||
if (index == 0) {
|
||||
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
||||
|
|
@ -309,15 +309,27 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
|||
if (index == 3) {
|
||||
str = pico_serial_str;
|
||||
}
|
||||
|
||||
chr_count = strlen(str);
|
||||
if (chr_count > 31) {
|
||||
chr_count = 31;
|
||||
else if (index == 2) {
|
||||
if (phy_data.usb_product_present) {
|
||||
str = phy_data.usb_product;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert ASCII string into UTF-16
|
||||
for (uint8_t i = 0; i < chr_count; i++) {
|
||||
_desc_str[1 + i] = str[i];
|
||||
uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1;
|
||||
if (index >= 4) {
|
||||
const char *product = phy_data.usb_product_present ? phy_data.usb_product : string_desc_arr[2];
|
||||
uint8_t len = MIN(strlen(product), buff_avail);
|
||||
for (int ix = 0; ix < len; chr_count++, ix++) {
|
||||
_desc_str[1 + chr_count] = product[ix];
|
||||
}
|
||||
buff_avail -= len;
|
||||
if (buff_avail > 0) {
|
||||
_desc_str[1 + chr_count++] = ' ';
|
||||
buff_avail--;
|
||||
}
|
||||
}
|
||||
for (int ix = 0; ix < MIN(strlen(str), buff_avail); chr_count++, ix++) {
|
||||
_desc_str[1 + chr_count] = str[ix];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue