Add Libusb to cmake and HID files.

This commit is contained in:
Matthew Parlane 2012-12-24 12:58:11 +13:00
parent c626d5aae3
commit d9dd94ac8b
5 changed files with 89 additions and 23 deletions

View file

@ -414,6 +414,16 @@ else(SDL2_FOUND)
endif(SDL_FOUND)
endif(SDL2_FOUND)
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include(FindLibUSB OPTIONAL)
endif()
if(LIBUSB_FOUND)
message("Using shared LibUSB")
include_directories(${LIBUSB_INCLUDE_DIR})
else(LIBUSB_FOUND)
endif(LIBUSB_FOUND)
set(SFML_FIND_VERSION TRUE)
set(SFML_FIND_VERSION_MAJOR 1)
set(SFML_FIND_VERSION_MINOR 5)

View file

@ -0,0 +1,39 @@
# - Find libusb-1.0 library
# This module defines
# LIBUSB_INCLUDE_DIR, where to find bluetooth.h
# LIBUSB_LIBRARIES, the libraries needed to use libusb-1.0.
# LIBUSB_FOUND, If false, do not try to use libusb-1.0.
#
# Copyright (c) 2009, Michal Cihar, <michal@cihar.com>
#
# vim: expandtab sw=4 ts=4 sts=4:
if (NOT LIBUSB_FOUND)
pkg_check_modules (LIBUSB_PKG libusb-1.0)
find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h
PATHS
${LIBUSB_PKG_INCLUDE_DIRS}
/usr/include/libusb-1.0
/usr/include
/usr/local/include
)
find_library(LIBUSB_LIBRARIES NAMES usb-1.0
PATHS
${LIBUSB_PKG_LIBRARY_DIRS}
/usr/lib
/usr/local/lib
)
if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
set(LIBUSB_FOUND TRUE CACHE INTERNAL "libusb-1.0 found")
message(STATUS "Found libusb-1.0: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARIES}")
else(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found")
message(STATUS "libusb-1.0 not found.")
endif(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)
endif (NOT LIBUSB_FOUND)

View file

@ -138,6 +138,7 @@ set(SRCS Src/ActionReplay.cpp
Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp
Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp
Src/IPC_HLE/WII_IPC_HLE_Device_hid.cpp
Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp
Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp
Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp
@ -194,6 +195,12 @@ set(SRCS Src/ActionReplay.cpp
set(LIBS bdisasm inputcommon videoogl videosoftware sfml-network)
if(LIBUSB_FOUND)
# Using shared LibUSB
set(LIBS ${LIBS} ${LIBUSB_LIBRARIES})
endif(LIBUSB_FOUND)
if(WIN32)
set(SRCS ${SRCS} Src/HW/BBA-TAP/TAP_Win32.cpp Src/stdafx.cpp
Src/HW/WiimoteReal/IOWin.cpp)

View file

@ -64,7 +64,7 @@ bool CWII_IPC_HLE_Device_hid::Close(u32 _CommandAddress, bool _bForce)
u32 CWII_IPC_HLE_Device_hid::Update()
{
u32 work_done = 0;
int ret = -4;
//int ret = -4;
//timeval tv;
@ -214,16 +214,15 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
case IOCTL_HID_INTERRUPT_OUT:
case IOCTL_HID_INTERRUPT_IN:
{
int transfered = 0;
u32 dev_num = Memory::Read_U32(BufferIn+0x10);
u32 endpoint = Memory::Read_U32(BufferIn+0x14);
u32 length = Memory::Read_U32(BufferIn+0x18);
u32 data = Memory::Read_U32(BufferIn+0x1C);
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt %s)(%d,%d,%p) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt %s)(%d,%d,%X) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
Parameter == IOCTL_HID_INTERRUPT_IN ? "In" : "Out", endpoint, length, data, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
int ret = 0;
void * context = NULL;
ReturnValue = -4;
libusb_device_handle * dev_handle = GetDeviceByDevNum(dev_num);
@ -233,7 +232,6 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
ReturnValue = -4;
goto int_in_end_print;
}
int transfered = 0;
if(libusb_interrupt_transfer(dev_handle, endpoint, (unsigned char*)Memory::GetPointer(data), length, &transfered, 0 ) == 0)
{
@ -251,7 +249,7 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
int_in_end_print:
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt %s)(%d,%d,%p) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt %s)(%d,%d,%X) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
Parameter == IOCTL_HID_INTERRUPT_IN ? "In" : "Out", endpoint, length, data, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
break;
@ -333,11 +331,11 @@ void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize)
{
int OffsetBuffer = BufferOut;
int OffsetStart = 0;
int OffsetDevice = 0;
int d, c,ic,i,e; /* config, interface container, interface, endpoint */
//int OffsetDevice = 0;
int d,c,ic,i,e; /* config, interface container, interface, endpoint */
libusb_device **list;
libusb_device *found = NULL;
//libusb_device *found = NULL;
ssize_t cnt = libusb_get_device_list(NULL, &list);
for (d = 0; d < cnt; d++)
@ -346,17 +344,18 @@ void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize)
struct libusb_device_descriptor desc;
int dRet = libusb_get_device_descriptor (device, &desc);
DEBUG_LOG(WII_IPC_HID, "Vendor: %d Product: %X Devnum: %X",desc.idVendor, desc.idProduct);
u32 devNum = (libusb_get_bus_number (device) << 8) | libusb_get_device_address (device);
DEBUG_LOG(WII_IPC_HID, "Vendor: %d Product: %X Devnum: %X",desc.idVendor, desc.idProduct, devNum);
if (desc.idVendor != 0x21A4)
continue;
u32 devNum = 0;//(libusb_get_bus_number (device) << 8) | libusb_get_device_address (device);
DEBUG_LOG(WII_IPC_HID, "Found device with Vendor: %d Product: %d Devnum: %d, Error: %d",desc.idVendor, desc.idProduct, devNum, dRet);
OffsetStart = OffsetBuffer;
OffsetBuffer += 4; // skip length for now, fill at end
Memory::Write_U32(devNum, OffsetBuffer); //write device num
Memory::Write_U32( 0/*devNum*/, OffsetBuffer); //write device num
OffsetBuffer += 4;
WiiHIDDeviceDescriptor wii_device;
@ -413,7 +412,7 @@ void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize)
}
libusb_free_device_list(list, TRUE);
libusb_free_device_list(list, 1);
Memory::Write_U32(0xFFFFFFFF, OffsetBuffer); // no more devices
@ -439,6 +438,8 @@ libusb_device_handle * CWII_IPC_HLE_Device_hid::GetDeviceByDevNum(u32 devNum)
libusb_device_handle *handle = NULL;
ssize_t cnt;
devNum = 0x204;
if (open_devices.find(devNum) != open_devices.end())
return open_devices[devNum];
@ -449,13 +450,22 @@ libusb_device_handle * CWII_IPC_HLE_Device_hid::GetDeviceByDevNum(u32 devNum)
for (i = 0; i < cnt; i++) {
libusb_device *device = list[i];
if (libusb_open(device, &handle))
break;
int ret = libusb_open(device, &handle);
if (ret)
{
DEBUG_LOG(WII_IPC_HID, "Failed to open device with error = %d", ret);
continue;
}
//struct libusb_device_descriptor desc;
u32 deviceID = (libusb_get_bus_number (device) << 8) | libusb_get_device_address (device);
DEBUG_LOG(WII_IPC_HID, "Testing device id == %d", deviceID);
if (deviceID == devNum)
{
open_devices[devNum] = handle;
break;
}
else
{
libusb_close(handle);
@ -463,8 +473,8 @@ libusb_device_handle * CWII_IPC_HLE_Device_hid::GetDeviceByDevNum(u32 devNum)
}
}
libusb_free_device_list(list, TRUE);
libusb_free_device_list(list, 1);
return handle;
}
}

