#include #include #include #include #include #include "ftd2xx.h" int main(int argc, char* argv[]) { FT_STATUS stat; FT_HANDLE ft; int rv; FT_SetVIDPID(0x0403, 0x7fd0); stat = FT_Open(0, &ft); if (stat) {printf("FT_Open failed\n");return 1;} FT_DEVICE dev; static const char* devlut[] = { "BM","AM","100ax","unk","2232c","232r","2232h","4232h","232h", "X-series","4222h0", "4222h12","4222h3","4222prog"}; stat = FT_GetDeviceInfo(ft, &dev, NULL, NULL, NULL, NULL); if (stat) {printf("getdevinfo failed\n");rv=1;goto finish;} printf("dev=%d %s\n", dev, devlut[dev]); static FT_PROGRAM_DATA pdata; // "MUST set signature1 and signature2 before calling FF_EE_Read" pdata.Signature1 = 0; pdata.Signature2 = 0xffffffff; pdata.Manufacturer = malloc(256); pdata.ManufacturerId = malloc(256); pdata.Description = malloc(256); pdata.SerialNumber = malloc(256); stat = FT_EE_Read(ft, &pdata); if (stat){printf("FT_EE_Read failed\n");rv=1;goto finish;} printf("Signature1 = 0x%08x\n", pdata.Signature1); printf("Signature2 = 0x%08x\n", pdata.Signature2); printf("Version = %04x\n", pdata.Version); printf("VendorId = 0x%04x\n", pdata.VendorId); printf("ProductId = 0x%04x\n", pdata.ProductId); printf("Manufacturer = %s\n", pdata.Manufacturer); printf("ManufacturerId = %s\n", pdata.ManufacturerId); printf("Description = %s\n", pdata.Description); printf("SerialNumber = %s\n", pdata.SerialNumber); printf("MaxPower = %d\n", pdata.MaxPower); printf("PnP = %d\n", pdata.PnP); printf("SelfPowered = %d\n", pdata.SelfPowered); printf("RemoteWakeup = %d\n", pdata.RemoteWakeup); if (dev== FT_DEVICE_BM) { /* Rev4 (FT232B) extensions */ printf("BM:\n"); printf("---\n"); printf("\tRev4 = 0x%X\n", pdata.Rev4); printf("\tIsoIn = 0x%X\n", pdata.IsoIn); printf("\tIsoOut = 0x%X\n", pdata.IsoOut); printf("\tPullDownEnable = 0x%X\n", pdata.PullDownEnable); printf("\tSerNumEnable = 0x%X\n", pdata.SerNumEnable); printf("\tUSBVersionEnable = 0x%X\n", pdata.USBVersionEnable); printf("\tUSBVersion = 0x%X\n", pdata.USBVersion); } if (dev== FT_DEVICE_2232C) { /* Rev 5 (FT2232C) extensions */ printf("2232RC:\n"); printf("-------\n"); printf("\tRev5 = 0x%X\n", pdata.Rev5); printf("\tIsoInA = 0x%X\n", pdata.IsoInA); printf("\tIsoInB = 0x%X\n", pdata.IsoInB); printf("\tIsoOutA = 0x%X\n", pdata.IsoOutA); printf("\tIsoOutB = 0x%X\n", pdata.IsoOutB); printf("\tPullDownEnable5 = 0x%X\n", pdata.PullDownEnable5); printf("\tSerNumEnable5 = 0x%X\n", pdata.SerNumEnable5); printf("\tUSBVersionEnable5 = 0x%X\n", pdata.USBVersionEnable5); printf("\tUSBVersion5 = 0x%X\n", pdata.USBVersion5); printf("\tAIsHighCurrent = 0x%X\n", pdata.AIsHighCurrent); printf("\tBIsHighCurrent = 0x%X\n", pdata.BIsHighCurrent); printf("\tIFAIsFifo = 0x%X\n", pdata.IFAIsFifo); printf("\tIFAIsFifoTar = 0x%X\n", pdata.IFAIsFifoTar); printf("\tIFAIsFastSer = 0x%X\n", pdata.IFAIsFastSer); printf("\tAIsVCP = 0x%X\n", pdata.AIsVCP); printf("\tIFBIsFifo = 0x%X\n", pdata.IFBIsFifo); printf("\tIFBIsFifoTar = 0x%X\n", pdata.IFBIsFifoTar); printf("\tIFBIsFastSer = 0x%X\n", pdata.IFBIsFastSer); printf("\tBIsVCP = 0x%X\n", pdata.BIsVCP); } if (dev== FT_DEVICE_232R) { /* Rev 6 (FT232R) extensions */ printf("232R:\n"); printf("-----\n"); printf("\tUseExtOsc = 0x%X\n", pdata.UseExtOsc); // Use External Oscillator printf("\tHighDriveIOs = 0x%X\n", pdata.HighDriveIOs); // High Drive I/Os printf("\tEndpointSize = 0x%X\n", pdata.EndpointSize); // Endpoint size printf("\tPullDownEnableR = 0x%X\n", pdata.PullDownEnableR); // non-zero if pull down enabled printf("\tSerNumEnableR = 0x%X\n", pdata.SerNumEnableR); // non-zero if serial number to be used printf("\tInvertTXD = 0x%X\n", pdata.InvertTXD); // non-zero if invert TXD printf("\tInvertRXD = 0x%X\n", pdata.InvertRXD); // non-zero if invert RXD printf("\tInvertRTS = 0x%X\n", pdata.InvertRTS); // non-zero if invert RTS printf("\tInvertCTS = 0x%X\n", pdata.InvertCTS); // non-zero if invert CTS printf("\tInvertDTR = 0x%X\n", pdata.InvertDTR); // non-zero if invert DTR printf("\tInvertDSR = 0x%X\n", pdata.InvertDSR); // non-zero if invert DSR printf("\tInvertDCD = 0x%X\n", pdata.InvertDCD); // non-zero if invert DCD printf("\tInvertRI = 0x%X\n", pdata.InvertRI); // non-zero if invert RI printf("\tCbus0 = 0x%X\n", pdata.Cbus0); // Cbus Mux control printf("\tCbus1 = 0x%X\n", pdata.Cbus1); // Cbus Mux control printf("\tCbus2 = 0x%X\n", pdata.Cbus2); // Cbus Mux control printf("\tCbus3 = 0x%X\n", pdata.Cbus3); // Cbus Mux control printf("\tCbus4 = 0x%X\n", pdata.Cbus4); // Cbus Mux control printf("\tRIsD2XX = 0x%X\n", pdata.RIsD2XX); // non-zero if using D2XX } uint32_t uasz, uard; stat = FT_EE_UASize(ft, &uasz); if (stat) {printf("FT_EE_UASize failed\n");rv=1;goto finish;} printf("UASize = 0x%x\n", uasz); uint8_t* data = (uint8_t*)malloc(uasz); stat = FT_EE_UARead(ft, data, uasz, &uard); if (stat) {printf("FT_EE_UARead failed\n");rv=1;goto finish;} if (uasz != uard){printf("FT_EE_UARead bad len\n");rv=1;goto finish;} FILE* f = fopen("ua.bin", "wb+"); fwrite(data, 1, uasz, f); fclose(f); f = fopen("ee.bin", "wb+"); for (size_t i = 0; ; ++i) { uint16_t val; stat = FT_ReadEE(ft, (uint32_t)i, &val); if (stat) {printf("FT_ReadEE failed at i=%zu (%zu bytes)\n", i, i<<1); break;} fwrite(&val, 2, 1, f); } fclose(f); finish: FT_Close(ft); return rv; }