Skip to content

Commit 9c9f5aa

Browse files
authored
Touchscreen support for PS Vita (#18165)
1 parent 887effc commit 9c9f5aa

4 files changed

Lines changed: 95 additions & 5 deletions

File tree

config.def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
#define DEFAULT_TOUCH_SCALE 1
8686

87-
#if defined(RARCH_MOBILE) || defined(HAVE_LIBNX) || defined(__WINRT__) || defined(EMSCRIPTEN)
87+
#if defined(RARCH_MOBILE) || defined(HAVE_LIBNX) || defined(__WINRT__) || defined(EMSCRIPTEN) || defined (VITA)
8888
#define DEFAULT_POINTER_ENABLE true
8989
#else
9090
#define DEFAULT_POINTER_ENABLE false

gfx/drivers/vita2d_gfx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,9 @@ static void vita2d_set_viewport_wrapper(void *data, unsigned vp_width,
10421042
vita->vp.height = vp_height;
10431043
}
10441044

1045+
vita->vp.full_width = vita->vp.width;
1046+
vita->vp.full_height = vita->vp.height;
1047+
10451048
vita2d_set_viewport(vita->vp.x, vita->vp.y, vita->vp.width, vita->vp.height);
10461049
vita2d_set_projection(vita, &ortho, allow_rotate);
10471050

input/drivers/psp_input.c

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030
#include <psp2/kernel/processmgr.h>
3131
#include <psp2/hid.h>
3232
#include <psp2/motion.h>
33+
#include <psp2/touch.h>
3334
#define VITA_NUM_SCANCODES 115 /* size of rarch_key_map_vita */
3435
#define VITA_MAX_SCANCODE 0xE7
3536
#define VITA_NUM_MODIFIERS 11 /* number of modifiers reported */
3637
#define MOUSE_MAX_X 960
3738
#define MOUSE_MAX_Y 544
39+
/* Update to SCE_TOUCH_PORT_MAX_NUM to enable back touch polling */
40+
#define VITA_MAX_TOUCH SCE_TOUCH_PORT_FRONT+1
3841
#elif defined(PSP)
3942
#include <pspctrl.h>
4043
#endif
@@ -46,6 +49,8 @@
4649
#include <defines/psp_defines.h>
4750

4851
#include "../input_driver.h"
52+
#include "../../retroarch.h"
53+
#include "../../verbosity.h"
4954

5055
/* TODO/FIXME -
5156
* fix game focus toggle */
@@ -77,6 +82,10 @@ typedef struct psp_input
7782
int32_t mouse_x_delta;
7883
int32_t mouse_y_delta;
7984
uint8_t prev_keys[6];
85+
#ifdef VITA
86+
SceTouchData touch[SCE_TOUCH_PORT_MAX_NUM];
87+
SceTouchPanelInfo panelInfo[SCE_TOUCH_PORT_MAX_NUM];
88+
#endif
8089
bool keyboard_state[VITA_MAX_SCANCODE + 1];
8190
bool mouse_button_left;
8291
bool mouse_button_right;
@@ -88,6 +97,7 @@ static void vita_input_poll(void *data)
8897
{
8998
psp_input_t *psp = (psp_input_t*)data;
9099
unsigned int i = 0;
100+
int port = 0;
91101
int key_sym = 0;
92102
unsigned key_code = 0;
93103
uint8_t mod_code = 0;
@@ -226,6 +236,10 @@ static void vita_input_poll(void *data)
226236
psp->mouse_y = 0;
227237
else if (psp->mouse_y > MOUSE_MAX_Y)
228238
psp->mouse_y = MOUSE_MAX_Y;
239+
240+
for(port = 0; port < VITA_MAX_TOUCH; port++){
241+
sceTouchPeek(port, &psp->touch[port], 1);
242+
}
229243
}
230244

231245
static int16_t vita_input_state(
@@ -283,6 +297,56 @@ static int16_t vita_input_state(
283297
return val;
284298
}
285299
break;
300+
301+
case RETRO_DEVICE_POINTER:
302+
case RARCH_DEVICE_POINTER_SCREEN:
303+
{
304+
/* Same pointer state is reported for all ports. */
305+
if (idx < SCE_TOUCH_MAX_REPORT)
306+
{
307+
struct video_viewport vp = {0};
308+
bool screen =
309+
(device == RARCH_DEVICE_POINTER_SCREEN);
310+
int16_t res_x = 0;
311+
int16_t res_y = 0;
312+
int16_t res_screen_x = 0;
313+
int16_t res_screen_y = 0;
314+
float tmp_x, tmp_y;
315+
316+
video_driver_get_viewport_info(&vp);
317+
tmp_x = (psp->touch[0].report[idx].x - psp->panelInfo[0].minAaX) * vp.width/(psp->panelInfo[0].maxAaX - psp->panelInfo[0].minAaX);
318+
tmp_y = (psp->touch[0].report[idx].y - psp->panelInfo[0].minAaY) * vp.height/(psp->panelInfo[0].maxAaY - psp->panelInfo[0].minAaY);
319+
320+
if (video_driver_translate_coord_viewport_confined_wrap(
321+
&vp,
322+
(int)tmp_x,
323+
(int)tmp_y,
324+
&res_x, &res_y, &res_screen_x, &res_screen_y))
325+
{
326+
if (screen)
327+
{
328+
res_x = res_screen_x;
329+
res_y = res_screen_y;
330+
}
331+
332+
switch (id)
333+
{
334+
case RETRO_DEVICE_ID_POINTER_X:
335+
return res_x;
336+
case RETRO_DEVICE_ID_POINTER_Y:
337+
return res_y;
338+
case RETRO_DEVICE_ID_POINTER_PRESSED:
339+
return (idx < psp->touch[0].reportNum);
340+
case RETRO_DEVICE_ID_POINTER_IS_OFFSCREEN:
341+
return input_driver_pointer_is_offscreen(res_x, res_y);
342+
case RETRO_DEVICE_ID_POINTER_COUNT:
343+
return psp->touch[0].reportNum;
344+
}
345+
}
346+
}
347+
}
348+
break;
349+
286350
#endif
287351
}
288352

@@ -302,12 +366,13 @@ static void psp_input_free_input(void *data)
302366

303367
static uint64_t psp_input_get_capabilities(void *data)
304368
{
305-
return
369+
return
306370
#ifdef VITA
307-
(1 << RETRO_DEVICE_KEYBOARD)
308-
| (1 << RETRO_DEVICE_MOUSE) |
371+
(1 << RETRO_DEVICE_KEYBOARD)
372+
| (1 << RETRO_DEVICE_MOUSE)
373+
| (1 << RETRO_DEVICE_POINTER) |
309374
#endif
310-
(1 << RETRO_DEVICE_JOYPAD)
375+
(1 << RETRO_DEVICE_JOYPAD)
311376
| (1 << RETRO_DEVICE_ANALOG);
312377
}
313378

@@ -403,6 +468,24 @@ static void *vita_input_initialize(const char *joypad_driver)
403468
psp->mouse_x = 0;
404469
psp->mouse_y = 0;
405470

471+
for(i = 0; i < SCE_TOUCH_PORT_MAX_NUM; i++){
472+
if (i < VITA_MAX_TOUCH)
473+
sceTouchSetSamplingState(i, 1);
474+
else
475+
sceTouchSetSamplingState(i, 0);
476+
sceTouchDisableTouchForce(i);
477+
/*sceTouchEnableTouchForce(i);*/
478+
sceTouchGetPanelInfo(i, &psp->panelInfo[i]);
479+
RARCH_DBG("[vita]: touch panel %d info, active x min/max %d/%d \n",
480+
i, psp->panelInfo[i].minAaX, psp->panelInfo[i].maxAaX);
481+
RARCH_DBG("[vita]: touch panel %d info, active y min/max %d/%d \n",
482+
i, psp->panelInfo[i].minAaY, psp->panelInfo[i].maxAaY);
483+
RARCH_DBG("[vita]: touch panel %d info, display x min/max %d/%d \n",
484+
i, psp->panelInfo[i].minDispX, psp->panelInfo[i].maxDispX);
485+
RARCH_DBG("[vita]: touch panel %d info, display y min/max %d/%d \n",
486+
i, psp->panelInfo[i].minDispY, psp->panelInfo[i].maxDispY);
487+
}
488+
406489
return psp;
407490
}
408491
#else

menu/menu_driver.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,11 @@ static float menu_input_get_dpi(
11541154
mets.type = DISPLAY_METRIC_DPI;
11551155
mets.value = &dpi;
11561156
if (!video_context_driver_get_metrics(&mets))
1157+
#ifdef VITA
1158+
dpi = 220.0f;
1159+
#else
11571160
dpi = 0.0f;
1161+
#endif
11581162

11591163
dpi_cached = true;
11601164
last_video_width = video_width;

0 commit comments

Comments
 (0)