Jason Engelman / Mbed 2 deprecated BlueUSB

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AutoEvents.cpp Source File

AutoEvents.cpp

00001 
00002 /*
00003 Copyright (c) 2010 Peter Barrett
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 /*
00024 CP210
00025 HubStatusChange Hub:0 Port:1 00010101
00026 ResetPort Hub:0 Port:1
00027 HubStatusChange Hub:0 Port:1 00100103
00028 Connect Hub:0 Port:1 full
00029 Class 00 found 10C4:EA60
00030 AddEndpoint D:01 A:01 T:02 P:0040 I:00
00031 LoadDevice 1 FF:00:00
00032 1: Silicon Labs
00033 2: CP2103 USB to UART Bridge Controller
00034 
00035 ////
00036 CP210
00037 HubStatusChange Hub:0 Port:1 00010101
00038 ResetPort Hub:0 Port:1
00039 HubStatusChange Hub:0 Port:1 00100103
00040 Connect Hub:0 Port:1 full
00041 Class 00 found 10C4:EA60
00042 AddEndpoint D:01 A:00 T:00 P:0040 I:00
00043 AddEndpoint D:01 A:81 T:02 P:0040 I:00
00044 AddEndpoint D:01 A:01 T:02 P:0040 I:00
00045 LoadDevice 1 FF:00:00
00046 1: Silicon Labs
00047 2: CP2103 USB to UART Bridge Controller
00048 
00049 ///
00050 FTDI
00051 HubStatusChange Hub:0 Port:1 00010101
00052 ResetPort Hub:0 Port:1
00053 HubStatusChange Hub:0 Port:1 00100103
00054 Connect Hub:0 Port:1 full
00055 
00056 Class 00 found 0403:6001
00057 AddEndpoint D:01 A:00 T:00 P:0008 I:00
00058 AddEndpoint D:01 A:81 T:02 P:0040 I:00
00059 AddEndpoint D:01 A:02 T:02 P:0040 I:00
00060 LoadDevice 1 FF:FF:FF
00061 1: FTDI
00062 2: FT232R USB UART
00063 //
00064 
00065 mouse
00066 HubStatusChange Hub:0 Port:1 00010301
00067 ResetPort Hub:0 Port:1
00068 HubStatusChange Hub:0 Port:1 00100303
00069 Connect Hub:0 Port:1 slow
00070 Class 00 found 046D:C019
00071 AddEndpoint D:01 A:00 T:00 P:0008 I:00
00072 Skipping descriptor 21 (9 bytes)
00073 AddEndpoint D:01 A:81 T:03 P:0005 I:0A
00074 LoadDevice 1 03:01:02
00075 1: Logitech
00076 2: Logitech USB Optical Mouse
00077 Auto Event for 81 00030102
00078 
00079 
00080 usbhd
00081 
00082 HubStatusChange Hub:0 Port:1 00010101
00083 ResetPort Hub:0 Port:1
00084 HubStatusChange Hub:0 Port:1 00100103
00085 Connect Hub:0 Port:1 full
00086 Class 00 found 1E3D:2088
00087 AddEndpoint D:01 A:00 T:00 P:0040 I:00
00088 AddEndpoint D:01 A:01 T:02 P:0040 I:00
00089 AddEndpoint D:01 A:81 T:02 P:0040 I:00
00090 LoadDevice 1 08:06:50
00091 1: V88     
00092 2: V88             
00093 Dumping root dir
00094 _START~1.HTM 256
00095 AUTORUN.INF 256
00096 desktop.ini 256
00097 STARTH~1.HTM 256
00098 html 256
00099        
00100 some tplink shit usb 54mbit wireless
00101        
00102 sChange Hub:0 Port:1 00010101
00103 ResetPort Hub:0 Port:1
00104 HubStatusChange Hub:0 Port:1 00100103
00105 Connect Hub:0 Port:1 full
00106 Class 00 found 148F:2573
00107 AddEndpoint D:01 A:00 T:00 P:0040 I:00
00108 AddEndpoint D:01 A:81 T:02 P:0040 I:00
00109 AddEndpoint D:01 A:01 T:02 P:0040 I:00
00110 LoadDevice 1 FF:FF:FF
00111 1: Ralink
00112 2: 54M.USB.......
00113 
00114 
00115 */
00116 
00117 #include "mbed.h"
00118 #include "USBHost.h"
00119 #include "Utils.h"
00120 
00121 //#include "CP2103.h"
00122 
00123 /* Config request types */
00124 #define REQTYPE_HOST_TO_DEVICE    0x40
00125 #define REQTYPE_DEVICE_TO_HOST    0xc0
00126 
00127 /* Config request codes */
00128 #define CP210X_SPECIFIC        0xFF
00129 
00130 /* CP210X_SPECIFIC */
00131 #define GPIO_WRITE              0x37E1
00132 #define GPIO_READ               0x00C2
00133 #define PORT_CONFIG             0x370C
00134 #define WRITE_VID               0x3701
00135 #define WRITE_PID               0x3702
00136 #define WRITE_PRODUCT           0x3703
00137 #define WRITE_SERIAL            0x3704
00138 #define WRITE_POWER             0x3706
00139 #define WRITE_RELEASE           0x3707
00140 
00141 
00142 /* CP210X_IFC_ENABLE */
00143 #define UART_ENABLE        0x0001
00144 #define UART_DISABLE        0x0000
00145 
00146 #define CP210X_IFC_ENABLE    0x00
00147 
00148 #define CP210X_GPIO0    (1<<0)
00149 #define CP210X_GPIO1    (1<<1)
00150 #define CP210X_GPIO2    (1<<2)
00151 #define CP210X_GPIO3    (1<<3)
00152 
00153 struct cp210x_port_state_t {
00154   uint16_t mode;
00155   uint16_t low_power;
00156   uint16_t latch;
00157 } ;//cp210x_get_config
00158 
00159 struct cp210x_port_config_t {
00160   struct cp210x_port_state_t reset; /**< Port state applied on after reset. */
00161   struct cp210x_port_state_t suspend; /**< Port state applied on suspend. */
00162   unsigned char enhanced_fxn; /**< Enable/disable enhanced port functions. */
00163 } ;//__attribute__ ((packed));
00164 
00165 
00166 typedef struct
00167 {
00168     char *device_name;
00169     uint8_t input; /**< Mask of GPIOs to be configured as inputs. */
00170     uint8_t output; /**< Mask of GPIOs to be configured as outputs. */
00171     uint8_t hi; /**< Mask of GPIOs to be set. */
00172     uint8_t lo; /**< Mask of GPIOs to be cleared. */
00173     uint8_t toggle; /**< Mask of GPIOs to be toggled. */
00174     int dump; /**< Dump structures. */
00175 }
00176 config_t;
00177 
00178 
00179 static const char *pin_names[] =
00180 {
00181     "RI", "DCD", "DTR", "DSR", "TXD", "RXD", "RTS", "CTS",
00182     "GPIO_0", "GPIO_1", "GPIO_2", "GPIO_3",
00183     "reserved", "reserved", "SUSPEND", "/SUSPEND"
00184 };
00185 
00186 static const char *fxn_names[] =
00187 {
00188     "GPIO_0_TXLED",
00189     "GPIO_1_RXLED",
00190     "GPIO_2_RS485",
00191     "reserved",
00192     "WEAKPULLUP_RESET",
00193     "WEAKPULLUP_SUSPEND",
00194     "SERIAL_DYNAMIC_SUSPEND",
00195     "GPIO_DYNAMIC_SUSPEND"
00196 };
00197 
00198 #define AUTOEVT(_class,_subclass,_protocol) (((_class) << 16) | ((_subclass) << 8) | _protocol)
00199 #define AUTO_KEYBOARD AUTOEVT(CLASS_HID,1,1)
00200 #define AUTO_MOUSE AUTOEVT(CLASS_HID,1,2)
00201 
00202 u8 auto_mouse[4];       // buttons,dx,dy,scroll
00203 u8 auto_keyboard[8];    // modifiers,reserved,keycode1..keycode6
00204 u8 auto_joystick[4];    // x,y,buttons,throttle
00205 
00206 void AutoEventCallback(int device, int endpoint, int status, u8* data, int len, void* userData)
00207 {
00208     int evt = (int)userData;
00209     switch (evt)
00210     {
00211         case AUTO_KEYBOARD:
00212             printf("AUTO_KEYBOARD ");
00213             break;
00214         case AUTO_MOUSE:
00215             printf("AUTO_MOUSE ");
00216             break;
00217         default:
00218             printf("HUH ");
00219     }
00220     printfBytes("data",data,len);
00221     USBInterruptTransfer(device,endpoint,data,len,AutoEventCallback,userData);
00222 }
00223 
00224 //  Establish transfers for interrupt events
00225 void AddAutoEvent(int device, InterfaceDescriptor* id, EndpointDescriptor* ed)
00226 {
00227     if ((ed->bmAttributes & 3) != ENDPOINT_INTERRUPT || !(ed->bEndpointAddress & 0x80))
00228         return;
00229     
00230     // Make automatic interrupt enpoints for known devices
00231     u32 evt = AUTOEVT(id->bInterfaceClass,id->bInterfaceSubClass,id->bInterfaceProtocol);
00232     u8* dst = 0;
00233     int len;
00234     switch (evt)
00235     {
00236         case AUTO_MOUSE:
00237             dst = auto_mouse;
00238             len = sizeof(auto_mouse);
00239             break;
00240         case AUTO_KEYBOARD:
00241             dst = auto_keyboard;
00242             len = sizeof(auto_keyboard);
00243             break;
00244         default:
00245             printf("Interrupt endpoint %02X %08X\n",ed->bEndpointAddress,evt);
00246             break;
00247     }
00248     if (dst)
00249     {
00250         printf("Auto Event for %02X %08X\n",ed->bEndpointAddress,evt);
00251         USBInterruptTransfer(device,ed->bEndpointAddress,dst,len,AutoEventCallback,(void*)evt);
00252     }
00253 }
00254 
00255 void PrintString(int device, int i)
00256 {
00257     u8 buffer[256];
00258     int le = GetDescriptor(device,DESCRIPTOR_TYPE_STRING,i,buffer,255);
00259     if (le < 0)
00260          return;
00261     char* dst = (char*)buffer;
00262     for (int j = 2; j < le; j += 2)
00263         *dst++ = buffer[j];
00264     *dst = 0;
00265     printf("%d:%s\n",i,(const char*)buffer);
00266  }
00267  
00268 //  Walk descriptors and create endpoints for a given device
00269 int StartAutoEvent(int device, int configuration, int interfaceNumber)
00270 {
00271     u8 buffer[255];
00272     int err = GetDescriptor(device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,255);
00273     if (err < 0)
00274         return err;
00275 
00276     int len = buffer[2] | (buffer[3] << 8);
00277     u8* d = buffer;
00278     u8* end = d + len;
00279     while (d < end)
00280     {
00281         if (d[1] == DESCRIPTOR_TYPE_INTERFACE)
00282         {
00283             InterfaceDescriptor* id = (InterfaceDescriptor*)d;
00284             if (id->bInterfaceNumber == interfaceNumber)
00285             {
00286                  d += d[0];
00287                 while (d < end && d[1] != DESCRIPTOR_TYPE_INTERFACE)
00288                 {
00289                     if (d[1] == DESCRIPTOR_TYPE_ENDPOINT)
00290                         AddAutoEvent(device,id,(EndpointDescriptor*)d);
00291                     d += d[0];
00292                 }
00293             }
00294         }
00295         d += d[0];
00296     }
00297     return 0;
00298 }
00299 
00300 
00301 
00302 //  Implemented in main.cpp
00303 int OnDiskInsert(int device);
00304 
00305 //  Implemented in TestShell.cpp
00306 int OnBluetoothInsert(int device);
00307 
00308 static int cp210x_set_config(int device, u8 request,
00309         unsigned int *data, int size)
00310 {
00311 /*
00312         result = usb_control_msg(serial->dev,
00313                 usb_sndctrlpipe(serial->dev, 0),
00314                 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
00315                 0, buf, size, 300);
00316     */            
00317                 
00318     return  USBControlTransfer(device,
00319          REQTYPE_HOST_TO_DEVICE, request, 0x0000, 0,
00320          (u8*)data, sizeof(*data),0);
00321 
00322      
00323 }
00324 
00325 
00326 void
00327 print_bits8( const uint8_t value )
00328 {
00329     int i = 7;
00330     printf("b");
00331     do
00332     {
00333         printf("%c", value & (1<<i) ? '1' : '0');
00334     }
00335     while( i-- );
00336 }
00337 
00338 void
00339 print_bits16( const uint16_t value )
00340 {
00341     int i = 15;
00342     printf("b");
00343     do
00344     {
00345         printf("%c", value & (1<<i) ? '1' : '0');
00346     }
00347     while( i-- );
00348 }
00349  
00350  
00351 int cp210x_get_port_config(int device,struct cp210x_port_config_t *data)
00352 {
00353     int result;
00354 
00355     /* Issue the request, attempting to read 'size' bytes */
00356     //result = cp2103_usb_control_msg(
00357     //    CP210X_SPECIFIC, REQTYPE_DEVICE_TO_HOST, PORT_CONFIG, 0,
00358     //    data, sizeof(*data));
00359 
00360     result = USBControlTransfer(device,
00361          REQTYPE_DEVICE_TO_HOST, CP210X_SPECIFIC, PORT_CONFIG, 0,
00362          (u8*)data, sizeof(*data),0);
00363 
00364     if (result != sizeof(*data)) {
00365         printf("Unable to get port_config, result = %d", result);
00366         return -1;
00367     }
00368 
00369     printf("reset: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
00370         " - supend: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
00371         " - enhanced_fxn: 0x%02X",
00372         data->reset.mode, data->reset.low_power, data->reset.latch,
00373         data->suspend.mode, data->suspend.low_power,
00374         data->suspend.latch, data->enhanced_fxn
00375         );
00376 
00377     return 0;
00378 }
00379 
00380 int cp210x_set_port_config(int device,struct cp210x_port_config_t *data)
00381 {
00382     int result;
00383 
00384     printf("reset: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
00385         " - supend: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
00386         " - enhanced_fxn: 0x%02X",
00387         data->reset.mode, data->reset.low_power, data->reset.latch,
00388         data->suspend.mode, data->suspend.low_power,
00389         data->suspend.latch, data->enhanced_fxn
00390         );
00391 
00392     /* Issue the request, attempting to read 'size' bytes */
00393 //    result = cp2103_usb_control_msg(
00394 //        CP210X_SPECIFIC, REQTYPE_HOST_TO_DEVICE, PORT_CONFIG, 0,
00395 //        data, sizeof(*data));
00396 
00397     result = USBControlTransfer(device,
00398          REQTYPE_HOST_TO_DEVICE, CP210X_SPECIFIC, PORT_CONFIG, 0,
00399          (u8*)data, sizeof(*data),0);
00400 
00401 
00402 
00403     if (result != sizeof(*data)) {
00404         printf("Unable to set port_config, result = %d", result);
00405         return -1;
00406     }
00407 
00408     return 0;
00409 }
00410 
00411 static int cp210x_set_config_single(int device,
00412         u8 request, unsigned int data)
00413 {
00414     return cp210x_set_config(device, request, &data, 2);
00415 }
00416 
00417 static int cp210x_read_gpio(int device, int offset)
00418 {
00419     int result;
00420     u8 *data;
00421     /* Issue the request, attempting to read 'size' bytes */
00422     //result = cp210x_control_msg(serial,
00423     //    CP210X_SPECIFIC, REQTYPE_DEVICE_TO_HOST, GPIO_READ,
00424     //    0, data, sizeof(*data));
00425 
00426     result = USBControlTransfer(device,
00427          REQTYPE_DEVICE_TO_HOST, CP210X_SPECIFIC, GPIO_READ, 0,
00428          (u8*)data, sizeof(*data),0);
00429 
00430 
00431     if (result != sizeof(*data)) {
00432         printf("%s: Unable to read gpio latch, ");
00433         return -1;
00434     }
00435 
00436     printf("\n\rread latch value = 0x%02X", *data);
00437 print_bits8(*data);
00438     return 0;// data & (1<<(offset & 0x0F));
00439 }
00440 
00441 static int cp210x_write_gpio(int device, const u8 mask,
00442         const u8 value)
00443 {
00444     
00445     int result;
00446 
00447     printf("writing to latch mask = 0x%02X, value = 0x%02X", mask, value);
00448 
00449     //result = cp210x_control_msg(serial,
00450     //    CP210X_SPECIFIC, REQTYPE_HOST_TO_DEVICE, GPIO_WRITE,
00451     //    (value << 8) | mask, NULL, 0);
00452 
00453     u8 val = (value << 8)| mask ;
00454     result = USBControlTransfer(device,
00455          REQTYPE_HOST_TO_DEVICE, CP210X_SPECIFIC, GPIO_WRITE,  
00456          (value << 8)| mask,
00457          0, NULL,0);
00458 
00459     if (result < 0) {
00460         printf( "%s: Unable to write into gpio latch, ");
00461         return -1;
00462     }
00463 
00464     return 0;
00465 }
00466 
00467 static void cp210x_gpio_set(int device,
00468     unsigned offset, int value)
00469 {
00470     (void)cp210x_write_gpio(device,
00471         (1<<(offset & 0x0F)), value ? 0xFF : 0x00);
00472 }
00473 static int cp210x_gpio_input_mask(int device, u8 mask)
00474 {
00475     struct cp210x_port_config_t config = {};
00476     int result;
00477 
00478     mask &= 0x0F;
00479 
00480     /* configure masked gpio as open-drain and set masked latch bits */
00481     result = cp210x_get_port_config(device, &config);
00482     if (result == 0) {
00483         config.reset.mode &= ~(((u16)mask)<<8);
00484         config.reset.latch |=  ((u16)mask)<<8;
00485         config.suspend.mode &= ~(((u16)mask)<<8);
00486         config.suspend.latch |= ((u16)mask)<<8;
00487         result = cp210x_set_port_config(device, &config);
00488     }
00489     return result;
00490 }
00491 
00492 static int cp210x_gpio_output_mask(int device, u8 mask)
00493 {
00494     struct cp210x_port_config_t config = {};
00495     int result;
00496 
00497     mask &= 0x0F;
00498 
00499     /* configure masked gpio as push-pull */
00500     result = cp210x_get_port_config(device, &config);
00501     if (result == 0) {
00502         config.reset.mode |= ((u16)mask)<<8;
00503         config.suspend.mode |= ((u16)mask)<<8;
00504         result = cp210x_set_port_config(device, &config);
00505     }
00506     return result;
00507 }
00508 
00509 
00510 void
00511 dump_port_config( const struct cp210x_port_config_t config )
00512 {
00513     int i;
00514     printf("--- Dump of port configuration --- \n\r");
00515     printf("Raw data:\n\r");
00516     printf("reset.mode        = 0x%04X ", config.reset.mode);
00517     print_bits16(config.reset.mode); printf("\n\r");
00518     printf("reset.low_power   = 0x%04X ", config.reset.low_power);
00519     print_bits16(config.reset.low_power); printf("\n\r");
00520     printf("reset.latch       = 0x%04X ", config.reset.latch);
00521     print_bits16(config.reset.latch); printf("\n\r");
00522     printf("suspend.mode      = 0x%04X ", config.suspend.mode);
00523     print_bits16(config.suspend.mode); printf("\n\r");
00524     printf("suspend.low_power = 0x%04X ", config.suspend.low_power);
00525     print_bits16(config.suspend.low_power); printf("\n\r");
00526     printf("suspend.latch     = 0x%04X ", config.suspend.latch);
00527     print_bits16(config.suspend.latch); printf("\n\r");
00528     printf("enhanced_fxn      = 0x%02X ", config.enhanced_fxn);
00529     print_bits8(config.enhanced_fxn); printf("\n\r");
00530     printf("\n\r");
00531     printf("Configuration applied on after reset / suspend (mode, low_power, latch):\n\r");
00532     for ( i=0; i<16; i++ )
00533     {
00534         printf("%-20s %s   %s/%s %c/%c %c/%c\n\r",
00535             pin_names[i],
00536             ((config.reset.mode & (1<<i)) == 0 && (config.reset.latch & (1<<i))) ? "IN " : "OUT",
00537             (config.reset.mode & (1<<i)) ? " Push-Pull" : "Open-Drain",
00538             (config.suspend.mode & (1<<i)) ? "Push-Pull " : "Open-Drain",
00539             (config.reset.low_power & (1<<i)) ? '1' : '0',
00540             (config.suspend.low_power & (1<<i)) ? '1' : '0',
00541             (config.reset.latch & (1<<i)) ? '1' : '0',
00542             (config.suspend.latch & (1<<i)) ? '1' : '0');
00543     }
00544     printf("\n\r");
00545     printf("Enhanced functions:\n\r");
00546     for ( i=0; i<8; i++ )
00547     {
00548         printf("%-24s %s\n\r",
00549             fxn_names[i],
00550             (config.enhanced_fxn & (1<<i)) ? "ENABLED" : "DISABLED");
00551     }
00552     printf("--- End of Dump --- \n\r");
00553     printf("\n\r");
00554 }
00555 
00556 
00557 
00558 
00559 int OnCP210xInsert(int device)
00560 {
00561     printf("CP210x inserted of %d\n",device);
00562 
00563     struct cp210x_port_config_t *data;
00564 
00565        int result;
00566        u16 *tes;
00567 
00568    result = cp210x_get_port_config( device,data);
00569 
00570 
00571 
00572    
00573     
00574    // for (i = 0; i <  sizeof(*data); i++)
00575      //   data[i] = le32_to_cpu(data[i]);
00576 
00577     printf("reset: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
00578         " - supend: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
00579         " - enhanced_fxn: 0x%02X --------------------------------------------------",
00580         data->reset.mode, data->reset.low_power, data->reset.latch,
00581         data->suspend.mode, data->suspend.low_power,
00582         data->suspend.latch, data->enhanced_fxn
00583         );
00584 printf(" HERE \n\r");
00585 
00586 dump_port_config(*data);
00587 
00588  //   if (cp210x_set_config_single(device, CP210X_IFC_ENABLE, UART_ENABLE)) {
00589   //      printf(" Unable to enable UART\n");
00590         
00591   //  }
00592   cp210x_gpio_output_mask(device,0xf);
00593   cp210x_read_gpio(device,0);cp210x_read_gpio(device,1);cp210x_read_gpio(device,2);cp210x_read_gpio(device,3);
00594 
00595   cp210x_gpio_set(device,0,0xff);
00596    cp210x_gpio_set(device,1,0x0);
00597    
00598   cp210x_gpio_set(device,2,0xff);
00599    cp210x_gpio_set(device,3,0x0);
00600    
00601  // cp210x_gpio_set(device,2,0xff);
00602   // cp210x_gpio_set(device,3,0xf);
00603    
00604   cp210x_read_gpio(device,0);cp210x_read_gpio(device,1);cp210x_read_gpio(device,2);cp210x_read_gpio(device,3);
00605   
00606 printf(" HERE2 \n\r");
00607    result = cp210x_get_port_config( device,data);
00608 dump_port_config(*data);
00609     return 0;
00610 }
00611 
00612 
00613 int OnFTDIInsert(int device);   
00614 
00615 void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc)
00616 {
00617     printf("LoadDevice %d %02X:%02X:%02X\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol);
00618     char s[128];
00619     for (int i = 1; i < 3; i++)
00620     {
00621         if (GetString(device,i,s,sizeof(s)) < 0)
00622             break;
00623         printf("%d: %s\n",i,s);
00624     }
00625     
00626     switch (interfaceDesc->bInterfaceClass)
00627     {
00628         case CLASS_MASS_STORAGE:
00629             if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50)
00630                 OnDiskInsert(device);    // it's SCSI!
00631             break;
00632         case CLASS_WIRELESS_CONTROLLER:
00633             if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01)
00634                 OnBluetoothInsert(device);    // it's bluetooth!
00635             break;
00636         case CLASS_VENDOR_SPECIFIC:
00637             //Silicon Labs CP210x
00638             if (interfaceDesc->bInterfaceSubClass == 0x00 && interfaceDesc->bInterfaceProtocol == 0x00) {
00639                 OnCP210xInsert(device);  
00640                 
00641                 }
00642             //FTDI Serial
00643             if (interfaceDesc->bInterfaceSubClass == 0xFF && interfaceDesc->bInterfaceProtocol == 0xFF)
00644                 OnFTDIInsert(device);   
00645             break;
00646         default:
00647             StartAutoEvent(device,1,0);
00648             break;
00649     }
00650 }