Clean up USB VID/PID declarations

== DETAILS

USB Vendor and Product IDs are in little-endian byte order, and they
need to be byteswapped on big-endian systems.

This approach allows us to use the standard hex notation for the VID/HID
values, and give them meaningful names, and only swap on the platforms
that need it. Also prevents having to abuse SWAP16() in the platform-
specific code.
This commit is contained in:
gblues 2017-12-24 18:29:00 -08:00 committed by twinaphex
parent 0f66bc3297
commit 8f900de65e
3 changed files with 35 additions and 16 deletions

View File

@ -20,6 +20,7 @@
#include <string/stdstring.h>
#include "../input_driver.h"
#include "../../verbosity.h"
#include "joypad_connection.h"
@ -75,16 +76,16 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn,
pad_connection_interface_t *iface;
} pad_map[] =
{
{ "Nintendo RVL-CNT-01", 1406, 816, &pad_connection_wii },
{ "Nintendo RVL-CNT-01-UC", 1406, 816, &pad_connection_wiiupro },
{ "Wireless Controller", 1356, 1476, &pad_connection_ps4 },
{ "PLAYSTATION(R)3 Controller", 1356, 616, &pad_connection_ps3 },
{ "PLAYSTATION(R)3 Controller", 787, 8406, &pad_connection_ps3 },
{ "Generic SNES USB Controller", 2079, 58369, &pad_connection_snesusb },
{ "Generic NES USB Controller", 121, 17, &pad_connection_nesusb },
{ "Wii U GC Controller Adapter", 1406, 823, &pad_connection_wiiugca },
{ "PS2/PSX Controller Adapter", 2064, 1, &pad_connection_ps2adapter },
{ "PSX to PS3 Controller Adapter", 2064, 3, &pad_connection_psxadapter },
{ "Nintendo RVL-CNT-01", VID_NINTENDO, PID_NINTENDO_PRO, &pad_connection_wii },
{ "Nintendo RVL-CNT-01-UC", VID_NINTENDO, PID_NINTENDO_PRO, &pad_connection_wiiupro },
{ "Wireless Controller", VID_SONY, PID_SONY_DS4, &pad_connection_ps4 },
{ "PLAYSTATION(R)3 Controller", VID_SONY, PID_SONY_DS3, &pad_connection_ps3 },
{ "PLAYSTATION(R)3 Controller", VID_PS3_CLONE, PID_DS3_CLONE, &pad_connection_ps3 },
{ "Generic SNES USB Controller", VID_SNES_CLONE, PID_SNES_CLONE, &pad_connection_snesusb },
{ "Generic NES USB Controller", VID_MICRONTEK, PID_MICRONTEK_NES, &pad_connection_nesusb },
{ "Wii U GC Controller Adapter", VID_NINTENDO, PID_NINTENDO_GCA, &pad_connection_wiiugca },
{ "PS2/PSX Controller Adapter", VID_PCS, PID_PCS_PS2PSX, &pad_connection_ps2adapter },
{ "PSX to PS3 Controller Adapter", VID_PCS, PID_PCS_PSX2PS3, &pad_connection_psxadapter },
{ "Mayflash DolphinBar", 1406, 774, &pad_connection_wii },
{ 0, 0}
};
@ -112,9 +113,11 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn,
}
#if 0
RARCH_LOG("name: %s\n", name);
RARCH_LOG("%d VID, PID %d (config)\n", vid, pid);
RARCH_LOG("%d VID, PID %d\n", pad_map[i].vid, pad_map[i].pid);
RARCH_LOG("[connect] %s\n", pad_map[i].name);
RARCH_LOG("[connect] VID: Expected: %04x got: %04x\n",
pad_map[i].vid, vid);
RARCH_LOG("[connect] PID: Expected: %04x got: %04x\n",
pad_map[i].pid, pid);
#endif
if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid))

View File

@ -22,9 +22,26 @@
#include <libretro.h>
#include <retro_miscellaneous.h>
#include <retro_endianness.h>
#include "../input_driver.h"
#define VID_NINTENDO swap_if_big16(0x057e)
#define VID_SONY swap_if_big16(0x054c)
#define VID_MICRONTEK swap_if_big16(0x0079)
#define VID_PCS swap_if_big16(0x0810)
#define VID_PS3_CLONE swap_if_big16(0x0313)
#define VID_SNES_CLONE swap_if_big16(0x081f)
#define PID_NINTENDO_PRO swap_if_big16(0x0330)
#define PID_SONY_DS3 swap_if_big16(0x0268)
#define PID_SONY_DS4 swap_if_big16(0x05c4)
#define PID_DS3_CLONE swap_if_big16(0x20d6)
#define PID_SNES_CLONE swap_if_big16(0xe401)
#define PID_MICRONTEK_NES swap_if_big16(0x0011)
#define PID_NINTENDO_GCA swap_if_big16(0x0337)
#define PID_PCS_PS2PSX swap_if_big16(0x0001)
#define PID_PCS_PSX2PS3 swap_if_big16(0x0003)
struct joypad_connection
{
bool connected;

View File

@ -323,8 +323,7 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) {
RARCH_LOG("[hid]: pad_connection_pad_init\n");
adapter->slot = pad_connection_pad_init(hid->connections,
// "hid", event->vendor_id, event->product_id, adapter,
"hid", SWAP16(event->vendor_id), SWAP16(event->product_id), adapter,
"hid", event->vendor_id, event->product_id, adapter,
&wiiu_hid);
if(adapter->slot < 0) {