Comprare ftdi->type and do not set it in EEPROM Structure initialization
[libftdi] / src / ftdi.c
index 7b96610..33ed148 100644 (file)
@@ -2186,34 +2186,34 @@ void ftdi_eeprom_initdefaults(struct ftdi_context *ftdi)
         return;
 
     eeprom = ftdi->eeprom;
+    memset(eeprom, 0, sizeof(struct ftdi_eeprom));
 
     eeprom->vendor_id = 0x0403;
-    eeprom->product_id = 0x6001;
-
-    eeprom->self_powered = 1;
-    eeprom->remote_wakeup = 1;
-    eeprom->release = 0;
-
-    eeprom->in_is_isochronous = 0;
-    eeprom->out_is_isochronous = 0;
-    eeprom->suspend_pull_downs = 0;
-
-    eeprom->use_serial = 0;
-    eeprom->change_usb_version = 0;
+    eeprom->use_serial = USE_SERIAL_NUM;
+    if((ftdi->type == TYPE_AM) || (ftdi->type == TYPE_BM) ||
+       (ftdi->type == TYPE_R))
+        eeprom->product_id = 0x6001;
+    else
+        eeprom->product_id = 0x6010;
+    switch (ftdi->type)
+    {
+    case TYPE_2232H:
+        eeprom->release = 0x200;
+        break;
+    default:
+        eeprom->release = 0;
+    }
     eeprom->usb_version = 0x0200;
-    eeprom->max_power = 0;
+    eeprom->max_power = 100;
 
     eeprom->manufacturer = NULL;
     eeprom->product = NULL;
     eeprom->serial = NULL;
-    for (i=0; i < 5; i++)
-    {
-        eeprom->cbus_function[i] = 0;
-    }
-    eeprom->high_current_a = 0;
-    eeprom->invert = 0;
 
-    eeprom->size = FTDI_MAX_EEPROM_SIZE;
+    if(ftdi->type == TYPE_R)
+        eeprom->size = 0x80;
+    else
+        eeprom->size = -1;
 }
 
 /**
@@ -2294,18 +2294,28 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi, unsigned char *output)
         if (eeprom->high_current_a) return -5;
     }
 
-    size_check = eeprom->size;
-    size_check -= 28; // 28 are always in use (fixed)
+    size_check = 0x80;
+    switch(ftdi->type)
+    {
+    case TYPE_2232H:
+    case TYPE_4232H:
+        size_check -= 4;
+    case TYPE_R:
+        size_check -= 4;
+    case TYPE_2232C:
+        size_check -= 4;
+    case TYPE_AM:
+    case TYPE_BM:
+        size_check -= 0x14*2;
+    }
 
-    // Top half of a 256byte eeprom is used just for strings and checksum
-    // it seems that the FTDI chip will not read these strings from the lower half
-    // Each string starts with two bytes; offset and type (0x03 for string)
-    // the checksum needs two bytes, so without the string data that 8 bytes from the top half
-    if (eeprom->size>=256) size_check = 120;
     size_check -= manufacturer_size*2;
     size_check -= product_size*2;
     size_check -= serial_size*2;
 
+    /* Space for the string type and pointer bytes */
+    size_check -= -6;
+
     // eeprom size exceeded?
     if (size_check < 0)
         return (-1);
@@ -2553,7 +2563,7 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, unsigned char *buf, int size,
     eeprom->in_is_isochronous  = buf[0x0A]&0x01;
     eeprom->out_is_isochronous = buf[0x0A]&0x02;
     eeprom->suspend_pull_downs = buf[0x0A]&0x04;
-    eeprom->use_serial         = buf[0x0A]&0x08;
+    eeprom->use_serial         = buf[0x0A] & USE_SERIAL_NUM;
     eeprom->change_usb_version = buf[0x0A]&0x10;
 
 
@@ -2709,7 +2719,7 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, unsigned char *buf, int size,
                     channel_mode[eeprom->channel_a_type],
                     (eeprom->channel_a_driver)?" VCP":"",
                     (eeprom->high_current_a)?" High Currenr IO":"");
-        if (ftdi->type == TYPE_2232C)
+        if (ftdi->type >= TYPE_2232C)
             fprintf(stdout,"Channel B has Mode %s%s%s\n", 
                     channel_mode[eeprom->channel_b_type],
                     (eeprom->channel_b_driver)?" VCP":"",