From 7990c32ad63d087a042842fca8b504da633ff920 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 18:07:36 +0200 Subject: [PATCH 1/7] Don't call init if an error is returned --- Usb.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index d1a3592c..3ffbfbe4 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -580,23 +580,24 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo devConfig[parent]->ResetHubPort(port); } } - 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 + if (!rcode || rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) { rcode = devConfig[driver]->Init(parent, port, lowspeed); - } - if (rcode) { - // Issue a bus reset, because the device may be in a limbo state - if (parent == 0) { - // Send a bus reset on the root interface. - regWr(rHCTL, bmBUSRST); //issue bus reset - delay(102); // delay 102ms, compensate for clock inaccuracy. - } else { - // reset parent port - devConfig[parent]->ResetHubPort(port); + 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); + } + if (rcode) { + // Issue a bus reset, because the device may be in a limbo state + if (parent == 0) { + // Send a bus reset on the root interface. + regWr(rHCTL, bmBUSRST); //issue bus reset + delay(102); // delay 102ms, compensate for clock inaccuracy. + } else { + // reset parent port + devConfig[parent]->ResetHubPort(port); + } } - } return rcode; } From 6adc0843d573070c5b68f8a2e530fb5a3639984c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 18:14:16 +0200 Subject: [PATCH 2/7] More elegant way of doing: 7990c32ad63d087a042842fca8b504da633ff920 --- Usb.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index 3ffbfbe4..d7fd44ce 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -579,24 +579,24 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo // reset parent port devConfig[parent]->ResetHubPort(port); } - } - if (!rcode || rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) { + } 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); - 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); - } - if (rcode) { - // Issue a bus reset, because the device may be in a limbo state - if (parent == 0) { - // Send a bus reset on the root interface. - regWr(rHCTL, bmBUSRST); //issue bus reset - delay(102); // delay 102ms, compensate for clock inaccuracy. - } else { - // reset parent port - devConfig[parent]->ResetHubPort(port); - } + } + if (rcode) { + // Issue a bus reset, because the device may be in a limbo state + if (parent == 0) { + // Send a bus reset on the root interface. + regWr(rHCTL, bmBUSRST); //issue bus reset + delay(102); // delay 102ms, compensate for clock inaccuracy. + } else { + // reset parent port + devConfig[parent]->ResetHubPort(port); } } return rcode; From 3b733fc962fd7412bc7b2e2bbd986f2993e8e9e8 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 18:27:51 +0200 Subject: [PATCH 3/7] Better way to retry when hrJERR is returned --- Usb.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index d7fd44ce..f1e6bc49 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. @@ -585,8 +585,7 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo 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 From 01e0e6cf2d0aea1da8512d979c904dae889efe15 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 18:52:37 +0200 Subject: [PATCH 4/7] Don't clear pairWithWii --- BTD.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 993e2540..921b0714 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -300,7 +300,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 +413,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); From 81ed31e1fe6512be4598747718381973098027db Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 19:05:08 +0200 Subject: [PATCH 5/7] Check for hrJERR after ConfigureDevice too --- Usb.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Usb.cpp b/Usb.cpp index f1e6bc49..caa931ce 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -579,6 +579,9 @@ again: // 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; From 7a02a0762054cde165efc176e7100d18b9c26b33 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 19:51:20 +0200 Subject: [PATCH 6/7] Don't change error code if it returned hrJERR --- BTD.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BTD.cpp b/BTD.cpp index 921b0714..5ed762a5 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; }; From a312a45d0b30e68db5ba3ee68e8bc9597edc6ca3 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 19:51:41 +0200 Subject: [PATCH 7/7] Print if connection failed --- BTD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTD.cpp b/BTD.cpp index 5ed762a5..a714b5d6 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -467,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;