mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 06:32:48 +00:00
(Input HID) Cleanups/buildfixes
This commit is contained in:
parent
1b24c37919
commit
0003074cfe
@ -70,43 +70,44 @@ extern pad_connection_interface_t ds3_pad_connection;
|
||||
static void ds3_update_pad_state(ds3_instance_t *instance);
|
||||
static void ds3_update_analog_state(ds3_instance_t *instance);
|
||||
|
||||
#if defined(WIIU)
|
||||
static int32_t ds3_send_activation_packet(ds3_instance_t *instance)
|
||||
{
|
||||
int32_t result;
|
||||
#if defined(WIIU)
|
||||
result = HID_SET_REPORT(instance->handle,
|
||||
return HID_SET_REPORT(instance->handle,
|
||||
HID_REPORT_FEATURE,
|
||||
DS3_ACTIVATION_REPORT_ID,
|
||||
ds3_activation_packet,
|
||||
sizeof(ds3_activation_packet));
|
||||
#else
|
||||
HID_SEND_CONTROL(instance->handle,
|
||||
ds3_activation_packet, sizeof(ds3_activation_packet));
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static uint32_t set_protocol(ds3_instance_t *instance, int protocol)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
#if defined(WIIU)
|
||||
result = HID_SET_PROTOCOL(instance->handle, 1);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
return HID_SET_PROTOCOL(instance->handle, 1);
|
||||
}
|
||||
#else
|
||||
static int32_t ds3_send_activation_packet(ds3_instance_t *instance)
|
||||
{
|
||||
HID_SEND_CONTROL(instance->handle,
|
||||
ds3_activation_packet, sizeof(ds3_activation_packet));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t set_protocol(ds3_instance_t *instance, int protocol)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t ds3_send_control_packet(ds3_instance_t *instance)
|
||||
{
|
||||
/* TODO/FIXME - C89-incompatible */
|
||||
uint8_t packet_buffer[sizeof(ds3_control_packet)];
|
||||
int32_t result = 0;
|
||||
memcpy(packet_buffer, ds3_control_packet, sizeof(ds3_control_packet));
|
||||
|
||||
packet_buffer[LED_OFFSET] = 0;
|
||||
if(instance->pad) {
|
||||
if(instance->pad)
|
||||
packet_buffer[LED_OFFSET] = 1 << ((instance->slot % 4) + 1);
|
||||
}
|
||||
packet_buffer[MOTOR1_OFFSET] = instance->motors[1] >> 8;
|
||||
packet_buffer[MOTOR2_OFFSET] = instance->motors[0] >> 8;
|
||||
|
||||
@ -130,26 +131,25 @@ static int32_t ds3_send_control_packet(ds3_instance_t *instance)
|
||||
|
||||
static void *ds3_init(void *handle)
|
||||
{
|
||||
ds3_instance_t *instance;
|
||||
int errors = 0;
|
||||
RARCH_LOG("[ds3]: init\n");
|
||||
instance = (ds3_instance_t *)calloc(1, sizeof(ds3_instance_t));
|
||||
if(!instance)
|
||||
goto error;
|
||||
ds3_isntance_t *instance = (ds3_instance_t *)
|
||||
malloc(sizeof(ds3_instance_t));
|
||||
if (!instance)
|
||||
return NULL;
|
||||
|
||||
memset(instance, 0, sizeof(ds3_instance_t));
|
||||
instance->handle = handle;
|
||||
|
||||
RARCH_LOG("[ds3]: setting protocol\n");
|
||||
/* Setting protocol */
|
||||
|
||||
/* this might fail, but we don't care. */
|
||||
set_protocol(instance, 1);
|
||||
|
||||
RARCH_LOG("[ds3]: sending control packet\n");
|
||||
/* Sending control packet.. */
|
||||
if(ds3_send_control_packet(instance) < 0)
|
||||
errors++;
|
||||
|
||||
RARCH_LOG("[ds3]: sending activation packet\n");
|
||||
/* Sending activation packet.. */
|
||||
if(ds3_send_activation_packet(instance) < 0)
|
||||
errors++;
|
||||
|
||||
@ -160,11 +160,9 @@ static void *ds3_init(void *handle)
|
||||
if(!instance->pad)
|
||||
goto error;
|
||||
|
||||
RARCH_LOG("[ds3]: init complete.\n");
|
||||
return instance;
|
||||
|
||||
error:
|
||||
RARCH_ERR("[ds3]: init failed.\n");
|
||||
error:
|
||||
if(instance)
|
||||
free(instance);
|
||||
return NULL;
|
||||
@ -218,9 +216,9 @@ static void *ds3_pad_init(void *data, uint32_t slot, hid_driver_t *driver)
|
||||
static void ds3_pad_deinit(void *data)
|
||||
{
|
||||
ds3_instance_t *pad = (ds3_instance_t *)data;
|
||||
if(pad) {
|
||||
input_autoconfigure_disconnect(pad->slot, ds3_pad_connection.get_name(pad));
|
||||
}
|
||||
if(pad)
|
||||
input_autoconfigure_disconnect(pad->slot,
|
||||
ds3_pad_connection.get_name(pad));
|
||||
}
|
||||
|
||||
static void ds3_get_buttons(void *data, input_bits_t *state)
|
||||
@ -233,7 +231,9 @@ static void ds3_get_buttons(void *data, input_bits_t *state)
|
||||
|
||||
if(pad->buttons & 0x10000)
|
||||
BIT256_SET_PTR(state, RARCH_MENU_TOGGLE);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
BIT256_CLEAR_ALL_PTR(state);
|
||||
}
|
||||
}
|
||||
@ -302,14 +302,17 @@ static void ds3_update_pad_state(ds3_instance_t *instance)
|
||||
|
||||
instance->buttons = 0;
|
||||
|
||||
pressed_keys = instance->data[2]|(instance->data[3] << 8)|((instance->data[4] & 0x01) << 16);
|
||||
pressed_keys = instance->data[2] |
|
||||
(instance->data[3] << 8) |
|
||||
((instance->data[4] & 0x01) << 16);
|
||||
|
||||
for(i = 0; i < 17; i++)
|
||||
instance->buttons |= (pressed_keys & (1 << i)) ?
|
||||
(1 << button_mapping[i]) : 0;
|
||||
}
|
||||
|
||||
static void ds3_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t strength)
|
||||
static void ds3_set_rumble(void *data,
|
||||
enum retro_rumble_effect effect, uint16_t strength)
|
||||
{
|
||||
ds3_instance_t *pad = (ds3_instance_t *)data;
|
||||
}
|
||||
@ -336,12 +339,10 @@ static const char *ds3_get_name(void *data)
|
||||
static int16_t ds3_button(void *data, uint16_t joykey)
|
||||
{
|
||||
ds3_instance_t *pad = (ds3_instance_t *)data;
|
||||
|
||||
if (!pad)
|
||||
return 0;
|
||||
if (joykey < 31)
|
||||
if (pad->buttons & (1 << joykey))
|
||||
ret |= (1 << joykey);
|
||||
return (pad->buttons & (1 << joykey));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,8 @@
|
||||
|
||||
extern pad_connection_interface_t ds4_pad_connection;
|
||||
|
||||
typedef struct ds4_instance {
|
||||
typedef struct ds4_instance
|
||||
{
|
||||
void *handle;
|
||||
joypad_connection_t *pad;
|
||||
int slot;
|
||||
@ -37,43 +38,40 @@ typedef struct ds4_instance {
|
||||
*/
|
||||
static void *ds4_init(void *handle)
|
||||
{
|
||||
ds4_instance_t *instance;
|
||||
instance = (ds4_instance_t *)calloc(1, sizeof(ds4_instance_t));
|
||||
if(!instance)
|
||||
goto error;
|
||||
ds4_instance_t *instance = (ds4_instance_t *)
|
||||
malloc(sizeof(ds4_instance_t));
|
||||
if (!instance)
|
||||
return NULL;
|
||||
|
||||
memset(instance, 0, sizeof(ds4_instance_t));
|
||||
instance->handle = handle;
|
||||
instance->pad = hid_pad_register(instance, &ds4_pad_connection);
|
||||
if(!instance->pad)
|
||||
goto error;
|
||||
|
||||
RARCH_LOG("[ds4]: init complete.\n");
|
||||
return instance;
|
||||
|
||||
error:
|
||||
RARCH_ERR("[ds4]: init failed.\n");
|
||||
if(instance)
|
||||
if (!instance->pad)
|
||||
{
|
||||
free(instance);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void ds4_free(void *data)
|
||||
{
|
||||
ds4_instance_t *instance = (ds4_instance_t *)data;
|
||||
|
||||
if(instance) {
|
||||
if (!instance)
|
||||
return;
|
||||
|
||||
hid_pad_deregister(instance->pad);
|
||||
free(instance);
|
||||
}
|
||||
}
|
||||
|
||||
static void ds4_handle_packet(void *data, uint8_t *buffer, size_t size)
|
||||
{
|
||||
ds4_instance_t *instance = (ds4_instance_t *)data;
|
||||
|
||||
if(instance && instance->pad)
|
||||
if (instance && instance->pad)
|
||||
instance->pad->iface->packet_handler(instance->pad->data, buffer, size);
|
||||
}
|
||||
|
||||
@ -94,53 +92,28 @@ static void *ds4_pad_init(void *data, uint32_t slot, hid_driver_t *driver)
|
||||
{
|
||||
ds4_instance_t *instance = (ds4_instance_t *)data;
|
||||
|
||||
if(!instance)
|
||||
if (!instance)
|
||||
return NULL;
|
||||
|
||||
instance->slot = slot;
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void ds4_pad_deinit(void *data)
|
||||
{
|
||||
}
|
||||
|
||||
static void ds4_get_buttons(void *data, input_bits_t *state)
|
||||
{
|
||||
ds4_instance_t *instance = (ds4_instance_t *)data;
|
||||
if(!instance)
|
||||
return;
|
||||
|
||||
/* TODO: get buttons */
|
||||
}
|
||||
|
||||
static void ds4_packet_handler(void *data, uint8_t *packet, uint16_t size)
|
||||
{
|
||||
ds4_instance_t *instance = (ds4_instance_t *)data;
|
||||
if(!instance)
|
||||
if (!instance)
|
||||
return;
|
||||
|
||||
RARCH_LOG_BUFFER(packet, size);
|
||||
}
|
||||
|
||||
static void ds4_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t strength)
|
||||
{
|
||||
}
|
||||
|
||||
static int16_t ds4_get_axis(void *data, unsigned axis)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *ds4_get_name(void *data)
|
||||
{
|
||||
return "Sony DualShock 4";
|
||||
}
|
||||
|
||||
static int16_t ds4_button(void *data, uint16_t joykey)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static void ds4_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t strength) { }
|
||||
static int16_t ds4_get_axis(void *data, unsigned axis) { return 0; }
|
||||
static const char *ds4_get_name(void *data) { return "Sony DualShock 4"; }
|
||||
static int16_t ds4_button(void *data, uint16_t joykey) { return 0; }
|
||||
static void ds4_pad_deinit(void *data) { }
|
||||
static void ds4_get_buttons(void *data, input_bits_t *state) { }
|
||||
|
||||
pad_connection_interface_t ds4_pad_connection = {
|
||||
ds4_pad_init,
|
||||
|
@ -48,11 +48,12 @@ joypad_connection_t *hid_pad_register(
|
||||
int slot;
|
||||
joypad_connection_t *result;
|
||||
|
||||
if(!pad_handle)
|
||||
if (!pad_handle)
|
||||
return NULL;
|
||||
|
||||
slot = pad_connection_find_vacant_pad(hid_instance.pad_list);
|
||||
if(slot < 0)
|
||||
|
||||
if (slot < 0)
|
||||
{
|
||||
RARCH_ERR("[hid]: failed to find a vacant pad.\n");
|
||||
return NULL;
|
||||
@ -69,10 +70,10 @@ joypad_connection_t *hid_pad_register(
|
||||
|
||||
void hid_pad_deregister(joypad_connection_t *pad)
|
||||
{
|
||||
if(!pad)
|
||||
if (!pad)
|
||||
return;
|
||||
|
||||
if(pad->data)
|
||||
if (pad->data)
|
||||
{
|
||||
pad->iface->deinit(pad->data);
|
||||
pad->data = NULL;
|
||||
@ -84,15 +85,15 @@ void hid_pad_deregister(joypad_connection_t *pad)
|
||||
|
||||
static bool init_pad_list(hid_driver_instance_t *instance, unsigned slots)
|
||||
{
|
||||
if(!instance || slots > MAX_USERS)
|
||||
if (!instance || slots > MAX_USERS)
|
||||
return false;
|
||||
|
||||
if(instance->pad_list)
|
||||
if (instance->pad_list)
|
||||
return true;
|
||||
|
||||
RARCH_LOG("[hid]: initializing pad list...\n");
|
||||
/* Initializing pad list.. */
|
||||
instance->pad_list = pad_connection_init(slots);
|
||||
if(!instance->pad_list)
|
||||
if (!instance->pad_list)
|
||||
return false;
|
||||
|
||||
instance->max_slot = slots;
|
||||
@ -115,27 +116,25 @@ bool hid_init(hid_driver_instance_t *instance,
|
||||
input_device_driver_t *pad_driver,
|
||||
unsigned slots)
|
||||
{
|
||||
RARCH_LOG("[hid]: initializing instance with %d pad slots\n", slots);
|
||||
if(!instance || !hid_driver || !pad_driver || slots > MAX_USERS)
|
||||
void *os_driver_data = NULL;
|
||||
if (!instance || !hid_driver || !pad_driver || slots > MAX_USERS)
|
||||
return false;
|
||||
|
||||
RARCH_LOG("[hid]: initializing HID subsystem driver...\n");
|
||||
instance->os_driver_data = hid_driver->init();
|
||||
if(!instance->os_driver_data)
|
||||
/* Initializing HID subsystem driver */
|
||||
os_driver_data = hid_driver->init();
|
||||
if (!os_driver_data)
|
||||
return false;
|
||||
|
||||
if(!init_pad_list(instance, slots))
|
||||
if (!init_pad_list(instance, slots))
|
||||
{
|
||||
hid_driver->free(instance->os_driver_data);
|
||||
instance->os_driver_data = NULL;
|
||||
hid_driver->free(os_driver_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
instance->os_driver_data = os_driver_data;
|
||||
instance->os_driver = hid_driver;
|
||||
instance->pad_driver = pad_driver;
|
||||
|
||||
RARCH_LOG("[hid]: instance initialization complete.\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -146,20 +145,15 @@ bool hid_init(hid_driver_instance_t *instance,
|
||||
*/
|
||||
void hid_deinit(hid_driver_instance_t *instance)
|
||||
{
|
||||
if(!instance)
|
||||
if (!instance)
|
||||
return;
|
||||
|
||||
RARCH_LOG("[hid]: destroying instance\n");
|
||||
|
||||
if(instance->os_driver && instance->os_driver_data)
|
||||
{
|
||||
RARCH_LOG("[hid]: tearing down HID subsystem driver...\n");
|
||||
if (instance->os_driver && instance->os_driver_data)
|
||||
instance->os_driver->free(instance->os_driver_data);
|
||||
}
|
||||
|
||||
RARCH_LOG("[hid]: destroying pad data...\n");
|
||||
/* Destroying pad data.. */
|
||||
pad_connection_destroy(instance->pad_list);
|
||||
|
||||
RARCH_LOG("[hid]: wiping instance data...\n");
|
||||
/* Wiping instance data.. */
|
||||
memset(instance, 0, sizeof(hid_driver_instance_t));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user