From 5f5cc963cf138235b394898fb48c299b444fa57a Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 1 Mar 2015 12:44:49 +0100 Subject: [PATCH 1/6] GC Adapter: stop searching adapters after one has been added --- Source/Core/Core/HW/SI_GCAdapter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index e5cfcea886..7354abd55a 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -155,6 +155,7 @@ void Setup() else { AddGCAdapter(device); + break; } } else if ((ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)) @@ -170,6 +171,7 @@ void Setup() else { AddGCAdapter(device); + break; } } } From ad49de77401c9136e17858ff4d194935918988e1 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 1 Mar 2015 12:54:41 +0100 Subject: [PATCH 2/6] =?UTF-8?q?GC=20Adapter:=20don=E2=80=99t=20stop=20scan?= =?UTF-8?q?ning=20after=20failing=20to=20claim=20an=20adapter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only call Shutdown() after all devices have been tested. --- Source/Core/Core/HW/SI_GCAdapter.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index 7354abd55a..324e64a890 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -143,14 +143,12 @@ void Setup() if (ret == LIBUSB_ERROR_NOT_SUPPORTED) s_libusb_driver_not_supported = true; } - Shutdown(); } else if ((ret = libusb_kernel_driver_active(s_handle, 0)) == 1) { if ((ret = libusb_detach_kernel_driver(s_handle, 0)) && ret != LIBUSB_ERROR_NOT_SUPPORTED) { ERROR_LOG(SERIALINTERFACE, "libusb_detach_kernel_driver failed with error: %d", ret); - Shutdown(); } else { @@ -161,12 +159,10 @@ void Setup() else if ((ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)) { ERROR_LOG(SERIALINTERFACE, "libusb_kernel_driver_active error ret = %d", ret); - Shutdown(); } else if ((ret = libusb_claim_interface(s_handle, 0))) { ERROR_LOG(SERIALINTERFACE, "libusb_claim_interface failed with error: %d", ret); - Shutdown(); } else { @@ -175,6 +171,8 @@ void Setup() } } } + if (!s_detected) + Shutdown(); libusb_free_device_list(list, 1); } From ebedc805459152b6a5af3eeafd712ea8a7978c1a Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 2 Mar 2015 01:13:45 +0100 Subject: [PATCH 3/6] GC Adapter: never call libusb_reset_device() There should be no need to do this, and performing a reset breaks things on any other software using the device (e.g. another dolphin instance). --- Source/Core/Core/HW/SI_GCAdapter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index 324e64a890..d2ed8dc96a 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -235,7 +235,6 @@ void Reset() if (s_handle) { libusb_release_interface(s_handle, 0); - libusb_reset_device(s_handle); libusb_close(s_handle); s_handle = nullptr; } From 5a10be7fef3fb0ccc7984272f3c98f5dfaacaa25 Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 10 Mar 2015 10:48:25 +0100 Subject: [PATCH 4/6] GC Adapter: fix a crash on exit s_detected is better for detecting that a thread is actually running. Also make sure the claim_interface is always called when we detect an adapter. --- Source/Core/Core/HW/SI_GCAdapter.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index d2ed8dc96a..a4410881cc 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -150,15 +150,12 @@ void Setup() { ERROR_LOG(SERIALINTERFACE, "libusb_detach_kernel_driver failed with error: %d", ret); } - else - { - AddGCAdapter(device); - break; - } } - else if ((ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)) + // this split is needed so that we don't avoid claiming the interface when + // detaching the kernel driver is successful + if (ret != 0) { - ERROR_LOG(SERIALINTERFACE, "libusb_kernel_driver_active error ret = %d", ret); + continue; } else if ((ret = libusb_claim_interface(s_handle, 0))) { @@ -224,7 +221,7 @@ void Shutdown() void Reset() { - if (!SConfig::GetInstance().m_GameCubeAdapter) + if (!s_detected) return; if (s_adapter_thread_running.TestAndClear()) @@ -333,7 +330,7 @@ void Output(int chan, u8 rumble_command) bool IsDetected() { - return s_handle != nullptr; + return s_detected; } bool IsDriverDetected() From 88ab6352dd5fe3f5852d3f57b4414265816ee533 Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 10 Mar 2015 17:47:02 +0100 Subject: [PATCH 5/6] =?UTF-8?q?GC=20Adapter:=20do=20not=20proceed=20with?= =?UTF-8?q?=20the=20input=20read=20if=20the=20thread=20isn=E2=80=99t=20run?= =?UTF-8?q?ning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the Init() call does not work in the fallback path, then abort. --- Source/Core/Core/HW/SI_GCAdapter.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index a4410881cc..6a81bedbdc 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -249,9 +249,15 @@ void Input(int chan, GCPadStatus* pad) if (s_handle == nullptr) { if (s_detected) + { Init(); + if (s_handle == nullptr) + return; + } else + { return; + } } u8 controller_payload_copy[37]; From b9af0c4d127e4ced0844bc32ff85ade7d63c2b46 Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 10 Mar 2015 19:16:33 +0100 Subject: [PATCH 6/6] GC Adapter: Do not abort if some libusb functions are not supported Also remove a typo. --- Source/Core/Core/HW/SI_GCAdapter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index 6a81bedbdc..99d2362841 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -104,7 +104,7 @@ void Setup() int dRet = libusb_get_device_descriptor(device, &desc); if (dRet) { - // could not aquire the descriptor, no point in trying to use it. + // could not acquire the descriptor, no point in trying to use it. ERROR_LOG(SERIALINTERFACE, "libusb_get_device_descriptor failed with error: %d", dRet); continue; } @@ -153,7 +153,7 @@ void Setup() } // this split is needed so that we don't avoid claiming the interface when // detaching the kernel driver is successful - if (ret != 0) + if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { continue; }