diff --git a/BTD.cpp b/BTD.cpp index 993e2540..a714b5d6 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -110,7 +110,8 @@ FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(rcode); #endif - rcode = USB_ERROR_FailGetDevDescr; + if (rcode != hrJERR) + rcode = USB_ERROR_FailGetDevDescr; Release(); return rcode; }; @@ -300,7 +301,7 @@ void BTD::clearAllVariables() { } connectToWii = false; - pairWithWii = false; + incomingWii = false; bAddress = 0; // Clear device address bNumEP = 1; // Must have to be reset to 1 qNextPollTime = 0; // Reset next poll time @@ -413,7 +414,7 @@ void BTD::HCI_event_task() { break; case EV_INQUIRY_COMPLETE: - if (inquiry_counter >= 5) { + if (inquiry_counter >= 5 && pairWithWii) { inquiry_counter = 0; #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80); @@ -466,7 +467,7 @@ void BTD::HCI_event_task() { hci_handle = hcibuf[3] | ((hcibuf[4] & 0x0F) << 8); // store the handle for the ACL connection hci_event_flag |= HCI_FLAG_CONN_COMPLETE; // set connection complete flag } -#ifdef EXTRADEBUG +#ifdef DEBUG_USB_HOST else { Notify(PSTR("\r\nConnection Failed"), 0x80); hci_state = HCI_CHECK_WII_SERVICE; diff --git a/Usb.cpp b/Usb.cpp index 4566733e..6bcf092e 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -566,10 +566,10 @@ uint8_t USB::DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed) { }; uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed) { - uint8_t rcode = 0; //printf("AttemptConfig: parent = %i, port = %i\r\n", parent, port); - rcode = devConfig[driver]->ConfigureDevice(parent, port, lowspeed); +again: + uint8_t rcode = devConfig[driver]->ConfigureDevice(parent, port, lowspeed); if (rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) { if (parent == 0) { // Send a bus reset on the root interface. @@ -579,12 +579,16 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo // reset parent port devConfig[parent]->ResetHubPort(port); } - } + } else if (rcode == hrJERR) { // Some devices returns this when plugged in - trying to initialize the device again usually works + delay(100); + goto again; + } else if (rcode) + return rcode; + rcode = devConfig[driver]->Init(parent, port, lowspeed); if (rcode == hrJERR) { // Some devices returns this when plugged in - trying to initialize the device again usually works delay(100); - devConfig[driver]->ConfigureDevice(parent, port, lowspeed); // Just ignore the returned value - rcode = devConfig[driver]->Init(parent, port, lowspeed); + goto again; } if (rcode) { // Issue a bus reset, because the device may be in a limbo state @@ -596,7 +600,6 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo // reset parent port devConfig[parent]->ResetHubPort(port); } - } return rcode; }