Fix interface strings when are not all enabled.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-01-26 01:19:56 +01:00
parent 50488cc890
commit 20f2b3b74b
2 changed files with 11 additions and 1 deletions

View File

@@ -74,7 +74,9 @@ queue_t card_to_usb_q = {0};
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
extern tusb_desc_device_t desc_device; extern tusb_desc_device_t desc_device;
#endif #endif
void usb_init() { extern char *string_desc_itf[4], *string_desc_arr[];
void usb_init()
{
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
if (phy_data.vidpid_present) { if (phy_data.vidpid_present) {
desc_device.idVendor = phy_data.vid; desc_device.idVendor = phy_data.vid;
@@ -108,20 +110,24 @@ void usb_init() {
if (enabled_usb_itf & PHY_USB_ITF_HID) { if (enabled_usb_itf & PHY_USB_ITF_HID) {
ITF_HID_CTAP = ITF_HID_TOTAL++; ITF_HID_CTAP = ITF_HID_TOTAL++;
ITF_HID = ITF_TOTAL++; ITF_HID = ITF_TOTAL++;
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[5];
} }
if (enabled_usb_itf & PHY_USB_ITF_KB) { if (enabled_usb_itf & PHY_USB_ITF_KB) {
ITF_HID_KB = ITF_HID_TOTAL++; ITF_HID_KB = ITF_HID_TOTAL++;
ITF_KEYBOARD = ITF_TOTAL++; ITF_KEYBOARD = ITF_TOTAL++;
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[6];
} }
#endif #endif
#ifdef USB_ITF_CCID #ifdef USB_ITF_CCID
if (enabled_usb_itf & PHY_USB_ITF_CCID) { if (enabled_usb_itf & PHY_USB_ITF_CCID) {
ITF_SC_CCID = ITF_SC_TOTAL++; ITF_SC_CCID = ITF_SC_TOTAL++;
ITF_CCID = ITF_TOTAL++; ITF_CCID = ITF_TOTAL++;
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[7];
} }
if (enabled_usb_itf & PHY_USB_ITF_WCID) { if (enabled_usb_itf & PHY_USB_ITF_WCID) {
ITF_SC_WCID = ITF_SC_TOTAL++; ITF_SC_WCID = ITF_SC_TOTAL++;
ITF_WCID = ITF_TOTAL++; ITF_WCID = ITF_TOTAL++;
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[8];
} }
#endif #endif
card_locked_itf = ITF_TOTAL; card_locked_itf = ITF_TOTAL;

View File

@@ -316,6 +316,7 @@ uint8_t const *tud_descriptor_bos_cb(void) {
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// array of pointer to string descriptors // array of pointer to string descriptors
char *string_desc_itf[4] = {0};
char const *string_desc_arr [] = { char const *string_desc_arr [] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409) (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"Pol Henarejos", // 1: Manufacturer "Pol Henarejos", // 1: Manufacturer
@@ -369,6 +370,9 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
str = phy_data.usb_product; str = phy_data.usb_product;
} }
} }
else if (index >= 5 && string_desc_itf[index - 5] != NULL) {
str = string_desc_itf[index - 5];
}
uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1;
if (index >= 4) { if (index >= 4) {