Skip to content

Commit

Permalink
Merge pull request libretro#5997 from libretro/new_hid
Browse files Browse the repository at this point in the history
New HID system (courtesy of gblues)
  • Loading branch information
inactive123 authored Dec 30, 2017
2 parents 7e61f08 + ec45df7 commit 0389bc6
Show file tree
Hide file tree
Showing 67 changed files with 1,839 additions and 7,871 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ wiiu/wut/elf2rpl/elf2rpl
/.lst
*.3dsx
*.smdh
/pkg/wiiu/retroarch
/pkg/wiiu/wiiu
/pkg/wiiu/rpx

# Ctags
/tags
Expand Down Expand Up @@ -117,6 +120,5 @@ obj-unix/
/pkg/msvc/msvc-2010/Release Cg/*.obj
/pkg/msvc/msvc-2010/Release Cg/*.res
/pkg/msvc/msvc-2010/Release Cg/*.pdb

retroarch.cfg
Makefile.local
12 changes: 9 additions & 3 deletions Makefile.wiiu
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
TARGET := retroarch_wiiu
BUILD_HBL_ELF = 1
BUILD_RPX = 1
BUILD_RPX = 1
DEBUG = 0
GRIFFIN_BUILD = 0
WHOLE_ARCHIVE_LINK = 0
HAVE_HID = 1

ifneq ($(V), 1)
Q := @
endif

PC_DEVELOPMENT_IP_ADDRESS ?=
PC_DEVELOPMENT_TCP_PORT ?=
PC_DEVELOPMENT_IP_ADDRESS ?=192.168.29.137
PC_DEVELOPMENT_TCP_PORT ?=4405

OBJ :=
OBJ += wiiu/input/wiiu_hid.o
OBJ += wiiu/input/wpad_driver.o
OBJ += wiiu/input/kpad_driver.o
OBJ += wiiu/input/hidpad_driver.o
OBJ += wiiu/input/pad_functions.o
OBJ += wiiu/system/memory.o
OBJ += wiiu/system/exception_handler.o
OBJ += wiiu/system/missing_libc_functions.o
Expand Down
14 changes: 1 addition & 13 deletions frontend/drivers/platform_wiiu.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "system/memory.h"
#include "system/exception_handler.h"
#include <sys/iosupport.h>

#include <wiiu/syshid.h>
#include <wiiu/os/foreground.h>
#include <wiiu/gx2/event.h>
#include <wiiu/procui.h>
Expand All @@ -58,10 +58,6 @@
#include <wiiu/vpad.h>
#include <wiiu/kpad.h>

#if defined(ENABLE_CONTROLLER_PATCHER)
#include "wiiu/controller_patcher/ControllerPatcherWrapper.h"
#endif

#include <fat.h>
#include <iosuhax.h>
#include "wiiu_dbg.h"
Expand Down Expand Up @@ -432,9 +428,6 @@ int main(int argc, char **argv)
KPADInit();
#endif
verbosity_enable();
#if !defined(IS_SALAMANDER) && defined(ENABLE_CONTROLLER_PATCHER)
ControllerPatcherInit();
#endif
fflush(stdout);
DEBUG_VAR(ARGV_PTR);
if(ARGV_PTR && ((u32)ARGV_PTR < 0x01000000))
Expand Down Expand Up @@ -494,9 +487,6 @@ int main(int argc, char **argv)

}
while (1);
#if !defined(IS_SALAMANDER) && defined(ENABLE_CONTROLLER_PATCHER)
ControllerPatcherDeInit();
#endif
main_exit(NULL);
#endif
#endif
Expand Down Expand Up @@ -651,9 +641,7 @@ void _start(int argc, char **argv)
memoryInitialize();
__init();
fsdev_init();

main(argc, argv);

fsdev_exit();

/* TODO: fix elf2rpl so it doesn't error with "Could not find matching symbol
Expand Down
2 changes: 1 addition & 1 deletion input/connect/connect_nesusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct hidpad_nesusb_data
uint32_t buttons;
};

static void* hidpad_nesusb_init(void *data, uint32_t slot, send_control_t ptr)
static void* hidpad_nesusb_init(void *data, uint32_t slot, hid_driver_t *driver)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_nesusb_data* device = (struct hidpad_nesusb_data*)
Expand Down
2 changes: 1 addition & 1 deletion input/connect/connect_ps2adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct hidpad_ps2adapter_data
uint32_t buttons;
};

static void* hidpad_ps2adapter_init(void *data, uint32_t slot, send_control_t ptr)
static void* hidpad_ps2adapter_init(void *data, uint32_t slot, hid_driver_t *driver)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_ps2adapter_data* device = (struct hidpad_ps2adapter_data*)
Expand Down
47 changes: 38 additions & 9 deletions input/connect/connect_ps3.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,28 @@
#include "joypad_connection.h"
#include "../input_defines.h"

#ifdef WIIU
#include <wiiu/syshid.h>
#endif

struct hidpad_ps3_data
{
struct pad_connection* connection;
send_control_t send_control;
hid_driver_t *driver;
uint8_t data[512];
uint32_t slot;
uint32_t buttons;
bool have_led;
uint16_t motors[2];
};

/*
* TODO: give these more meaningful names.
*/

