X-Git-Url: http://developer.intra2net.com/git/?a=blobdiff_plain;f=src%2Fftdi.c;h=ab57c2759dd5941adce9a6a6829adb03cc5e450d;hb=ac4a82a5f51231ae1fc0e8b189245e7aecd2cad7;hp=5cb3ca57d32b4c655b00e20b19d1547327554d23;hpb=3a2847493a8f21b6400868a34ce56b1efd2fa690;p=libftdi diff --git a/src/ftdi.c b/src/ftdi.c index 5cb3ca5..ab57c27 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -289,13 +289,13 @@ int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devli struct libusb_device_descriptor desc; if (libusb_get_device_descriptor(dev, &desc) < 0) - ftdi_error_return(-6, "libusb_get_device_descriptor() failed"); + ftdi_error_return_free_device_list(-6, "libusb_get_device_descriptor() failed", devs); if (desc.idVendor == vendor && desc.idProduct == product) { *curdev = (struct ftdi_device_list*)malloc(sizeof(struct ftdi_device_list)); if (!*curdev) - ftdi_error_return(-3, "out of memory"); + ftdi_error_return_free_device_list(-3, "out of memory", devs); (*curdev)->next = NULL; (*curdev)->dev = dev; @@ -304,7 +304,7 @@ int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devli count++; } } - + libusb_free_device_list(devs,1); return count; } @@ -428,7 +428,7 @@ static unsigned int _ftdi_determine_max_packet_size(struct ftdi_context *ftdi, l // Determine maximum packet size. Init with default value. // New hi-speed devices from FTDI use a packet size of 512 bytes // but could be connected to a normal speed USB hub -> 64 bytes packet size. - if (ftdi->type == TYPE_2232H || ftdi->type == TYPE_4232H) + if (ftdi->type == TYPE_2232H || ftdi->type == TYPE_4232H || ftdi->type == TYPE_232H ) packet_size = 512; else packet_size = 64; @@ -564,6 +564,8 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi, libusb_device *dev) ftdi->type = TYPE_2232H; else if (desc.bcdDevice == 0x800) ftdi->type = TYPE_4232H; + else if (desc.bcdDevice == 0x900) + ftdi->type = TYPE_232H; // Determine maximum packet size ftdi->max_packet_size = _ftdi_determine_max_packet_size(ftdi, dev); @@ -2205,6 +2207,10 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer, if ((ftdi->type == TYPE_AM) || (ftdi->type == TYPE_BM) || (ftdi->type == TYPE_R)) eeprom->product_id = 0x6001; + else if (ftdi->type == TYPE_4232H) + eeprom->product_id = 0x6011; + else if (ftdi->type == TYPE_232H) + eeprom->product_id = 0x6014; else eeprom->product_id = 0x6010; if (ftdi->type == TYPE_AM) @@ -2226,6 +2232,7 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer, if (eeprom->product) free (eeprom->product); eeprom->product = NULL; + if(product) { eeprom->product = malloc(strlen(product)+1); if (eeprom->product) @@ -2365,6 +2372,9 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) case TYPE_4232H: output[0x07] = 0x08; break; + case TYPE_232H: + output[0x07] = 0x09; + break; default: output[0x07] = 0x00; } @@ -2407,9 +2417,12 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) // Dynamic content // Strings start at 0x94 (TYPE_AM, TYPE_BM) // 0x96 (TYPE_2232C), 0x98 (TYPE_R) and 0x9a (TYPE_x232H) + // 0xa0 (TYPE_232H) i = 0; switch (ftdi->type) { + case TYPE_232H: + i += 2; case TYPE_2232H: case TYPE_4232H: i += 2; @@ -2641,7 +2654,20 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) break; case TYPE_4232H: + output[0x18] = eeprom->chip; fprintf(stderr,"FIXME: Build FT4232H specific EEPROM settings\n"); + break; + case TYPE_232H: + output[0x00] = (eeprom->channel_a_type); + if ( eeprom->channel_a_driver == DRIVER_VCP) + output[0x00] |= DRIVER_VCPH; + else + output[0x00] &= ~DRIVER_VCPH; + + output[0x1e] = eeprom->chip; + fprintf(stderr,"FIXME: Build FT232H specific EEPROM settings\n"); + break; + } // calculate checksum @@ -2877,10 +2903,17 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) eeprom->group3_schmitt = (buf[0x0d] >> 4) & IS_SCHMITT; eeprom->group3_slew = (buf[0x0d] >> 4) & SLOW_SLEW; } + else if (ftdi->type == TYPE_232H) + { + eeprom->channel_a_type = buf[0x00] & 0xf; + eeprom->channel_a_driver = (buf[0x00] & DRIVER_VCPH)?DRIVER_VCP:0; + eeprom->chip = buf[0x1e]; + /*FIXME: Decipher more values*/ + } if (verbose) { - char *channel_mode[] = {"UART","245","CPU", "unknown", "OPTO"}; + char *channel_mode[] = {"UART","245","CPU", "unknown", "OPTO", "unknown1","unknown2","unknown3","FT1284"}; fprintf(stdout, "VID: 0x%04x\n",eeprom->vendor_id); fprintf(stdout, "PID: 0x%04x\n",eeprom->product_id); fprintf(stdout, "Release: 0x%04x\n",release); @@ -2913,7 +2946,7 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) channel_mode[eeprom->channel_a_type], (eeprom->channel_a_driver)?" VCP":"", (eeprom->high_current_a)?" High Current IO":""); - if ((ftdi->type >= TYPE_2232C) && (ftdi->type != TYPE_R)) + if ((ftdi->type >= TYPE_2232C) && (ftdi->type != TYPE_R) && (ftdi->type != TYPE_232H)) fprintf(stdout,"Channel B has Mode %s%s%s\n", channel_mode[eeprom->channel_b_type], (eeprom->channel_b_driver)?" VCP":"", @@ -3430,6 +3463,9 @@ int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr, case TYPE_4232H: chip_type_location = 0x18; break; + case TYPE_232H: + chip_type_location = 0x1e; + break; default: ftdi_error_return(-4, "Device can't access unprotected area"); }