build fixes
[libftdi] / ftdi / ftdi.c
index 37d4385..97b3fcf 100644 (file)
@@ -44,8 +44,11 @@ int ftdi_init(struct ftdi_context *ftdi) {
 
     ftdi->error_str = NULL;
 
-    // all fine. Now allocate the readbuffer
-    return ftdi_read_data_set_chunksize(ftdi, 4096);
+    /* All fine. Now allocate the readbuffer
+       Note: A readbuffer size above 64 bytes results in buggy input.
+             This seems to be a hardware limitation as noted
+            in the ftdi_sio driver */
+    return ftdi_read_data_set_chunksize(ftdi, 64);
 }
 
 
@@ -104,6 +107,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 +268,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;
@@ -281,7 +294,7 @@ int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate) {
         baudrate = baudrate*4;
     }
 
-    actual_baudrate = convert_baudrate(baudrate, ftdi, &value, &index);
+    actual_baudrate = ftdi_convert_baudrate(baudrate, ftdi, &value, &index);
     if (actual_baudrate <= 0) {
         ftdi->error_str = "Silly baudrate <= 0.";
         return -1;
@@ -434,7 +447,7 @@ int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksi
 }
 
 
-int ftdi_readt_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize) {
+int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize) {
     *chunksize = ftdi->readbuffer_chunksize;
     return 0;
 }
@@ -510,8 +523,8 @@ int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency) {
 
 
 void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom) {
-    eeprom->vendor_id = 0403;
-    eeprom->product_id = 6001;
+    eeprom->vendor_id = 0x0403;
+    eeprom->product_id = 0x6001;
 
     eeprom->self_powered = 1;
     eeprom->remote_wakeup = 1;
@@ -523,7 +536,7 @@ void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom) {
 
     eeprom->use_serial = 0;
     eeprom->change_usb_version = 0;
-    eeprom->usb_version = 200;
+    eeprom->usb_version = 0x0200;
     eeprom->max_power = 0;
 
     eeprom->manufacturer = NULL;