#define DS3_ACTIVATION_REPORT_ID 0xf4
#define DS3_RUMBLE_REPORT_ID 0x01

static void hidpad_ps3_send_control(struct hidpad_ps3_data* device)
{
/* TODO: Can this be modified to turn off motion tracking? */
Expand All @@ -49,20 +60,28 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// Turn on the appropriate LED
report_buffer[11] = 1 << ((device->slot % 4) + 1);
// Set rumble state
report_buffer[4] = device->motors[1] >> 8;
report_buffer[6] = device->motors[0] >> 8;
#ifdef HAVE_WIIUSB_HID
report_buffer[1] = 0x03; /* send control message type */
device->send_control(device->connection, &report_buffer[1], sizeof(report_buffer)-1);
device->driver->send_control(device->connection, &report_buffer[1], sizeof(report_buffer)-1);
#elif defined(WIIU)
device->driver->set_report(device->connection,
HID_REPORT_OUTPUT,
DS3_RUMBLE_REPORT_ID,
report_buffer+2,
sizeof(report_buffer) - (2*sizeof(uint8_t)));
#else
device->send_control(device->connection, report_buffer, sizeof(report_buffer));
device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer));
#endif
}

static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr)
static void* hidpad_ps3_init(void *data, uint32_t slot, hid_driver_t *driver)
{
#ifdef HAVE_WIIUSB_HID
#if defined(HAVE_WIIUSB_HID) || defined(WIIU)
/* Special command to enable Sixaxis, first byte defines the message type */
static uint8_t magic_data[] = {0x02, 0x42, 0x0c, 0x00, 0x00};
#elif defined(IOS)
Expand All @@ -82,12 +101,22 @@ static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr)
return NULL;
}

device->connection = connection;
device->slot = slot;
device->send_control = ptr;
device->connection = connection;
device->slot = slot;
device->driver = driver;

#if defined(IOS) || defined(HAVE_WIIUSB_HID)
device->send_control(device->connection, magic_data, sizeof(magic_data));
device->driver->send_control(device->connection, magic_data, sizeof(magic_data));
#endif

#ifdef WIIU
device->driver->set_protocol(device->connection, 1);
hidpad_ps3_send_control(device);
device->driver->set_report(device->connection,
HID_REPORT_FEATURE,
DS3_ACTIVATION_REPORT_ID,
magic_data+1,
(sizeof(magic_data) - sizeof(uint8_t)));
#endif

#ifndef HAVE_WIIUSB_HID
Expand Down
14 changes: 7 additions & 7 deletions input/connect/connect_ps4.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct ps4
struct hidpad_ps4_data
{
struct pad_connection* connection;
send_control_t send_control;
hid_driver_t *driver;
struct ps4 data;
uint32_t slot;
bool have_led;
Expand All @@ -119,11 +119,11 @@ static void hidpad_ps4_send_control(struct hidpad_ps4_data* device)
report_buffer[11] = rgb[(device->slot % 4)][2];
#endif

device->send_control(device->connection,
device->driver->send_control(device->connection,
report_buffer, sizeof(report_buffer));
}

static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr)
static void* hidpad_ps4_init(void *data, uint32_t slot, hid_driver_t *driver)
{
#if 0
uint8_t magic_data[0x25];
Expand All @@ -138,14 +138,14 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr)
if (!connection)
goto error;

device->connection = connection;
device->slot = slot;
device->send_control = ptr;
device->connection = connection;
device->slot = slot;
device->driver = driver;

#if 0
/* TODO - unsure of this */
/* This is needed to get full input packet over bluetooth. */
device->send_control(device->connection, magic_data, 0x2);
device->driver->send_control(device->connection, magic_data, 0x2);
(void)magic_data;
#endif

Expand Down
2 changes: 1 addition & 1 deletion input/connect/connect_psxadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct hidpad_psxadapter_data
uint32_t buttons;
};

