mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
(Vita) Autodetect connection of controllers on PSTV
This commit is contained in:
parent
a2d9ca3e47
commit
90678dd3de
@ -20,7 +20,12 @@
|
||||
|
||||
#include "../../configuration.h"
|
||||
|
||||
#if defined(SN_TARGET_PSP2) || defined(VITA)
|
||||
#if defined(VITA)
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
#define PSP_MAX_PADS 4
|
||||
static int psp2_model;
|
||||
static SceCtrlPortInfo old_ctrl_info, curr_ctrl_info;
|
||||
#elif defined(SN_TARGET_PSP2)
|
||||
#define PSP_MAX_PADS 4
|
||||
#else
|
||||
#define PSP_MAX_PADS 1
|
||||
@ -33,7 +38,17 @@ extern uint64_t lifecycle_state;
|
||||
static const char *psp_joypad_name(unsigned pad)
|
||||
{
|
||||
#ifdef VITA
|
||||
return "Vita Controller";
|
||||
if (psp2_model != SCE_KERNEL_MODEL_VITATV)
|
||||
return "Vita Controller";
|
||||
|
||||
switch (curr_ctrl_info.port[pad + 1]) {
|
||||
case SCE_CTRL_TYPE_DS3:
|
||||
return "DS3 Controller";
|
||||
case SCE_CTRL_TYPE_DS4:
|
||||
return "DS4 Controller";
|
||||
default:
|
||||
return "Unpaired";
|
||||
}
|
||||
#else
|
||||
return "PSP Controller";
|
||||
#endif
|
||||
@ -62,6 +77,14 @@ static bool psp_joypad_init(void *data)
|
||||
|
||||
(void)data;
|
||||
|
||||
#if defined(VITA)
|
||||
psp2_model = sceKernelGetModelForCDialog();
|
||||
if (psp2_model != SCE_KERNEL_MODEL_VITATV)
|
||||
players_count = 1;
|
||||
sceCtrlGetControllerPortInfo(&curr_ctrl_info);
|
||||
memcpy(&old_ctrl_info, &curr_ctrl_info, sizeof(SceCtrlPortInfo));
|
||||
#endif
|
||||
|
||||
for (i = 0; i < players_count; i++)
|
||||
psp_joypad_autodetect_add(i);
|
||||
|
||||
@ -134,6 +157,27 @@ static void psp_joypad_poll(void)
|
||||
sceCtrlSetSamplingCycle(0);
|
||||
#endif
|
||||
|
||||
#ifdef VITA
|
||||
if (psp2_model != SCE_KERNEL_MODEL_VITATV) {
|
||||
players_count = 1;
|
||||
} else {
|
||||
sceCtrlGetControllerPortInfo(&curr_ctrl_info);
|
||||
for (player = 0; player < players_count; player++) {
|
||||
if (old_ctrl_info.port[player + 1] == curr_ctrl_info.port[player + 1])
|
||||
continue;
|
||||
|
||||
if (old_ctrl_info.port[player + 1] != SCE_CTRL_TYPE_UNPAIRED &&
|
||||
curr_ctrl_info.port[player + 1] == SCE_CTRL_TYPE_UNPAIRED)
|
||||
input_config_autoconfigure_disconnect(player, psp_joypad.ident);
|
||||
|
||||
if (old_ctrl_info.port[player + 1] == SCE_CTRL_TYPE_UNPAIRED &&
|
||||
curr_ctrl_info.port[player + 1] != SCE_CTRL_TYPE_UNPAIRED)
|
||||
psp_joypad_autodetect_add(player);
|
||||
}
|
||||
memcpy(&old_ctrl_info, &curr_ctrl_info, sizeof(SceCtrlPortInfo));
|
||||
}
|
||||
#endif
|
||||
|
||||
CtrlSetSamplingMode(DEFAULT_SAMPLING_MODE);
|
||||
|
||||
BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE);
|
||||
@ -143,12 +187,21 @@ static void psp_joypad_poll(void)
|
||||
unsigned j, k;
|
||||
SceCtrlData state_tmp;
|
||||
unsigned i = player;
|
||||
#if defined(VITA)
|
||||
unsigned p = (psp2_model == SCE_KERNEL_MODEL_VITATV) ? player + 1 : player;
|
||||
if (curr_ctrl_info.port[p] == SCE_CTRL_TYPE_UNPAIRED) {
|
||||
continue;
|
||||
}
|
||||
#elif defined(SN_TARGET_PSP2)
|
||||
/* Dumb hack, but here's the explanation -
|
||||
* sceCtrlPeekBufferPositive's port parameter
|
||||
* can be 0 or 1 to read the first controller on
|
||||
* a PSTV, but HAS to be 0 for a real VITA and 2
|
||||
* for the 2nd controller on a PSTV */
|
||||
unsigned p = (player > 0) ? player+1 : player;
|
||||
#else
|
||||
unsigned p = player;
|
||||
#endif
|
||||
int32_t ret = CtrlPeekBufferPositive(p, &state_tmp, 1);
|
||||
|
||||
pad_state[i] = 0;
|
||||
|
@ -273,6 +273,8 @@ const char* const input_builtin_autoconfs[] =
|
||||
#endif
|
||||
#if defined(VITA) || defined(SN_TARGET_PSP2)
|
||||
DECL_AUTOCONF_DEVICE("Vita Controller", "vita", PSPINPUT_DEFAULT_BINDS),
|
||||
DECL_AUTOCONF_DEVICE("DS3 Controller", "vita", PSPINPUT_DEFAULT_BINDS),
|
||||
DECL_AUTOCONF_DEVICE("DS4 Controller", "vita", PSPINPUT_DEFAULT_BINDS),
|
||||
#elif defined(PSP)
|
||||
DECL_AUTOCONF_DEVICE("PSP Controller", "psp", PSPINPUT_DEFAULT_BINDS),
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user