mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
Fix analog for DS3, plus some cleanups
== DETAILS - DS3 analog wasn't working mainly because I forgot to actually declare the axes in input/input_autoconfig.c when declaring the pad. Whoops. - I also moved the axis decoding logic to a more central place, because it clearly is not Wii U specific. - Removed some dead commented-out code == TESTING Can use analog inputs on both GCA and DS3. Tested in Mario 3 on Nestopia core. Haven't tested with any actual analog games, but I did confirm via logging that the correct ranges are produced.
This commit is contained in:
parent
f7135bcee6
commit
1d84c0eca1
@ -198,6 +198,7 @@ OBJ += frontend/frontend.o \
|
||||
$(LIBRETRO_COMM_DIR)/hash/rhash.o \
|
||||
audio/audio_driver.o \
|
||||
$(LIBRETRO_COMM_DIR)/audio/audio_mixer.o \
|
||||
input/common/input_common.o \
|
||||
input/input_driver.o \
|
||||
input/input_mapper.o \
|
||||
led/led_driver.o \
|
||||
|
@ -50,15 +50,6 @@ ifeq ($(WIIU_HID),1)
|
||||
OBJ += wiiu/input/hidpad_driver.o
|
||||
OBJ += wiiu/input/wiiu_hid.o
|
||||
OBJ += input/connect/joypad_connection.o \
|
||||
input/connect/connect_ps2adapter.o \
|
||||
input/connect/connect_psxadapter.o \
|
||||
input/connect/connect_ps3.o \
|
||||
input/connect/connect_ps4.o \
|
||||
input/connect/connect_wii.o \
|
||||
input/connect/connect_nesusb.o \
|
||||
input/connect/connect_snesusb.o \
|
||||
input/connect/connect_wiiupro.o \
|
||||
input/connect/connect_wiiugca.o \
|
||||
input/common/hid/hid_device_driver.o \
|
||||
input/common/hid/device_wiiu_gca.o \
|
||||
input/common/hid/device_ds3.o \
|
||||
|
@ -25,6 +25,7 @@ typedef struct ds3_instance {
|
||||
int slot;
|
||||
bool led_set;
|
||||
uint32_t buttons;
|
||||
int16_t analog_state[3][2];
|
||||
uint16_t motors[2];
|
||||
uint8_t data[64];
|
||||
} ds3_instance_t;
|
||||
@ -68,17 +69,8 @@ static int control_packet_size = sizeof(control_packet);
|
||||
|
||||
extern pad_connection_interface_t ds3_pad_connection;
|
||||
|
||||
static void print_error(const char *fmt, int32_t errcode)
|
||||
{
|
||||
int16_t err1, err2;
|
||||
|
||||
err1 = errcode & 0x0000ffff;
|
||||
err2 = ((errcode & 0xffff0000) >> 16);
|
||||
|
||||
RARCH_ERR(fmt, err1, err2);
|
||||
}
|
||||
|
||||
static void update_pad_state(ds3_instance_t *instance);
|
||||
static void update_analog_state(ds3_instance_t *instance);
|
||||
|
||||
static int32_t send_activation_packet(ds3_instance_t *instance)
|
||||
{
|
||||
@ -93,8 +85,6 @@ static int32_t send_activation_packet(ds3_instance_t *instance)
|
||||
HID_SEND_CONTROL(instance->handle,
|
||||
activation_packet, sizeof(activation_packet));
|
||||
#endif
|
||||
if(result < 0)
|
||||
print_error("[ds3]: activation packet failed (%d:%d)\n", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -104,8 +94,6 @@ 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);
|
||||
if(result)
|
||||
print_error("[ds3]: set protocol failed (%d:%d)\n", result);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
@ -134,8 +122,6 @@ static int32_t send_control_packet(ds3_instance_t *instance)
|
||||
DS3_RUMBLE_REPORT_ID,
|
||||
packet_buffer+PACKET_OFFSET,
|
||||
control_packet_size-PACKET_OFFSET);
|
||||
if(result < 0)
|
||||
print_error("[ds3]: send control packet failed: (%d:%d)\n", result);
|
||||
#else
|
||||
HID_SEND_CONTROL(instance->handle,
|
||||
packet_buffer+PACKET_OFFSET,
|
||||
@ -157,10 +143,8 @@ static void *ds3_init(void *handle)
|
||||
instance->handle = handle;
|
||||
|
||||
RARCH_LOG("[ds3]: setting protocol\n");
|
||||
/*
|
||||
if(set_protocol(instance, 1))
|
||||
errors++;
|
||||
*/
|
||||
|
||||
/* this might fail, but we don't care. */
|
||||
set_protocol(instance, 1);
|
||||
|
||||
RARCH_LOG("[ds3]: sending control packet\n");
|
||||
@ -275,6 +259,22 @@ static void ds3_packet_handler(void *data, uint8_t *packet, uint16_t size)
|
||||
|
||||
memcpy(instance->data, packet, size);
|
||||
update_pad_state(instance);
|
||||
update_analog_state(instance);
|
||||
}
|
||||
|
||||
static void update_analog_state(ds3_instance_t *instance)
|
||||
{
|
||||
int pad_axis;
|
||||
int16_t interpolated;
|
||||
unsigned stick, axis;
|
||||
|
||||
for(pad_axis = 0; pad_axis < 4; pad_axis++)
|
||||
{
|
||||
axis = pad_axis % 2 ? 0 : 1;
|
||||
stick = pad_axis / 2;
|
||||
interpolated = instance->data[6+pad_axis];
|
||||
instance->analog_state[stick][axis] = (interpolated - 128) * 256;
|
||||
}
|
||||
}
|
||||
|
||||
static void update_pad_state(ds3_instance_t *instance)
|
||||
@ -318,17 +318,15 @@ static void ds3_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t
|
||||
|
||||
static int16_t ds3_get_axis(void *data, unsigned axis)
|
||||
{
|
||||
axis_data axis_data;
|
||||
ds3_instance_t *pad = (ds3_instance_t *)data;
|
||||
int16_t val;
|
||||
|
||||
if(!pad || axis >= 4)
|
||||
gamepad_read_axis_data(axis, &axis_data);
|
||||
|
||||
if(!pad || axis_data.axis >= 4)
|
||||
return 0;
|
||||
|
||||
val = pad->data[6+axis];
|
||||
// val = pad->data[7+axis];
|
||||
val = (val - 128) * 256;
|
||||
|
||||
return val;
|
||||
return gamepad_get_axis_value(pad->analog_state, &axis_data);
|
||||
}
|
||||
|
||||
static const char *ds3_get_name(void *data)
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "hid_device_driver.h"
|
||||
#include "../../../wiiu/input/wiiu_hid.h"
|
||||
|
||||
#ifdef WII
|
||||
static uint8_t activation_packet[] = { 0x01, 0x13 };
|
||||
@ -259,9 +258,7 @@ static void update_analog_state(gca_pad_t *pad)
|
||||
{
|
||||
int pad_axis;
|
||||
int16_t interpolated;
|
||||
int16_t stage1, stage2;
|
||||
unsigned stick, axis;
|
||||
uint8_t val;
|
||||
|
||||
/* 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
|
||||
@ -321,12 +318,12 @@ static int16_t wiiu_gca_get_axis(void *data, unsigned axis)
|
||||
|
||||
gca_pad_t *pad = (gca_pad_t *)data;
|
||||
|
||||
pad_functions.read_axis_data(axis, &axis_data);
|
||||
gamepad_read_axis_data(axis, &axis_data);
|
||||
|
||||
if(!pad || axis_data.axis >= 4)
|
||||
return 0;
|
||||
|
||||
return pad_functions.get_axis_value(axis_data.axis, pad->analog_state, axis_data.is_negative);
|
||||
return gamepad_get_axis_value(pad->analog_state, &axis_data);
|
||||
}
|
||||
|
||||
static const char *wiiu_gca_get_name(void *data)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "../../input_driver.h"
|
||||
#include "../../connect/joypad_connection.h"
|
||||
#include "../../include/hid_driver.h"
|
||||
#include "../../include/gamepad.h"
|
||||
#include "../../../verbosity.h"
|
||||
#include "../../../tasks/tasks_internal.h"
|
||||
|
||||
|
@ -20,8 +20,16 @@
|
||||
|
||||
#include "../input_driver.h"
|
||||
|
||||
typedef struct pad_connection_listener_interface {
|
||||
struct pad_connection_listener_interface {
|
||||
void (*connected)(unsigned port, input_device_driver_t *driver);
|
||||
} pad_connection_listener_t;
|
||||
};
|
||||
|
||||
typedef struct _axis_data {
|
||||
int32_t axis;
|
||||
bool is_negative;
|
||||
} axis_data;
|
||||
|
||||
void gamepad_read_axis_data(uint32_t axis, axis_data *data);
|
||||
int16_t gamepad_get_axis_value(int16_t state[3][2], axis_data *data);
|
||||
|
||||
#endif /* GAMEPAD_H__ */
|
||||
|
@ -267,7 +267,16 @@ DECL_BTN_EX(down, 5, "D-Pad Down") \
|
||||
DECL_BTN_EX(left, 6, "D-Pad left") \
|
||||
DECL_BTN_EX(right, 7, "D-Pad Right") \
|
||||
DECL_BTN_EX(r3, 15, "R3") \
|
||||
DECL_BTN_EX(l3, 14, "L3")
|
||||
DECL_BTN_EX(l3, 14, "L3") \
|
||||
DECL_AXIS_EX(l_x_plus, +1, "L Analog right") \
|
||||
DECL_AXIS_EX(l_x_minus, -1, "L Analog left") \
|
||||
DECL_AXIS_EX(l_y_plus, +0, "L Analog up") \
|
||||
DECL_AXIS_EX(l_y_minus, -0, "L Analog down") \
|
||||
DECL_AXIS_EX(r_x_plus, +3, "R Analog right") \
|
||||
DECL_AXIS_EX(r_x_minus, -3, "R Analog left") \
|
||||
DECL_AXIS_EX(r_y_plus, +2, "R Analog up") \
|
||||
DECL_AXIS_EX(r_y_minus, -2, "R Analog down")
|
||||
|
||||
|
||||
#define WIIUINPUT_GAMEPAD_DEFAULT_BINDS \
|
||||
DECL_BTN_EX(menu_toggle, 1, "Home") \
|
||||
|
@ -27,5 +27,6 @@ typedef struct {
|
||||
uint16_t analogs[8];
|
||||
} input_bits_t;
|
||||
typedef struct joypad_connection joypad_connection_t;
|
||||
typedef struct pad_connection_listener_interface pad_connection_listener_t;
|
||||
|
||||
#endif /* __INPUT_TYPES__H */
|
||||
|
@ -75,21 +75,8 @@ void wiiu_pad_set_axis_value(int16_t state[3][2], int16_t left_x, int16_t left_y
|
||||
state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y] = touch_y;
|
||||
}
|
||||
|
||||
|
||||
void wiiu_pad_read_axis_data(uint32_t axis, axis_data *data)
|
||||
{
|
||||
data->axis = AXIS_POS_GET(axis);
|
||||
data->is_negative = false;
|
||||
|
||||
if(data->axis >= AXIS_INVALID)
|
||||
{
|
||||
data->axis = AXIS_NEG_GET(axis);
|
||||
data->is_negative = true;
|
||||
}
|
||||
}
|
||||
|
||||
wiiu_pad_functions_t pad_functions = {
|
||||
wiiu_pad_get_axis_value,
|
||||
wiiu_pad_set_axis_value,
|
||||
wiiu_pad_read_axis_data,
|
||||
gamepad_read_axis_data,
|
||||
};
|
||||
|
@ -22,7 +22,6 @@ typedef struct wiiu_adapter wiiu_adapter_t;
|
||||
typedef struct wiiu_attach wiiu_attach_event;
|
||||
typedef struct _wiiu_event_list wiiu_event_list;
|
||||
typedef struct _wiiu_adapter_list wiiu_adapter_list;
|
||||
typedef struct _axis_data axis_data;
|
||||
typedef struct _wiiu_pad_functions wiiu_pad_functions_t;
|
||||
|
||||
#endif /* __WIIU_HID_TYPES__H */
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define __WIIU_INPUT__H
|
||||
|
||||
#include "wiiu_hid_types.h"
|
||||
#include "../../input/include/gamepad.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../../config.h"
|
||||
@ -56,11 +57,6 @@
|
||||
#define WIIU_ANALOG_FACTOR 0x7ff0
|
||||
#define WIIU_READ_STICK(stick) ((stick) * WIIU_ANALOG_FACTOR)
|
||||
|
||||
struct _axis_data {
|
||||
int32_t axis;
|
||||
bool is_negative;
|
||||
};
|
||||
|
||||
struct _wiiu_pad_functions {
|
||||
int16_t (*get_axis_value)(int32_t axis, int16_t state[3][2], bool is_negative);
|
||||
void (*set_axis_value)(int16_t state[3][2], int16_t left_x, int16_t left_y,
|
||||
|
Loading…
Reference in New Issue
Block a user