static void* hidpad_psxadapter_init(void *data, uint32_t slot, send_control_t ptr)
static void* hidpad_psxadapter_init(void *data, uint32_t slot, hid_driver_t *driver)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_psxadapter_data* device = (struct hidpad_psxadapter_data*)
Expand Down
2 changes: 1 addition & 1 deletion input/connect/connect_snesusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct hidpad_snesusb_data
uint32_t buttons;
};

static void* hidpad_snesusb_init(void *data, uint32_t slot, send_control_t ptr)
static void* hidpad_snesusb_init(void *data, uint32_t slot, hid_driver_t *driver)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_snesusb_data* device = (struct hidpad_snesusb_data*)
Expand Down
16 changes: 8 additions & 8 deletions input/connect/connect_wii.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct connect_wii_wiimote_t
int unid;

struct pad_connection* connection;
send_control_t send_control;
hid_driver_t *driver;

/* Various state flags. */
uint32_t state;
Expand Down Expand Up @@ -195,7 +195,7 @@ static int wiimote_send(struct connect_wii_wiimote_t* wm,
printf("\n");
#endif

wm->send_control(wm->connection, buf, len + 2);
wm->driver->send_control(wm->connection, buf, len + 2);
return 1;
}

Expand Down Expand Up @@ -616,7 +616,7 @@ static void hidpad_wii_deinit(void *data)
}

static void* hidpad_wii_init(void *data, uint32_t slot,
send_control_t ptr)
hid_driver_t *driver)
{
struct pad_connection *connection = (struct pad_connection*)data;
struct connect_wii_wiimote_t *device = (struct connect_wii_wiimote_t*)
Expand All @@ -628,11 +628,11 @@ static void* hidpad_wii_init(void *data, uint32_t slot,
if (!connection)
goto error;

device->connection = connection;
device->unid = slot;
device->state = WIIMOTE_STATE_CONNECTED;
device->exp.type = EXP_NONE;
device->send_control = ptr;
device->connection = connection;
device->unid = slot;
device->state = WIIMOTE_STATE_CONNECTED;
device->exp.type = EXP_NONE;
device->driver = driver;

wiimote_handshake(device, -1, NULL, -1);

Expand Down
43 changes: 24 additions & 19 deletions input/connect/connect_wiiugca.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@
struct hidpad_wiiugca_data
{
struct pad_connection* connection;
send_control_t send_control;
hid_driver_t *driver;
uint8_t data[64];
uint32_t slot;
uint32_t buttons;
};

static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr)
static void* hidpad_wiiugca_init(void *data, uint32_t slot, hid_driver_t *driver)
{
#ifdef WIIU
static uint8_t magic_data[] = {0x13}; /* Special command to enable reading */
#else
static uint8_t magic_data[] = {0x01, 0x13}; /* Special command to enable reading */
#endif
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_wiiugca_data* device = (struct hidpad_wiiugca_data*)
calloc(1, sizeof(struct hidpad_wiiugca_data));
Expand All @@ -47,10 +51,11 @@ static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr)
return NULL;
}

device->connection = connection;
device->slot = slot;
device->send_control = ptr;
device->send_control(device->connection, magic_data, sizeof(magic_data));
device->connection = connection;
device->slot = slot;
device->driver = driver;

device->driver->send_control(device->connection, magic_data, sizeof(magic_data));

return device;
}
Expand All @@ -65,13 +70,13 @@ static void hidpad_wiiugca_deinit(void *data)

static void hidpad_wiiugca_get_buttons(void *data, retro_bits_t *state)
{
struct hidpad_wiiugca_data *device = (struct hidpad_wiiugca_data*)data;
if (device)
{
BITS_COPY16_PTR(state, device->buttons);
}
else
BIT256_CLEAR_ALL_PTR(state);
struct hidpad_wiiugca_data *device = (struct hidpad_wiiugca_data*)data;
if (device)
{
BITS_COPY16_PTR(state, device->buttons);
}
else
BIT256_CLEAR_ALL_PTR(state);
}

static int16_t hidpad_wiiugca_get_axis(void *data, unsigned axis)
Expand Down Expand Up @@ -129,16 +134,16 @@ static void hidpad_wiiugca_packet_handler(void *data, uint8_t *packet, uint16_t
static void hidpad_wiiugca_set_rumble(void *data,
enum retro_rumble_effect effect, uint16_t strength)
{
(void)data;
(void)effect;
(void)strength;
(void)data;
(void)effect;
(void)strength;
}

const char * hidpad_wiiugca_get_name(void *data)
{
(void)data;
/* For now we return a single static name */
return "Wii U GC Controller Adapter";
(void)data;
/* For now we return a single static name */
return "Wii U GC Controller Adapter";
}

pad_connection_interface_t pad_connection_wiiugca = {
Expand Down
Loading

0 comments on commit 0389bc6

Please sign in to comment.