/** * @file descriptor.c * @brief overwrite usb device descriptor * @version 1.00 * @date 2019-05-06 */ #include "usb/device/usb_stack.h" #include "usb/device/descriptor.h" #include "usb/device/uac_audio.h" #include "app_config.h" #define LOG_TAG_CONST USB #define LOG_TAG "[USB]" #define LOG_ERROR_ENABLE #define LOG_DEBUG_ENABLE #define LOG_INFO_ENABLE /* #define LOG_DUMP_ENABLE */ #define LOG_CLI_ENABLE #include "debug.h" #if TCFG_USB_SLAVE_ENABLE static const u8 sDeviceDescriptor[] = { // in Unicode 0x02, // iProduct: Index to string descriptor that contains the string in Unicode 0x03, // iSerialNumber: none 0x01 // bNumConfigurations: 1 }; static const u8 LANGUAGE_STR[] = { 0x04, 0x03, 0x09, 0x04 }; static const u8 product_string[] = { 42, 0x03, 'U', 0x00, 'S', 0x00, 'B', 0x00, ' ', 0x00, 'C', 0x00, 'o', 0x00, 'm', 0x00, 'p', 0x00, 'o', 0x00, 's', 0x00, 'i', 0x00, 't', 0x00, 'e', 0x00, ' ', 0x00, 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, }; static const u8 MANUFACTURE_STR[] = { 34, //该描述符的长度为34字节 0x03, //字符串描述符的类型编码为0x03 0x4a, 0x00, //J 0x69, 0x00, //i 0x65, 0x00, //e 0x6c, 0x00, //l 0x69, 0x00, //i 0x20, 0x00, // 0x54, 0x00, //T 0x65, 0x00, //e 0x63, 0x00, //c 0x68, 0x00, //h 0x6e, 0x00, //n 0x6f, 0x00, //o 0x6c, 0x00, //l 0x6f, 0x00, //o 0x67, 0x00, //g 0x79, 0x00, //y }; static const u8 sConfigDescriptor[] = { //> 4; if (bcd > 9) { bcd = bcd - 0xa + 'A'; } else { bcd = bcd + '0'; } ptr[2 + i * 4] = bcd; bcd = flash_id[i] & 0xf; if (bcd > 9) { bcd = bcd - 0xa + 'A'; } else { bcd = bcd + '0'; } ptr[2 + i * 4 + 2] = bcd; } } else { memcpy(ptr, serial_string, serial_string[0]); } #endif } #if USB_ROOT2 static const u8 ee_string[] = {0x12, 0x03, 0x4D, 0x00, 0x53, 0x00, 0x46, 0x00, 0x54, 0x00, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x90, 0x00 }; void get_string_ee(u8 *ptr) { memcpy(ptr, ee_string, ee_string[0]); } #endif void get_product_str(u8 *ptr) { memcpy(ptr, product_string, product_string[0]); } const u8 *usb_get_config_desc() { return sConfigDescriptor; } const u8 *usb_get_string_desc(u32 id) { const u8 *pstr = uac_get_string(id); if (pstr != NULL) { return pstr; } return NULL; } #endif