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");
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];
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;
}
-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;
{
output[0x1a + j] = eeprom->cbus_function[j];
}
+ output[0x0b] = eeprom->rs232_inversion;
break;
}
*/
int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose)
{
- unsigned char i, j;
+ int i, j;
unsigned short checksum, eeprom_checksum, value;
unsigned char manufacturer_size = 0, product_size = 0, serial_size = 0;
int eeprom_size;
}
else if (ftdi->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;
eeprom->group1_drive = (buf[0x0c] >> 4) & 0x03;
eeprom->group1_schmitt = (buf[0x0c] >> 4) & IS_SCHMITT;
eeprom->group1_slew = (buf[0x0c] >> 4) & SLOW_SLEW;
+
+ eeprom->rs232_inversion = buf[0xb];
}
if (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"
}
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#",
if (eeprom->cbus_function[i]<= CBUSH_AWAKE)
fprintf(stdout,"CBUS%d Function: %s\n", i, cbush_mux[eeprom->cbus_function[i]]);
}
+ if(eeprom->rs232_inversion ) {
+ struct bitnames {
+ int mask;
+ char *name;
+ };
+
+ struct bitnames invbitlist[] = {
+ {INVERT_TXD, "TXD"},
+ {INVERT_RXD, "RXD"},
+ {INVERT_RTS, "RTS"},
+ {INVERT_CTS, "CTS"},
+ {INVERT_DTR, "DTR"},
+ {INVERT_DSR, "DSR"},
+ {INVERT_DCD, "DCD"},
+ {INVERT_RI, "RI"},
+ {0, NULL},
+ };
+ int i, n;
+ printf("Inversion on ");
+ for (i=0, n=0; invbitlist[i].mask;i++) {
+ if(eeprom->rs232_inversion & invbitlist[i].mask) {
+ if (n++) printf (",");
+ printf (" %s", invbitlist[i].name);
+ }
+ }
+ printf (" Pin%s\n",(n==1)?"":"s");
+ }
}
if (ftdi->type == TYPE_R)
case CHIP_SIZE:
*value = ftdi->eeprom->size;
break;
+ case RS232_INVERSION:
+ *value = ftdi->eeprom->rs232_inversion;
+ break;
default:
ftdi_error_return(-1, "Request for unknown EEPROM value");
}
break;
case CHIP_SIZE:
ftdi_error_return(-2, "EEPROM Value can't be changed");
+ break;
+ case RS232_INVERSION:
+ ftdi->eeprom->rs232_inversion = value;
+ break;
+
default :
ftdi_error_return(-1, "Request to unknown EEPROM value");
}