Example #1
0
//*****************************************************
//* Name:			pindmdInit
//* Purpose:	initialize ftdi driver
//* In:
//* Out:
//*****************************************************
void pinddrvInit(void)
{
	UINT8 deviceId;

#ifdef PINDMD2
	int ret = 0;
	enabled = 1;
	do16 = 1;
	//f = fopen("debug.txt","w");

	//init usb library
	usb_init();
	//find busses
	usb_find_busses();
	//find devices
	usb_find_devices();

	//try to open our device
	if( !( device = open_dev() ) ) {
		//if not successfull, print error message
		MessageBox(NULL, "PinDMD not found", "Error", MB_ICONERROR);
		enabled = 0;
		return;
	}
	//set configuration
	if( usb_set_configuration( device, MY_CONFIG ) < 0 ) {
		MessageBox(NULL, "PinDMD cannot configure", "Error", MB_ICONERROR);
		enabled = 0;
		usb_close( device );
		return;
	}
	//try to claim interface for use
	if( usb_claim_interface( device, MY_INTF ) < 0 ) {
		MessageBox(NULL, "PinDMD cannot claim interface", "Error", MB_ICONERROR);
		enabled = 0;
		usb_close( device );
		return;
	}
	// SETUP async
	ret = usb_bulk_setup_async( device, &asyncWriteContext, EP_OUT );
	if( ret < 0 ) {
		MessageBox(NULL, "PinDMD cannot setup async", "Error", MB_ICONERROR);
		enabled = 0;
		//relese interface
		usb_release_interface( device, MY_INTF );
		//close device and exit
		usb_close( device );
		return;
	}
	//if(f)
	//	fprintf(f,"all ok:%d \n",enabled);
#else
	FT_DEVICE_LIST_INFO_NODE *devInfo;
	DWORD numDevs;
	UINT8 i;
	UINT8 BitMode;
	deviceId = 0;
	sendFrameCount=0;

	// create the device information list
	ftStatus = FT_CreateDeviceInfoList(&numDevs);
	enabled = 0;

	// ftdi devices found
	if (numDevs > 0) {
		// allocate storage for list based on numDevs
		devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
		// get the device information list
		ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs);
		// info request successful
		if (ftStatus == FT_OK) {
			for (i = 0; i < numDevs; i++) {
				// search for pindmd board serial number
				if((strcmp(devInfo[i].SerialNumber,"DMD1000")==0) || (strcmp(devInfo[i].SerialNumber,"DMD1001")==0) || (strcmp(devInfo[i].SerialNumber,"DMD2000A")==0)){
					// assign divice id (incase other ftdi devices are connected)
					deviceId=i;
					enabled = 1;
				}
				// pinDMD 2
				//if(strcmp(devInfo[i].SerialNumber,"DMD2000A")==0)
				//	pinDMD_Version = 2;
				// slow usb
				if(strcmp(devInfo[i].SerialNumber,"DMD1001")==0)
					slowUSB = 1;
			}
		}
	} else {
		enabled=0;
		return;
	}

	// get handle on device
	ftStatus = FT_Open(deviceId, &ftHandle);
	if(ftStatus != FT_OK){
		// FT_Open failed return;
		enabled=0;
		return;
	}
	
	// check pinDMD firmware to see if its 16 colour (bit4=true)
	FT_SetBitMode(ftHandle, 0x0, 0x20);
	ftStatus = FT_GetBitMode(ftHandle, &BitMode);
	if (ftStatus == FT_OK) {
		// BitMode contains current value
		do16	= ((BitMode&0x08)==0x08);
		doOther = ((BitMode&0x04)==0x04);
	}

	// original pinDMD
	//if(pinDMD_Version==1){
		// set Asynchronous Bit Bang Mode
		FT_SetBitMode(ftHandle, 0xff, 0x1);
		// set Baud
		FT_SetBaudRate(ftHandle, slowUSB?11000:12000);  // Actually 10400 * 16
	// new pinDMD 2 FPGA
	/*} else {
			do16 = 1;
      FT_SetBitMode(ftHandle, 0xff, 0);
      Sleep(10);
      FT_SetBitMode(ftHandle, 0xff, 0x40);
      FT_SetLatencyTimer(ftHandle, 16);
      FT_SetUSBParameters(ftHandle,0x10000, 0x10000);
      FT_SetFlowControl(ftHandle, FT_FLOW_RTS_CTS, 0x0, 0x0);
      FT_Purge(ftHandle, FT_PURGE_RX);
      Sleep(10);
	}*/
