(HID) Uniquely name symbols

This commit is contained in:
twinaphex 2019-05-27 14:32:40 +02:00
parent 277b5c9462
commit 5bf829339d
6 changed files with 159 additions and 144 deletions

View File

@ -30,7 +30,7 @@ typedef struct ds3_instance {
uint8_t data[64]; uint8_t data[64];
} ds3_instance_t; } ds3_instance_t;
static uint8_t activation_packet[] = { static uint8_t ds3_activation_packet[] = {
#if defined(IOS) #if defined(IOS)
0x53, 0xF4, 0x53, 0xF4,
#elif defined(HAVE_WIIUSB_HID) #elif defined(HAVE_WIIUSB_HID)
@ -51,7 +51,7 @@ static uint8_t activation_packet[] = {
#define MOTOR1_OFFSET 4 #define MOTOR1_OFFSET 4
#define MOTOR2_OFFSET 6 #define MOTOR2_OFFSET 6
static uint8_t control_packet[] = { static uint8_t ds3_control_packet[] = {
0x52, 0x01, 0x52, 0x01,
0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -65,25 +65,23 @@ static uint8_t control_packet[] = {
0x00, 0x00, 0x00 0x00, 0x00, 0x00
}; };
static int control_packet_size = sizeof(control_packet);
extern pad_connection_interface_t ds3_pad_connection; extern pad_connection_interface_t ds3_pad_connection;
static void update_pad_state(ds3_instance_t *instance); static void ds3_update_pad_state(ds3_instance_t *instance);
static void update_analog_state(ds3_instance_t *instance); static void ds3_update_analog_state(ds3_instance_t *instance);
static int32_t send_activation_packet(ds3_instance_t *instance) static int32_t ds3_send_activation_packet(ds3_instance_t *instance)
{ {
int32_t result; int32_t result;
#if defined(WIIU) #if defined(WIIU)
result = HID_SET_REPORT(instance->handle, result = HID_SET_REPORT(instance->handle,
HID_REPORT_FEATURE, HID_REPORT_FEATURE,
DS3_ACTIVATION_REPORT_ID, DS3_ACTIVATION_REPORT_ID,
activation_packet, ds3_activation_packet,
sizeof(activation_packet)); sizeof(ds3_activation_packet));
#else #else
HID_SEND_CONTROL(instance->handle, HID_SEND_CONTROL(instance->handle,
activation_packet, sizeof(activation_packet)); ds3_activation_packet, sizeof(ds3_activation_packet));
#endif #endif
return result; return result;
@ -99,11 +97,11 @@ static uint32_t set_protocol(ds3_instance_t *instance, int protocol)
return result; return result;
} }
static int32_t send_control_packet(ds3_instance_t *instance) static int32_t ds3_send_control_packet(ds3_instance_t *instance)
{ {
uint8_t packet_buffer[control_packet_size]; uint8_t packet_buffer[sizeof(ds3_control_packet)];
int32_t result = 0; int32_t result = 0;
memcpy(packet_buffer, control_packet, control_packet_size); memcpy(packet_buffer, ds3_control_packet, sizeof(ds3_control_packet));
packet_buffer[LED_OFFSET] = 0; packet_buffer[LED_OFFSET] = 0;
if(instance->pad) { if(instance->pad) {
@ -121,11 +119,11 @@ static int32_t send_control_packet(ds3_instance_t *instance)
HID_REPORT_OUTPUT, HID_REPORT_OUTPUT,
DS3_RUMBLE_REPORT_ID, DS3_RUMBLE_REPORT_ID,
packet_buffer+PACKET_OFFSET, packet_buffer+PACKET_OFFSET,
control_packet_size-PACKET_OFFSET); sizeof(ds3_control_packet)-PACKET_OFFSET);
#else #else
HID_SEND_CONTROL(instance->handle, HID_SEND_CONTROL(instance->handle,
packet_buffer+PACKET_OFFSET, packet_buffer+PACKET_OFFSET,
control_packet_size-PACKET_OFFSET); sizeof(ds3_control_packet)-PACKET_OFFSET);
#endif /* WIIU */ #endif /* WIIU */
return result; return result;
} }
@ -148,11 +146,11 @@ static void *ds3_init(void *handle)
set_protocol(instance, 1); set_protocol(instance, 1);
RARCH_LOG("[ds3]: sending control packet\n"); RARCH_LOG("[ds3]: sending control packet\n");
if(send_control_packet(instance) < 0) if(ds3_send_control_packet(instance) < 0)
errors++; errors++;
RARCH_LOG("[ds3]: sending activation packet\n"); RARCH_LOG("[ds3]: sending activation packet\n");
if(send_activation_packet(instance) < 0) if(ds3_send_activation_packet(instance) < 0)
errors++; errors++;
if(errors) if(errors)
@ -246,23 +244,23 @@ static void ds3_packet_handler(void *data, uint8_t *packet, uint16_t size)
if(instance->pad && !instance->led_set) if(instance->pad && !instance->led_set)
{ {
send_control_packet(instance); ds3_send_control_packet(instance);
instance->led_set = true; instance->led_set = true;
} }
if(size > control_packet_size) if(size > sizeof(ds3_control_packet))
{ {
RARCH_ERR("[ds3]: Expecting packet to be %d but was %d\n", RARCH_ERR("[ds3]: Expecting packet to be %d but was %d\n",
control_packet_size, size); sizeof(ds3_control_packet), size);
return; return;
} }
memcpy(instance->data, packet, size); memcpy(instance->data, packet, size);
update_pad_state(instance); ds3_update_pad_state(instance);
update_analog_state(instance); ds3_update_analog_state(instance);
} }
static void update_analog_state(ds3_instance_t *instance) static void ds3_update_analog_state(ds3_instance_t *instance)
{ {
int pad_axis; int pad_axis;
int16_t interpolated; int16_t interpolated;
@ -277,7 +275,7 @@ static void update_analog_state(ds3_instance_t *instance)
} }
} }
static void update_pad_state(ds3_instance_t *instance) static void ds3_update_pad_state(ds3_instance_t *instance)
{ {
uint32_t i, pressed_keys; uint32_t i, pressed_keys;

View File

@ -16,7 +16,7 @@
#include "hid_device_driver.h" #include "hid_device_driver.h"
extern pad_connection_interface_t null_pad_connection; extern pad_connection_interface_t hid_null_pad_connection;
/* /*
* This is the instance data structure for the pad you are implementing. * This is the instance data structure for the pad you are implementing.
@ -24,7 +24,8 @@ extern pad_connection_interface_t null_pad_connection;
* sense for the pad you're writing for. The pointer to this structure * sense for the pad you're writing for. The pointer to this structure
* will be passed in as a void pointer to the methods you implement below. * will be passed in as a void pointer to the methods you implement below.
*/ */
typedef struct null_instance { typedef struct hid_null_instance
{
void *handle; /* a handle to the HID subsystem adapter */ void *handle; /* a handle to the HID subsystem adapter */
joypad_connection_t *pad; /* a pointer to the joypad connection you assign joypad_connection_t *pad; /* a pointer to the joypad connection you assign
in init() */ in init() */
@ -33,7 +34,7 @@ typedef struct null_instance {
uint16_t motors[2]; /* rumble strength, if appropriate */ uint16_t motors[2]; /* rumble strength, if appropriate */
uint8_t data[64]; /* a buffer large enough to hold the device's uint8_t data[64]; /* a buffer large enough to hold the device's
max rx packet */ max rx packet */
} null_instance_t; } hid_null_instance_t;
/** /**
* Use the HID_ macros (see input/include/hid_driver.h) to send data packets * Use the HID_ macros (see input/include/hid_driver.h) to send data packets
@ -49,15 +50,14 @@ typedef struct null_instance {
*/ */
static void *null_init(void *handle) static void *null_init(void *handle)
{ {
null_instance_t *instance; hid_null_instance_t *instance = (hid_null_instance_t *)calloc(1, sizeof(hid_null_instance_t));
instance = (null_instance_t *)calloc(1, sizeof(null_instance_t)); if (!instance)
if(!instance)
goto error; goto error;
memset(instance, 0, sizeof(null_instance_t)); memset(instance, 0, sizeof(hid_null_instance_t));
instance->handle = handle; instance->handle = handle;
instance->pad = hid_pad_register(instance, &null_pad_connection); instance->pad = hid_pad_register(instance, &hid_null_pad_connection);
if(!instance->pad) if (!instance->pad)
goto error; goto error;
RARCH_LOG("[null]: init complete.\n"); RARCH_LOG("[null]: init complete.\n");
@ -65,7 +65,7 @@ static void *null_init(void *handle)
error: error:
RARCH_ERR("[null]: init failed.\n"); RARCH_ERR("[null]: init failed.\n");
if(instance) if (instance)
free(instance); free(instance);
return NULL; return NULL;
@ -77,9 +77,10 @@ static void *null_init(void *handle)
*/ */
static void null_free(void *data) static void null_free(void *data)
{ {
null_instance_t *instance = (null_instance_t *)data; hid_null_instance_t *instance = (hid_null_instance_t *)data;
if(instance) { if (instance)
{
hid_pad_deregister(instance->pad); hid_pad_deregister(instance->pad);
free(instance); free(instance);
} }
@ -92,9 +93,9 @@ static void null_free(void *data)
*/ */
static void null_handle_packet(void *data, uint8_t *buffer, size_t size) static void null_handle_packet(void *data, uint8_t *buffer, size_t size)
{ {
null_instance_t *instance = (null_instance_t *)data; hid_null_instance_t *instance = (hid_null_instance_t *)data;
if(instance && instance->pad) if (instance && instance->pad)
instance->pad->iface->packet_handler(instance->pad->data, buffer, size); instance->pad->iface->packet_handler(instance->pad->data, buffer, size);
} }
@ -123,11 +124,11 @@ hid_device_t null_hid_device = {
* But if you need to track multiple pads attached to the same HID device * But if you need to track multiple pads attached to the same HID device
* (see: Wii U GC adapter), you can allocate that memory here. * (see: Wii U GC adapter), you can allocate that memory here.
*/ */
static void *null_pad_init(void *data, uint32_t slot, hid_driver_t *driver) static void *hid_null_pad_init(void *data, uint32_t slot, hid_driver_t *driver)
{ {
null_instance_t *instance = (null_instance_t *)data; hid_null_instance_t *instance = (hid_null_instance_t *)data;
if(!instance) if (!instance)
return NULL; return NULL;
instance->slot = slot; instance->slot = slot;
@ -135,9 +136,9 @@ static void *null_pad_init(void *data, uint32_t slot, hid_driver_t *driver)
} }
/** /**
* If you allocate any memory in null_pad_init() above, de-allocate it here. * If you allocate any memory in hid_null_pad_init() above, de-allocate it here.
*/ */
static void null_pad_deinit(void *data) static void hid_null_pad_deinit(void *data)
{ {
} }
@ -145,10 +146,10 @@ static void null_pad_deinit(void *data)
* Translate the button data from the pad into the input_bits_t format * Translate the button data from the pad into the input_bits_t format
* that RetroArch can use. * that RetroArch can use.
*/ */
static void null_get_buttons(void *data, input_bits_t *state) static void hid_null_get_buttons(void *data, input_bits_t *state)
{ {
null_instance_t *instance = (null_instance_t *)data; hid_null_instance_t *instance = (hid_null_instance_t *)data;
if(!instance) if (!instance)
return; return;
/* TODO: get buttons */ /* TODO: get buttons */
@ -157,10 +158,10 @@ static void null_get_buttons(void *data, input_bits_t *state)
/** /**
* Handle a single packet for the pad. * Handle a single packet for the pad.
*/ */
static void null_packet_handler(void *data, uint8_t *packet, uint16_t size) static void hid_null_packet_handler(void *data, uint8_t *packet, uint16_t size)
{ {
null_instance_t *instance = (null_instance_t *)data; hid_null_instance_t *instance = (hid_null_instance_t *)data;
if(!instance) if (!instance)
return; return;
RARCH_LOG_BUFFER(packet, size); RARCH_LOG_BUFFER(packet, size);
@ -169,7 +170,7 @@ static void null_packet_handler(void *data, uint8_t *packet, uint16_t size)
/** /**
* If the pad doesn't support rumble, then this can just be a no-op. * If the pad doesn't support rumble, then this can just be a no-op.
*/ */
static void null_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t strength) static void hid_null_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t strength)
{ {
} }
@ -182,7 +183,7 @@ static void null_set_rumble(void *data, enum retro_rumble_effect effect, uint16_
* - (-32768,-32768) is top-left * - (-32768,-32768) is top-left
* - (32767,32767) is bottom-right * - (32767,32767) is bottom-right
*/ */
static int16_t null_get_axis(void *data, unsigned axis) static int16_t hid_null_get_axis(void *data, unsigned axis)
{ {
return 0; return 0;
} }
@ -191,7 +192,7 @@ static int16_t null_get_axis(void *data, unsigned axis)
* The name the pad will show up as in the UI, also used to auto-assign * The name the pad will show up as in the UI, also used to auto-assign
* buttons in input/input_autodetect_builtin.c * buttons in input/input_autodetect_builtin.c
*/ */
static const char *null_get_name(void *data) static const char *hid_null_get_name(void *data)
{ {
return "Null HID Pad"; return "Null HID Pad";
} }
@ -199,7 +200,7 @@ static const char *null_get_name(void *data)
/** /**
* Read the state of a single button. * Read the state of a single button.
*/ */
static bool null_button(void *data, uint16_t joykey) static bool hid_null_button(void *data, uint16_t joykey)
{ {
return false; return false;
} }
@ -207,13 +208,13 @@ static bool null_button(void *data, uint16_t joykey)
/** /**
* Fill in the joypad interface * Fill in the joypad interface
*/ */
pad_connection_interface_t null_pad_connection = { pad_connection_interface_t hid_null_pad_connection = {
null_pad_init, hid_null_pad_init,
null_pad_deinit, hid_null_pad_deinit,
null_packet_handler, hid_null_packet_handler,
null_set_rumble, hid_null_set_rumble,
null_get_buttons, hid_null_get_buttons,
null_get_axis, hid_null_get_axis,
null_get_name, hid_null_get_name,
null_button hid_null_button
}; };

View File

@ -27,12 +27,13 @@ static uint8_t activation_packet[] = { 0x13 };
#define GCA_PORT_CONNECTED 0x10 #define GCA_PORT_CONNECTED 0x10
#define GCA_WAVEBIRD_CONNECTED 0x22 #define GCA_WAVEBIRD_CONNECTED 0x22
typedef struct wiiu_gca_instance { typedef struct hid_wiiu_gca_instance
void *handle; {
bool online; void *handle;
uint8_t device_state[37]; bool online;
joypad_connection_t *pads[4]; uint8_t device_state[37];
} wiiu_gca_instance_t; joypad_connection_t *pads[4];
} hid_wiiu_gca_instance_t;
typedef struct gca_pad_data typedef struct gca_pad_data
{ {
@ -44,17 +45,18 @@ typedef struct gca_pad_data
int16_t analog_state[3][2]; // analog state int16_t analog_state[3][2]; // analog state
} gca_pad_t; } gca_pad_t;
static void update_pad_state(wiiu_gca_instance_t *instance); static void wiiu_gca_update_pad_state(hid_wiiu_gca_instance_t *instance);
static void unregister_pad(wiiu_gca_instance_t *instance, int port); static void wiiu_gca_unregister_pad(hid_wiiu_gca_instance_t *instance, int port);
extern pad_connection_interface_t wiiu_gca_pad_connection; extern pad_connection_interface_t wiiu_gca_pad_connection;
static void *wiiu_gca_init(void *handle) static void *wiiu_gca_init(void *handle)
{ {
RARCH_LOG("[gca]: allocating driver instance...\n"); RARCH_LOG("[gca]: allocating driver instance...\n");
wiiu_gca_instance_t *instance = calloc(1, sizeof(wiiu_gca_instance_t)); hid_wiiu_gca_instance_t *instance = calloc(1, sizeof(hid_wiiu_gca_instance_t));
if(instance == NULL) goto error; if(instance == NULL)
memset(instance, 0, sizeof(wiiu_gca_instance_t)); return NULL;
memset(instance, 0, sizeof(hid_wiiu_gca_instance_t));
instance->handle = handle; instance->handle = handle;
hid_instance.os_driver->send_control(handle, activation_packet, sizeof(activation_packet)); hid_instance.os_driver->send_control(handle, activation_packet, sizeof(activation_packet));
@ -71,15 +73,17 @@ static void *wiiu_gca_init(void *handle)
return NULL; return NULL;
} }
static void wiiu_gca_free(void *data) { static void wiiu_gca_free(void *data)
wiiu_gca_instance_t *instance = (wiiu_gca_instance_t *)data; {
hid_wiiu_gca_instance_t *instance = (hid_wiiu_gca_instance_t *)data;
int i; int i;
if(instance) { if(instance)
{
instance->online = false; instance->online = false;
for(i = 0; i < 4; i++) for (i = 0; i < 4; i++)
unregister_pad(instance, i); wiiu_gca_unregister_pad(instance, i);
free(instance); free(instance);
} }
@ -87,7 +91,7 @@ static void wiiu_gca_free(void *data) {
static void wiiu_gca_handle_packet(void *data, uint8_t *buffer, size_t size) static void wiiu_gca_handle_packet(void *data, uint8_t *buffer, size_t size)
{ {
wiiu_gca_instance_t *instance = (wiiu_gca_instance_t *)data; hid_wiiu_gca_instance_t *instance = (hid_wiiu_gca_instance_t *)data;
if(!instance || !instance->online) if(!instance || !instance->online)
{ {
RARCH_WARN("[gca]: instance null or not ready yet.\n"); RARCH_WARN("[gca]: instance null or not ready yet.\n");
@ -102,10 +106,10 @@ static void wiiu_gca_handle_packet(void *data, uint8_t *buffer, size_t size)
} }
memcpy(instance->device_state, buffer, size); memcpy(instance->device_state, buffer, size);
update_pad_state(instance); wiiu_gca_update_pad_state(instance);
} }
static void update_pad_state(wiiu_gca_instance_t *instance) static void wiiu_gca_update_pad_state(hid_wiiu_gca_instance_t *instance)
{ {
int i, port; int i, port;
unsigned char port_connected; unsigned char port_connected;
@ -114,8 +118,9 @@ static void update_pad_state(wiiu_gca_instance_t *instance)
return; return;
joypad_connection_t *pad; joypad_connection_t *pad;
/* process each pad */ /* process each pad */
for(i = 1; i < 37; i += 9) for (i = 1; i < 37; i += 9)
{ {
port = i / 9; port = i / 9;
pad = instance->pads[port]; pad = instance->pads[port];
@ -140,13 +145,13 @@ static void update_pad_state(wiiu_gca_instance_t *instance)
} else { } else {
if(pad != NULL) { if(pad != NULL) {
RARCH_LOG("[gca]: Gamepad at port %d disconnected.\n", port+1); RARCH_LOG("[gca]: Gamepad at port %d disconnected.\n", port+1);
unregister_pad(instance, port); wiiu_gca_unregister_pad(instance, port);
} }
} }
} }
} }
static void unregister_pad(wiiu_gca_instance_t *instance, int slot) static void wiiu_gca_unregister_pad(hid_wiiu_gca_instance_t *instance, int slot)
{ {
if(!instance || slot < 0 || slot >= 4 || instance->pads[slot] == NULL) if(!instance || slot < 0 || slot >= 4 || instance->pads[slot] == NULL)
return; return;
@ -238,7 +243,7 @@ static void update_buttons(gca_pad_t *pad)
pressed_keys = pad->data[1] | (pad->data[2] << 8); pressed_keys = pad->data[1] | (pad->data[2] << 8);
pad->buttons = 0; pad->buttons = 0;
for(i = 0; i < 12; i++) for (i = 0; i < 12; i++)
pad->buttons |= (pressed_keys & (1 << i)) ? pad->buttons |= (pressed_keys & (1 << i)) ?
(1 << button_mapping[i]) : 0; (1 << button_mapping[i]) : 0;
} }
@ -261,7 +266,7 @@ static void update_analog_state(gca_pad_t *pad)
/* GameCube analog axis are 8-bit unsigned, where 128/128 is center. /* GameCube analog axis are 8-bit unsigned, where 128/128 is center.
* So, we subtract 128 to get a signed, 0-based value and then mulitply * So, we subtract 128 to get a signed, 0-based value and then mulitply
* by 256 to get the 16-bit range RetroArch expects. */ * by 256 to get the 16-bit range RetroArch expects. */
for(pad_axis = 0; pad_axis < 4; pad_axis++) for (pad_axis = 0; pad_axis < 4; pad_axis++)
{ {
axis = pad_axis % 2 ? 0 : 1; axis = pad_axis % 2 ? 0 : 1;
stick = pad_axis / 2; stick = pad_axis / 2;

View File

@ -16,7 +16,8 @@
#include "../include/gamepad.h" #include "../include/gamepad.h"
enum pad_axes { enum gamepad_pad_axes
{
AXIS_LEFT_ANALOG_X, AXIS_LEFT_ANALOG_X,
AXIS_LEFT_ANALOG_Y, AXIS_LEFT_ANALOG_Y,
AXIS_RIGHT_ANALOG_X, AXIS_RIGHT_ANALOG_X,
@ -24,11 +25,11 @@ enum pad_axes {
AXIS_INVALID AXIS_INVALID
}; };
static int16_t clamp_axis(int16_t value, bool is_negative) static int16_t gamepad_clamp_axis(int16_t value, bool is_negative)
{ {
if(is_negative && value > 0) if (is_negative && value > 0)
return 0; return 0;
if(!is_negative && value < 0) if (!is_negative && value < 0)
return 0; return 0;
return value; return value;
@ -72,5 +73,5 @@ int16_t gamepad_get_axis_value(int16_t state[3][2], axis_data *data)
break; break;
} }
return clamp_axis(value, data->is_negative); return gamepad_clamp_axis(value, data->is_negative);
} }

View File

@ -33,11 +33,11 @@ static bool wiiu_hid_joypad_query(void *data, unsigned slot)
static joypad_connection_t *get_pad(wiiu_hid_t *hid, unsigned slot) static joypad_connection_t *get_pad(wiiu_hid_t *hid, unsigned slot)
{ {
if(!wiiu_hid_joypad_query(hid, slot)) if (!wiiu_hid_joypad_query(hid, slot))
return NULL; return NULL;
joypad_connection_t *result = HID_PAD_CONNECTION_PTR(slot); joypad_connection_t *result = HID_PAD_CONNECTION_PTR(slot);
if(!result || !result->connected || !result->iface || !result->data) if (!result || !result->connected || !result->iface || !result->data)
return NULL; return NULL;
return result; return result;
@ -47,7 +47,7 @@ static const char *wiiu_hid_joypad_name(void *data, unsigned slot)
{ {
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if(!pad) if (!pad)
return NULL; return NULL;
return pad->iface->get_name(pad->data); return pad->iface->get_name(pad->data);
@ -57,7 +57,7 @@ static void wiiu_hid_joypad_get_buttons(void *data, unsigned slot, input_bits_t
{ {
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if(pad) if (pad)
pad->iface->get_buttons(pad->data, state); pad->iface->get_buttons(pad->data, state);
} }
@ -65,7 +65,7 @@ static bool wiiu_hid_joypad_button(void *data, unsigned slot, uint16_t joykey)
{ {
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if(!pad) if (!pad)
return false; return false;
return pad->iface->button(pad->data, joykey); return pad->iface->button(pad->data, joykey);
@ -76,7 +76,7 @@ static bool wiiu_hid_joypad_rumble(void *data, unsigned slot,
{ {
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if(!pad) if (!pad)
return false; return false;
pad->iface->set_rumble(pad->data, effect, strength); pad->iface->set_rumble(pad->data, effect, strength);
@ -87,7 +87,7 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned slot, uint32_t joyaxis)
{ {
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if(!pad) if (!pad)
return 0; return 0;
return pad->iface->get_axis(pad->data, joyaxis); return pad->iface->get_axis(pad->data, joyaxis);
@ -148,7 +148,7 @@ static void wiiu_hid_free(const void *data)
static void wiiu_hid_poll(void *data) static void wiiu_hid_poll(void *data)
{ {
wiiu_hid_t *hid = (wiiu_hid_t *)data; wiiu_hid_t *hid = (wiiu_hid_t *)data;
if(hid == NULL) if (!hid)
return; return;
synchronized_process_adapters(hid); synchronized_process_adapters(hid);
@ -159,7 +159,8 @@ static void wiiu_hid_send_control(void *data, uint8_t *buf, size_t size)
wiiu_adapter_t *adapter = (wiiu_adapter_t *)data; wiiu_adapter_t *adapter = (wiiu_adapter_t *)data;
int32_t result; int32_t result;
if (!adapter) { if (!adapter)
{
RARCH_ERR("[hid]: send_control: bad adapter.\n"); RARCH_ERR("[hid]: send_control: bad adapter.\n");
return; return;
} }
@ -172,7 +173,7 @@ static void wiiu_hid_send_control(void *data, uint8_t *buf, size_t size)
* to write a single byte was 0xffe2ff97, which works out to -30 and -105. * to write a single byte was 0xffe2ff97, which works out to -30 and -105.
* I have no idea what these mean. */ * I have no idea what these mean. */
result = HIDWrite(adapter->handle, adapter->tx_buffer, adapter->tx_size, NULL, NULL); result = HIDWrite(adapter->handle, adapter->tx_buffer, adapter->tx_size, NULL, NULL);
if(result < 0) if (result < 0)
{ {
int16_t r1 = (result & 0x0000FFFF); int16_t r1 = (result & 0x0000FFFF);
int16_t r2 = ((result & 0xFFFF0000) >> 16); int16_t r2 = ((result & 0xFFFF0000) >> 16);
@ -227,14 +228,14 @@ static int32_t wiiu_hid_read(void *data, void *buffer, size_t size)
wiiu_adapter_t *adapter = (wiiu_adapter_t *)data; wiiu_adapter_t *adapter = (wiiu_adapter_t *)data;
int32_t result; int32_t result;
if(!adapter) if (!adapter)
return -1; return -1;
if(size > adapter->rx_size) if (size > adapter->rx_size)
return -1; return -1;
result = HIDRead(adapter->handle, buffer, size, NULL, NULL); result = HIDRead(adapter->handle, buffer, size, NULL, NULL);
if(result < 0) if (result < 0)
report_hid_error("read failed", adapter, result); report_hid_error("read failed", adapter, result);
return result; return result;
@ -293,7 +294,8 @@ static void stop_polling_thread(wiiu_hid_t *hid)
return; return;
/* Unregister our HID client so we don't get any new events. */ /* Unregister our HID client so we don't get any new events. */
if(hid->client) { if (hid->client)
{
HIDDelClient(hid->client); HIDDelClient(hid->client);
hid->client = NULL; hid->client = NULL;
} }
@ -329,7 +331,8 @@ static void log_device(HIDDevice *device)
static uint8_t try_init_driver(wiiu_adapter_t *adapter) static uint8_t try_init_driver(wiiu_adapter_t *adapter)
{ {
adapter->driver_handle = adapter->driver->init(adapter); adapter->driver_handle = adapter->driver->init(adapter);
if(adapter->driver_handle == NULL) { if (adapter->driver_handle == NULL)
{
RARCH_ERR("[hid]: Failed to initialize driver: %s\n", RARCH_ERR("[hid]: Failed to initialize driver: %s\n",
adapter->driver->name); adapter->driver->name);
return ADAPTER_STATE_DONE; return ADAPTER_STATE_DONE;
@ -345,7 +348,8 @@ static void synchronized_process_adapters(wiiu_hid_t *hid)
bool keep_prev = false; bool keep_prev = false;
OSFastMutex_Lock(&(adapters.lock)); OSFastMutex_Lock(&(adapters.lock));
for(adapter = adapters.list; adapter != NULL; adapter = adapter_next)
for (adapter = adapters.list; adapter != NULL; adapter = adapter_next)
{ {
adapter_next = adapter->next; adapter_next = adapter->next;
@ -360,7 +364,7 @@ static void synchronized_process_adapters(wiiu_hid_t *hid)
break; break;
case ADAPTER_STATE_GC: case ADAPTER_STATE_GC:
/* remove from the list */ /* remove from the list */
if(prev == NULL) if (!prev)
adapters.list = adapter->next; adapters.list = adapter->next;
else else
prev->next = adapter->next; prev->next = adapter->next;
@ -400,9 +404,9 @@ static wiiu_adapter_t *synchronized_lookup_adapter(uint32_t handle)
OSFastMutex_Lock(&(adapters.lock)); OSFastMutex_Lock(&(adapters.lock));
wiiu_adapter_t *iterator; wiiu_adapter_t *iterator;
for(iterator = adapters.list; iterator != NULL; iterator = iterator->next) for (iterator = adapters.list; iterator != NULL; iterator = iterator->next)
{ {
if(iterator->handle == handle) if (iterator->handle == handle)
break; break;
} }
OSFastMutex_Unlock(&(adapters.lock)); OSFastMutex_Unlock(&(adapters.lock));
@ -423,17 +427,20 @@ static int32_t wiiu_attach_callback(HIDClient *client,
{ {
wiiu_attach_event *event = NULL; wiiu_attach_event *event = NULL;
if(attach) { if (attach)
{
RARCH_LOG("[hid]: Device attach event generated.\n"); RARCH_LOG("[hid]: Device attach event generated.\n");
log_device(device); log_device(device);
} else { }
else
{
RARCH_LOG("[hid]: Device detach event generated.\n"); RARCH_LOG("[hid]: Device detach event generated.\n");
} }
if (device) if (device)
event = new_attach_event(device); event = new_attach_event(device);
if(!event) if (!event)
goto error; goto error;
event->type = attach; event->type = attach;
@ -453,7 +460,7 @@ static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event)
/* this will signal the read loop to stop for this adapter /* this will signal the read loop to stop for this adapter
* the read loop method will update this to ADAPTER_STATE_GC * the read loop method will update this to ADAPTER_STATE_GC
* so the adapter poll method can clean it up. */ * so the adapter poll method can clean it up. */
if(adapter) if (adapter)
adapter->connected = false; adapter->connected = false;
} }
@ -461,7 +468,7 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event)
{ {
wiiu_adapter_t *adapter = new_adapter(event); wiiu_adapter_t *adapter = new_adapter(event);
if(!adapter) if (!adapter)
{ {
RARCH_ERR("[hid]: Failed to allocate adapter.\n"); RARCH_ERR("[hid]: Failed to allocate adapter.\n");
goto error; goto error;
@ -483,21 +490,23 @@ static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error,
uint8_t *buffer, uint32_t buffer_size, void *userdata) uint8_t *buffer, uint32_t buffer_size, void *userdata)
{ {
wiiu_adapter_t *adapter = (wiiu_adapter_t *)userdata; wiiu_adapter_t *adapter = (wiiu_adapter_t *)userdata;
if(!adapter) if (!adapter)
{ {
RARCH_ERR("read_loop_callback: bad userdata\n"); RARCH_ERR("read_loop_callback: bad userdata\n");
return; return;
} }
if(error < 0) if (error < 0)
{ {
report_hid_error("async read failed", adapter, error); report_hid_error("async read failed", adapter, error);
} }
if(adapter->state == ADAPTER_STATE_READING) { if (adapter->state == ADAPTER_STATE_READING)
{
adapter->state = ADAPTER_STATE_READY; adapter->state = ADAPTER_STATE_READY;
if(error == 0) { if (error == 0)
{
adapter->driver->handle_packet(adapter->driver_handle, adapter->driver->handle_packet(adapter->driver_handle,
buffer, buffer_size); buffer, buffer_size);
} }
@ -506,7 +515,7 @@ static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error,
static void report_hid_error(const char *msg, wiiu_adapter_t *adapter, int32_t error) static void report_hid_error(const char *msg, wiiu_adapter_t *adapter, int32_t error)
{ {
if(error >= 0) if (error >= 0)
return; return;
int16_t hid_error_code = error & 0xffff; int16_t hid_error_code = error & 0xffff;
@ -573,13 +582,13 @@ static void wiiu_hid_polling_thread_cleanup(OSThread *thread, void *stack)
do do
{ {
incomplete = 0; incomplete = 0;
for(adapter = adapters.list; adapter != NULL; adapter = adapter->next) for (adapter = adapters.list; adapter != NULL; adapter = adapter->next)
{ {
if(adapter->state == ADAPTER_STATE_READING) if (adapter->state == ADAPTER_STATE_READING)
incomplete++; incomplete++;
} }
if(incomplete == 0) if (incomplete == 0)
{ {
RARCH_LOG("All in-flight reads complete.\n"); RARCH_LOG("All in-flight reads complete.\n");
while(adapters.list != NULL) while(adapters.list != NULL)
@ -591,10 +600,10 @@ static void wiiu_hid_polling_thread_cleanup(OSThread *thread, void *stack)
} }
} }
if(incomplete) if (incomplete)
usleep(5000); usleep(5000);
if(++retries >= 1000) if (++retries >= 1000)
{ {
RARCH_WARN("[hid]: timed out waiting for in-flight read to finish.\n"); RARCH_WARN("[hid]: timed out waiting for in-flight read to finish.\n");
incomplete = 0; incomplete = 0;
@ -606,13 +615,13 @@ static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list)
{ {
wiiu_attach_event *event, *event_next = NULL; wiiu_attach_event *event, *event_next = NULL;
if(!hid || !list) if (!hid || !list)
return; return;
for(event = list; event != NULL; event = event_next) for (event = list; event != NULL; event = event_next)
{ {
event_next = event->next; event_next = event->next;
if(event->type == HID_DEVICE_ATTACH) if (event->type == HID_DEVICE_ATTACH)
wiiu_hid_attach(hid, event); wiiu_hid_attach(hid, event);
else else
wiiu_hid_detach(hid, event); wiiu_hid_detach(hid, event);
@ -622,7 +631,8 @@ static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list)
static void wiiu_poll_adapter(wiiu_adapter_t *adapter) static void wiiu_poll_adapter(wiiu_adapter_t *adapter)
{ {
if(!adapter->connected) { if (!adapter->connected)
{
adapter->state = ADAPTER_STATE_DONE; adapter->state = ADAPTER_STATE_DONE;
return; return;
} }
@ -637,12 +647,12 @@ static void wiiu_poll_adapters(wiiu_hid_t *hid)
wiiu_adapter_t *it; wiiu_adapter_t *it;
OSFastMutex_Lock(&(adapters.lock)); OSFastMutex_Lock(&(adapters.lock));
for(it = adapters.list; it != NULL; it = it->next) for (it = adapters.list; it != NULL; it = it->next)
{ {
if(it->state == ADAPTER_STATE_READY) if (it->state == ADAPTER_STATE_READY)
wiiu_poll_adapter(it); wiiu_poll_adapter(it);
if(it->state == ADAPTER_STATE_DONE) if (it->state == ADAPTER_STATE_DONE)
it->state = ADAPTER_STATE_GC; it->state = ADAPTER_STATE_GC;
} }
@ -696,7 +706,7 @@ static wiiu_hid_t *new_hid(void)
static void delete_hid(wiiu_hid_t *hid) static void delete_hid(wiiu_hid_t *hid)
{ {
RARCH_LOG("[hid]: delete_hid()\n"); RARCH_LOG("[hid]: delete_hid()\n");
if(hid) if (hid)
free(hid); free(hid);
} }
@ -709,7 +719,7 @@ static HIDClient *new_hidclient(void)
static void delete_hidclient(HIDClient *client) static void delete_hidclient(HIDClient *client)
{ {
RARCH_LOG("[hid]: delete_hidclient()\n"); RARCH_LOG("[hid]: delete_hidclient()\n");
if(client) if (client)
free(client); free(client);
} }
@ -741,17 +751,17 @@ static void delete_adapter(wiiu_adapter_t *adapter)
if (!adapter) if (!adapter)
return; return;
if(adapter->rx_buffer) if (adapter->rx_buffer)
{ {
free(adapter->rx_buffer); free(adapter->rx_buffer);
adapter->rx_buffer = NULL; adapter->rx_buffer = NULL;
} }
if(adapter->tx_buffer) if (adapter->tx_buffer)
{ {
free(adapter->tx_buffer); free(adapter->tx_buffer);
adapter->tx_buffer = NULL; adapter->tx_buffer = NULL;
} }
if(adapter->driver && adapter->driver_handle) { if (adapter->driver && adapter->driver_handle) {
adapter->driver->free(adapter->driver_handle); adapter->driver->free(adapter->driver_handle);
adapter->driver_handle = NULL; adapter->driver_handle = NULL;
adapter->driver = NULL; adapter->driver = NULL;
@ -763,14 +773,14 @@ static void delete_adapter(wiiu_adapter_t *adapter)
static wiiu_attach_event *new_attach_event(HIDDevice *device) static wiiu_attach_event *new_attach_event(HIDDevice *device)
{ {
hid_device_t *driver = hid_device_driver_lookup(device->vid, device->pid); hid_device_t *driver = hid_device_driver_lookup(device->vid, device->pid);
if(!driver) if (!driver)
{ {
RARCH_ERR("[hid]: Failed to locate driver for device vid=%04x pid=%04x\n", RARCH_ERR("[hid]: Failed to locate driver for device vid=%04x pid=%04x\n",
device->vid, device->pid); device->vid, device->pid);
return NULL; return NULL;
} }
wiiu_attach_event *event = alloc_zeroed(4, sizeof(wiiu_attach_event)); wiiu_attach_event *event = alloc_zeroed(4, sizeof(wiiu_attach_event));
if(!event) if (!event)
return NULL; return NULL;
event->driver = driver; event->driver = driver;
@ -790,14 +800,14 @@ static wiiu_attach_event *new_attach_event(HIDDevice *device)
static void delete_attach_event(wiiu_attach_event *event) static void delete_attach_event(wiiu_attach_event *event)
{ {
if(event) if (event)
free(event); free(event);
} }
void *alloc_zeroed(size_t alignment, size_t size) void *alloc_zeroed(size_t alignment, size_t size)
{ {
void *result = memalign(alignment, size); void *result = memalign(alignment, size);
if(result) if (result)
memset(result, 0, size); memset(result, 0, size);
return result; return result;

View File

@ -167,7 +167,7 @@ static void wiiusb_get_description(usb_device_entry *device,
{ {
const usb_interfacedesc *inter = &config->interfaces[i]; const usb_interfacedesc *inter = &config->interfaces[i];
for(k = 0; k < (int)inter->bNumEndpoints; k++) for (k = 0; k < (int)inter->bNumEndpoints; k++)
{ {
const usb_endpointdesc *epdesc = &inter->endpoints[k]; const usb_endpointdesc *epdesc = &inter->endpoints[k];
bool is_int = (epdesc->bmAttributes & 0x03) == USB_ENDPOINT_INTERRUPT; bool is_int = (epdesc->bmAttributes & 0x03) == USB_ENDPOINT_INTERRUPT;
@ -368,7 +368,7 @@ static bool wiiusb_hid_new_device(wiiusb_hid_t *hid, int32_t id)
{ {
struct wiiusb_adapter *temp; struct wiiusb_adapter *temp;
if(!hid) if (!hid)
return false; /* false, so we do not proceed to add it */ return false; /* false, so we do not proceed to add it */
temp = hid->adapters_head; temp = hid->adapters_head;
@ -536,7 +536,7 @@ static int16_t wiiusb_hid_joypad_axis(void *data,
if (val >= 0) if (val >= 0)
val = 0; val = 0;
} }
else if(AXIS_POS_GET(joyaxis) < 4) else if (AXIS_POS_GET(joyaxis) < 4)
{ {
val = pad_connection_get_axis(&hid->connections[port], val = pad_connection_get_axis(&hid->connections[port],
port, AXIS_POS_GET(joyaxis)); port, AXIS_POS_GET(joyaxis));