More fixes, GC pad kinda sorta works

== DETAILS

- Added a new method to the joypad_connection_t interface for
  getting a single button
- wired everything into the hidpad driver
- for testing purposes, hacking the top-level joypad driver
  so that kpad isn't used
- add a new RARCH_LOG_BUFFER method to verbosity for logging the
  contents of a binary buffer (useful for writing/debugging pad drivers)
- fix a few bugs in the wiiu GC pad driver

The button mapping isn't quite right, and I'm not sure what's
going wrong.
This commit is contained in:
gblues 2018-03-29 23:33:31 -07:00
parent 89c1ba7929
commit 5060c2aac4
9 changed files with 160 additions and 110 deletions

View File

@ -101,6 +101,8 @@ static void wiiu_gca_handle_packet(void *data, uint8_t *buffer, size_t size)
return;
}
//RARCH_LOG_BUFFER(buffer, size);
memcpy(instance->device_state, buffer, size);
update_pad_state(instance);
}
@ -239,6 +241,29 @@ static void wiiu_gca_get_buttons(void *data, retro_bits_t *state)
}
}
static void log_bitmask(uint32_t bits)
{
char buf[33];
int i;
for(i = 0; i < 32; i++)
{
buf[i] = (bits & (1 << i)) ? '1' : '0';
}
buf[32] = '\0';
RARCH_LOG("pressed_keys: %s\n", buf);
}
/**
* The USB packet provides a 9-byte data packet for each pad.
*
* byte 0: connection status (0x14 = connected, 0x04 = disconnected)
* bytes 1-2: digital buttons
* bytes 3-4: left analog stick x/y
* bytes 5-6: right analog stick x/y
* bytes 7-8: L/R analog state (note that these have digital buttons too)
*/
static void wiiu_gca_packet_handler(void *data, uint8_t *packet, uint16_t size)
{
gca_pad_t *pad = (gca_pad_t *)data;
@ -263,9 +288,13 @@ static void wiiu_gca_packet_handler(void *data, uint8_t *packet, uint16_t size)
if(!pad || !packet || size > sizeof(pad->data))
return;
/* RARCH_LOG_BUFFER(packet, size); */
memcpy(pad->data, packet, size);
pad->buttons = 0;
pressed_keys = pad->data[3] | (pad->data[4] << 8);
pressed_keys = pad->data[1] | (pad->data[2] << 8);
log_bitmask(pressed_keys);
for(i = 0; i < 12; i++)
{
@ -289,7 +318,7 @@ static int16_t wiiu_gca_get_axis(void *data, unsigned axis)
if(!pad || axis >= 4)
return 0;
val = pad->data[5+axis];
val = pad->data[3+axis];
switch(axis)
{
@ -309,13 +338,23 @@ static int16_t wiiu_gca_get_axis(void *data, unsigned axis)
return val;
}
const char *wiiu_gca_get_name(void *data)
static const char *wiiu_gca_get_name(void *data)
{
gca_pad_t *pad = (gca_pad_t *)data;
return "GameCube Controller";
}
static bool wiiu_gca_button(void *data, uint16_t joykey)
{
gca_pad_t *pad = (gca_pad_t *)data;
if(!pad)
return false;
return (pad->buttons & joykey);
}
pad_connection_interface_t wiiu_gca_pad_connection = {
wiiu_gca_pad_init,
wiiu_gca_pad_deinit,
@ -323,5 +362,6 @@ pad_connection_interface_t wiiu_gca_pad_connection = {
wiiu_gca_set_rumble,
wiiu_gca_get_buttons,
wiiu_gca_get_axis,
wiiu_gca_get_name
wiiu_gca_get_name,
wiiu_gca_button
};

View File

@ -61,6 +61,7 @@ typedef struct pad_connection_interface
void (*get_buttons)(void *data, retro_bits_t *state);
int16_t (*get_axis)(void *data, unsigned axis);
const char* (*get_name)(void *data);
bool (*button)(void *data, uint16_t joykey);
} pad_connection_interface_t;
typedef struct joypad_connection joypad_connection_t;

View File

@ -40,9 +40,10 @@ static input_device_driver_t *get_driver_for_pad(unsigned pad)
{
if(wpad_driver.query_pad(pad))
return &wpad_driver;
/*
if(kpad_driver.query_pad(pad))
return &kpad_driver;
*/
#ifdef WIIU_HID
return &hidpad_driver;
#else
@ -84,11 +85,7 @@ static bool wiiu_joypad_init(void* data)
static bool wiiu_joypad_query_pad(unsigned pad)
{
#ifdef WIIU_HID
return ready && pad < MAX_USERS;
#else
return ready && pad < 5;
#endif
}
static void wiiu_joypad_destroy(void)
@ -138,7 +135,7 @@ static void wiiu_joypad_poll(void)
static const char* wiiu_joypad_name(unsigned pad)
{
if(!wiiu_joypad_query_pad(pad))
return "N/A";
return "Snuffleupagus";
return pad_drivers[pad]->name(pad);
}

View File

@ -52,6 +52,19 @@ struct hid_driver
int32_t (*read)(void *handle, void *buf, size_t size);
};
#define HID_GET_BUTTONS(pad, state) hid_instance.os_driver->get_buttons( \
hid_instance.os_driver_data, pad, state)
#define HID_BUTTON(pad, key) hid_instance.os_driver->button( \
hid_instance.os_driver_data, pad, key)
#define HID_AXIS(pad, axis) hid_instance.os_driver->axis( \
hid_instance.os_driver_data, pad, axis)
#define HID_PAD_NAME(pad) hid_instance.os_driver->name( \
hid_instance.os_driver_data, pad)
#define HID_POLL() hid_instance.os_driver->poll( \
hid_instance.os_driver_data)
struct hid_driver_instance {
hid_driver_t *os_driver;
void *os_driver_data;

View File

@ -228,6 +228,20 @@ DECL_AXIS(r_y_minus, +3)
#ifdef WIIU
#define WIIUINPUT_GAMECUBE_DEFAULT_BINDS \
DECL_BTN_EX(b, 0, "B") \
DECL_BTN_EX(y, 1, "Y") \
DECL_BTN_EX(select, 2, "Z") \
DECL_BTN_EX(start, 3, "Start/Pause") \
DECL_BTN_EX(up, 4, "D-Pad Up") \
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(a, 8, "A") \
DECL_BTN_EX(x, 9, "X") \
DECL_BTN_EX(l, 10, "L") \
DECL_BTN_EX(r, 11, "R")
#define WIIUINPUT_GAMEPAD_DEFAULT_BINDS \
DECL_BTN_EX(menu_toggle, 1, "Home") \
DECL_BTN_EX(select, 2, "-") \

View File

@ -193,6 +193,37 @@ void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap)
#endif
}
void RARCH_LOG_BUFFER(uint8_t *data, size_t size)
{
int i, offset;
int padding = size % 16;
uint8_t buf[16];
RARCH_LOG("== %d-byte buffer ==================\n", size);
for(i = 0, offset = 0; i < size; i++)
{
buf[offset] = data[i];
offset++;
if(offset == 16)
{
offset = 0;
RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
}
}
if(padding)
{
for(i = padding; i < 16; i++)
buf[i] = 0xff;
RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
}
RARCH_LOG("==================================\n");
}
void RARCH_LOG(const char *fmt, ...)
{
va_list ap;

View File

@ -86,7 +86,7 @@ void logger_send_v(const char *__format, va_list args);
logger_send_v(fmt, vp); \
} while (0)
#else
#else /* IS_SALAMANDER */
#define RARCH_LOG(...) do { \
logger_send("" __VA_ARGS__); \
@ -123,11 +123,14 @@ void logger_send_v(const char *__format, va_list args);
logger_send("[OUTPUT] " tag); \
logger_send_v(fmt, vp); \
} while (0)
#endif
#else
#define RARCH_LOG_BUFFER(...) do { } while(0)
#else /* HAVE_LOGGER */
void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap);
void RARCH_LOG(const char *fmt, ...);
void RARCH_LOG_BUFFER(uint8_t *buffer, size_t size);
void RARCH_LOG_OUTPUT(const char *msg, ...);
void RARCH_WARN(const char *fmt, ...);
void RARCH_ERR(const char *fmt, ...);
@ -135,7 +138,7 @@ void RARCH_ERR(const char *fmt, ...);
#define RARCH_LOG_OUTPUT_V RARCH_LOG_V
#define RARCH_WARN_V RARCH_LOG_V
#define RARCH_ERR_V RARCH_LOG_V
#endif
#endif /* HAVE_LOGGER */
RETRO_END_DECLS

