commit
8b5a61b8fd
|
@ -16,3 +16,5 @@
|
||||||
[submodule "libusb"]
|
[submodule "libusb"]
|
||||||
path = Externals/libusb/libusb
|
path = Externals/libusb/libusb
|
||||||
url = https://github.com/libusb/libusb.git
|
url = https://github.com/libusb/libusb.git
|
||||||
|
branch = master
|
||||||
|
shallow = true
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4239bc3a50014b8e6a5a2a59df1fff3b7469543b
|
Subproject commit ba698478afc3d3a72644eef9fc4cd24ce8383a4c
|
|
@ -25,6 +25,15 @@
|
||||||
#include "InputCommon/GCAdapter.h"
|
#include "InputCommon/GCAdapter.h"
|
||||||
#include "InputCommon/GCPadStatus.h"
|
#include "InputCommon/GCPadStatus.h"
|
||||||
|
|
||||||
|
#if defined(LIBUSB_API_VERSION)
|
||||||
|
#define LIBUSB_API_VERSION_EXIST 1
|
||||||
|
#else
|
||||||
|
#define LIBUSB_API_VERSION_EXIST 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LIBUSB_API_VERSION_ATLEAST(v) (LIBUSB_API_VERSION_EXIST && LIBUSB_API_VERSION >= (v))
|
||||||
|
#define LIBUSB_API_HAS_HOTPLUG LIBUSB_API_VERSION_ATLEAST(0x01000102)
|
||||||
|
|
||||||
namespace GCAdapter
|
namespace GCAdapter
|
||||||
{
|
{
|
||||||
static bool CheckDeviceAccess(libusb_device* device);
|
static bool CheckDeviceAccess(libusb_device* device);
|
||||||
|
@ -71,7 +80,7 @@ static bool s_libusb_hotplug_enabled = true;
|
||||||
#else
|
#else
|
||||||
static bool s_libusb_hotplug_enabled = false;
|
static bool s_libusb_hotplug_enabled = false;
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
|
#if LIBUSB_API_HAS_HOTPLUG
|
||||||
static libusb_hotplug_callback_handle s_hotplug_handle;
|
static libusb_hotplug_callback_handle s_hotplug_handle;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -89,6 +98,8 @@ static std::array<bool, SerialInterface::MAX_SI_CHANNELS> s_config_rumble_enable
|
||||||
|
|
||||||
static void Read()
|
static void Read()
|
||||||
{
|
{
|
||||||
|
Common::SetCurrentThreadName("GCAdapter Read Thread");
|
||||||
|
|
||||||
int payload_size = 0;
|
int payload_size = 0;
|
||||||
while (s_adapter_thread_running.IsSet())
|
while (s_adapter_thread_running.IsSet())
|
||||||
{
|
{
|
||||||
|
@ -110,6 +121,8 @@ static void Read()
|
||||||
|
|
||||||
static void Write()
|
static void Write()
|
||||||
{
|
{
|
||||||
|
Common::SetCurrentThreadName("GCAdapter Write Thread");
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -134,7 +147,7 @@ static void Write()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
|
#if LIBUSB_API_HAS_HOTPLUG
|
||||||
static int HotplugCallback(libusb_context* ctx, libusb_device* dev, libusb_hotplug_event event,
|
static int HotplugCallback(libusb_context* ctx, libusb_device* dev, libusb_hotplug_event event,
|
||||||
void* user_data)
|
void* user_data)
|
||||||
{
|
{
|
||||||
|
@ -165,7 +178,7 @@ static void ScanThreadFunc()
|
||||||
Common::SetCurrentThreadName("GC Adapter Scanning Thread");
|
Common::SetCurrentThreadName("GC Adapter Scanning Thread");
|
||||||
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread started");
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread started");
|
||||||
|
|
||||||
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
|
#if LIBUSB_API_HAS_HOTPLUG
|
||||||
#ifndef __FreeBSD__
|
#ifndef __FreeBSD__
|
||||||
s_libusb_hotplug_enabled = libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) != 0;
|
s_libusb_hotplug_enabled = libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) != 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -322,11 +335,17 @@ static bool CheckDeviceAccess(libusb_device* device)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool detach_failed = false;
|
||||||
ret = libusb_kernel_driver_active(s_handle, 0);
|
ret = libusb_kernel_driver_active(s_handle, 0);
|
||||||
if (ret == 1)
|
if (ret == 1)
|
||||||
{
|
{
|
||||||
|
// On macos detaching would fail without root or entitlement.
|
||||||
|
// We assume user is using GCAdapterDriver and therefor don't want to detach anything
|
||||||
|
#if !defined(__APPLE__)
|
||||||
ret = libusb_detach_kernel_driver(s_handle, 0);
|
ret = libusb_detach_kernel_driver(s_handle, 0);
|
||||||
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)
|
detach_failed = ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND && ret != LIBUSB_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
|
if (detach_failed)
|
||||||
ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_detach_kernel_driver failed with error: {}", ret);
|
ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_detach_kernel_driver failed with error: {}", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +357,7 @@ static bool CheckDeviceAccess(libusb_device* device)
|
||||||
|
|
||||||
// this split is needed so that we don't avoid claiming the interface when
|
// this split is needed so that we don't avoid claiming the interface when
|
||||||
// detaching the kernel driver is successful
|
// detaching the kernel driver is successful
|
||||||
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)
|
if (detach_failed)
|
||||||
{
|
{
|
||||||
libusb_close(s_handle);
|
libusb_close(s_handle);
|
||||||
s_handle = nullptr;
|
s_handle = nullptr;
|
||||||
|
@ -398,12 +417,12 @@ static void AddGCAdapter(libusb_device* device)
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
StopScanThread();
|
StopScanThread();
|
||||||
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
|
#if LIBUSB_API_HAS_HOTPLUG
|
||||||
if (s_libusb_context->IsValid() && s_libusb_hotplug_enabled)
|
if (s_libusb_context->IsValid() && 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
|
#endif
|
||||||
s_libusb_context.reset();
|
|
||||||
Reset();
|
Reset();
|
||||||
|
s_libusb_context.reset();
|
||||||
|
|
||||||
s_status = NO_ADAPTER_DETECTED;
|
s_status = NO_ADAPTER_DETECTED;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue