diff --git a/lib_xua/api/xua_endpoint0.h b/lib_xua/api/xua_endpoint0.h index c741225f..bf279c5c 100644 --- a/lib_xua/api/xua_endpoint0.h +++ b/lib_xua/api/xua_endpoint0.h @@ -40,6 +40,52 @@ void XUA_Endpoint0_setVendorId(unsigned short vid); */ void XUA_Endpoint0_setProductId(unsigned short pid); + +/** Function to set the Vendor ID value + * + * \param vid vendor ID value to set +*/ +#ifdef __XC__ +extern "C" { +#endif + void XUA_Endpoint0_setVendorStr(char* vendor_str); +#ifdef __XC__ +} +#endif + +#ifdef __XC__ +extern "C" { +#endif + void XUA_Endpoint0_setProductStr(char* product_str); +#ifdef __XC__ +} +#endif + +/** Function to set the Vendor ID value + * + * \param vid vendor ID value to set +*/ +#ifdef __XC__ +extern "C" { +#endif +char* XUA_Endpoint0_getVendorStr(); +#ifdef __XC__ +} +#endif + +/** Function to set the Product ID value + * + * \param pid Product ID value to set +*/ +#ifdef __XC__ +extern "C" { +#endif +char* XUA_Endpoint0_getProductStr(); +#ifdef __XC__ +} +#endif + + /** Function to get the Vendor ID value * * \return Vendor ID value diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index 2a183c72..bb296555 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -8,7 +8,7 @@ #include #include #include - +#include #include "xua.h" #if XUA_USB_EN @@ -217,6 +217,92 @@ void XUA_Endpoint0_setVendorId(unsigned short vid) { devDesc_Audio2.idVendor = vid; #endif // AUDIO_CLASS == 1} } +#include "print.h" +void copyCombinedStrings(char* string1, char* string2, char* string_buffer) { + uint32_t string_size = MIN(strlen(string1), MAX_STRING_SIZE); + memset(string_buffer, 0, MAX_STRING_SIZE); + memcpy(string_buffer, string1, string_size); + string_size = MIN(strlen(string1)+1, MAX_STRING_SIZE); + if (string_sizeMAX_STRING_SIZE) { + memcpy(string_buffer+strlen(string1)+1, string2, MAX_STRING_SIZE-strlen(string1)-1); + } else { + memcpy(string_buffer+strlen(string1)+1, string2, strlen(string2)); + } +} + +void XUA_Endpoint0_setVendorStr(char* vendor_str) { + uint32_t string_size = MIN(strlen(vendor_str), MAX_STRING_SIZE); + + memset(g_strTable.vendorStr, 0, MAX_STRING_SIZE); + memcpy(g_strTable.vendorStr, vendor_str, string_size); +#if (AUDIO_CLASS == 2) + copyCombinedStrings(g_strTable.clockSelectorStr, vendor_str, "Clock Selector"); + copyCombinedStrings(g_strTable.internalClockSourceStr, vendor_str, "Internal Clock"); +#endif +#if SPDIF_RX + copyCombinedStrings(g_strTable.spdifClockSourceStr, vendor_str, "S/PDIF Clock"); +#endif +#if ADAT_RX + copyCombinedStrings(g_strTable.adatClockSourceStr, vendor_str, "ADAT Clock"); +#endif +#if (XUA_DFU_EN == 1) + copyCombinedStrings(g_strTable.dfuStr, vendor_str, "DFU"); +#endif +#ifdef USB_CONTROL_DESCS + copyCombinedStrings(g_strTable.ctrlStr, vendor_str, "Control"); +#endif +#ifdef MIDI + copyCombinedStrings(g_strTable.midiOutStr, vendor_str, "MIDI Out"); + copyCombinedStrings(g_strTable.midiInStr, vendor_str, "MIDI In"); +#endif +} + +void XUA_Endpoint0_setProductStr(char* product_str) { + uint32_t string_size = MIN(strlen(product_str), MAX_STRING_SIZE); +#if (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) + memset(g_strTable.productStr_Audio1, 0, MAX_STRING_SIZE); + memset(g_strTable.outputInterfaceStr_Audio1, 0, MAX_STRING_SIZE); + memset(g_strTable.inputInterfaceStr_Audio1, 0, MAX_STRING_SIZE); + memset(g_strTable.usbInputTermStr_Audio1, 0, MAX_STRING_SIZE); + memset(g_strTable.usbOutputTermStr_Audio1, 0, MAX_STRING_SIZE); + + memcpy(g_strTable.productStr_Audio1, product_str, string_size); + memcpy(g_strTable.outputInterfaceStr_Audio1, product_str, string_size); + memcpy(g_strTable.inputInterfaceStr_Audio1, product_str, string_size); + memcpy(g_strTable.usbInputTermStr_Audio1, product_str, string_size); + memcpy(g_strTable.usbOutputTermStr_Audio1, product_str, string_size); +#elif (AUDIO_CLASS == 2) + memset(g_strTable.productStr_Audio2, 0, MAX_STRING_SIZE); + memset(g_strTable.outputInterfaceStr_Audio2, 0, MAX_STRING_SIZE); + memset(g_strTable.inputInterfaceStr_Audio2, 0, MAX_STRING_SIZE); + memset(g_strTable.usbInputTermStr_Audio2, 0, MAX_STRING_SIZE); + memset(g_strTable.usbOutputTermStr_Audio2, 0, MAX_STRING_SIZE); + + memcpy(g_strTable.productStr_Audio1, product_str, string_size); + memcpy(g_strTable.outputInterfaceStr_Audio2, product_str, string_size); + memcpy(g_strTable.inputInterfaceStr_Audio2, product_str, string_size); + memcpy(g_strTable.usbInputTermStr_Audio2, product_str, string_size); + memcpy(g_strTable.usbOutputTermStr_Audio2, product_str, string_size); +#endif +} + +char* XUA_Endpoint0_getVendorStr() { + return g_strTable.vendorStr; +} + +char* XUA_Endpoint0_getProductStr() { + #if (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) + return g_strTable.productStr_Audio1; + #elif (AUDIO_CLASS == 2) + return g_strTable.productStr_Audio2; + #endif +} void XUA_Endpoint0_setProductId(unsigned short pid) { #if (AUDIO_CLASS == 1) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index 5e51b3dd..521bdd64 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -20,13 +20,15 @@ #include "iap2.h" /* Defines iAP EA Native Transport protocol name */ #endif +#define MAX_STRING_SIZE (32) + #define APPEND_VENDOR_STR(x) VENDOR_STR" "#x #define APPEND_PRODUCT_STR_A2(x) PRODUCT_STR_A2 " "#x #define APPEND_PRODUCT_STR_A1(x) PRODUCT_STR_A1 " "#x -#define STR_TABLE_ENTRY(name) char *name +#define STR_TABLE_ENTRY(name) char name[MAX_STRING_SIZE] #define ISO_EP_ATTRIBUTES_ASYNCH 0x05 //ISO, ASYNCH, DATA EP #define ISO_EP_ATTRIBUTES_ADAPTIVE 0x09 //ISO, ADAPTIVE, DATA EP @@ -327,6 +329,7 @@ StringDescTable_t g_strTable = .usbOutputTermStr_Audio2 = APPEND_PRODUCT_STR_A2(), #endif #if (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) + .productStr_Audio1 = PRODUCT_STR_A1, .outputInterfaceStr_Audio1 = APPEND_PRODUCT_STR_A1(), .inputInterfaceStr_Audio1 = APPEND_PRODUCT_STR_A1(), @@ -2293,6 +2296,8 @@ unsigned char cfgDesc_Null[] = * To work around this we repeat MAX_FREQ_FS multiple times in some cases */ #define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) + const unsigned num_freqs_a1 = MAX(3, (0 #if(MIN_FREQ <= 8000) && (MAX_FREQ_FS >= 8000) + 1