View File

@ -47,13 +47,13 @@ static bool hidpad_init(void *data)
return false;
}
/* hid_instance.pad_list[0].connected = true; */
hid_instance.pad_list[0].connected = true;
/*
for(i = 0; i < (WIIU_WIIMOTE_CHANNELS+1); i++)
{
hid_instance.pad_list[i].connected = true;
}
*/
hidpad_poll();
ready = true;
@ -63,7 +63,7 @@ static bool hidpad_init(void *data)
static bool hidpad_query_pad(unsigned pad)
{
return ready && (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS);
return ready && pad < MAX_USERS;
}
static void hidpad_destroy(void)
@ -78,11 +78,7 @@ static bool hidpad_button(unsigned pad, uint16_t button)
if (!hidpad_query_pad(pad))
return false;
#if 0
return hid_driver->button(hid_data, pad, button);
#else
return false;
#endif
return HID_BUTTON(pad, button);
}
static void hidpad_get_buttons(unsigned pad, retro_bits_t *state)
@ -90,10 +86,7 @@ static void hidpad_get_buttons(unsigned pad, retro_bits_t *state)
if (!hidpad_query_pad(pad))
BIT256_CLEAR_ALL_PTR(state);
#if 0
hid_driver->get_buttons(hid_data, pad, state);
#endif
BIT256_CLEAR_ALL_PTR(state);
HID_GET_BUTTONS(pad, state);
}
static int16_t hidpad_axis(unsigned pad, uint32_t axis)
@ -101,17 +94,13 @@ static int16_t hidpad_axis(unsigned pad, uint32_t axis)
if (!hidpad_query_pad(pad));
return 0;
#if 0
return hid_driver->axis(hid_data, pad, axis);
#else
return 0;
#endif
return HID_AXIS(pad, axis);
}
static void hidpad_poll(void)
{
if (ready)
hid_instance.os_driver->poll(hid_instance.os_driver_data);
HID_POLL();
}
static const char *hidpad_name(unsigned pad)
@ -119,11 +108,7 @@ static const char *hidpad_name(unsigned pad)
if (!hidpad_query_pad(pad))
return "N/A";
#if 1
return PAD_NAME_HID;
#else
return hid_driver->name(hid_data, pad);
#endif
return HID_PAD_NAME(pad);
}
input_device_driver_t hidpad_driver =

