diff --git a/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino index 1b22ec48767c3898ee45d83348270be7fa305824..ea7509cbce84fe4e9d44e07ad72afb321e08703d 100644 --- a/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino +++ b/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -26,7 +26,7 @@ USBHost usb; ADK adk(&usb,"Arduino SA", "Arduino_Terminal", - "Arduino Due X", + "Arduino Terminal for Android", "1.0", "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk", "1"); @@ -37,7 +37,10 @@ void setup(void) while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection SERIAL_PORT_MONITOR.println("\r\nADK demo start"); - delay(200); + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay(20); } #define RCVSIZE 128 diff --git a/libraries/USBHost/examples/KeyboardController/KeyboardController.ino b/libraries/USBHost/examples/KeyboardController/KeyboardController.ino index cabaf8b804f0477870ae63f051ae7f570773c1ff..b869ad8035e752d5064c957219ebf1f9d90c0145 100644 --- a/libraries/USBHost/examples/KeyboardController/KeyboardController.ino +++ b/libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -76,7 +76,10 @@ void setup() while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection SERIAL_PORT_MONITOR.println("Keyboard Controller Program started"); - delay( 200 ); + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay( 20 ); } void loop() diff --git a/libraries/USBHost/examples/MouseController/MouseController.ino b/libraries/USBHost/examples/MouseController/MouseController.ino index 505121ac51c5ed72374bcc410a76cad20f00db98..5f90d59a713414edab8d390083d876dce2b9f541 100644 --- a/libraries/USBHost/examples/MouseController/MouseController.ino +++ b/libraries/USBHost/examples/MouseController/MouseController.ino @@ -87,7 +87,7 @@ void setup() if (usb.Init() == -1) SERIAL_PORT_MONITOR.println("OSC did not start."); - delay( 200 ); + delay( 20 ); } void loop() diff --git a/libraries/USBHost/examples/USB_desc/USB_desc.ino b/libraries/USBHost/examples/USB_desc/USB_desc.ino index e5c2b0df60ea71cb70c96a67f24c61cad341f8eb..0bc039b58e6499412f0f8788531266d171b6ab6b 100644 --- a/libraries/USBHost/examples/USB_desc/USB_desc.ino +++ b/libraries/USBHost/examples/USB_desc/USB_desc.ino @@ -67,7 +67,7 @@ void setup() if (usb.Init() == -1) SERIAL_PORT_MONITOR.println("OSC did not start."); - delay( 200 ); + delay( 20 ); next_time = millis() + 10000; } diff --git a/libraries/USBHost/src/Usb.cpp b/libraries/USBHost/src/Usb.cpp index bfd92cf646ad077d329988657d362512ff5e10a7..ea2b8c46ceab3e62a5a80425c3cca0a40335eca6 100644 --- a/libraries/USBHost/src/Usb.cpp +++ b/libraries/USBHost/src/Usb.cpp @@ -323,7 +323,7 @@ uint32_t USBHost::outTransfer(uint32_t addr, uint32_t ep, uint32_t nbytes, uint8 return OutTransfer(pep, nak_limit, nbytes, data); } -volatile unsigned int jcb =0; + uint32_t USBHost::OutTransfer(EpInfo *pep, uint32_t nak_limit, uint32_t nbytes, uint8_t *data) { uint32_t rcode = 0, retry_count; uint8_t *data_p = data; //local copy of the data pointer diff --git a/libraries/USBHost/src/adk.cpp b/libraries/USBHost/src/adk.cpp index f5a7e2adfd9a0c96555097403c048d70242791c7..e271cb4a4b654205092adabe1f2fc53b12b12622 100644 --- a/libraries/USBHost/src/adk.cpp +++ b/libraries/USBHost/src/adk.cpp @@ -118,11 +118,11 @@ uint32_t ADK::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) - return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; - // Extract Max Packet Size from device descriptor - epInfo[0].maxPktSize = udd->bMaxPacketSize0; + // Extract Max Packet Size from device descriptor + epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device SET_ADDRESS rcode = pUsb->setAddr(0, 0, bAddress); @@ -135,7 +135,7 @@ uint32_t ADK::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { return rcode; }//if (rcode... - //USBTRACE2("\r\nAddr:", bAddress); + USBTRACE2("\r\nAddr:", bAddress); // Spec says you should wait at least 200ms. //delay(300); @@ -159,26 +159,26 @@ uint32_t ADK::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { //get pointer to assigned address record p = addrPool.GetUsbDevicePtr(bAddress); - if(!p) { + if(!p) { return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; - } + } p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer - only EP0 is known rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); - if(rcode) { + if(rcode) { goto FailSetDevTblEntry; - } + } - //check if ADK device is already in accessory mode; if yes, configure and exit - if(udd->idVendor == ADK_VID && - (udd->idProduct == ADK_PID || udd->idProduct == ADB_PID)) { - USBTRACE("\r\nAcc.mode device detected"); - /* go through configurations, find first bulk-IN, bulk-OUT EP, fill epInfo and quit */ - num_of_conf = udd->bNumConfigurations; + //check if ADK device is already in accessory mode; if yes, configure and exit + if(udd->idVendor == ADK_VID && + (udd->idProduct == ADK_PID || udd->idProduct == ADB_PID)) { + USBTRACE("\r\nAcc.mode device detected"); + /* go through configurations, find first bulk-IN, bulk-OUT EP, fill epInfo and quit */ + num_of_conf = udd->bNumConfigurations; - USBTRACE2("\r\nNC:",num_of_conf); + USBTRACE2("\r\nNC:",num_of_conf); for (uint32_t i = 0; i < num_of_conf; i++) { ConfigDescParser<0, 0, 0, 0> confDescrParser(this); @@ -194,13 +194,13 @@ uint32_t ADK::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); } #endif - if(rcode) { + if(rcode) { goto FailGetConfDescr; } - if(bNumEP > 2) { + if(bNumEP > 2) { break; } - } // for (uint32_t i=0; i<num_of_conf; i++... + } // for (uint32_t i=0; i<num_of_conf; i++... if(bNumEP == 3) { // Assign epInfo to epinfo pointer - this time all 3 endpoins @@ -212,128 +212,136 @@ uint32_t ADK::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); - if(rcode) { - goto FailSetConfDescr; - } - /* print endpoint structure */ - /* - USBTRACE("\r\nEndpoint Structure:"); - USBTRACE("\r\nEP0:"); - USBTRACE2("\r\nAddr: ", epInfo[0].epAddr); - USBTRACE2("\r\nMax.pkt.size: ", epInfo[0].maxPktSize); - USBTRACE2("\r\nAttr: ", epInfo[0].epAttribs); - USBTRACE("\r\nEpout:"); - USBTRACE2("\r\nAddr: ", epInfo[epDataOutIndex].epAddr); - USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataOutIndex].maxPktSize); - USBTRACE2("\r\nAttr: ", epInfo[epDataOutIndex].epAttribs); - USBTRACE("\r\nEpin:"); - USBTRACE2("\r\nAddr: ", epInfo[epDataInIndex].epAddr); - USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataInIndex].maxPktSize); - USBTRACE2("\r\nAttr: ", epInfo[epDataInIndex].epAttribs); - */ - - USBTRACE("\r\nConfiguration successful"); + if(rcode) { + goto FailSetConfDescr; + } + /* print endpoint structure */ + + USBTRACE("\r\nEndpoint Structure:"); + USBTRACE("\r\nEP0:"); + USBTRACE2("\r\nAddr: ", epInfo[0].epAddr); + USBTRACE2("\r\nMax.pkt.size: ", epInfo[0].maxPktSize); + USBTRACE2("\r\nAttr: ", epInfo[0].epAttribs); + USBTRACE("\r\nEpout:"); + USBTRACE2("\r\nAddr: ", epInfo[epDataOutIndex].epAddr); + USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataOutIndex].maxPktSize); + USBTRACE2("\r\nAttr: ", epInfo[epDataOutIndex].epAttribs); + USBTRACE("\r\nEpin:"); + USBTRACE2("\r\nAddr: ", epInfo[epDataInIndex].epAddr); + USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataInIndex].maxPktSize); + USBTRACE2("\r\nAttr: ", epInfo[epDataInIndex].epAttribs); + + + USBTRACE("\r\nConfiguration successful"); ready = true; - return 0; //successful configuration - }//if( buf->idVendor == ADK_VID... - - //probe device - get accessory protocol revision - { - uint32_t adkproto = 0; - delay(1); - //rcode = getProto((uint8_t*) & adkproto); // ADK_GETPROTO 0x33 - rcode = getProto((uint8_t*)buf); + return 0; //successful configuration + }//if( buf->idVendor == ADK_VID... + + //probe device - get accessory protocol revision + { + uint32_t adkproto = 0; + delay(1); + //rcode = getProto((uint8_t*) & adkproto); // ADK_GETPROTO 0x33 + rcode = getProto((uint8_t*)buf); #if defined(XOOM) - //added by Jaylen Scott Vanorden - if(rcode) { - USBTRACE2("\r\nGot 1st bad code for proto: ", rcode); - // Try once more - rcode = getProto((uint8_t*) & adkproto); - } -#endif - if(rcode) { - goto FailGetProto; //init fails - } - adkproto = buf[0] | (buf[1]<<8); - USBTRACE2("\r\nADK protocol rev. ", adkproto); + //added by Jaylen Scott Vanorden + if(rcode) { + USBTRACE2("\r\nGot 1st bad code for proto: ", rcode); + // Try once more + rcode = getProto((uint8_t*) & adkproto); } - - delay(100); -static unsigned int volatile jcb; - //sending ID strings - jcb = sendStr(ACCESSORY_STRING_MANUFACTURER, manufacturer); // ADK_SENDSTR 0x34 - delay(10); - jcb = sendStr(ACCESSORY_STRING_MODEL, model); - delay(10); - sendStr(ACCESSORY_STRING_DESCRIPTION, description); - delay(10); - sendStr(ACCESSORY_STRING_VERSION, version); - delay(10); - sendStr(ACCESSORY_STRING_URI, uri); - delay(10); - sendStr(ACCESSORY_STRING_SERIAL, serial); - - delay(100); - - //switch to accessory mode - //the Android phone will reset - rcode = switchAcc(); +#endif if(rcode) { - goto FailSwAcc; //init fails + goto FailGetProto; //init fails } - rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; - delay(100); // 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 */ + adkproto = buf[0] | (buf[1]<<8); + USBTRACE2("\r\nADK protocol rev. ", adkproto); + } + + delay(100); + + //sending ID strings + // ADK_SENDSTR 0x34 + if( sendStr(ACCESSORY_STRING_MANUFACTURER, manufacturer) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_MANUFACTURER"); } + delay(10); + if( sendStr(ACCESSORY_STRING_MODEL, model) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_MODEL"); } + delay(10); + if( sendStr(ACCESSORY_STRING_DESCRIPTION, description) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_DESCRIPTION"); } + delay(10); + if( sendStr(ACCESSORY_STRING_VERSION, version) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_VERSION"); } + delay(10); + if( sendStr(ACCESSORY_STRING_URI, uri) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_URI"); } + delay(10); + if( sendStr(ACCESSORY_STRING_SERIAL, serial) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_SERIAL"); } + + delay(100); + + USBTRACE("\r\nSwitch to accessory mode"); + //switch to accessory mode + //the Android phone will reset + rcode = switchAcc(); + if(rcode) { + goto FailSwAcc; //init fails + } + rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; + delay(100); // 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 */ FailGetDevDescr: #ifdef DEBUG_USB_HOST - NotifyFailGetDevDescr(rcode); + NotifyFailGetDevDescr(rcode); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST - NotifyFailSetDevTblEntry(rcode); - goto Fail; + NotifyFailSetDevTblEntry(rcode); + goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST - NotifyFailGetConfDescr(rcode); - goto Fail; + NotifyFailGetConfDescr(rcode); + goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST - NotifyFailSetConfDescr(rcode); - goto Fail; + NotifyFailSetConfDescr(rcode); + goto Fail; #endif FailGetProto: #ifdef DEBUG_USB_HOST - USBTRACE("\r\ngetProto:"); - goto Fail; + USBTRACE("\r\ngetProto:"); + goto Fail; #endif FailSwAcc: #ifdef DEBUG_USB_HOST - USBTRACE("\r\nswAcc:"); - goto Fail; + USBTRACE("\r\nswAcc:"); + goto Fail; #endif - //FailOnInit: - // USBTRACE("OnInit:"); - // goto Fail; - // + //FailOnInit: + // USBTRACE("OnInit:"); + // goto Fail; + // SwAttempt: #ifdef DEBUG_USB_HOST - USBTRACE("\r\nAccessory mode switch attempt"); + USBTRACE("\r\nAccessory mode switch attempt"); Fail: #endif - //USBTRACE2("\r\nADK Init Failed, error code: ", rcode); - //NotifyFail(rcode); + USBTRACE2("\r\nADK Init Failed, error code: ", rcode); + //NotifyFail(rcode); Release(); return rcode; } @@ -375,8 +383,8 @@ uint32_t ADK::Release() { } uint32_t ADK::RcvData(uint8_t *bytes_rcvd, uint8_t *dataptr) { - //USBTRACE2("\r\nAddr: ", bAddress ); - //USBTRACE2("\r\nEP: ",epInfo[epDataInIndex].epAddr); + USBTRACE2("\r\nAddr: ", bAddress ); + USBTRACE2("\r\nEP: ",epInfo[epDataInIndex].epAddr); return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); } diff --git a/libraries/USBHost/src/adk.h b/libraries/USBHost/src/adk.h index 75047f6604237dae0c888829afb8cc0b269a643d..ffd22cf3e1f215e965fb416d5546ac82a9536a61 100644 --- a/libraries/USBHost/src/adk.h +++ b/libraries/USBHost/src/adk.h @@ -29,7 +29,7 @@ e-mail : support@circuitsathome.com // #define ADK_PID 0x2D00 // #define ADB_PID 0x2D01 -//JCB +// JCB #define ADK_VID 0x04E8 #define ADK_PID 0x685C #define ADB_PID 0x685D