libftdi: (tomj) autodetection of chip type
authorThomas Jarosch <opensource@intra2net.com>
Wed, 2 Jun 2004 12:30:04 +0000 (12:30 +0000)
committerThomas Jarosch <opensource@intra2net.com>
Wed, 2 Jun 2004 12:30:04 +0000 (12:30 +0000)
ftdi/ftdi.c
ftdi/ftdi.h

index 86e87ce..11dd3bc 100644 (file)
@@ -104,6 +104,16 @@ int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product) {
                     if (ftdi_set_baudrate (ftdi, 9600) != 0)
                         return -7;
 
+                   // Try to guess chip type
+                   // Bug in the BM type chips: bcdDevice is 0x200 for serial == 0
+                   if (dev->descriptor.bcdDevice == 0x400 || (dev->descriptor.bcdDevice == 0x200
+                            && dev->descriptor.iSerialNumber == 0))
+                       ftdi->type = TYPE_BM;
+                   else if (dev->descriptor.bcdDevice == 0x200)
+                       ftdi->type = TYPE_AM;
+                   else if (dev->descriptor.bcdDevice == 0x500)
+                       ftdi->type = TYPE_2232C;
+
                     return 0;
                 } else {
                     ftdi->error_str = "usb_open() failed";
@@ -255,7 +265,7 @@ static int ftdi_convert_baudrate(int baudrate, struct ftdi_context *ftdi,
     }
     // Split into "value" and "index" values
     *value = (unsigned short)(encoded_divisor & 0xFFFF);
-    if(ftdi->type == TYPE_FT2232C) {
+    if(ftdi->type == TYPE_2232C) {
         *index = (unsigned short)(encoded_divisor >> 8);
         *index &= 0xFF00;
         *index |= ftdi->interface;
index a0aec2d..943b611 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <usb.h>
 
-enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_FT2232C=2 };
+enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2 };
 
 struct ftdi_context {
     // USB specific