Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions firmware/src/our_descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions firmware/src/our_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 25 additions & 9 deletions firmware/src/tinyusb_stuff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down