mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 09:01:24 +02:00
Use USB product field in the descriptor.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
10
src/main.c
10
src/main.c
@@ -323,6 +323,16 @@ int main(void) {
|
|||||||
gpio_pulldown_dis(BOOT_PIN);
|
gpio_pulldown_dis(BOOT_PIN);
|
||||||
|
|
||||||
tusb_cfg.string_descriptor[3] = pico_serial_str;
|
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;
|
tusb_cfg.configuration_descriptor = desc_config;
|
||||||
|
|
||||||
tinyusb_driver_install(&tusb_cfg);
|
tinyusb_driver_install(&tusb_cfg);
|
||||||
|
|||||||
@@ -266,14 +266,14 @@ char const *string_desc_arr [] = {
|
|||||||
"Pol Henarejos", // 1: Manufacturer
|
"Pol Henarejos", // 1: Manufacturer
|
||||||
"Pico Key", // 2: Product
|
"Pico Key", // 2: Product
|
||||||
"11223344", // 3: Serials, should use chip ID
|
"11223344", // 3: Serials, should use chip ID
|
||||||
"Pico Key Config" // 4: Vendor Interface
|
"Config" // 4: Vendor Interface
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
, "Pico Key HID Interface"
|
, "HID Interface"
|
||||||
, "Pico Key HID Keyboard Interface"
|
, "HID Keyboard Interface"
|
||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
, "Pico Key CCID Interface"
|
, "CCID OTP FIDO Interface"
|
||||||
, "Pico Key WebCCID Interface"
|
, "WebCCID Interface"
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -291,7 +291,7 @@ static uint16_t _desc_str[32];
|
|||||||
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||||
(void) langid;
|
(void) langid;
|
||||||
|
|
||||||
uint8_t chr_count;
|
uint8_t chr_count = 0;
|
||||||
|
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
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) {
|
if (index == 3) {
|
||||||
str = pico_serial_str;
|
str = pico_serial_str;
|
||||||
}
|
}
|
||||||
|
else if (index == 2) {
|
||||||
chr_count = strlen(str);
|
if (phy_data.usb_product_present) {
|
||||||
if (chr_count > 31) {
|
str = phy_data.usb_product;
|
||||||
chr_count = 31;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert ASCII string into UTF-16
|
uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1;
|
||||||
for (uint8_t i = 0; i < chr_count; i++) {
|
if (index >= 4) {
|
||||||
_desc_str[1 + i] = str[i];
|
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user