Merge pull request #7712 from linkmauve/gcadapter-flatten
Flatten a GCAdapter function
This commit is contained in:
commit
c785ccba27
|
@ -244,53 +244,42 @@ static void Setup()
|
||||||
|
|
||||||
static bool CheckDeviceAccess(libusb_device* device)
|
static bool CheckDeviceAccess(libusb_device* device)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
libusb_device_descriptor desc;
|
libusb_device_descriptor desc;
|
||||||
int dRet = libusb_get_device_descriptor(device, &desc);
|
int ret = libusb_get_device_descriptor(device, &desc);
|
||||||
if (dRet)
|
if (ret)
|
||||||
{
|
{
|
||||||
// could not acquire 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);
|
ERROR_LOG(SERIALINTERFACE, "libusb_get_device_descriptor failed with error: %d", ret);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desc.idVendor == 0x057e && desc.idProduct == 0x0337)
|
if (desc.idVendor != 0x057e || desc.idProduct != 0x0337)
|
||||||
{
|
{
|
||||||
|
// This isn’t the device we are looking for.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
NOTICE_LOG(SERIALINTERFACE, "Found GC Adapter with Vendor: %X Product: %X Devnum: %d",
|
NOTICE_LOG(SERIALINTERFACE, "Found GC Adapter with Vendor: %X Product: %X Devnum: %d",
|
||||||
desc.idVendor, desc.idProduct, 1);
|
desc.idVendor, desc.idProduct, 1);
|
||||||
|
|
||||||
u8 bus = libusb_get_bus_number(device);
|
u8 bus = libusb_get_bus_number(device);
|
||||||
u8 port = libusb_get_device_address(device);
|
u8 port = libusb_get_device_address(device);
|
||||||
ret = libusb_open(device, &s_handle);
|
ret = libusb_open(device, &s_handle);
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
if (ret == LIBUSB_ERROR_ACCESS)
|
if (ret == LIBUSB_ERROR_ACCESS)
|
||||||
{
|
|
||||||
if (dRet)
|
|
||||||
{
|
{
|
||||||
ERROR_LOG(SERIALINTERFACE,
|
ERROR_LOG(SERIALINTERFACE,
|
||||||
"Dolphin does not have access to this device: Bus %03d Device "
|
|
||||||
"%03d: ID ????:???? (couldn't get id).",
|
|
||||||
bus, port);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ERROR_LOG(
|
|
||||||
SERIALINTERFACE,
|
|
||||||
"Dolphin does not have access to this device: Bus %03d Device %03d: ID %04X:%04X.",
|
"Dolphin does not have access to this device: Bus %03d Device %03d: ID %04X:%04X.",
|
||||||
bus, port, desc.idVendor, desc.idProduct);
|
bus, port, desc.idVendor, desc.idProduct);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
if (ret)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
ERROR_LOG(SERIALINTERFACE, "libusb_open failed to open device with error = %d", ret);
|
ERROR_LOG(SERIALINTERFACE, "libusb_open failed to open device with error = %d", ret);
|
||||||
if (ret == LIBUSB_ERROR_NOT_SUPPORTED)
|
if (ret == LIBUSB_ERROR_NOT_SUPPORTED)
|
||||||
s_libusb_driver_not_supported = true;
|
s_libusb_driver_not_supported = true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = libusb_kernel_driver_active(s_handle, 0);
|
ret = libusb_kernel_driver_active(s_handle, 0);
|
||||||
if (ret == 1)
|
if (ret == 1)
|
||||||
{
|
{
|
||||||
|
@ -298,7 +287,7 @@ static bool CheckDeviceAccess(libusb_device* device)
|
||||||
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)
|
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)
|
||||||
ERROR_LOG(SERIALINTERFACE, "libusb_detach_kernel_driver failed with error: %d", ret);
|
ERROR_LOG(SERIALINTERFACE, "libusb_detach_kernel_driver failed with error: %d", ret);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 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 (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)
|
||||||
|
@ -306,11 +295,12 @@ static bool CheckDeviceAccess(libusb_device* device)
|
||||||
|
|
||||||
ret = libusb_claim_interface(s_handle, 0);
|
ret = libusb_claim_interface(s_handle, 0);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
{
|
||||||
ERROR_LOG(SERIALINTERFACE, "libusb_claim_interface failed with error: %d", ret);
|
ERROR_LOG(SERIALINTERFACE, "libusb_claim_interface failed with error: %d", ret);
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddGCAdapter(libusb_device* device)
|
static void AddGCAdapter(libusb_device* device)
|
||||||
|
|
Loading…
Reference in New Issue