#endif
}
int ftdi_init()
{
FT_DEVICE ftDevice; 
DWORD deviceID; 
char SerialNumber[16+1]; 
char Description[64+1]; 

// Does an FTDI device exist?
printf("Checking for FTDI devices...\n");
ftStatus = FT_CreateDeviceInfoList(&dwNumDevs);

// Get the number of FTDI devices
if (ftStatus != FT_OK) // Did the command execute OK?
{
	printf("Error in getting the number of devices\n");
	return 1; // Exit with error
}

if (dwNumDevs < 1) // Exit if we don't see any
{
	printf("There are no FTDI devices installed\n");
	return 1; // Exist with error
}

printf("%d FTDI devices found - the count includes individual ports on a single chip\n", dwNumDevs);

ftHandle=NULL;

//go thru' list of devices
for(int i=0; i<dwNumDevs; i++)
{
	printf("Open port %d\n",i);
	ftStatus = FT_Open(i, &ftHandle);
	if (ftStatus != FT_OK)
	{
		printf("Open Failed with error %d\n", ftStatus);
		printf("If runing on Linux then try <rmmod ftdi_sio> first\n");
		continue;
	}

	FT_PROGRAM_DATA ftData; 
	char ManufacturerBuf[32]; 
	char ManufacturerIdBuf[16]; 
	char DescriptionBuf[64]; 
	char SerialNumberBuf[16]; 

	ftData.Signature1 = 0x00000000; 
	ftData.Signature2 = 0xffffffff; 
	ftData.Version = 0x00000003;      //3 = FT2232H extensions
	ftData.Manufacturer = ManufacturerBuf; 
	ftData.ManufacturerId = ManufacturerIdBuf; 
	ftData.Description = DescriptionBuf; 
	ftData.SerialNumber = SerialNumberBuf; 
	ftStatus = FT_EE_Read(ftHandle,&ftData);
	if (ftStatus == FT_OK)
	{ 
		printf("\tDevice: %s\n\tSerial: %s\n", ftData.Description, ftData.SerialNumber);
		printf("\tDevice Type: %02X\n", ftData.IFAIsFifo7 );
		break;
	}
	else
	{
		printf("\tCannot read ext flash\n");
	}
}

if(ftHandle==NULL)
{
	printf("NO FTDI chip with FIFO function\n");
	return -1;
}

//ENABLE SYNC FIFO MODE
ftStatus |= FT_SetBitMode(ftHandle, 0xFF, 0x00);
ftStatus |= FT_SetBitMode(ftHandle, 0xFF, 0x40);

if (ftStatus != FT_OK)
{
	printf("Error in initializing1 %d\n", ftStatus);
	FT_Close(ftHandle);
	return 1; // Exit with error
}

UCHAR LatencyTimer = 2; //our default setting is 2
ftStatus |= FT_SetLatencyTimer(ftHandle, LatencyTimer); 
ftStatus |= FT_SetUSBParameters(ftHandle,0x10000,0x10000);
ftStatus |= FT_SetFlowControl(ftHandle,FT_FLOW_RTS_CTS,0x10,0x13);

if (ftStatus != FT_OK)
{
	printf("Error in initializing2 %d\n", ftStatus);
	FT_Close(ftHandle);
	return 1; // Exit with error
}

//return with success
return 0;
}
Example #3
0
int main(int argc, char ** argv)
{
	
	DWORD devIndex = 0; 
	char Buffer[255];
	ftdi_pins.pins = 0xF1;
	ftdi_pins.clk = HIGH;
	DWORD p = 0;
	byte e1 = 0xff;
	byte e2 = 0;

	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, 7);
	if (argc < 2) {
		printf("Please specify the hex file\n");
		return 1;
	}

	
	FT_STATUS ftStatus = FT_ListDevices((PVOID)devIndex, Buffer, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER);
	if (ftStatus == FT_OK) {

		int bytes = load_file(argv[1]);

		ftStatus = FT_OpenEx(Buffer, FT_OPEN_BY_SERIAL_NUMBER, &ftdi_chip);
		FT_SetBitMode(ftdi_chip, PIN_TX | PIN_RX | PIN_CTS, 1); // BIT BANG MODE
		FT_SetBaudRate(ftdi_chip, BAUD_RATE);						 

		setPin(RST_8051, LOW);
		setPin(MOSI_8051, LOW);
		setPin(CLK_8051, LOW);
		setPin(RST_8051, HIGH);
		
		Sleep(500);
		printf("%x\n", progEnable());		
		Sleep(1100);

		eraseChip();

		for (int i = from_addr; i < to_addr + 1; i++) {
			printf("%02X", readProgmem(0, i));
		}
		printf("\n");


		for (int i = from_addr; i < to_addr + 1; i++) {
			printf("%02X", memory[i]);
		}
		printf("\n");
		
		// write memory
		for (int i = from_addr; i < to_addr+1; i++) {
			writeProgmem(0, i, memory[i]);
			printf("%02X", readProgmem(0, i));
		}
		printf("\n");
		

		Sleep(1000);
		setPin(RST_8051, LOW);
		Sleep(500);

		FT_Close(ftdi_chip);

		getchar();
	}
	else {
		printf("Can't open FTDI chip\n");
		return 1;
	}

	return 0;
}
Example #4
0
void writebits(UCHAR Mask)
{
	DWORD devIndex = 0;
	DWORD numDevs;

	UCHAR ucMask =0x0;
	ftStatus = FT_CreateDeviceInfoList(&numDevs);
	if (ftStatus == FT_OK)
	{ 
		// printf("Number of devices is %d\n",numDevs);
	}
	if (numDevs > 0)
	{
		// allocate storage for list based on numDevs
		devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);  // get the device information list
		ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs); 
		if (ftStatus == FT_OK)
		{
			/*
			for (i = 0; i < numDevs; i++)
			{ 
				printf("Dev %d:\n",i);
				printf(" Flags=0x%x\n",devInfo[i].Flags);
				printf(" Type=%s\n",devices[devInfo[i].Type]); 
				printf(" ID=0x%x\n",devInfo[i].ID);
				printf(" LocId=0x%x\n",devInfo[i].LocId);
				printf(" SerialNumber=%s\n",devInfo[i].SerialNumber);
				printf(" Description=%s\n",devInfo[i].Description);
				printf(" ftHandle=0x%x\n",devInfo[i].ftHandle);			

			}
			*/
		}
		else
		{
			
		}

		i=0;
		ftStatus = FT_Open(i,&ftHandle);

		if (ftStatus == FT_OK)
		{ 
			// printf("open OK\n");
		}
		else
		{
			printf("Open failed! \n");
		}
	
			ucMask = Mask;
		
	// Set CBUS pins states
		ftStatus = FT_SetBitMode(ftHandle,ucMask,0x20);

	// Check to see if write successful
		if (ftStatus == FT_OK) {
			printf("CBUS Write Succesful: 0x%02X\n",ucMask);
		}
		else
		{
			printf("CBUS write failed!\n");
		}
	// Close device handle
	ftStatus = FT_Close(ftHandle);
	}
}