Skip to content

Commit

Permalink
Fix USB gamepad support
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
revvv authored and inactive123 committed Mar 27, 2022
1 parent b6ae697 commit 78e7d23
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions input/drivers_hid/wiiu_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <retro_endianness.h>
#include "../include/wiiu/hid.h"
#include <wiiu/os/atomic.h>
#include <string/stdstring.h>
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 78e7d23

Please sign in to comment.