View File

@ -19,8 +19,6 @@
static wiiu_event_list events;
static wiiu_adapter_list adapters;
static void log_buffer(uint8_t *data, uint32_t len);
static bool wiiu_hid_joypad_query(void *data, unsigned slot)
{
wiiu_hid_t *hid = (wiiu_hid_t *)data;
@ -30,51 +28,66 @@ static bool wiiu_hid_joypad_query(void *data, unsigned slot)
return slot < hid->driver->max_slot;
}
static const char *wiiu_hid_joypad_name(void *data, unsigned slot)
static joypad_connection_t *get_pad(wiiu_hid_t *hid, unsigned slot)
{
if (!wiiu_hid_joypad_query(data, slot))
if(!wiiu_hid_joypad_query(hid, slot))
return NULL;
wiiu_hid_t *hid = (wiiu_hid_t *)data;
joypad_connection_t *result = &(hid->driver->pad_list[slot]);
if(!result || !result->connected || !result->iface || !result->data)
return NULL;
return hid->driver->pad_list[slot].iface->get_name(data);
return result;
}
static void wiiu_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
static const char *wiiu_hid_joypad_name(void *data, unsigned slot)
{
(void)data;
(void)port;
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
BIT256_CLEAR_ALL_PTR(state);
if(!pad)
return NULL;
return pad->iface->get_name(pad->data);
}
static bool wiiu_hid_joypad_button(void *data, unsigned port, uint16_t joykey)
static void wiiu_hid_joypad_get_buttons(void *data, unsigned slot, retro_bits_t *state)
{
(void)data;
(void)port;
(void)joykey;
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
return false;
if(pad)
pad->iface->get_buttons(pad->data, state);
}
static bool wiiu_hid_joypad_rumble(void *data, unsigned pad,
static bool wiiu_hid_joypad_button(void *data, unsigned slot, uint16_t joykey)
{
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if(!pad)
return false;
return pad->iface->button(pad->data, joykey);
}
static bool wiiu_hid_joypad_rumble(void *data, unsigned slot,
enum retro_rumble_effect effect, uint16_t strength)
{
(void)data;
(void)pad;
(void)effect;
(void)strength;
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if(!pad)
return false;
pad->iface->set_rumble(pad->data, effect, strength);
return false;
}
static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis)
static int16_t wiiu_hid_joypad_axis(void *data, unsigned slot, uint32_t joyaxis)
{
(void)data;
(void)port;
(void)joyaxis;
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
return 0;
if(!pad)
return 0;
return pad->iface->get_axis(pad->data, joyaxis);
}
static void *wiiu_hid_init(hid_driver_instance_t *driver)
@ -464,53 +477,6 @@ void wiiu_start_read_loop(wiiu_adapter_t *adapter)
adapter);
}
/**
* Takes a buffer and formats it for the log file, 16 bytes per line.
*
* When the end of the buffer is reached, it is padded out with 0xff. So e.g.
* a 5-byte buffer might look like:
*
* 5 bytes read fro HIDRead:
* 0102030405ffffff ffffffffffffffff
* ==================================
*/
static void log_buffer(uint8_t *data, uint32_t len)
{
int i, o;
int padding = len % 16;
uint8_t buf[16];
(uint8_t *)data;
(uint32_t)len;
RARCH_LOG("%d bytes read from HIDRead:\n", len);
for(i = 0, o = 0; i < len; i++)
{
buf[o] = data[i];
o++;
if(o == 16)
{
o = 0;
RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
}
}
if(padding)
{
for(i = padding; i < 16; i++)
buf[i] = 0xff;
RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
}
RARCH_LOG("==================================\n");
}
static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error,
uint8_t *buffer, uint32_t buffer_size, void *userdata)
{