XOOMの動作状況を聞き処理を変えてみました。 USBケーブルを抜いた際に処理を終了するようにしました。

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
abe00makoto
Date:
Fri May 27 18:51:15 2011 +0000
Parent:
2:a05c7cbe396f
Commit message:
nexus one support
maybe support add XOOM ,nexus S

Changed in this revision

ADK.cpp Show annotated file Show diff for this revision Revisions of this file
ADK.h Show annotated file Show diff for this revision Revisions of this file
AutoEvents.cpp Show annotated file Show diff for this revision Revisions of this file
USBHost.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ADK.cpp	Thu May 26 19:08:55 2011 +0000
+++ b/ADK.cpp	Fri May 27 18:51:15 2011 +0000
@@ -23,6 +23,7 @@
 #endif
 
 
+
 PwmOut led1(LED1);
 PwmOut led2(LED2);
 PwmOut led3(LED3);
@@ -48,23 +49,19 @@
     sw1.mode(PullUp);
     sw2.mode(PullUp);
     sw3.mode(PullUp);
-
-    //sw1.fall(sw1_write);
-   // sw1.rise(sw1_write);
-
-    sw1b=sw2b=sw3b=0;
-
+    sw1b=sw2b=sw3b=sw1;
 }
 
 void AdkUSB::loop() {
     log("enter loop\r\n");
     u8 buf[3];
     int ret=-1;
-    
-    while (1) {
+    //booting wait
+    //wait(10);
+    while (!this->_loopend) {
         bool w_flag=false;
         //wait_ms(4);
- 
+
         buf[0]=0x01;
         //switch1
         if (sw1!=sw1b) {
@@ -72,7 +69,7 @@
             buf[1]=0;
             buf[2]=!sw1;
             ret=this->write(buf,sizeof(buf));
-            wait_ms(4);
+            //wait_ms(4);
             sw1b=sw1;
             w_flag=true;
         }
@@ -82,7 +79,7 @@
             buf[1]=1;
             buf[2]=!sw2;
             ret=this->write(buf,sizeof(buf));
-            wait_ms(4);
+            //wait_ms(4);
             sw2b=sw2;
             w_flag=true;
         }
@@ -92,31 +89,33 @@
             buf[1]=2;
             buf[2]=!sw3;
             ret=this->write(buf,sizeof(buf));
-            wait_ms(4);
+            //wait_ms(4);
             sw3b=sw3;
             w_flag=true;
         }
 
-        if(!w_flag)
-        {
-          buf[0]=buf[1]=buf[2]=0;
-          ret=this->write(buf,sizeof(buf));
-        }
-        
-        if (ret<0) {
-            led1=led2=led3=led4=0.0;
-            log("---------------------------------------------------------------loop end\r\n");
-            return;
-
+        if (!w_flag) {
+            buf[0]=buf[1]=buf[2]=0;
+            ret=this->write(buf,sizeof(buf));
         }
     }
+
+    //reset
+    led1=led2=led3=led4=0.0;
+    log("---------------------------------------------------------------loop end\r\n");
 }
 void AdkreadCallback(int device, int endpoint, int status, u8* buf, int len, void* userData) {
 
     log("AdkreadCallback(int device=%d, int endpoint=%x, int status=%d, u8* buf=%p, int len=%d, void* userData=%p)\r\n",
         device,endpoint,status,buf,len,userData);
 
-    //AdkUSB* t = (AdkUSB*)userData;
+    AdkUSB* t = (AdkUSB*)userData;
+    if (status!=0) {
+        log("loop end.\r\n");
+        t->loopend();
+        return;
+    }
+
 
     if (buf[0] == 0x2) {
         if (buf[1] == 0x0) {
@@ -170,7 +169,6 @@
     sendString(device,ACCESSORY_STRING_VERSION,"1.0");
     sendString(device,ACCESSORY_STRING_URI,"http://www.android.com");
     sendString(device,ACCESSORY_STRING_SERIAL,"0000000012345678");
-
     USBControlTransfer(device,
                        HOST_TO_DEVICE |REQUEST_TYPE_VENDOR|RECIPIENT_DEVICE,
                        ACCESSORY_START,
@@ -181,7 +179,7 @@
                        0,
                        0 );
 
-    wait(1);
+    wait_ms(400);
 
     return true;
 
@@ -207,14 +205,15 @@
 void sendString(int device, int index, const char *str) {
 
     LOG("send_string start(%d,%d,%s)  %d \r\n",device,index,str,strlen(str)+1);
-
-    //this is diffrent  google's sample but error ocard same sample
+    u8 buffer[255];
+    strcpy((char*)buffer,str);
+    //thankyou curryman san
     USBControlTransfer(device,
-                       DEVICE_TO_HOST /*HOST_TO_DEVIC use error why? please teach me*/|REQUEST_TYPE_VENDOR|RECIPIENT_DEVICE,
+                       HOST_TO_DEVICE|REQUEST_TYPE_VENDOR|RECIPIENT_DEVICE,
                        ACCESSORY_SEND_STRING,
                        0,//value
                        index,
-                       (u8*)str,
+                       buffer,
                        strlen(str)+1
                       );
 
@@ -241,10 +240,13 @@
 void AdkreadCallback(int device, int endpoint, int status, u8* buf, int len, void* userData);
 
 AdkUSB::AdkUSB(int device, int configuration, int interfaceNumber) {
+
     log("connecting Android \r\n");
     _device = device;
     _configuration = configuration;
     _interfaceNumber = interfaceNumber;
+    //for loop()
+    _loopend=false;
     printf("device = %d configuration = %d interfaceNumber = %d\r\n", device, configuration, interfaceNumber);
     int err;
 
@@ -310,7 +312,7 @@
     err = SetConfiguration(device,configuration);
     if (err < 0) {
         log("SetConfiguration error\r\n");
-        wait(10);
+        return;
     }
 
     log("interrupt setup\r\n");
--- a/ADK.h	Thu May 26 19:08:55 2011 +0000
+++ b/ADK.h	Fri May 27 18:51:15 2011 +0000
@@ -29,6 +29,9 @@
     int read(u8 *buff, int len );
     int write(u8 *buff, int len );
     void loop();
+    void loopend(){
+      _loopend=true;
+    };
     
     
     
@@ -39,6 +42,8 @@
     int _device;
     int _configuration;
     int _interfaceNumber;
+    
+    bool _loopend;
 
   
 };
--- a/AutoEvents.cpp	Thu May 26 19:08:55 2011 +0000
+++ b/AutoEvents.cpp	Fri May 27 18:51:15 2011 +0000
@@ -249,16 +249,16 @@
     char s[128];
     u8 my_mac[6] = {0x00, 0x02, 0x72, 0xAD, 0xF3, 0x5B}; // mac address of my Bluetooth device
 
-/*
-    u8 buf2[6];
+    /*
+        u8 buf2[6];
 
-    buf2[0] = 0x00;
-    buf2[1] = 0x02;
-    buf2[2] = 0x72;
-    buf2[3] = 0xAD;
-    buf2[4] = 0xF3;
-    buf2[5] = 0x5B;
-*/
+        buf2[0] = 0x00;
+        buf2[1] = 0x02;
+        buf2[2] = 0x72;
+        buf2[3] = 0xAD;
+        buf2[4] = 0xF3;
+        buf2[5] = 0x5B;
+    */
 
     for (int i = 1; i < 3; i++) {
         if (GetString(device,i,s,sizeof(s)) < 0)
@@ -266,18 +266,42 @@
         printf("%d: %s\r\n",i,s);
     }
 
+    //for android ADK
+    if ( ( deviceDesc->idVendor != 0x18D1 ||
+            ( deviceDesc->idProduct != 0x2D00 && deviceDesc->idProduct != 0x2D01))
+            &&switchDevice(device)) {
+            
+        printf("  try to change accmode.interfaceDesc->bInterfaceClass=%d\r\n",interfaceDesc->bInterfaceClass);
+        //1th root
+        //accmode_support=true;
+        printf("accessory mode ok.\r\n");
+        return;
+    }
+
+    if (deviceDesc->idVendor == 0x18D1 &&
+            (deviceDesc->idProduct == 0x2D00 || deviceDesc->idProduct == 0x2D01)) {
+        //2th root
+        printf("connecting Android.\r\n");
+        printf("idVender=%x  idProduct=%x  interfaceDesc->bInterfaceClass=%d\r\n",deviceDesc->idVendor,deviceDesc->idProduct,interfaceDesc->bInterfaceClass);
+        AdkUSB _AdkUSB(device,1,0);
+        _AdkUSB.loop();
+        return;
+
+    }
+
+
     switch (interfaceDesc->bInterfaceClass) {
-            /*
-                    case CLASS_MASS_STORAGE:
-                        if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50)
-                            OnDiskInsert(device);    // it's SCSI!
-                        break;
-            */
+        case CLASS_MASS_STORAGE:
+            if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50)
+                OnDiskInsert(device);    // it's SCSI!
+            break;
+
         case CLASS_WIRELESS_CONTROLLER:
             if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01)
                 OnBluetoothInsert(device);    // it's bluetooth!
             break;
         case CLASS_HID:
+
             printf("idVendor = %04X idProduct = %04X \r\n",deviceDesc->idVendor,deviceDesc->idProduct);
             //printf("device = %d configuration = %d interfaceNumber = %d\r\n", device, configuration, interfaceNumber);
             //if (deviceDesc->idVendor == 0x054C &&  deviceDesc->idProduct == 0x0268) StartPS3Event(device,1,0);
@@ -293,22 +317,7 @@
             } else StartAutoEvent(device,1,0);
             break;
 
-        case CLASS_VENDOR_SPECIFIC:
-            if (deviceDesc->idVendor == 0x18D1 &&
-                    (deviceDesc->idProduct == 0x2D00 || deviceDesc->idProduct == 0x2D01)) 
-            {
-
-                printf("accessory mode ok.\r\n");
-                printf("idVender=%x  idProduct=%x  interfaceDesc->bInterfaceClass=%d\r\n",deviceDesc->idVendor,deviceDesc->idProduct,interfaceDesc->bInterfaceClass);
-                AdkUSB _AdkUSB(device,1,0);
-                _AdkUSB.loop();
-          
-            }
-            break;
-
         default:
-            printf("  try to change accmode.interfaceDesc->bInterfaceClass=%d\r\n",interfaceDesc->bInterfaceClass);
-            if (switchDevice(device))break;
 
             printf("Not yet supported \r\n");
             //StartAutoEvent(device,1,0);
--- a/USBHost.cpp	Thu May 26 19:08:55 2011 +0000
+++ b/USBHost.cpp	Fri May 27 18:51:15 2011 +0000
@@ -24,6 +24,7 @@
 #include "mbed.h"
 #include "USBHost.h"
 
+
 //    Config (default uses x bytes)
 #define MAX_DEVICES 8                // Max number of devices
 #define MAX_ENDPOINTS_TOTAL 16        // Max number of endpoints total
@@ -758,7 +759,7 @@
     }
 
     void ResetPort(int hub, int port)
-    {
+    {        
         LOG("ResetPort Hub:%d Port:%d\r\n",hub,port);
         _connectPending++;            // Only reset/add 1 device at a time
         if (hub == 0)