Start wiring up the HID driver

- add alloc/free for necessary objects
- register callback with Wii U OS

Don't think I've put the unregister bit in, so this is very likely
broken.
This commit is contained in:
gblues 2017-12-02 01:01:43 -08:00 committed by twinaphex
parent e80d99dbae
commit 3b92cce6bf

View File

@ -15,6 +15,10 @@
*/
#include <stdlib.h>
#include <string.h>
#include <wiiu/os.h>
#include <wiiu/syshid.h>
#include "../input_defines.h"
#include "../input_driver.h"
@ -22,8 +26,31 @@
typedef struct wiiu_hid
{
void *empty;
uint32_t nsyshid;
HIDClient *client;
HIDAttachCallback attach_callback;
} wiiu_hid_t;
typedef struct wiiu_hid_user
{
unsigned char *buffer;
uint32_t nsishid;
void *hid_read;
void *hid_write;
uint32_t transfersize;
} wiiu_hid_user_t;
static wiiu_hid_t *new_wiiu_hid_t(void);
static void delete_wiiu_hid_t(wiiu_hid_t *hid);
static HIDClient *new_hidclient(void);
static void delete_hidclient(HIDClient *hid);
int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach);
/**
* HID driver entrypoints registered with hid_driver_t
*/
static bool wiiu_hid_joypad_query(void *data, unsigned pad)
{
return pad < MAX_USERS;
@ -73,15 +100,33 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis)
static void *wiiu_hid_init(void)
{
return (wiiu_hid_t*)calloc(1, sizeof(wiiu_hid_t));
wiiu_hid_t *hid = new_wiiu_hid_t();
HIDClient *client = new_hidclient();
if(!hid || !client)
goto error;
HIDAddClient(client, hid->attach_callback);
hid->client = client;
return hid;
error:
if(hid)
delete_wiiu_hid_t(hid);
if(client)
free(client);
return NULL;
}
static void wiiu_hid_free(void *data)
{
wiiu_hid_t *hid_wiiu = (wiiu_hid_t*)data;
wiiu_hid_t *hid = (wiiu_hid_t*)data;
if (hid_wiiu)
free(hid_wiiu);
if (hid) {
delete_wiiu_hid_t(hid);
}
}
static void wiiu_hid_poll(void *data)
@ -89,6 +134,67 @@ static void wiiu_hid_poll(void *data)
(void)data;
}
/**
* Callbacks
*/
int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) {
return 0;
}
static void wiiu_read_callback(uint32_t handle, int32_t errno, unsigned char *buffer, uint32_t transferred, void *usr) {
}
static void wiiu_write_callback(uint32_t handle, int32_t errno, unsigned char *buffer, uint32_t transferred, void *usr) {
}
/**
* Allocation/deallocation
*/
static wiiu_hid_t *new_wiiu_hid_t(void) {
wiiu_hid_t *hid = (wiiu_hid_t*)calloc(1, sizeof(wiiu_hid_t));
if(!hid)
goto error;
memset(hid, 0, sizeof(wiiu_hid_t));
hid->attach_callback = wiiu_attach_callback;
return hid;
error:
if(hid)
delete_wiiu_hid_t(hid);
return NULL;
}
static void delete_wiiu_hid_t(wiiu_hid_t *hid) {
if(!hid)
return;
if(hid->client) {
HIDDelClient(hid->client);
delete_hidclient(hid->client);
}
free(hid);
}
static HIDClient *new_hidclient() {
HIDClient *client = calloc(1, sizeof(HIDClient));
if(client != NULL) {
memset(client, 0, sizeof(HIDClient));
}
return client;
}
static void delete_hidclient(HIDClient *client) {
if(client)
free(client);
}
hid_driver_t wiiu_hid = {
wiiu_hid_init,
wiiu_hid_joypad_query,