From d5f5f179588e0633f9b801a6058a987916e80847 Mon Sep 17 00:00:00 2001 From: alextrical <35117191+alextrical@users.noreply.github.com> Date: Sat, 10 May 2025 18:53:51 +0100 Subject: [PATCH 1/4] Add Custom Manuf and Product Identifiers --- firmware/src/our_descriptor.cc | 2 ++ firmware/src/our_descriptor.h | 2 ++ firmware/src/tinyusb_stuff.cc | 44 +++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/firmware/src/our_descriptor.cc b/firmware/src/our_descriptor.cc index e138bebe..f34cb0b5 100644 --- a/firmware/src/our_descriptor.cc +++ b/firmware/src/our_descriptor.cc @@ -661,6 +661,8 @@ const our_descriptor_def_t our_descriptors[] = { .descriptor_length = sizeof(our_report_descriptor_stadia), .vid = 0x18D1, .pid = 0x9400, + .manufacturer = "Google", + .product = "stadia", .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..dc76a77b 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[64] = ""; + char product[64] = ""; 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..d30264bc 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 64 + +// 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,16 +114,23 @@ 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 }; +// 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 +// }; + // Invoked when received GET DEVICE DESCRIPTOR // Application return pointer to descriptor uint8_t const* tud_descriptor_device_cb() { @@ -151,6 +170,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 (our_descriptor->manufacturer != "") { + strcpy(manufacturer, our_descriptor->manufacturer); + } + if (our_descriptor->product != "") { + strcpy(product, our_descriptor->product); + } + if (index == 0) { memcpy(&_desc_str[1], string_desc_arr[0], 2); chr_count = 1; @@ -173,7 +199,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 && our_descriptor->product == product) { 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]; From 1438b9bff4062736c5028056f8271b7531abd71d Mon Sep 17 00:00:00 2001 From: alextrical <35117191+alextrical@users.noreply.github.com> Date: Sat, 10 May 2025 18:54:18 +0100 Subject: [PATCH 2/4] Commit --- firmware/src/tinyusb_stuff.cc | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/firmware/src/tinyusb_stuff.cc b/firmware/src/tinyusb_stuff.cc index d30264bc..bcd00ec6 100644 --- a/firmware/src/tinyusb_stuff.cc +++ b/firmware/src/tinyusb_stuff.cc @@ -121,16 +121,6 @@ char* string_desc_arr[] = { product, // 2: Product }; -// 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 -// }; - // Invoked when received GET DEVICE DESCRIPTOR // Application return pointer to descriptor uint8_t const* tud_descriptor_device_cb() { @@ -170,10 +160,10 @@ const char id_chars[33] = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { uint8_t chr_count; - if (our_descriptor->manufacturer != "") { + if (strlen(our_descriptor->manufacturer) != 0) { strcpy(manufacturer, our_descriptor->manufacturer); } - if (our_descriptor->product != "") { + if (strlen(our_descriptor->product) != 0) { strcpy(product, our_descriptor->product); } @@ -199,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 && our_descriptor->product == product) { + 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]; From b4da011127d411d1c0c84d71f60c8a1513f00b39 Mon Sep 17 00:00:00 2001 From: alextrical <35117191+alextrical@users.noreply.github.com> Date: Sat, 10 May 2025 19:29:07 +0100 Subject: [PATCH 3/4] Add Manufacturer and Product names --- firmware/src/our_descriptor.cc | 7 +++++-- firmware/src/our_descriptor.h | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/firmware/src/our_descriptor.cc b/firmware/src/our_descriptor.cc index f34cb0b5..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,8 +664,8 @@ const our_descriptor_def_t our_descriptors[] = { .descriptor_length = sizeof(our_report_descriptor_stadia), .vid = 0x18D1, .pid = 0x9400, - .manufacturer = "Google", - .product = "stadia", + .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 dc76a77b..3838335b 100644 --- a/firmware/src/our_descriptor.h +++ b/firmware/src/our_descriptor.h @@ -34,8 +34,8 @@ struct our_descriptor_def_t { uint32_t descriptor_length; uint16_t vid = 0; uint16_t pid = 0; - char manufacturer[64] = ""; - char product[64] = ""; + 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; From eee850fdb81331919fe05b9b94d3bc786d9baf07 Mon Sep 17 00:00:00 2001 From: alextrical <35117191+alextrical@users.noreply.github.com> Date: Sat, 10 May 2025 19:32:25 +0100 Subject: [PATCH 4/4] Set max string length for Product and Manufacturing name --- firmware/src/tinyusb_stuff.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/src/tinyusb_stuff.cc b/firmware/src/tinyusb_stuff.cc index bcd00ec6..c8d62935 100644 --- a/firmware/src/tinyusb_stuff.cc +++ b/firmware/src/tinyusb_stuff.cc @@ -38,7 +38,7 @@ #define USB_PID 0xBAF2 // Define maximum string lengths to ensure buffer safety -#define MAX_STRING_LENGTH 64 +#define MAX_STRING_LENGTH 31 // Create modifiable string buffers char lang[2] = {0x09, 0x04};