Make ADK work as per USB spec.

This commit is contained in:
Andrew J. Kroll 2013-07-15 07:47:20 -04:00
parent 416ca04fee
commit 47b9b257d6
2 changed files with 11 additions and 4 deletions

14
adk.cpp
View file

@ -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;
//

1
adk.h
View file

@ -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();