X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=src%2Fftdi.c;h=fe146b75ad8254f36e564136bf11da6006268fe1;hp=03a10be5bf23208aefd2c0d30398f3ea657079ee;hb=1ad9e4cc95b76fa304f6e21723eaf2fb457e0006;hpb=f45f42373318c5504e7d42168991808fb017ca0c diff --git a/src/ftdi.c b/src/ftdi.c index 03a10be..fe146b7 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -328,9 +328,9 @@ int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devli if (libusb_get_device_descriptor(dev, &desc) < 0) ftdi_error_return_free_device_list(-6, "libusb_get_device_descriptor() failed", devs); - if (((vendor != 0 && product != 0) && + if (((vendor || product) && desc.idVendor == vendor && desc.idProduct == product) || - ((vendor == 0 && product == 0) && + (!(vendor || product) && (desc.idVendor == 0x403) && (desc.idProduct == 0x6001 || desc.idProduct == 0x6010 || desc.idProduct == 0x6011 || desc.idProduct == 0x6014))) { @@ -413,8 +413,8 @@ int ftdi_usb_get_strings(struct ftdi_context * ftdi, struct libusb_device * dev, if ((ftdi==NULL) || (dev==NULL)) return -1; - if (libusb_open(dev, &ftdi->usb_dev) < 0) - ftdi_error_return(-4, "libusb_open() failed"); + if (ftdi->usb_dev == NULL && libusb_open(dev, &ftdi->usb_dev) < 0) + ftdi_error_return(-4, "libusb_open() failed"); if (libusb_get_device_descriptor(dev, &desc) < 0) ftdi_error_return(-11, "libusb_get_device_descriptor() failed"); @@ -1018,8 +1018,8 @@ static int ftdi_to_clkbits_AM(int baudrate, unsigned long *encoded_divisor) static const char am_adjust_up[8] = {0, 0, 0, 1, 0, 3, 2, 1}; static const char am_adjust_dn[8] = {0, 0, 0, 1, 0, 1, 2, 3}; int divisor, best_divisor, best_baud, best_baud_diff; - divisor = 24000000 / baudrate; int i; + divisor = 24000000 / baudrate; // Round down to supported fraction (AM only) divisor -= am_adjust_dn[divisor & 7]; @@ -1393,7 +1393,7 @@ int ftdi_write_data(struct ftdi_context *ftdi, const unsigned char *buf, int siz return offset; } -static void ftdi_read_data_cb(struct libusb_transfer *transfer) +static void LIBUSB_CALL ftdi_read_data_cb(struct libusb_transfer *transfer) { struct ftdi_transfer_control *tc = (struct ftdi_transfer_control *) transfer->user_data; struct ftdi_context *ftdi = tc->ftdi; @@ -1475,7 +1475,7 @@ static void ftdi_read_data_cb(struct libusb_transfer *transfer) } -static void ftdi_write_data_cb(struct libusb_transfer *transfer) +static void LIBUSB_CALL ftdi_write_data_cb(struct libusb_transfer *transfer) { struct ftdi_transfer_control *tc = (struct ftdi_transfer_control *) transfer->user_data; struct ftdi_context *ftdi = tc->ftdi; @@ -3065,6 +3065,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) { output[0x1a + j] = eeprom->cbus_function[j]; } + output[0x0b] = eeprom->invert; break; } @@ -3120,6 +3121,21 @@ static unsigned char bit2type(unsigned char bits) } return 0; } +/* Decode 230X / 232R type chips invert bits + * Prints directly to stdout. +*/ +static void print_inverted_bits(int invert) +{ + char *r_bits[] = {"TXD","RXD","RTS","CTS","DTR","DSR","DCD","RI"}; + int i; + + fprintf(stdout,"Inverted bits:"); + for (i=0; i<8; i++) + if ((invert & (1<type == TYPE_232H) { - int i; - eeprom->channel_a_type = buf[0x00] & 0xf; eeprom->channel_a_driver = (buf[0x00] & DRIVER_VCPH)?DRIVER_VCP:0; eeprom->clock_polarity = buf[0x01] & FT1284_CLK_IDLE_STATE; @@ -3391,6 +3405,8 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) eeprom->group1_drive = (buf[0x0c] >> 4) & 0x03; eeprom->group1_schmitt = (buf[0x0c] >> 4) & IS_SCHMITT; eeprom->group1_slew = (buf[0x0c] >> 4) & SLOW_SLEW; + + eeprom->invert = buf[0xb]; } if (verbose) @@ -3474,7 +3490,6 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) } else if (ftdi->type == TYPE_232H) { - int i; char *cbush_mux[] = {"TRISTATE","RXLED","TXLED", "TXRXLED","PWREN", "SLEEP","DRIVE_0","DRIVE_1","IOMODE","TXDEN", "CLK30","CLK15","CLK7_5" @@ -3496,7 +3511,6 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) } else if (ftdi->type == TYPE_230X) { - int i; char *cbush_mux[] = {"TRISTATE","RXLED","TXLED", "TXRXLED","PWREN", "SLEEP","DRIVE_0","DRIVE_1","IOMODE","TXDEN", "CLK24","CLK12","CLK6","BAT_DETECT","BAT_DETECT#", @@ -3516,6 +3530,9 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) if (eeprom->cbus_function[i]<= CBUSH_AWAKE) fprintf(stdout,"CBUS%d Function: %s\n", i, cbush_mux[eeprom->cbus_function[i]]); } + + if (eeprom->invert) + print_inverted_bits(eeprom->invert); } if (ftdi->type == TYPE_R) @@ -3527,14 +3544,8 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose) char *cbus_BB[] = {"RXF","TXE","RD", "WR"}; if (eeprom->invert) - { - char *r_bits[] = {"TXD","RXD","RTS", "CTS","DTR","DSR","DCD","RI"}; - fprintf(stdout,"Inverted bits:"); - for (i=0; i<8; i++) - if ((eeprom->invert & (1<invert); + for (i=0; i<5; i++) { if (eeprom->cbus_function[i]