diff --git a/adk.cpp b/adk.cpp index ea6e6224..f07da6ac 100644 --- a/adk.cpp +++ b/adk.cpp @@ -58,14 +58,18 @@ ready(false) { } } +uint8_t ADK::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { + return Init(parent, port, lowspeed); // Just call Init. Yes, really! +} + /* Connection initialization of an Android phone */ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; uint8_t rcode; + uint8_t num_of_conf; // number of configurations UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; - uint8_t num_of_conf; // number of configurations // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); @@ -114,7 +118,6 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { // Extract Max Packet Size from device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; - // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if (rcode) { @@ -126,6 +129,8 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { }//if (rcode... //USBTRACE2("\r\nAddr:", bAddress); + // Spec says you should wait at least 200ms. + delay(300); p->lowspeed = false; @@ -222,7 +227,8 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) { goto FailSwAcc; //init fails } - rcode = -1; + rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; + delay(1000); // Give Android a chance to do its reset. This is a guess, and possibly could be lower. goto SwAttempt; //switch to accessory mode attempted /* diagnostic messages */ @@ -266,7 +272,7 @@ SwAttempt: #ifdef DEBUG_USB_HOST USBTRACE("\r\nAccessory mode switch attempt"); #endif -//FailOnInit: + //FailOnInit: // USBTRACE("OnInit:"); // goto Fail; // diff --git a/adk.h b/adk.h index 4ea0ed63..590f008e 100644 --- a/adk.h +++ b/adk.h @@ -110,6 +110,7 @@ public: // USBDeviceConfig implementation + virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed); virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); virtual uint8_t Release();