Merge pull request #3436 from endrift/fix-libusb

HW: Fix libusb support for older libusb APIs
This commit is contained in:
Ryan Houdek 2016-01-03 12:35:08 -05:00
commit a898aa1585
2 changed files with 9 additions and 1 deletions

View File

@ -23,7 +23,7 @@ elseif (NOT LIBUSB_FOUND)
/usr/local/include /usr/local/include
) )
find_library(LIBUSB_LIBRARIES NAMES usb-1.0 find_library(LIBUSB_LIBRARIES NAMES usb-1.0 usb
PATHS PATHS
${LIBUSB_PKG_LIBRARY_DIRS} ${LIBUSB_PKG_LIBRARY_DIRS}
/usr/lib /usr/lib

View File

@ -50,7 +50,9 @@ static std::function<void(void)> s_detect_callback;
static bool s_libusb_driver_not_supported = false; static bool s_libusb_driver_not_supported = false;
static libusb_context* s_libusb_context = nullptr; static libusb_context* s_libusb_context = nullptr;
static bool s_libusb_hotplug_enabled = false; static bool s_libusb_hotplug_enabled = false;
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
static libusb_hotplug_callback_handle s_hotplug_handle; static libusb_hotplug_callback_handle s_hotplug_handle;
#endif
static u8 s_endpoint_in = 0; static u8 s_endpoint_in = 0;
static u8 s_endpoint_out = 0; static u8 s_endpoint_out = 0;
@ -72,6 +74,7 @@ static void Read()
} }
} }
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
static int HotplugCallback(libusb_context* ctx, libusb_device* dev, libusb_hotplug_event event, void* user_data) static int HotplugCallback(libusb_context* ctx, libusb_device* dev, libusb_hotplug_event event, void* user_data)
{ {
if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED)
@ -86,12 +89,14 @@ static int HotplugCallback(libusb_context* ctx, libusb_device* dev, libusb_hotpl
} }
return 0; return 0;
} }
#endif
static void ScanThreadFunc() static void ScanThreadFunc()
{ {
Common::SetCurrentThreadName("GC Adapter Scanning Thread"); Common::SetCurrentThreadName("GC Adapter Scanning Thread");
NOTICE_LOG(SERIALINTERFACE, "GC Adapter scanning thread started"); NOTICE_LOG(SERIALINTERFACE, "GC Adapter scanning thread started");
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
s_libusb_hotplug_enabled = libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) != 0; s_libusb_hotplug_enabled = libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) != 0;
if (s_libusb_hotplug_enabled) if (s_libusb_hotplug_enabled)
{ {
@ -100,6 +105,7 @@ static void ScanThreadFunc()
if (s_libusb_hotplug_enabled) if (s_libusb_hotplug_enabled)
NOTICE_LOG(SERIALINTERFACE, "Using libUSB hotplug detection"); NOTICE_LOG(SERIALINTERFACE, "Using libUSB hotplug detection");
} }
#endif
while (s_adapter_detect_thread_running.IsSet()) while (s_adapter_detect_thread_running.IsSet())
{ {
@ -302,8 +308,10 @@ static void AddGCAdapter(libusb_device* device)
void Shutdown() void Shutdown()
{ {
StopScanThread(); StopScanThread();
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
if (s_libusb_hotplug_enabled) if (s_libusb_hotplug_enabled)
libusb_hotplug_deregister_callback(s_libusb_context, s_hotplug_handle); libusb_hotplug_deregister_callback(s_libusb_context, s_hotplug_handle);
#endif
Reset(); Reset();
if (s_libusb_context) if (s_libusb_context)