static inline int ft245r_sync(PROGRAMMER * pgm) { FT_STATUS r; UCHAR ch; r = FT_GetBitMode(handle, &ch); if (r != FT_OK) return -1; return 0; }
int main(int argc, char *argv[]) { DWORD dwBytesInQueue = 0; FT_STATUS ftStatus; FT_HANDLE ftHandle; unsigned char ucMode = 0x00; int iport; if(argc > 1) { sscanf(argv[1], "%d", &iport); } else { iport = 0; } ftStatus = FT_Open(iport, &ftHandle); 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; } ftStatus = FT_SetBitMode(ftHandle, 0xFF, 1); if(ftStatus != FT_OK) { printf("Failed to set bit mode\n"); } FT_SetBaudRate(ftHandle, 9600); FT_Write(ftHandle, &ucMode, 1, &dwBytesInQueue); ftStatus = FT_GetBitMode(ftHandle, &ucMode); if(ftStatus != FT_OK) { printf("Failed to get bit mode\n"); } else { printf("ucMode = 0x%X\n", ucMode); } FT_Close(ftHandle); return 0; }
byte getPin(byte pin) { static DWORD b = 0; byte buffer = 0; FT_GetBitMode(ftdi_chip, &buffer); buffer = buffer | 0x0F; ftdi_pins.pins |= buffer; ftdi_pins.pins &= buffer; switch (pin) { case MISO_8051: return ftdi_pins.miso; case MOSI_8051: return ftdi_pins.mosi; case CLK_8051: return ftdi_pins.clk; case RST_8051: return ftdi_pins.rst; } return 0; }
void readBits(void) { byte ucMask; // Get CBUS pins states ftStatus = FT_GetBitMode(ftHandle,&ucMask); // Check to see if read successful if (ftStatus == FT_OK) { printf("read bits value: 0x%02X \n",ucMask); } else { printf("readbits failed\n"); } // Close device handle ftStatus = FT_Close(ftHandle); }
int main(int argc, char *argv[]) { DWORD bytesWritten = 0; DWORD baudRate = 9600; FT_STATUS ftStatus = FT_OK; FT_HANDLE ftHandle; UCHAR outputData; UCHAR pinStatus; int portNumber; if (argc > 1) { sscanf(argv[1], "%d", &portNumber); } else { portNumber = 0; } ftStatus = FT_Open(portNumber, &ftHandle); if (ftStatus != FT_OK) { /* FT_Open can fail if the ftdi_sio module is already loaded. */ printf("FT_Open(%d) failed (error %d).\n", portNumber, (int)ftStatus); printf("Use lsmod to check if ftdi_sio (and usbserial) are present.\n"); printf("If so, unload them using rmmod, as they conflict with ftd2xx.\n"); return 1; } /* Enable bit-bang mode, where 8 UART pins (RX, TX, RTS etc.) become * general-purpose I/O pins. */ printf("Selecting asynchronous bit-bang mode.\n"); ftStatus = FT_SetBitMode(ftHandle, 0xFF, /* sets all 8 pins as outputs */ FT_BITMODE_ASYNC_BITBANG); if (ftStatus != FT_OK) { printf("FT_SetBitMode failed (error %d).\n", (int)ftStatus); goto exit; } /* In bit-bang mode, setting the baud rate gives a clock rate * 16 times higher, e.g. baud = 9600 gives 153600 bytes per second. */ printf("Setting clock rate to %d\n", baudRate * 16); ftStatus = FT_SetBaudRate(ftHandle, baudRate); if (ftStatus != FT_OK) { printf("FT_SetBaudRate failed (error %d).\n", (int)ftStatus); goto exit; } /* Use FT_Write to set values of output pins. Here we set * them to alternate low and high (0xAA == 10101010). */ outputData = 0xAA; ftStatus = FT_Write(ftHandle, &outputData, 1, &bytesWritten); if (ftStatus != FT_OK) { printf("FT_Write failed (error %d).\n", (int)ftStatus); goto exit; } /* Despite its name, GetBitMode samples the values of the data pins. */ ftStatus = FT_GetBitMode(ftHandle, &pinStatus); if (ftStatus != FT_OK) { printf("FT_GetBitMode failed (error %d).\n", (int)ftStatus); goto exit; } if (pinStatus != outputData) { printf("Failure: pin data is %02X, but expected %02X\n", (unsigned int)pinStatus, (unsigned int)outputData); goto exit; } printf("Success: pin data is %02X, as expected.\n", (unsigned int)pinStatus); exit: /* Return chip to default (UART) mode. */ (void)FT_SetBitMode(ftHandle, 0, /* ignored with FT_BITMODE_RESET */ FT_BITMODE_RESET); (void)FT_Close(ftHandle); return 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 }