Move HID driver into wiiu/ code
== DETAILS RetroArch's general HID drivers are intended as a full-on substitute for other input drivers such as XInput, DInput, SDL, etc. The Wii U port is, to my knowledge, the first case of heterogenous input drivers working concurrently. As such, I've moved things around: - The HID driver source is moved into the wiiu/input/ directory alongside the joypad subdrivers. - We no longer use the input_hid_init_first() method to instantiate; instead we just init the wiiu HID driver directly. - The HID pad driver and HID subsystem driver enjoy a tighter coupling, mainly having to do with the initialization of the joypad connections list, because there's no way to inform the HID driver's init() method how many slots to allocate. == TESTING Will test in a moment, but at least it compiles cleanly. ;)
This commit is contained in:
parent
704cc61fd8
commit
65c177a0ee
|
@ -14,7 +14,7 @@ PC_DEVELOPMENT_IP_ADDRESS ?=192.168.29.137
|
|||
PC_DEVELOPMENT_TCP_PORT ?=4405
|
||||
|
||||
OBJ :=
|
||||
OBJ += input/drivers_hid/wiiu_hid.o
|
||||
OBJ += wiiu/input/wiiu_hid.o
|
||||
OBJ += wiiu/input/wpad_driver.o
|
||||
OBJ += wiiu/input/kpad_driver.o
|
||||
OBJ += wiiu/input/hidpad_driver.o
|
||||
|
|
|
@ -199,9 +199,6 @@ static hid_driver_t *hid_drivers[] = {
|
|||
#endif
|
||||
#ifdef HW_RVL
|
||||
&wiiusb_hid,
|
||||
#endif
|
||||
#ifdef WIIU
|
||||
&wiiu_hid,
|
||||
#endif
|
||||
&null_hid,
|
||||
NULL,
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
#include "../../config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <wiiu/os.h>
|
||||
#include <wiiu/syshid.h>
|
||||
#include <wiiu/vpad.h>
|
||||
#include <wiiu/kpad.h>
|
||||
#include <string.h>
|
||||
|
@ -106,10 +111,71 @@ struct _wiiu_pad_functions {
|
|||
void (*connect)(unsigned pad, input_device_driver_t *driver);
|
||||
};
|
||||
|
||||
/**
|
||||
* HID driver data structures
|
||||
*/
|
||||
|
||||
typedef struct wiiu_hid {
|
||||
// used to register for HID notifications
|
||||
HIDClient *client;
|
||||
// list of HID pads
|
||||
joypad_connection_t *connections;
|
||||
// size of connections list
|
||||
unsigned connections_size;
|
||||
// thread state data for HID polling thread
|
||||
OSThread *polling_thread;
|
||||
// stack space for polling thread
|
||||
void *polling_thread_stack;
|
||||
// watch variable to tell the polling thread to terminate
|
||||
volatile bool polling_thread_quit;
|
||||
} wiiu_hid_t;
|
||||
|
||||
typedef struct wiiu_adapter wiiu_adapter_t;
|
||||
|
||||
struct wiiu_adapter {
|
||||
wiiu_adapter_t *next;
|
||||
wiiu_hid_t *hid;
|
||||
uint8_t state;
|
||||
uint8_t *rx_buffer;
|
||||
int32_t rx_size;
|
||||
int32_t slot;
|
||||
uint32_t handle;
|
||||
uint8_t interface_index;
|
||||
};
|
||||
|
||||
typedef struct wiiu_attach wiiu_attach_event;
|
||||
|
||||
struct wiiu_attach {
|
||||
wiiu_attach_event *next;
|
||||
uint32_t type;
|
||||
uint32_t handle;
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
uint8_t interface_index;
|
||||
uint8_t is_keyboard;
|
||||
uint8_t is_mouse;
|
||||
uint16_t max_packet_size_rx;
|
||||
uint16_t max_packet_size_tx;
|
||||
};
|
||||
|
||||
typedef struct _wiiu_event_list wiiu_event_list;
|
||||
typedef struct _wiiu_adapter_list wiiu_adapter_list;
|
||||
|
||||
struct _wiiu_event_list {
|
||||
OSFastMutex lock;
|
||||
wiiu_attach_event *list;
|
||||
};
|
||||
|
||||
struct _wiiu_adapter_list {
|
||||
OSFastMutex lock;
|
||||
wiiu_adapter_t *list;
|
||||
};
|
||||
|
||||
extern wiiu_pad_functions_t pad_functions;
|
||||
extern input_device_driver_t wiiu_joypad;
|
||||
extern input_device_driver_t wpad_driver;
|
||||
extern input_device_driver_t kpad_driver;
|
||||
extern input_device_driver_t hidpad_driver;
|
||||
extern hid_driver_t wiiu_hid;
|
||||
|
||||
#endif // __PAD_DRIVER__H
|
||||
|
|
|
@ -27,15 +27,51 @@ static const char *hidpad_name(unsigned pad);
|
|||
|
||||
static bool ready = false;
|
||||
|
||||
// if the GameCube adapter is attached, this will be the offset
|
||||
// of the first pad.
|
||||
static unsigned gca_pad = 0;
|
||||
static joypad_connection_t *hid_pads;
|
||||
static wiiu_hid_t *hid_data;
|
||||
static hid_driver_t *hid_driver;
|
||||
|
||||
static unsigned to_slot(unsigned pad) {
|
||||
return pad - (WIIU_WIIMOTE_CHANNELS+1);
|
||||
}
|
||||
|
||||
const void *get_hid_data(void) {
|
||||
return hid_data;
|
||||
}
|
||||
|
||||
static hid_driver_t *init_hid_driver(void)
|
||||
{
|
||||
unsigned connections_size = MAX_USERS - (WIIU_WIIMOTE_CHANNELS+1);
|
||||
hid_data = (wiiu_hid_t *)wiiu_hid.init();
|
||||
joypad_connection_t *connections = pad_connection_init(connections_size);
|
||||
|
||||
if(!hid_data || !connections)
|
||||
goto error;
|
||||
|
||||
hid_data->connections = connections;
|
||||
hid_data->connections_size = connections_size;
|
||||
return &wiiu_hid;
|
||||
|
||||
error:
|
||||
if(connections)
|
||||
free(connections);
|
||||
if(hid_data)
|
||||
{
|
||||
wiiu_hid.free(hid_data);
|
||||
free(hid_data);
|
||||
hid_data = NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool hidpad_init(void *data)
|
||||
{
|
||||
(void *)data;
|
||||
hid_pads = pad_connection_init(MAX_USERS-(WIIU_WIIMOTE_CHANNELS+1));
|
||||
hid_driver = init_hid_driver();
|
||||
if(!hid_driver)
|
||||
{
|
||||
RARCH_ERR("Failed to initialize HID driver.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
hidpad_poll();
|
||||
ready = true;
|
||||
|
@ -45,43 +81,57 @@ static bool hidpad_init(void *data)
|
|||
|
||||
static bool hidpad_query_pad(unsigned pad)
|
||||
{
|
||||
return (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS);
|
||||
return ready && (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS);
|
||||
}
|
||||
|
||||
static void hidpad_destroy(void)
|
||||
{
|
||||
ready = false;
|
||||
if(hid_pads) {
|
||||
pad_connection_destroy(hid_pads);
|
||||
hid_pads = NULL;
|
||||
|
||||
if(hid_driver)
|
||||
{
|
||||
hid_driver->free(get_hid_data());
|
||||
free(hid_data);
|
||||
hid_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool hidpad_button(unsigned pad, uint16_t button)
|
||||
{
|
||||
return false;
|
||||
if(!hidpad_query_pad(pad))
|
||||
return false;
|
||||
|
||||
return hid_driver->button(hid_data, to_slot(pad), button);
|
||||
}
|
||||
|
||||
static void hidpad_get_buttons(unsigned pad, retro_bits_t *state)
|
||||
{
|
||||
BIT256_CLEAR_ALL_PTR(state);
|
||||
if(!hidpad_query_pad(pad))
|
||||
BIT256_CLEAR_ALL_PTR(state);
|
||||
|
||||
hid_driver->get_buttons(hid_data, to_slot(pad), state);
|
||||
}
|
||||
|
||||
static int16_t hidpad_axis(unsigned pad, uint32_t axis)
|
||||
{
|
||||
return 0;
|
||||
if(!hidpad_query_pad(pad));
|
||||
return 0;
|
||||
|
||||
return hid_driver->axis(hid_data, to_slot(pad), axis);
|
||||
}
|
||||
|
||||
static void hidpad_poll(void)
|
||||
{
|
||||
if(ready)
|
||||
hid_driver->poll(hid_data);
|
||||
}
|
||||
|
||||
static const char *hidpad_name(unsigned pad)
|
||||
{
|
||||
if(!hidpad_query_pad(pad))
|
||||
return "n/a";
|
||||
return "N/A";
|
||||
|
||||
return PAD_NAME_HID;
|
||||
return hid_driver->name(hid_data, to_slot(pad));
|
||||
}
|
||||
|
||||
input_device_driver_t hidpad_driver =
|
||||
|
|
|
@ -14,29 +14,28 @@
|
|||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <wiiu/os.h>
|
||||
#include <wiiu/syshid.h>
|
||||
#include <retro_endianness.h>
|
||||
|
||||
#include "wiiu_hid.h"
|
||||
|
||||
static wiiu_event_list events;
|
||||
static wiiu_adapter_list adapters;
|
||||
|
||||
static bool wiiu_hid_joypad_query(void *data, unsigned pad)
|
||||
static bool wiiu_hid_joypad_query(void *data, unsigned slot)
|
||||
{
|
||||
return pad < MAX_USERS;
|
||||
wiiu_hid_t *hid = (wiiu_hid_t *)data;
|
||||
if(!hid)
|
||||
return false;
|
||||
|
||||
return slot < hid->connections_size;
|
||||
}
|
||||
|
||||
static const char *wiiu_hid_joypad_name(void *data, unsigned pad)
|
||||
static const char *wiiu_hid_joypad_name(void *data, unsigned slot)
|
||||
{
|
||||
if (pad >= MAX_USERS)
|
||||
return NULL;
|
||||
if(!wiiu_hid_joypad_query(data, slot))
|
||||
return NULL;
|
||||
|
||||
return NULL;
|
||||
wiiu_hid_t *hid = (wiiu_hid_t *)data;
|
||||
|
||||
return hid->connections[slot].iface->get_name(data);
|
||||
}
|
||||
|
||||
static void wiiu_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
|
||||
|
@ -81,14 +80,11 @@ static void *wiiu_hid_init(void)
|
|||
RARCH_LOG("[hid]: wiiu_hid: init\n");
|
||||
wiiu_hid_t *hid = new_hid();
|
||||
HIDClient *client = new_hidclient();
|
||||
joypad_connection_t *connections = pad_connection_init(MAX_HID_PADS);
|
||||
|
||||
if(!hid || !client || !connections) {
|
||||
if(!hid || !client) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
hid->connections = connections;
|
||||
|
||||
wiiu_hid_init_lists();
|
||||
start_polling_thread(hid);
|
||||
if(!hid->polling_thread)
|
||||
|
@ -103,8 +99,6 @@ static void *wiiu_hid_init(void)
|
|||
|
||||
error:
|
||||
RARCH_LOG("[hid]: initialization failed. cleaning up.\n");
|
||||
if(connections)
|
||||
free(connections);
|
||||
stop_polling_thread(hid);
|
||||
delete_hid(hid);
|
||||
delete_hidclient(client);
|
|
@ -16,70 +16,16 @@
|
|||
|
||||
#ifndef __WIIU_HID__H
|
||||
#define __WIIU_HID__H
|
||||
#include "../connect/joypad_connection.h"
|
||||
#include "../input_defines.h"
|
||||
#include "../input_driver.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
#include <wiiu/pad_driver.h>
|
||||
|
||||
#define DEVICE_UNUSED 0
|
||||
#define DEVICE_USED 1
|
||||
|
||||
#define MAX_HID_PADS 5
|
||||
|
||||
#define ADAPTER_STATE_NEW 0
|
||||
#define ADAPTER_STATE_READING 1
|
||||
#define ADAPTER_STATE_DONE 2
|
||||
|
||||
typedef struct wiiu_hid
|
||||
{
|
||||
HIDClient *client;
|
||||
joypad_connection_t *connections;
|
||||
OSThread *polling_thread;
|
||||
void *polling_thread_stack;
|
||||
volatile bool polling_thread_quit;
|
||||
} wiiu_hid_t;
|
||||
|
||||
typedef struct wiiu_adapter wiiu_adapter_t;
|
||||
|
||||
struct wiiu_adapter {
|
||||
wiiu_adapter_t *next;
|
||||
wiiu_hid_t *hid;
|
||||
uint8_t state;
|
||||
uint8_t *rx_buffer;
|
||||
uint32_t rx_size;
|
||||
int32_t slot;
|
||||
uint32_t handle;
|
||||
uint8_t interface_index;
|
||||
};
|
||||
|
||||
typedef struct wiiu_attach wiiu_attach_event;
|
||||
|
||||
struct wiiu_attach {
|
||||
wiiu_attach_event *next;
|
||||
uint32_t type;
|
||||
uint32_t handle;
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
uint8_t interface_index;
|
||||
uint8_t is_keyboard;
|
||||
uint8_t is_mouse;
|
||||
uint16_t max_packet_size_rx;
|
||||
uint16_t max_packet_size_tx;
|
||||
};
|
||||
|
||||
typedef struct _wiiu_event_list wiiu_event_list;
|
||||
typedef struct _wiiu_adapter_list wiiu_adapter_list;
|
||||
|
||||
struct _wiiu_event_list {
|
||||
OSFastMutex lock;
|
||||
wiiu_attach_event *list;
|
||||
};
|
||||
|
||||
struct _wiiu_adapter_list {
|
||||
OSFastMutex lock;
|
||||
wiiu_adapter_t *list;
|
||||
};
|
||||
|
||||
static void *alloc_zeroed(size_t alignment, size_t size);
|
||||
static OSThread *new_thread(void);
|
||||
static wiiu_hid_t *new_hid(void);
|
Loading…
Reference in New Issue