int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid, void *data, send_control_t ptr) { static const struct { const char* name; uint16_t vid; uint16_t pid; 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 }, { 0, 0} }; joypad_connection_t *s = NULL; int pad = pad_connection_find_vacant_pad(joyconn); if (pad == -1) return -1; s = &joyconn[pad]; if (s) { unsigned i; for (i = 0; name && pad_map[i].name; i++) { const char *name_match = strstr(pad_map[i].name, name); /* Never change, Nintendo. */ if(pad_map[i].vid == 1406 && pad_map[i].pid == 816) { if(!string_is_equal(pad_map[i].name, name)) continue; } if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid)) { s->iface = pad_map[i].iface; s->data = s->iface->init(data, pad, ptr); s->connected = true; break; } } } return pad; }
static bool wpad_init(void *data) { int slot = pad_connection_find_vacant_pad(hid_instance.pad_list); if(slot < 0) return false; hid_instance.pad_list[slot].connected = true; input_pad_connect(slot, &wpad_driver); wpad_poll(); ready = true; return true; }
int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid, void *data, send_control_t ptr) { int pad = pad_connection_find_vacant_pad(joyconn); if (pad != -1) { unsigned i; joypad_connection_t* s = (joypad_connection_t*)&joyconn[pad]; static const struct { const char* name; uint16_t vid; uint16_t pid; pad_connection_interface_t *iface; } pad_map[] = { { "Nintendo RVL-CNT-01", 1406, 816, &pad_connection_wii }, #if 0 { "Nintendo RVL-CNT-01-UC", 0, 0, &pad_connection_wii_u }, #endif { "Wireless Controller", 1356, 1476, &pad_connection_ps4 }, { "PLAYSTATION(R)3 Controller", 1356, 616, &pad_connection_ps3 }, { 0, 0} }; if (s) { for (i = 0; name && pad_map[i].name; i++) { const char *name_match = strstr(name, pad_map[i].name); if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid)) { s->iface = pad_map[i].iface; s->data = s->iface->init(data, pad, ptr); s->connected = true; return pad; } } } } return -1; }
joypad_connection_t *hid_pad_register(void *pad_handle, pad_connection_interface_t *iface) { int slot; joypad_connection_t *result; if(!pad_handle) return NULL; slot = pad_connection_find_vacant_pad(hid_instance.pad_list); if(slot < 0) { RARCH_ERR("[hid]: failed to find a vacant pad.\n"); return NULL; } result = &(hid_instance.pad_list[slot]); result->iface = iface; result->data = iface->init(pad_handle, slot, hid_instance.os_driver); result->connected = true; input_pad_connect(slot, hid_instance.pad_driver); return result; }