Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions skprx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

struct gamepad_report_t {
uint8_t report_id;
uint16_t buttons;
uint32_t buttons;
int8_t left_x;
int8_t left_y;
int8_t right_x;
Expand All @@ -33,6 +33,7 @@ static SceUID usb_thread_id;
static SceUID usb_event_flag_id;
static int vitastick_driver_registered = 0;
static int vitastick_driver_activated = 0;
uint8_t l2, r2, l3, r3;

static int send_hid_report_desc(void)
{
Expand Down Expand Up @@ -133,10 +134,10 @@ static void fill_gamepad_report(const SceCtrlData *pad, struct gamepad_report_t
if (pad->buttons & SCE_CTRL_START)
gamepad->buttons |= 1 << 9;

if (pad->buttons & SCE_CTRL_L3)
gamepad->buttons |= 1 << 10;
if (pad->buttons & SCE_CTRL_R3)
gamepad->buttons |= 1 << 11;
//if (pad->buttons & SCE_CTRL_L3)
// gamepad->buttons |= 1 << 10;
//if (pad->buttons & SCE_CTRL_R3)
// gamepad->buttons |= 1 << 11;

if (pad->buttons & SCE_CTRL_UP)
gamepad->buttons |= 1 << 12;
Expand All @@ -146,6 +147,14 @@ static void fill_gamepad_report(const SceCtrlData *pad, struct gamepad_report_t
gamepad->buttons |= 1 << 14;
if (pad->buttons & SCE_CTRL_LEFT)
gamepad->buttons |= 1 << 15;
if (l2)
gamepad->buttons |= 1 << 16;
if (r2)
gamepad->buttons |= 1 << 17;
if (l3)
gamepad->buttons |= 1 << 10;
if (r3)
gamepad->buttons |= 1 << 11;

gamepad->left_x = (int8_t)pad->lx - 128;
gamepad->left_y = (int8_t)pad->ly - 128;
Expand Down Expand Up @@ -539,3 +548,19 @@ int module_stop(SceSize argc, const void *args)

return SCE_KERNEL_STOP_SUCCESS;
}

int upload_trigger_state(uint8_t triggers)
{
unsigned long state;
int ret;

ENTER_SYSCALL(state);

l2 = triggers & (1 << 0);
r2 = triggers & (1 << 1);
l3 = triggers & (1 << 2);
r3 = triggers & (1 << 3);

EXIT_SYSCALL(state);
return 0;
}
1 change: 1 addition & 0 deletions skprx/uapi/vitastick_uapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern "C" {

int vitastick_start(void);
int vitastick_stop(void);
int upload_trigger_state(uint8_t triggers);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions skprx/usb_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ unsigned char hid_report_descriptor[] __attribute__ ((aligned(64))) = {
0x85, 0x01, // Report ID (1)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (0x01)
0x29, 0x10, // Usage Maximum (0x10)
0x29, 0x12, // Usage Maximum (0x12)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x95, 0x10, // Report Count (16)
0x95, 0x20, // Report Count (32)
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
Expand Down
1 change: 1 addition & 0 deletions skprx/vitastick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ vitastick:
functions:
- vitastick_start
- vitastick_stop
- upload_trigger_state
1 change: 1 addition & 0 deletions vpk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ target_link_libraries(${SHORT_NAME}
SceDisplay_stub
SceCtrl_stub
ScePower_stub
SceTouch_stub
)

vita_create_self(${SHORT_NAME}.self ${SHORT_NAME})
Expand Down
28 changes: 28 additions & 0 deletions vpk/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <psp2/ctrl.h>
#include <psp2/power.h>
#include <psp2/touch.h>
#include "vitastick_uapi.h"
#include "debugScreen.h"

Expand Down Expand Up @@ -49,8 +50,35 @@ void wait_key_press(const char *key_desc, unsigned int key_mask)
SceCtrlData pad;

printf("Press %s to exit.\n", key_desc);
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, 1);
sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, 1);
sceTouchEnableTouchForce(SCE_TOUCH_PORT_FRONT);
sceTouchEnableTouchForce(SCE_TOUCH_PORT_BACK);

SceTouchData touch_old[SCE_TOUCH_PORT_MAX_NUM];
SceTouchData touch[SCE_TOUCH_PORT_MAX_NUM];

while (1) {
memcpy(touch_old, touch, sizeof(touch_old));
int i;
uint8_t triggers = 0;

/* sample both back and front surfaces */
sceTouchPeek(SCE_TOUCH_PORT_BACK, &touch[SCE_TOUCH_PORT_BACK], 1);

/* print every touch coordinates on that surface */
for (i = 0; i < touch[SCE_TOUCH_PORT_BACK].reportNum; i++) {
if (touch[SCE_TOUCH_PORT_BACK].report[i].x < 800 && touch[SCE_TOUCH_PORT_BACK].report[i].y > 400)
triggers |= (1 << 0);
if (touch[SCE_TOUCH_PORT_BACK].report[i].x > 800 && touch[SCE_TOUCH_PORT_BACK].report[i].y > 400)
triggers |= (1 << 1);
if (touch[SCE_TOUCH_PORT_BACK].report[i].x > 800 && touch[SCE_TOUCH_PORT_BACK].report[i].y < 400)
triggers |= (1 << 2);
if (touch[SCE_TOUCH_PORT_BACK].report[i].x < 800 && touch[SCE_TOUCH_PORT_BACK].report[i].y < 400)
triggers |= (1 << 3);
}

upload_trigger_state(triggers);
sceCtrlReadBufferPositive(0, &pad, 1);
if ((pad.buttons & key_mask) == key_mask)
break;
Expand Down