2014-10-04 18:41:23 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-04-06 22:03:03 -05:00
|
|
|
*
|
2014-10-04 18:41:23 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-12-05 13:24:15 +01:00
|
|
|
#include <stdlib.h>
|
2015-04-02 17:49:32 +02:00
|
|
|
#include <string.h>
|
2015-11-28 02:31:19 +01:00
|
|
|
|
2016-01-20 04:07:24 +01:00
|
|
|
#include <string/stdstring.h>
|
2021-10-03 23:27:07 +00:00
|
|
|
#include "../tasks/tasks_internal.h"
|
2016-01-20 04:07:24 +01:00
|
|
|
|
2017-08-31 02:25:04 +02:00
|
|
|
#include "../input_driver.h"
|
2017-12-24 18:29:00 -08:00
|
|
|
#include "../../verbosity.h"
|
2015-11-28 02:31:19 +01:00
|
|
|
|
2014-10-04 18:41:23 +02:00
|
|
|
#include "joypad_connection.h"
|
2014-10-04 19:07:59 +02:00
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
/* We init the HID/VID to 0 because we need to do
|
|
|
|
endian magic that we can't do during the declaration */
|
2021-10-01 22:22:11 -07:00
|
|
|
joypad_connection_entry_t pad_map[] = {
|
|
|
|
{ "Nintendo RVL-CNT-01", 0, 0, &pad_connection_wii },
|
|
|
|
{ "Nintendo RVL-CNT-01-UC", 0, 0, &pad_connection_wiiupro },
|
|
|
|
{ "Wireless Controller", 0, 0, &pad_connection_ps4 },
|
|
|
|
{ "PLAYSTATION(R)3 Controller", 0, 0, &pad_connection_ps3 },
|
|
|
|
{ "PLAYSTATION(R)3 Controller", 0, 0, &pad_connection_ps3 },
|
|
|
|
{ "Generic SNES USB Controller", 0, 0, &pad_connection_snesusb },
|
|
|
|
{ "Generic NES USB Controller", 0, 0, &pad_connection_nesusb },
|
|
|
|
{ "Wii U GC Controller Adapter", 0, 0, &pad_connection_wiiugca },
|
|
|
|
{ "PS2/PSX Controller Adapter", 0, 0, &pad_connection_ps2adapter },
|
|
|
|
{ "PSX to PS3 Controller Adapter", 0, 0, &pad_connection_psxadapter },
|
|
|
|
{ "Mayflash DolphinBar", 0, 0, &pad_connection_wii },
|
|
|
|
{ "Retrode", 0, 0, &pad_connection_retrode },
|
|
|
|
{ "HORI mini wired PS4", 0, 0, &pad_connection_ps4_hori_mini },
|
|
|
|
{ 0, 0}
|
|
|
|
};
|
|
|
|
|
2020-08-28 20:42:55 +02:00
|
|
|
static bool joypad_is_end_of_list(joypad_connection_t *pad)
|
|
|
|
{
|
2021-10-06 02:28:55 +02:00
|
|
|
return pad
|
|
|
|
&& !pad->connected
|
|
|
|
&& !pad->iface
|
|
|
|
&& (pad->data == (void *)0xdeadbeef);
|
2020-08-28 20:42:55 +02:00
|
|
|
}
|
2017-12-30 16:36:54 -08:00
|
|
|
|
2015-04-04 23:34:04 +02:00
|
|
|
int pad_connection_find_vacant_pad(joypad_connection_t *joyconn)
|
2014-10-04 19:07:59 +02:00
|
|
|
{
|
2021-10-06 02:28:55 +02:00
|
|
|
unsigned i;
|
2014-10-04 19:07:59 +02:00
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if (!joyconn)
|
|
|
|
return -1;
|
2015-04-04 23:44:02 +02:00
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
for (i = 0; !joypad_is_end_of_list(&joyconn[i]); i++)
|
|
|
|
{
|
|
|
|
if(!joyconn[i].connected)
|
|
|
|
return i;
|
|
|
|
}
|
2015-01-19 05:01:31 +01:00
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
return -1;
|
2014-10-04 19:07:59 +02:00
|
|
|
}
|
|
|
|
|
2017-12-28 13:01:38 -08:00
|
|
|
static void set_end_of_list(joypad_connection_t *list, unsigned end)
|
|
|
|
{
|
2021-10-06 02:28:55 +02:00
|
|
|
joypad_connection_t *entry = (joypad_connection_t *)&list[end];
|
|
|
|
entry->connected = false;
|
|
|
|
entry->iface = NULL;
|
|
|
|
entry->data = (void*)0xdeadbeef;
|
2017-12-28 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Since the pad_connection_destroy() call needs to iterate through this
|
|
|
|
* list, we allocate pads+1 entries and use the extra spot to store a
|
|
|
|
* marker.
|
|
|
|
*/
|
2015-06-13 01:40:55 +02:00
|
|
|
joypad_connection_t *pad_connection_init(unsigned pads)
|
2014-10-04 22:32:14 +02:00
|
|
|
{
|
2015-06-25 17:25:09 +02:00
|
|
|
unsigned i;
|
2017-12-31 23:46:11 +01:00
|
|
|
joypad_connection_t *joyconn;
|
2017-12-30 16:36:54 -08:00
|
|
|
|
|
|
|
if(pads > MAX_USERS)
|
|
|
|
{
|
|
|
|
RARCH_WARN("[joypad] invalid number of pads requested (%d), using default (%d)\n",
|
|
|
|
pads, MAX_USERS);
|
|
|
|
pads = MAX_USERS;
|
|
|
|
}
|
|
|
|
|
2017-12-31 23:46:11 +01:00
|
|
|
joyconn = (joypad_connection_t*)calloc(pads+1, sizeof(joypad_connection_t));
|
2015-01-19 05:01:31 +01:00
|
|
|
|
|
|
|
if (!joyconn)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < pads; i++)
|
|
|
|
{
|
|
|
|
joypad_connection_t *conn = (joypad_connection_t*)&joyconn[i];
|
|
|
|
|
2016-05-23 22:04:00 +02:00
|
|
|
conn->connected = false;
|
|
|
|
conn->iface = NULL;
|
|
|
|
conn->data = NULL;
|
2015-01-19 05:01:31 +01:00
|
|
|
}
|
|
|
|
|
2017-12-28 13:01:38 -08:00
|
|
|
set_end_of_list(joyconn, pads);
|
|
|
|
|
2015-01-19 05:01:31 +01:00
|
|
|
return joyconn;
|
2014-10-04 22:32:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
void init_pad_map(void)
|
|
|
|
{
|
2018-01-01 15:27:52 +01:00
|
|
|
pad_map[0].vid = VID_NINTENDO;
|
|
|
|
pad_map[0].pid = PID_NINTENDO_PRO;
|
|
|
|
pad_map[1].vid = VID_NINTENDO;
|
|
|
|
pad_map[1].pid = PID_NINTENDO_PRO;
|
|
|
|
pad_map[2].vid = VID_SONY;
|
|
|
|
pad_map[2].pid = PID_SONY_DS4;
|
|
|
|
pad_map[3].vid = VID_SONY;
|
|
|
|
pad_map[3].pid = PID_SONY_DS3;
|
|
|
|
pad_map[4].vid = VID_PS3_CLONE;
|
|
|
|
pad_map[4].pid = PID_DS3_CLONE;
|
|
|
|
pad_map[5].vid = VID_SNES_CLONE;
|
|
|
|
pad_map[5].pid = PID_SNES_CLONE;
|
|
|
|
pad_map[6].vid = VID_MICRONTEK;
|
|
|
|
pad_map[6].pid = PID_MICRONTEK_NES;
|
|
|
|
pad_map[7].vid = VID_NINTENDO;
|
|
|
|
pad_map[7].pid = PID_NINTENDO_GCA;
|
|
|
|
pad_map[8].vid = VID_PCS;
|
|
|
|
pad_map[8].pid = PID_PCS_PS2PSX;
|
|
|
|
pad_map[9].vid = VID_PCS;
|
|
|
|
pad_map[9].pid = PID_PCS_PSX2PS3;
|
|
|
|
pad_map[10].vid = 1406;
|
|
|
|
pad_map[10].pid = 774;
|
2019-08-09 13:42:15 +02:00
|
|
|
pad_map[11].vid = VID_RETRODE;
|
|
|
|
pad_map[11].pid = PID_RETRODE;
|
2020-09-04 17:50:10 +06:00
|
|
|
pad_map[12].vid = VID_HORI_1;
|
|
|
|
pad_map[12].pid = PID_HORI_MINI_WIRED_PS4;
|
2021-10-01 22:22:11 -07:00
|
|
|
}
|
2018-01-01 15:27:52 +01:00
|
|
|
|
2022-03-15 15:35:18 +01:00
|
|
|
joypad_connection_entry_t *find_connection_entry(uint16_t vid, uint16_t pid, const char *name)
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-01 22:22:11 -07:00
|
|
|
unsigned i;
|
|
|
|
const bool has_name = !string_is_empty(name);
|
2016-01-14 09:51:17 +01:00
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if(pad_map[0].vid == 0)
|
2021-10-04 00:01:46 +00:00
|
|
|
init_pad_map();
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
for(i = 0; pad_map[i].name != NULL; i++)
|
|
|
|
{
|
2021-10-09 16:19:54 +02:00
|
|
|
const char *name_match = has_name
|
|
|
|
? strstr(pad_map[i].name, name)
|
|
|
|
: NULL;
|
|
|
|
/* The Wii Pro Controller and WiiU Pro controller have
|
|
|
|
* the same VID/PID, so we have to use the
|
2021-10-06 02:28:55 +02:00
|
|
|
* descriptor string to differentiate them. */
|
2021-10-09 16:19:54 +02:00
|
|
|
if( pad_map[i].vid == VID_NINTENDO
|
|
|
|
&& pad_map[i].pid == PID_NINTENDO_PRO)
|
2015-02-15 03:59:57 +01:00
|
|
|
{
|
2021-10-01 22:22:11 -07:00
|
|
|
if(!string_is_equal(pad_map[i].name, name))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if(name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid))
|
2021-10-01 22:22:11 -07:00
|
|
|
return &pad_map[i];
|
|
|
|
}
|
2016-12-16 20:16:55 +13:00
|
|
|
|
2021-10-01 22:22:11 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-11 00:39:13 -07:00
|
|
|
static int joypad_to_slot(joypad_connection_t *haystack,
|
|
|
|
joypad_connection_t *needle)
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
int i;
|
|
|
|
|
2021-10-11 00:39:13 -07:00
|
|
|
if(needle == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2021-10-06 02:28:55 +02:00
|
|
|
|
2021-10-11 00:39:13 -07:00
|
|
|
for(i = 0; !joypad_is_end_of_list(&haystack[i]); i++)
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-11 00:39:13 -07:00
|
|
|
if(&haystack[i] == needle)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-10-16 14:45:20 -07:00
|
|
|
void release_joypad(joypad_connection_t *joypad) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-11 00:39:13 -07:00
|
|
|
void legacy_pad_connection_pad_deregister(joypad_connection_t *pad_list, pad_connection_interface_t *iface, void *pad_data) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; !joypad_is_end_of_list(&pad_list[i]); i++)
|
|
|
|
{
|
|
|
|
if(pad_list[i].connection == pad_data) {
|
2021-10-17 00:13:48 -07:00
|
|
|
input_autoconfigure_disconnect(i, iface ? iface->get_name(pad_data) : NULL);
|
2021-10-16 14:45:20 -07:00
|
|
|
memset(&pad_list[i], 0, sizeof(joypad_connection_t));
|
2021-10-11 00:39:13 -07:00
|
|
|
return;
|
2021-10-03 23:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 00:39:13 -07:00
|
|
|
void pad_connection_pad_deregister(joypad_connection_t *joyconn,
|
|
|
|
pad_connection_interface_t *iface, void *pad_data)
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-11 00:39:13 -07:00
|
|
|
int i;
|
|
|
|
int slot;
|
2021-10-03 23:27:07 +00:00
|
|
|
|
2021-10-17 00:13:48 -07:00
|
|
|
if(!iface || !iface->multi_pad)
|
2021-10-13 14:56:22 +02:00
|
|
|
{
|
2021-10-11 00:39:13 -07:00
|
|
|
legacy_pad_connection_pad_deregister(joyconn, iface, pad_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-13 14:56:22 +02:00
|
|
|
for(i = 0; i < iface->max_pad; i++)
|
|
|
|
{
|
2021-10-11 00:39:13 -07:00
|
|
|
slot = joypad_to_slot(joyconn, iface->joypad(pad_data, i));
|
2021-10-13 14:56:22 +02:00
|
|
|
if(slot >= 0)
|
|
|
|
{
|
2021-10-11 00:39:13 -07:00
|
|
|
input_autoconfigure_disconnect(slot, iface->get_name(joyconn[slot].connection));
|
|
|
|
iface->pad_deinit(joyconn[slot].connection);
|
2021-10-16 14:45:20 -07:00
|
|
|
memset(&joyconn[slot], 0, sizeof(joypad_connection_t));
|
2021-10-11 00:39:13 -07:00
|
|
|
}
|
2021-10-03 23:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 00:39:13 -07:00
|
|
|
|
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
void pad_connection_pad_refresh(joypad_connection_t *joyconn,
|
|
|
|
pad_connection_interface_t *iface,
|
|
|
|
void *device_data, void *handle,
|
|
|
|
input_device_driver_t *input_driver)
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
int i, slot;
|
|
|
|
int8_t state;
|
|
|
|
joypad_connection_t *joypad;
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if (!iface->multi_pad || iface->max_pad < 1)
|
2021-10-03 23:27:07 +00:00
|
|
|
return;
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
for (i = 0; i < iface->max_pad; i++)
|
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
state = iface->status(device_data, i);
|
2021-10-06 02:28:55 +02:00
|
|
|
switch(state)
|
|
|
|
{
|
|
|
|
/* The pad slot is bound to a joypad
|
|
|
|
that's no longer connected */
|
2021-10-03 23:27:07 +00:00
|
|
|
case PAD_CONNECT_BOUND:
|
2021-10-05 02:25:52 +00:00
|
|
|
RARCH_LOG("PAD_CONNECT_BOUND (0x%02x)\n", state);
|
2021-10-03 23:27:07 +00:00
|
|
|
joypad = iface->joypad(device_data, i);
|
2021-10-13 14:56:22 +02:00
|
|
|
slot = joypad_to_slot(joyconn, joypad);
|
2021-10-06 02:28:55 +02:00
|
|
|
input_autoconfigure_disconnect(slot,
|
|
|
|
iface->get_name(joypad->connection));
|
|
|
|
|
2021-10-03 23:27:07 +00:00
|
|
|
iface->pad_deinit(joypad->connection);
|
|
|
|
memset(joypad, 0, sizeof(joypad_connection_t));
|
|
|
|
break;
|
2021-10-06 02:28:55 +02:00
|
|
|
/* The joypad is connected but has not been bound */
|
2021-10-03 23:27:07 +00:00
|
|
|
case PAD_CONNECT_READY:
|
|
|
|
slot = pad_connection_find_vacant_pad(joyconn);
|
2021-10-09 16:19:54 +02:00
|
|
|
if(slot >= 0)
|
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
joypad = &joyconn[slot];
|
2021-10-09 16:19:54 +02:00
|
|
|
joypad->connection = iface->pad_init(device_data,
|
|
|
|
i, joypad);
|
|
|
|
joypad->data = handle;
|
|
|
|
joypad->iface = iface;
|
2021-10-03 23:27:07 +00:00
|
|
|
joypad->input_driver = input_driver;
|
2021-10-09 16:19:54 +02:00
|
|
|
joypad->connected = true;
|
2021-10-03 23:27:07 +00:00
|
|
|
input_pad_connect(slot, input_driver);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-10-06 02:28:55 +02:00
|
|
|
if(state > 0x03)
|
2021-10-05 02:25:52 +00:00
|
|
|
RARCH_LOG("Unrecognized state: 0x%02x", state);
|
2021-10-03 23:27:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
void pad_connection_pad_register(joypad_connection_t *joyconn,
|
|
|
|
pad_connection_interface_t *iface,
|
|
|
|
void *device_data, void *handle,
|
|
|
|
input_device_driver_t *input_driver, int slot)
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
int i, status;
|
|
|
|
int found_slot;
|
|
|
|
int max_pad;
|
|
|
|
void *connection;
|
2021-10-06 02:28:55 +02:00
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
if( (iface->multi_pad)
|
|
|
|
&& (iface->max_pad <= 1 || !iface->status || !iface->pad_init))
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
RARCH_ERR("pad_connection_pad_register: multi-pad driver has incomplete implementation\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_pad = iface->multi_pad ? iface->max_pad : 1;
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
for(i = 0; i < max_pad; i++)
|
|
|
|
{
|
2021-10-09 16:19:54 +02:00
|
|
|
status = iface->multi_pad
|
|
|
|
? iface->status(device_data, i)
|
|
|
|
: PAD_CONNECT_READY;
|
|
|
|
if(status == PAD_CONNECT_READY)
|
|
|
|
{
|
|
|
|
found_slot = (slot == SLOT_AUTO)
|
|
|
|
? pad_connection_find_vacant_pad(joyconn)
|
|
|
|
: slot;
|
2021-10-06 02:28:55 +02:00
|
|
|
if(found_slot < 0)
|
2021-10-03 23:27:07 +00:00
|
|
|
continue;
|
|
|
|
connection = device_data;
|
2021-10-06 02:28:55 +02:00
|
|
|
if(iface->multi_pad)
|
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
RARCH_LOG("pad_connection_pad_register: multi-pad detected, initializing pad %d\n", i);
|
2021-10-09 16:19:54 +02:00
|
|
|
connection = iface->pad_init(device_data, i,
|
|
|
|
&joyconn[found_slot]);
|
2021-10-03 23:27:07 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
joyconn[found_slot].iface = iface;
|
|
|
|
joyconn[found_slot].data = handle;
|
|
|
|
joyconn[found_slot].connection = connection;
|
2021-10-03 23:27:07 +00:00
|
|
|
joyconn[found_slot].input_driver = input_driver;
|
2021-10-06 02:28:55 +02:00
|
|
|
joyconn[found_slot].connected = true;
|
2021-10-03 23:27:07 +00:00
|
|
|
|
|
|
|
RARCH_LOG("connecting pad to slot %d\n", found_slot);
|
|
|
|
input_pad_connect(found_slot, input_driver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
int32_t pad_connection_pad_init_entry(joypad_connection_t *joyconn,
|
|
|
|
joypad_connection_entry_t *entry,
|
|
|
|
void *data, hid_driver_t *driver)
|
2021-10-06 02:28:55 +02:00
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
joypad_connection_t *conn = NULL;
|
|
|
|
int pad = pad_connection_find_vacant_pad(joyconn);
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if (pad < 0)
|
2021-10-03 23:27:07 +00:00
|
|
|
return -1;
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if (!(conn = &joyconn[pad]))
|
2021-10-03 23:27:07 +00:00
|
|
|
return -1;
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
conn->iface = entry->iface;
|
|
|
|
conn->data = data;
|
2021-10-03 23:27:07 +00:00
|
|
|
conn->connection = conn->iface->init(data, pad, driver);
|
2021-10-06 02:28:55 +02:00
|
|
|
conn->connected = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We failed to find a matching pad.
|
|
|
|
* Set up one without an interface */
|
2021-10-03 23:27:07 +00:00
|
|
|
RARCH_DBG("Pad was not matched. Setting up without an interface.\n");
|
2021-10-06 02:28:55 +02:00
|
|
|
conn->iface = NULL;
|
|
|
|
conn->data = data;
|
|
|
|
conn->connected = true;
|
2021-10-03 23:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
2021-10-01 22:22:11 -07:00
|
|
|
int32_t pad_connection_pad_init(joypad_connection_t *joyconn,
|
|
|
|
const char *name, uint16_t vid, uint16_t pid,
|
|
|
|
void *data, hid_driver_t *driver)
|
|
|
|
{
|
|
|
|
joypad_connection_entry_t *entry = NULL;
|
|
|
|
|
2021-10-06 02:28:55 +02:00
|
|
|
if(pad_map[0].vid == 0)
|
2021-10-01 22:22:11 -07:00
|
|
|
init_pad_map();
|
|
|
|
|
2021-10-03 23:27:07 +00:00
|
|
|
entry = find_connection_entry(vid, pid, name);
|
2021-10-01 22:22:11 -07:00
|
|
|
|
2021-10-03 23:27:07 +00:00
|
|
|
return pad_connection_pad_init_entry(joyconn, entry, data, driver);
|
2014-10-04 19:07:59 +02:00
|
|
|
}
|
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
void pad_connection_pad_deinit(joypad_connection_t *joyconn,
|
|
|
|
uint32_t pad)
|
2014-10-04 19:07:59 +02:00
|
|
|
{
|
2015-04-04 23:44:02 +02:00
|
|
|
if (!joyconn || !joyconn->connected)
|
2014-10-06 01:49:00 +02:00
|
|
|
return;
|
2015-04-06 22:03:03 -05:00
|
|
|
|
2015-04-04 23:44:02 +02:00
|
|
|
if (joyconn->iface)
|
2015-01-19 05:01:31 +01:00
|
|
|
{
|
2021-10-03 23:27:07 +00:00
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
joyconn->iface->set_rumble(joyconn->connection,
|
|
|
|
RETRO_RUMBLE_STRONG, 0);
|
|
|
|
joyconn->iface->set_rumble(joyconn->connection,
|
|
|
|
RETRO_RUMBLE_WEAK, 0);
|
2015-02-15 03:59:57 +01:00
|
|
|
|
2015-04-04 23:44:02 +02:00
|
|
|
if (joyconn->iface->deinit)
|
2021-08-06 22:02:43 -05:00
|
|
|
joyconn->iface->deinit(joyconn->connection);
|
2015-01-19 05:01:31 +01:00
|
|
|
}
|
|
|
|
|
2021-08-06 22:02:43 -05:00
|
|
|
joyconn->iface = NULL;
|
|
|
|
joyconn->connected = false;
|
|
|
|
joyconn->connection = NULL;
|
2014-10-04 19:07:59 +02:00
|
|
|
}
|
|
|
|
|
2015-04-04 23:44:02 +02:00
|
|
|
void pad_connection_packet(joypad_connection_t *joyconn, uint32_t pad,
|
2014-10-04 19:07:59 +02:00
|
|
|
uint8_t* data, uint32_t length)
|
|
|
|
{
|
2015-04-06 22:21:28 -05:00
|
|
|
if (!joyconn || !joyconn->connected)
|
2014-10-06 01:49:00 +02:00
|
|
|
return;
|
2021-10-09 16:19:54 +02:00
|
|
|
if (
|
|
|
|
joyconn->connection
|
|
|
|
&& joyconn->iface
|
2021-10-15 16:02:34 -07:00
|
|
|
&& joyconn->iface->packet_handler) {
|
|
|
|
|
2021-08-06 22:02:43 -05:00
|
|
|
joyconn->iface->packet_handler(joyconn->connection, data, length);
|
2021-10-15 16:02:34 -07:00
|
|
|
|
|
|
|
}
|
2014-10-04 19:07:59 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 20:21:12 +02:00
|
|
|
void pad_connection_get_buttons(joypad_connection_t *joyconn,
|
|
|
|
unsigned pad, input_bits_t *state)
|
2014-10-04 20:53:58 +02:00
|
|
|
{
|
2021-08-06 22:02:43 -05:00
|
|
|
if (joyconn && joyconn->iface)
|
|
|
|
joyconn->iface->get_buttons(joyconn->connection, state);
|
2017-12-05 09:22:33 +01:00
|
|
|
else
|
2021-08-06 22:02:43 -05:00
|
|
|
BIT256_CLEAR_ALL_PTR( state );
|
2014-10-04 20:53:58 +02:00
|
|
|
}
|
|
|
|
|
2015-04-04 23:44:02 +02:00
|
|
|
int16_t pad_connection_get_axis(joypad_connection_t *joyconn,
|
2014-10-20 20:32:41 +02:00
|
|
|
unsigned idx, unsigned i)
|
2014-10-04 20:53:58 +02:00
|
|
|
{
|
2017-12-31 07:15:18 +01:00
|
|
|
if (!joyconn || !joyconn->iface)
|
2015-01-19 05:01:31 +01:00
|
|
|
return 0;
|
2021-08-06 22:02:43 -05:00
|
|
|
return joyconn->iface->get_axis(joyconn->connection, i);
|
2014-10-04 20:53:58 +02:00
|
|
|
}
|
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
bool pad_connection_has_interface(joypad_connection_t *joyconn,
|
|
|
|
unsigned pad)
|
2014-10-04 19:07:59 +02:00
|
|
|
{
|
2017-11-28 10:04:34 +00:00
|
|
|
if ( joyconn && pad < MAX_USERS
|
|
|
|
&& joyconn[pad].connected
|
2016-02-04 21:07:02 +01:00
|
|
|
&& joyconn[pad].iface)
|
2014-10-06 01:49:00 +02:00
|
|
|
return true;
|
2014-10-04 19:07:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-06 01:49:00 +02:00
|
|
|
void pad_connection_destroy(joypad_connection_t *joyconn)
|
2014-10-04 19:07:59 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2017-12-30 16:36:54 -08:00
|
|
|
for (i = 0; !joypad_is_end_of_list(&joyconn[i]); i ++)
|
2017-12-28 13:01:38 -08:00
|
|
|
pad_connection_pad_deinit(&joyconn[i], i);
|
2016-02-04 17:01:03 -05:00
|
|
|
|
|
|
|
free(joyconn);
|
2014-10-04 19:07:59 +02:00
|
|
|
}
|
|
|
|
|
2015-04-04 23:44:02 +02:00
|
|
|
bool pad_connection_rumble(joypad_connection_t *joyconn,
|
2014-10-06 01:49:00 +02:00
|
|
|
unsigned pad, enum retro_rumble_effect effect, uint16_t strength)
|
2014-10-04 19:07:59 +02:00
|
|
|
{
|
2015-04-04 23:44:02 +02:00
|
|
|
if (!joyconn->connected)
|
2015-01-19 05:01:31 +01:00
|
|
|
return false;
|
2016-01-14 09:51:17 +01:00
|
|
|
if (!joyconn->iface || !joyconn->iface->set_rumble)
|
2015-01-19 05:05:41 +01:00
|
|
|
return false;
|
2015-01-19 05:01:31 +01:00
|
|
|
|
2021-08-06 22:02:43 -05:00
|
|
|
joyconn->iface->set_rumble(joyconn->connection, effect, strength);
|
2015-01-19 05:01:31 +01:00
|
|
|
return true;
|
2014-10-04 19:07:59 +02:00
|
|
|
}
|
2016-02-04 17:01:03 -05:00
|
|
|
|
2021-10-09 16:19:54 +02:00
|
|
|
const char* pad_connection_get_name(joypad_connection_t *joyconn,
|
|
|
|
unsigned pad)
|
2016-02-04 17:01:03 -05:00
|
|
|
{
|
2017-12-31 07:15:18 +01:00
|
|
|
if (!joyconn || !joyconn->iface || !joyconn->iface->get_name)
|
2016-02-04 17:01:03 -05:00
|
|
|
return NULL;
|
2021-08-06 22:02:43 -05:00
|
|
|
return joyconn->iface->get_name(joyconn->connection);
|
2016-02-04 17:01:03 -05:00
|
|
|
}
|