From 78e7d23c144c862d65ae1bf7ee41a1228bdfa380 Mon Sep 17 00:00:00 2001 From: revvv <8734113+revvv@users.noreply.github.com> Date: Sat, 26 Mar 2022 16:09:12 +0100 Subject: [PATCH] Fix USB gamepad support 1. get_axis() didn't use AXIS_NEG_GET() / AXIS_POS_GET() 2. packet_handler() needs byte shift 3. log messages need SWAP_IF_BIG() --- input/drivers_hid/wiiu_hid.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index b86dcf7bbb..e8f1a5b9b3 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -14,6 +14,7 @@ * If not, see . */ +#include #include "../include/wiiu/hid.h" #include #include @@ -83,7 +84,21 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned slot, uint32_t joyaxis) if (!pad) return 0; - return pad->iface->get_axis(pad->connection, joyaxis); + if (AXIS_NEG_GET(joyaxis) < 4) + { + int16_t val = pad->iface->get_axis(pad->connection, AXIS_NEG_GET(joyaxis)); + + if (val < 0) + return val; + } + else if (AXIS_POS_GET(joyaxis) < 4) + { + int16_t val = pad->iface->get_axis(pad->connection, AXIS_POS_GET(joyaxis)); + + if (val > 0) + return val; + } + return 0; } static int16_t wiiu_hid_joypad_state( @@ -385,8 +400,8 @@ static void log_device(HIDDevice *device) RARCH_LOG(" handle: %d\n", device->handle); RARCH_LOG(" physical_device_inst: %d\n", device->physical_device_inst); - RARCH_LOG(" vid: 0x%x\n", device->vid); - RARCH_LOG(" pid: 0x%x\n", device->pid); + RARCH_LOG(" vid: 0x%04x\n", SWAP_IF_BIG(device->vid)); + RARCH_LOG(" pid: 0x%04x\n", SWAP_IF_BIG(device->pid)); RARCH_LOG(" interface_index: %d\n", device->interface_index); RARCH_LOG(" sub_class: %d\n", device->sub_class); RARCH_LOG(" protocol: %d\n", device->protocol); @@ -411,9 +426,11 @@ static uint8_t try_init_driver(wiiu_adapter_t *adapter) entry = find_connection_entry(adapter->vendor_id, adapter->product_id, adapter->device_name); if(!entry) { - RARCH_LOG("Failed to find entry for vid: 0x%x, pid: 0x%x, name: %s\n", adapter->vendor_id, adapter->product_id, adapter->device_name); + RARCH_LOG("Failed to find entry for vid: 0x%04x, pid: 0x%04x, name: %s\n", SWAP_IF_BIG(adapter->vendor_id), SWAP_IF_BIG(adapter->product_id), adapter->device_name); return ADAPTER_STATE_DONE; } + else + RARCH_LOG("Found entry for: vid: 0x%04x, pid: 0x%04x, name: %s\n", SWAP_IF_BIG(adapter->vendor_id), SWAP_IF_BIG(adapter->product_id), adapter->device_name); adapter->pad_driver = entry->iface; @@ -607,7 +624,10 @@ static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error, if (error == 0) { - adapter->pad_driver->packet_handler(adapter->pad_driver_data, buffer, buffer_size); + /* NOTE: packet_handler() expects that packet[1] is the first byte, so added -1. + * The Wii version puts the slot number in packet[0], which is not possible here: + * packet[0] is undefined! */ + adapter->pad_driver->packet_handler(adapter->pad_driver_data, buffer-1, buffer_size+1); } } }