View file

@ -21,7 +21,7 @@
#include "WII_IPC_HLE_Device.h"
#include <list>
/* Connection timed out */ #define ETRANSFER_TIMEDOUT -116
/* Connection timed out */
class CWII_IPC_HLE_Device_hid : public IWII_IPC_HLE_Device
{
@ -45,8 +45,8 @@ private:
IOCTL_HID_SET_SUSPEND = 0x01,
IOCTL_HID_CONTROL = 0x02,
IOCTL_HID_INTERRUPT_IN = 0x03,
IOCTL_HID_INTERRUPT_OUT = 0x04,
IOCTL_HID_GET_US_STRING = 0x05,
IOCTL_HID_INTERRUPT_OUT = 0x04,
IOCTL_HID_GET_US_STRING = 0x05,
IOCTL_HID_OPEN = 0x06,
IOCTL_HID_SHUTDOWN = 0x07,
IOCTL_HID_CANCEL_INTERRUPT = 0x08,
@ -113,7 +113,7 @@ private:
} WiiHIDEndpointDescriptor;
void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize);
void FillOutDevices(u32 BufferOut, u32 BufferOutSize);
void ConvertDeviceToWii(WiiHIDDeviceDescriptor *dest, const struct libusb_device_descriptor *src);
void ConvertConfigToWii(WiiHIDConfigDescriptor *dest, const struct libusb_config_descriptor *src);