diff --git a/firmware/src/our_descriptor.cc b/firmware/src/our_descriptor.cc index e138bebe..40b66d45 100644 --- a/firmware/src/our_descriptor.cc +++ b/firmware/src/our_descriptor.cc @@ -634,6 +634,8 @@ const our_descriptor_def_t our_descriptors[] = { .descriptor_length = sizeof(our_report_descriptor_horipad), .vid = 0x0F0D, .pid = 0x00C1, + .manufacturer = "HORI CO., LTD.", + .product = "HORIPAD for Nintendo Switch", .handle_received_report = do_handle_received_report, .clear_report = horipad_clear_report, .default_value = horipad_default_value, @@ -644,6 +646,7 @@ const our_descriptor_def_t our_descriptors[] = { .descriptor_length = sizeof(our_report_descriptor_ps4), .vid = 0x054C, .pid = 0x1234, + .manufacturer = "Sony Corp.", .device_connected = ps4_device_connected, .device_disconnected = ps4_device_disconnected, .main_loop_task = ps4_main_loop_task, @@ -661,6 +664,8 @@ const our_descriptor_def_t our_descriptors[] = { .descriptor_length = sizeof(our_report_descriptor_stadia), .vid = 0x18D1, .pid = 0x9400, + .manufacturer = "Google Inc.", + .product = "Stadia Controller", .handle_received_report = do_handle_received_report, .clear_report = stadia_clear_report, .default_value = ps4_stadia_default_value, diff --git a/firmware/src/our_descriptor.h b/firmware/src/our_descriptor.h index 0bdbc8e0..3838335b 100644 --- a/firmware/src/our_descriptor.h +++ b/firmware/src/our_descriptor.h @@ -34,6 +34,8 @@ struct our_descriptor_def_t { uint32_t descriptor_length; uint16_t vid = 0; uint16_t pid = 0; + char manufacturer[32] = ""; + char product[32] = ""; device_connected_t device_connected = nullptr; device_disconnected_t device_disconnected = nullptr; main_loop_task_t main_loop_task = nullptr; diff --git a/firmware/src/tinyusb_stuff.cc b/firmware/src/tinyusb_stuff.cc index b7d53bc1..c8d62935 100644 --- a/firmware/src/tinyusb_stuff.cc +++ b/firmware/src/tinyusb_stuff.cc @@ -37,6 +37,18 @@ #define USB_VID 0xCAFE #define USB_PID 0xBAF2 +// Define maximum string lengths to ensure buffer safety +#define MAX_STRING_LENGTH 31 + +// Create modifiable string buffers +char lang[2] = {0x09, 0x04}; +#ifdef PICO_RP2350 + char manufacturer[MAX_STRING_LENGTH] = "RP2350"; // 1: Manufacturer +#else + char manufacturer[MAX_STRING_LENGTH] = "RP2040"; // 1: Manufacturer +#endif +char product[MAX_STRING_LENGTH] = "HID Remapper XXXX"; + tusb_desc_device_t desc_device = { .bLength = sizeof(tusb_desc_device_t), .bDescriptorType = TUSB_DESC_DEVICE, @@ -102,14 +114,11 @@ const uint8_t* configuration_descriptors[] = { configuration_descriptor5, }; -char const* string_desc_arr[] = { - (const char[]){ 0x09, 0x04 }, // 0: is supported language is English (0x0409) -#ifdef PICO_RP2350 - "RP2350", // 1: Manufacturer -#else - "RP2040", // 1: Manufacturer -#endif - "HID Remapper XXXX", // 2: Product +// // Array of pointers to these modifiable strings +char* string_desc_arr[] = { + lang, // 0: is supported language is English (0x0409) + manufacturer, // 1: Manufacturer + product, // 2: Product }; // Invoked when received GET DEVICE DESCRIPTOR @@ -151,6 +160,13 @@ const char id_chars[33] = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { uint8_t chr_count; + if (strlen(our_descriptor->manufacturer) != 0) { + strcpy(manufacturer, our_descriptor->manufacturer); + } + if (strlen(our_descriptor->product) != 0) { + strcpy(product, our_descriptor->product); + } + if (index == 0) { memcpy(&_desc_str[1], string_desc_arr[0], 2); chr_count = 1; @@ -173,7 +189,7 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { _desc_str[1 + i] = str[i]; } - if (index == 2) { + if (index == 2 && strlen(our_descriptor->product) == 0) { uint64_t unique_id = get_unique_id(); for (uint8_t i = 0; i < 4; i++) { _desc_str[1 + chr_count - 4 + i] = id_chars[(unique_id >> (15 - i * 5)) & 0x1F];