void setCBUSbits(UCHAR cbus1)
{
	ftStatus = FT_Open(i,&ftHandle);
	ftStatus = FT_EE_Read(ftHandle, &ftData);
	if (ftStatus == FT_OK) {
			
		old_cbus1_state=ftData.Cbus1;  // save state of cbus1
	//	ftData.Cbus0=0;
		ftData.Cbus1 = cbus1;    //  0x0A will set to I/O mode, otherwise restore from old_cbus1_state
	//	ftData.Cbus2=1;
	//	ftData.Cbus3=2;
	//	ftData.Cbus4=1;

		ftStatus = FT_EE_Program(ftHandle, &ftData);
		if (ftStatus == FT_OK)
		{
			ftStatus = FT_CyclePort(ftHandle);
			if (ftStatus == FT_OK) 
			{ 
				// Port has been cycled.
				// Close the handle.
				ftStatus = FT_Close(ftHandle);
				if (ftStatus==FT_OK) {

					printf("Device Close OK! \n");
					ftStatus=FT_Rescan();
					Sleep(5000);

				}
				else
				{
					printf("Device Close Failed! \n");
				}
			}
			else
			{ 
				// FT_CyclePort FAILED!
				printf("CyclePort Failed!\n");
			}
		}
		else
		{ 
			// FT_EE_Program FAILED!
			printf("FT_EE_Program FAILED!\n");
		}
	}
}
Exemple #2
0
/* Writing data to EEPROM FTDI */
quint16 ftdiChip::on_EEPROM()
{
FT_STATUS ftStatus;
FT_PROGRAM_DATA ftData;
char ManufacturerBuf[32];
char ManufacturerIdBuf[16];
char DescriptionBuf[64];
char SerialNumberBuf[16];

memset(&ftData,0,sizeof(ftData));
ftData.Signature1 = 0x00000000;
ftData.Signature2 = 0xffffffff;
ftData.Version = 0x00000002;    // EEPROM structure with FT232R extensions  */
ftData.Manufacturer = ManufacturerBuf;
ftData.ManufacturerId = ManufacturerIdBuf;
ftData.Description = DescriptionBuf;
ftData.SerialNumber = SerialNumberBuf;
ftStatus = Open();
if(ftStatus==retOk){
    ftStatus = FT_EE_Read(hdUSB, &ftData);
    if (ftStatus != FT_OK) {
        emit signalStatusError(tr("Failed to open USB port"),true);
        return retErr;
        }
    strcpy(ftData.Manufacturer,"ELINTEL");
    strcpy(ftData.ManufacturerId,"FT");
    strcpy(ftData.Description,"Debag_for_UDZ");
    strcpy(ftData.SerialNumber,"FT000001");
    ftData.Cbus0 = 0x0A;
    ftData.Cbus1 = 0x0A;
    ftData.Cbus2 = 0x00;
    ftData.Cbus3 = 0x0A;
    ftData.Cbus4 = 0x01;
ftStatus = FT_EE_Program(hdUSB, &ftData);
    if (ftStatus != FT_OK){
        emit signalStatusError(tr("Error writing flash"),true);
        return retErr;
        }
    emit signalStatusOk(tr("Flash is successfully"));
    return retOk;
    }
emit signalStatusError(tr("Error writing flash"),true);
return retErr;
}
Exemple #3
0
int main(int argc, char *argv[])
{
	FT_STATUS	ftStatus;
	FT_HANDLE	ftHandle0;
	int iport;
	FT_PROGRAM_DATA Data;
	
	if(argc > 1) {
		sscanf(argv[1], "%d", &iport);
	}
	else {
		iport = 0;
	}
	printf("opening port %d\n", iport);
	FT_SetVIDPID(0x0403, 0x6011);
	ftStatus = FT_Open(iport, &ftHandle0);
	
	if(ftStatus != FT_OK) {
		/* 
			This can fail if the ftdi_sio driver is loaded
		 	use lsmod to check this and rmmod ftdi_sio to remove
			also rmmod usbserial
		 */
		printf("FT_Open(%d) failed\n", iport);
		return 1;
	}

	printf("ftHandle0 = %p\n", ftHandle0);

#ifndef BM_DEVICE
	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.VendorId = 0x0403;				
	Data.ProductId = 0x6001;
	Data.Manufacturer =  "FTDI";
	Data.ManufacturerId = "FT";
	Data.Description = "USB <-> Serial";
	Data.SerialNumber = "FT000001";		// if fixed, or NULL
	
	Data.MaxPower = 44;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 1;
	Data.Rev4 = 1;
	Data.IsoIn = 0;
	Data.IsoOut = 0;
	Data.PullDownEnable = 1;
	Data.SerNumEnable = 1;
	Data.USBVersionEnable = 0;
	Data.USBVersion = 0x110;
#else // If 2232C	

	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.VendorId = 0x0403;				
	Data.ProductId = 0x6010;
	Data.Manufacturer =  "FTDI";
	Data.ManufacturerId = "FT";
	Data.Description = "SPI";
	Data.SerialNumber = "FT123452";		// if fixed, or NULL
	
	Data.MaxPower = 200;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 0;
	Data.Rev4 = 0;
	Data.IsoIn = 0;
	Data.IsoOut = 0;
	Data.PullDownEnable = 0;
	Data.SerNumEnable = 0;
	Data.USBVersionEnable = 0;
	Data.USBVersion = 0;

	Data.Rev5 = 1;					// non-zero if Rev5 chip, zero otherwise
	Data.IsoInA = 0;				// non-zero if in endpoint is isochronous
	Data.IsoInB = 0;				// non-zero if in endpoint is isochronous
	Data.IsoOutA = 0;				// non-zero if out endpoint is isochronous
	Data.IsoOutB = 0;				// non-zero if out endpoint is isochronous
	Data.PullDownEnable5 = 0;		// non-zero if pull down enabled
	Data.SerNumEnable5 = 1;			// non-zero if serial number to be used
	Data.USBVersionEnable5 = 0;		// non-zero if chip uses USBVersion
	Data.USBVersion5 = 0x0200;		// BCD (0x0200 => USB2)
	Data.AIsHighCurrent = 0;		// non-zero if interface is high current
	Data.BIsHighCurrent = 0;		// non-zero if interface is high current
	Data.IFAIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFAIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFAIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.AIsVCP = 0;				// non-zero if interface is to use VCP drivers
	Data.IFBIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFBIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFBIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.BIsVCP = 0;				// non-zero if interface is to use VCP drivers

#endif								

	ftStatus = FT_EE_Program(ftHandle0, &Data);
	if(ftStatus != FT_OK) {
		printf("FT_EE_Program failed (%d)\n", ftStatus);
		FT_Close(ftHandle0);
	}
	FT_Close(ftHandle0);
	return 0;
}
Exemple #4
0
int getandcheckCBUS( FT_HANDLE ftHandle0 ) {
  FT_PROGRAM_DATA Data;
  int need_write = 0;
  FT_STATUS	ftStatus;

  if( ser_dbg )
    printf("ftHandle0 = %p\n", ftHandle0);

  Data.Signature1 = 0x00000000;
  Data.Signature2 = 0xffffffff;
  Data.Manufacturer = (char *)malloc(256);		// "FTDI"
  Data.ManufacturerId = (char *)malloc(256);	// "FT"
  Data.Description = (char *)malloc(256);			// "USB HS Serial Converter"
  Data.SerialNumber = (char *)malloc(256);		// "FT000001" if fixed, or NULL
  ftStatus = FT_EE_Read(ftHandle0, &Data);
  if(ftStatus != FT_OK) {
    printf("FT_EE_Read failed\n");
    FT_Close(ftHandle0);
    return 1;
  }

  if( ser_dbg ) {
    printf("Cbus0 = 0x%X\n", Data.Cbus0);				// Cbus Mux control
    printf("Cbus1 = 0x%X\n", Data.Cbus1);				// Cbus Mux control
    printf("Cbus2 = 0x%X\n", Data.Cbus2);				// Cbus Mux control
    printf("Cbus3 = 0x%X\n", Data.Cbus3);				// Cbus Mux control
    printf("Cbus4 = 0x%X\n", Data.Cbus4);				// Cbus Mux control
  }

  // check that cbus0 and 2 are write
  if( Data.Cbus0 != 0x0A ) {
    printf( "Cbus0 is %d, should be %d, updating!\n", Data.Cbus0, 0xA );
    Data.Cbus0 = 0x0A;
    need_write = 1;
  }
  
  if( Data.Cbus2 != 0x0A ) {
    printf( "Cbus2 is %d, should be %d, updating!\n", Data.Cbus2, 0xA );
    Data.Cbus2 = 0x0A;
    need_write = 1;
  }

  // check that CBUS3 is power enable
  if( Data.Cbus3 != 0x0A ) {  // was 01
    printf( "Cbus3 is %d, should be %d, updating!\n", Data.Cbus3, 0x1);
    //Data.Cbus2 = 0x0B;  // wierd, should be writing to cbus3, has no effect because current verion is alwasy default (0x01)

    Data.Cbus3 = 0x0A;

    need_write = 1;
  }

  // not necessary, but for the hell of it, cbus 1 is read
  if( Data.Cbus1 != 0x0A ) {
    printf( "Cbus1 is %d, should be %d, updating!\n", Data.Cbus1, 0xA );
    Data.Cbus1 = 0x0A;
    need_write = 1;
  }




if( need_write ) {
    printf( "Updating EEPROM to correct setting for safecast.\n" );
    ftStatus = FT_EE_Program(ftHandle0, &Data);
    if(ftStatus != FT_OK) {
      printf("FT_EE_Program failed (%d)\n", ftStatus);
      FT_Close(ftHandle0);
      return 1;
    }
    printf( "------> Now that the EEPROM is updated, unplug and replug the device.\n" );
  } else {
    printf( "EEPROM values are up to date, not modifying them\n" );
  }

   printf( "Updating CBUS3 for charging.\n" );  


  ftStatus = FT_SetBitMode(ftHandle0, 0x80, 0x20); // CBUS bitbang mode
  if(ftStatus != FT_OK) {
    printf("Failed to set CBUS\n");
  }else {
   
      printf("Set CBUS3 to LOW\n" );
  }




  return 0;

}
Exemple #5
0
int main(int argc, char *argv[])
{
	FT_STATUS	ftStatus;
	FT_HANDLE	ftHandle0;
	int iport;
	FT_PROGRAM_DATA Data;
	char *serialstr;
	if(argc == 3) {
		sscanf(argv[1], "%d", &iport);
		serialstr = argv[2];
	}
	else {
		fprintf(stderr, "syntax: %s iPort serialPrefix serialNumber\n", argv[0]);
		return -1;
	}
	//printf("opening port %d\n", iport);
	FT_SetVIDPID(0x0403, 0x6014);
	ftStatus = FT_Open(iport, &ftHandle0);
	if(ftStatus != FT_OK) {
		/* 
			This can fail if the ftdi_sio driver is loaded
		 	use lsmod to check this and rmmod ftdi_sio to remove
			also rmmod usbserial
		 */
		printf("FT_Open port %d failed\n", iport);
		return 1;
	}

	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.Version = 5;	//FT232H
	Data.VendorId = 0x0403;
	Data.ProductId = 0x6014;
	Data.Manufacturer =  "DLRC";
	Data.ManufacturerId = "FT";
	Data.Description = "DLRC SNAPNODE Plus Rev 2.0";
	Data.SerialNumber = serialstr;		// if fixed, or NULL

	Data.MaxPower = 500;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 1;

	//FT232H
	Data.PullDownEnableH = 1;	// non-zero if pull down enabled
	Data.SerNumEnableH = 1;		// non-zero if serial number to be used
	Data.ACSlowSlewH = 0;		// non-zero if AC pins have slow slew
	Data.ACSchmittInputH = 0;	// non-zero if AC pins are Schmitt input
	Data.ACDriveCurrentH = 4;	// valid values are 4mA, 8mA, 12mA, 16mA
	Data.ADSlowSlewH = 0; 		// non-zero if AD pins have slow slew
	Data.ADSchmittInputH = 0;	// non-zero if AD pins are Schmitt input
	Data.ADDriveCurrentH = 4;	// valid values are 4mA, 8mA, 12mA, 16mA
	Data.Cbus0H = 0;			// Cbus Mux control
	Data.Cbus1H = 0;			// Cbus Mux control
	Data.Cbus2H = 0;			// Cbus Mux control
	Data.Cbus3H = 1;			// Cbus Mux control
	Data.Cbus4H = 2;			// Cbus Mux control
	Data.Cbus5H = 0;			// Cbus Mux control
	Data.Cbus6H = 0;			// Cbus Mux control
	Data.Cbus7H = 0;			// Cbus Mux control
	Data.Cbus8H = 0;			// Cbus Mux control
	Data.Cbus9H = 0;			// Cbus Mux control
	Data.IsFifoH = 0;			// non-zero if interface is 245 FIFO
	Data.IsFifoTarH = 0;		// non-zero if interface is 245 FIFO CPU target
	Data.IsFastSerH = 0;		// non-zero if interface is Fast serial
	Data.IsFT1248H = 0;			// non-zero if interface is FT1248
	Data.FT1248CpolH = 0;		// FT1248 clock polarity - clock idle high (1) or clock idle low (0)
	Data.FT1248LsbH = 0;		// FT1248 data is LSB (1) or MSB (0)
	Data.FT1248FlowControlH = 0;// FT1248 flow control enable
	Data.IsVCPH = 1;			// non-zero if interface is to use VCP drivers
	Data.PowerSaveEnableH = 1;	// non-zero if using ACBUS7 to save power for self-powered designs

#ifdef H2232_DEVICE // If 2232C

	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.VendorId = 0x0403;				
	Data.ProductId = 0x6010;
	Data.Manufacturer =  "FTDI";
	Data.ManufacturerId = "FT";
	Data.Description = "SPI";
	Data.SerialNumber = "FT123452";		// if fixed, or NULL
	
	Data.MaxPower = 200;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 0;
	Data.Rev4 = 0;
	Data.IsoIn = 0;
	Data.IsoOut = 0;
	Data.PullDownEnable = 0;
	Data.SerNumEnable = 0;
	Data.USBVersionEnable = 0;
	Data.USBVersion = 0;

	Data.Rev5 = 1;					// non-zero if Rev5 chip, zero otherwise
	Data.IsoInA = 0;				// non-zero if in endpoint is isochronous
	Data.IsoInB = 0;				// non-zero if in endpoint is isochronous
	Data.IsoOutA = 0;				// non-zero if out endpoint is isochronous
	Data.IsoOutB = 0;				// non-zero if out endpoint is isochronous
	Data.PullDownEnable5 = 0;		// non-zero if pull down enabled
	Data.SerNumEnable5 = 1;			// non-zero if serial number to be used
	Data.USBVersionEnable5 = 0;		// non-zero if chip uses USBVersion
	Data.USBVersion5 = 0x0200;		// BCD (0x0200 => USB2)
	Data.AIsHighCurrent = 0;		// non-zero if interface is high current
	Data.BIsHighCurrent = 0;		// non-zero if interface is high current
	Data.IFAIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFAIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFAIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.AIsVCP = 0;				// non-zero if interface is to use VCP drivers
	Data.IFBIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFBIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFBIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.BIsVCP = 0;				// non-zero if interface is to use VCP drivers

#endif								

	ftStatus = FT_EE_Program(ftHandle0, &Data);
	if(ftStatus != FT_OK) {
		printf("FT_EE_Program failed (%d)\n", (int)ftStatus);
		FT_Close(ftHandle0);
		return -1;
	}
	//FT_CyclePort(ftHandle0);
	FT_Close(ftHandle0);
	return 0;
}
bool CMmcUsbHndlBase::EE_Program(	unsigned short p_usVendorId, 
									unsigned short p_usProductId, 
									char* p_pManufacturer, 
									unsigned int p_ulManufacturerLength,
									char* p_pDescription, 
									unsigned int p_ulDescriptionLength,
									char* p_pSerialNumber, 
									unsigned int p_ulSerialNumberLength,
									bool p_oUseVcpDriver)
{
    const unsigned int BUFFER_SIZE(64);

    FT_PROGRAM_DATA ftData;
    TCHAR ManufacturerBuf[BUFFER_SIZE];
    TCHAR ManufacturerIdBuf[BUFFER_SIZE];
    TCHAR DescriptionBuf[BUFFER_SIZE];
    TCHAR SerialNumberBuf[BUFFER_SIZE];
    BOOL oResult(FALSE);
    FT_STATUS ftStatus = FT_OK;

    //ResetErrorInfo
    //m_ErrorInfo.Reset();

	//Prepare Structure
    ftData.Signature1 = 0x00000000;
    ftData.Signature2 = 0xffffffff;
    ftData.Version = 0x00000002; // EEPROM structure with FT232R extensions
    ftData.Manufacturer = ManufacturerBuf;
    ftData.ManufacturerId = ManufacturerIdBuf;
    ftData.Description = DescriptionBuf;
    ftData.SerialNumber = SerialNumberBuf;

    //Read EE
    if(FT_OK == (ftStatus = FT_EE_Read(m_Handle, &ftData)))
    {
        //VendorId
        ftData.VendorId = p_usVendorId;

        //ProductId
        ftData.ProductId = p_usProductId;

        //Manufacturer
        if(p_ulManufacturerLength < BUFFER_SIZE)
        {
            memset(ManufacturerBuf, 0, BUFFER_SIZE*sizeof(char));
            if(p_pManufacturer) strcpy(ManufacturerBuf, p_pManufacturer);
        }

        //Description
        if(p_ulDescriptionLength < BUFFER_SIZE)
        {
            memset(DescriptionBuf, 0, BUFFER_SIZE*sizeof(TCHAR));
            if(p_pDescription) strcpy(DescriptionBuf, p_pDescription);
        }

        //SerialNumber
        if(p_ulSerialNumberLength < BUFFER_SIZE)
        {
            memset(SerialNumberBuf, 0, BUFFER_SIZE*sizeof(TCHAR));
            if(p_pSerialNumber) strcpy(SerialNumberBuf, p_pSerialNumber);
        }

        //UseVcpDriver
        if(p_oUseVcpDriver) ftData.RIsD2XX = 0; else ftData.RIsD2XX = 1;

        //Program EE
        if(FT_OK == (ftStatus = FT_EE_Program(m_Handle, &ftData)))
            oResult = TRUE;
        else
        {
        	std::string errormsg = GetFtStatusDescription(ftStatus);
			errormsg += ":FT_EE_Program";
			perror(errormsg.c_str());

            oResult = FALSE;
        }
    }
    else
    {
    	std::string errormsg = GetFtStatusDescription(ftStatus);
		errormsg += ":FT_EE_Read";
		perror(errormsg.c_str());

        oResult = FALSE;
    }
      
    return oResult;
}
int main(int argc, char *argv[])
{

  static const struct option long_opts[] = {
    {"prompt",     no_argument,       NULL, 'p'},
    {"verbose",    no_argument,       NULL, 'v'},
    {"help",       no_argument,       NULL, 'h'},
    {NULL,         no_argument,       NULL, 0}
  };

  opterr = 0;
  int c;
  int option_index = 0;
  while ((c = getopt_long(argc, argv, "vph", long_opts, &option_index)) != -1)
    switch (c) {
      case 'v':
        verbose++;
        break;
      case 'p':
        dont_prompt++;
        break;
      case 'h':
        print_usage();
        return EXIT_SUCCESS;
      case '?':
        fprintf(stderr, "Unknown option `-%c'.\n", optopt);
        return EXIT_FAILURE;
      default:
        abort();
     }
  
  DWORD num_devs;
  DWORD VID, PID;
  int iport = 0;

  /* See how many devices are plugged in, fail if greater than 1 */
  if (verbose)
    printf("Creating device info list\n");
  ft_status = FT_CreateDeviceInfoList(&num_devs);
  if (ft_status != FT_OK){
    fprintf(stderr,"ERROR : Failed to create device info list, ft_status = %d\n",ft_status);
    return EXIT_FAILURE;
  }
  if (verbose)
    printf("Making sure only one FTDI device is plugged in\n");
  /* Check that there aren't more than 1 device plugged in */
  if (num_devs > 1){
    fprintf(stderr,"ERROR : More than one FTDI device plugged in\n");
    return EXIT_FAILURE;
  }

  /* Get VID/PID from FTDI device */
  if (verbose)
    printf("Getting VID/PID from device\n");
  ft_status = FT_GetVIDPID(&VID,&PID);
  if (ft_status != FT_OK){
    fprintf(stderr,"ERROR : Failed to get VID and PID from FTDI device, ft_status = %d\n",ft_status);
    return EXIT_FAILURE;
  }
  if (verbose)
    printf("    VID = %04x, PID = %04x\n",VID,PID);
  /* Set the VID/PID found */
  if (verbose)
    printf("Setting VID/PID\n");
  ft_status = FT_SetVIDPID(VID,PID);
  if (ft_status != FT_OK){
    fprintf(stderr,"ERROR : Failed to set VID and PID, ft_status = %d\n",ft_status);
    return EXIT_FAILURE;
  }

  /* Get info about the device and print to user */
  //FT_GetDeviceInfoDetail seems to not work very reliably
  //DWORD lpdw_flags;
  //DWORD lpdw_type;
  //DWORD lpdw_id;
  //char pc_serial_number[16];
  //char pc_description[64];
  //ft_status = FT_GetDeviceInfoDetail(0,&lpdw_flags,&lpdw_type,&lpdw_id,NULL,pc_serial_number,pc_description,&ft_handle);
  //if (ft_status != FT_OK){
  //  fprintf(stderr,"ERROR : Failed to get device info, ft_status = %d\n",ft_status);
  //  return EXIT_FAILURE;
  //}
  //if (verbose || !dont_prompt){
  //  printf("Device Information : \n");
  //  printf("     Description   : %s\n", pc_description);
  //  printf("     Serial Number : %s\n", pc_serial_number);
  //  printf("     Flags         : 0x%x\n", lpdw_flags);
  //  printf("     Type          : 0x%x\n", lpdw_type);
  //  printf("     ID            : 0x%x\n", lpdw_id);
  //}

  /* Ask user if this is the correct device */
  if (!dont_prompt) {
    char correct_device;
    printf("Is this the correct device? (y/n) : ");
    scanf("%c",&correct_device);
    while ((correct_device != 'y') && (correct_device != 'n')) {
      printf("\rPlease enter y or n");
      scanf("%c",&correct_device);
    }
    if (correct_device == 'n'){
      printf("Exiting, since this is not the device we want to program\n");
      return EXIT_SUCCESS;
    }
  }

  /* Open the device */
  if (verbose)
    printf("Attempting to open device using read VID/PID...");
  ft_status = FT_Open(iport, &ft_handle);
  /* If that didn't work, try some other likely VID/PID combos */
  /* Try 0403:6014 */
  if (ft_status != FT_OK){
    if (verbose)
      printf("FAILED\nTrying VID=0x0403, PID=0x6014...");
    ft_status = FT_SetVIDPID(0x0403,0x6014);
    if (ft_status != FT_OK){
      fprintf(stderr,"ERROR : Failed to set VID and PID, ft_status = %d\n",ft_status);
      return EXIT_FAILURE;
    }
    ft_status = FT_Open(iport, &ft_handle);
  }
  /* Try 0403:8398 */
  if (ft_status != FT_OK){
    if (verbose)
      printf("FAILED\nTrying VID=0x0403, PID=0x8398...");
    ft_status = FT_SetVIDPID(0x0403,0x8398);
    if (ft_status != FT_OK){
      fprintf(stderr,"ERROR : Failed to set VID and PID, ft_status = %d\n",ft_status);
      return EXIT_FAILURE;
    }
    ft_status = FT_Open(iport, &ft_handle);
  }
  /* Exit program if we still haven't opened the device */
  if (ft_status != FT_OK){
    if (verbose)
      printf("FAILED\n");
    fprintf(stderr,"ERROR : Failed to open device : ft_status = %d\nHave you tried (sudo rmmod ftdi_sio)?\n",ft_status);
    return EXIT_FAILURE;
  }
  if (verbose)
    printf("SUCCESS\n");

  /* Erase the EEPROM */
  ft_status = FT_EraseEE(ft_handle);
  if(ft_status != FT_OK) {
    fprintf(stderr, "ERROR: Device EEPROM could not be erased : ft_status = %d\n", ft_status);
    return EXIT_FAILURE;
  }
  if (verbose)
    printf("Erased device's EEPROM\n");

  /* Assign appropriate values to eeprom data */
  eeprom_data.Signature1 = 0x00000000;
  eeprom_data.Signature2 = 0xffffffff;
  eeprom_data.Version = 5; /* 5=FT232H */
  eeprom_data.VendorId = USB_CUSTOM_VID;        
  eeprom_data.ProductId = USB_CUSTOM_PID;
  eeprom_data.Manufacturer = "FTDI";
  eeprom_data.ManufacturerId = "FT";
  eeprom_data.Description = "Piksi Passthrough";
  eeprom_data.IsFifoH = 1; /* needed for FIFO samples passthrough */

  /* Program device EEPROM */
  ft_status = FT_EE_Program(ft_handle, &eeprom_data);
  if (ft_status != FT_OK) {
    fprintf(stderr,"ERROR : Failed to program device EEPROM : ft_status = %d\n",ft_status);
    return EXIT_FAILURE;
  }
  if (verbose)
    printf("Programmed device's EEPROM\n");

  /* Reset the device */
  ft_status = FT_ResetDevice(ft_handle);
  if (ft_status != FT_OK) {
    fprintf(stderr, "ERROR: Device could not be reset : ft_status = %d\n", ft_status);
    return EXIT_FAILURE;
  }
  if (verbose)
    printf("Reset device\n");

  /* Close the device */
  if (verbose)
    printf("Closing device\n");
  FT_Close(ft_handle);
  if(ft_status != FT_OK) {
    fprintf(stderr,"ERROR : Failed to close device : ft_status = %d\n",ft_status);
    return EXIT_FAILURE;
  }

  printf("Re-configuring for FIFO mode successful, please unplug and replug your device now\n");

  return EXIT_SUCCESS;
}
Exemple #8
0
int main(int argc, char *argv[])
{
	FT_STATUS	ftStatus;
	FT_HANDLE	ftHandle0;
	int iport;
	FT_PROGRAM_DATA Data;
	FT_DEVICE	ftDevice; 
	
	if(argc > 1) {
		sscanf(argv[1], "%d", &iport);
	}
	else {
		iport = 0;
	}
	printf("opening port %d\n", iport);
	FT_SetVIDPID(0x0403, 0x6017);
	ftStatus = FT_Open(iport, &ftHandle0);
	
	if(ftStatus != FT_OK) {
		/* 
			This can fail if the ftdi_sio driver is loaded
		 	use lsmod to check this and rmmod ftdi_sio to remove
			also rmmod usbserial
		 */
		printf("FT_Open(%d) failed\n", iport);
		return 1;
	}

	printf("ftHandle0 = %p\n", ftHandle0);

		ftStatus = FT_GetDeviceInfo( 
				ftHandle0, 
				&ftDevice, 
				NULL, 
				NULL, 
				NULL, 
				NULL 
				); 

	if (ftStatus != FT_OK) { 
		printf("FT_GetDeviceType FAILED!\n");
		return 1;
	}  

	if (ftDevice == FT_DEVICE_BM) {

		Data.Signature1 = 0x00000000;
		Data.Signature2 = 0xffffffff;
		Data.VendorId = 0x0403;				
		Data.ProductId = 0x6001;
		Data.Manufacturer =  "FTDI";
		Data.ManufacturerId = "FT";
		Data.Description = "USB <-> Srial";
		Data.SerialNumber = "FT000001";		// if fixed, or NULL
		
		Data.MaxPower = 44;
		Data.PnP = 1;
		Data.SelfPowered = 0;
		Data.RemoteWakeup = 1;
		Data.Rev4 = 1;
		Data.IsoIn = 0;
		Data.IsoOut = 0;
		Data.PullDownEnable = 1;
		Data.SerNumEnable = 1;
		Data.USBVersionEnable = 0;
		Data.USBVersion = 0x110;

	}
	else if (ftDevice == FT_DEVICE_232R) {

		Data.Signature1 = 0x00000000;
		Data.Signature2 = 0xffffffff;
		Data.Version = 2;
		Data.VendorId = 0x0403;				
		Data.ProductId = 0x6001 ;
		Data.Manufacturer =  "FTDI";
		Data.ManufacturerId = "FT";
		Data.Description = "USB <-> Serial";
		Data.SerialNumber = "FT000008";		// if fixed, or NULL
		
		Data.MaxPower = 100;
		Data.PnP = 1;
		Data.SelfPowered = 0;
		Data.RemoteWakeup = 1;
			
		Data.UseExtOsc = 0x00;			// Use External Oscillator
		Data.HighDriveIOs = 0x00;			// High Drive I/Os
		Data.EndpointSize = 0x40;			// Endpoint size

		Data.PullDownEnableR = 0x00;		// non-zero if pull down enabled
		Data.SerNumEnableR = 0x01;		// non-zero if serial number to be used

		Data.InvertTXD = 0x00;			// non-zero if invert TXD
		Data.InvertRXD = 0x00;			// non-zero if invert RXD
		Data.InvertRTS = 0x00;			// non-zero if invert RTS
		Data.InvertCTS = 0x00;			// non-zero if invert CTS
		Data.InvertDTR = 0x00;			// non-zero if invert DTR
		Data.InvertDSR = 0x00;			// non-zero if invert DSR
		Data.InvertDCD = 0x00;			// non-zero if invert DCD
		Data.InvertRI = 0x00;				// non-zero if invert RI

		Data.Cbus0 = 0x02;				// Cbus Mux control
		Data.Cbus1 = 0x03;				// Cbus Mux control
		Data.Cbus2 = 0x01;				// Cbus Mux control
		Data.Cbus3 = 0x01;				// Cbus Mux control
		Data.Cbus4 = 0x05;				// Cbus Mux control

		Data.RIsD2XX = 0;				// non-zero if using VCP drivers

	}
	else if (ftDevice == FT_DEVICE_2232C) {

		Data.Signature1 = 0x00000000;
		Data.Signature2 = 0xffffffff;
		Data.VendorId = 0x0403;				
		Data.ProductId = 0x6010;
		Data.Manufacturer =  "FTDI";
		Data.ManufacturerId = "FT";
		Data.Description = "USB <-> Serial";
		Data.SerialNumber = "FT123442";		// if fixed, or NULL
		
		Data.MaxPower = 200;
		Data.PnP = 1;
		Data.SelfPowered = 0;
		Data.RemoteWakeup = 0;

		Data.Rev5 = 1;					// non-zero if Rev5 chip, zero otherwise
		Data.IsoInA = 0;				// non-zero if in endpoint is isochronous
		Data.IsoInB = 0;				// non-zero if in endpoint is isochronous
		Data.IsoOutA = 0;				// non-zero if out endpoint is isochronous
		Data.IsoOutB = 0;				// non-zero if out endpoint is isochronous
		Data.PullDownEnable5 = 0;		// non-zero if pull down enabled
		Data.SerNumEnable5 = 1;			// non-zero if serial number to be used
		Data.USBVersionEnable5 = 0;		// non-zero if chip uses USBVersion
		Data.USBVersion5 = 0x0200;		// BCD (0x0200 => USB2)
		Data.AIsHighCurrent = 0;		// non-zero if interface is high current
		Data.BIsHighCurrent = 0;		// non-zero if interface is high current
		Data.IFAIsFifo = 0;				// non-zero if interface is 245 FIFO
		Data.IFAIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
		Data.IFAIsFastSer = 0;			// non-zero if interface is Fast serial
		Data.AIsVCP = 0;				// non-zero if interface is to use VCP drivers
		Data.IFBIsFifo = 0;				// non-zero if interface is 245 FIFO
		Data.IFBIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
		Data.IFBIsFastSer = 0;			// non-zero if interface is Fast serial
		Data.BIsVCP = 0;				// non-zero if interface is to use VCP drivers

	}								

	ftStatus = FT_EE_Program(ftHandle0, &Data);
	if(ftStatus != FT_OK) {
		printf("FT_EE_Program failed (%d)\n", ftStatus);
	}
	FT_Close(ftHandle0);
	return 0;
}