概述
D2XX 驱动提供了两个函数用于查询和设置FT2232的不同器件IO模式。
FT_SetBitMode FT_GetBitMode
FT_SetBitMode
FT_STATUS FT_SetBitMode( FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucMode)
ftHandle:句柄
ucMask:用于控制GPIO的方向,即输入还是输出;0表示对应GPIO为输入,1表示对应GPIO为输出
ucMode:设置IO Mode
IO Mode | Value(hex) |
---|
Reset the IO Bit Mode | 0x0 | Asynchronous Bit Bang Mode | 0x1 | MPSSE | 0x2 | Synchronous Bit Bang Mode | 0x4 | MCU Host Bus Emulation | 0x8 | Fast Serial For Opto-Isolation | 0x10 |
FT_SetBitMode 例程
设置MPSSE
HANDLE ftHandle; // valid handle returned from FT_Open or FT_W32_CreateFile
FT_STATUS ftStatus;
UCHAR Mask = 0xff; // set all IOs to output
UCHAR Mode = 2; // set MPSSE mode
ftStatus = FT_SetBitMode(ftHandle,Mask,Mode);
if (ftStatus == FT_OK) {
// MPSSE Mode enabled
}
else {
// FT_SetBitMode FAILED!
}
设置Asynchronous Bit Bang Mode
HANDLE ftHandle; // valid handle returned from FT_Open or FT_W32_CreateFile
FT_STATUS ftStatus;
UCHAR Mask = 0x07; // set bits 0, 1 and 2 to output
UCHAR Mode = 1; // set Asynchronous Bit Bang mode
ftStatus = FT_SetBitMode(ftHandle,Mask,Mode);
if (ftStatus == FT_OK) {
// Asynchronous Bit bang Mode enabled
}
else {
// FT_SetBitMode FAILED!
}
Reset IO Bit Mode
ftStatus = FT_SetBitMode(ftHandle,0,0);
设置Synchrounous Bit Bang mode
HANDLE ftHandle; // valid handle returned from FT_Open or FT_W32_CreateFile
FT_STATUS ftStatus;
UCHAR Mask = 0x07; // set bits 0, 1 and 2 to output
UCHAR Mode = 0x4; // set Synchronous Bit Bang mode
ftStatus = FT_SetBitMode(ftHandle,Mask,Mode);
if (ftStatus == FT_OK) {
// Asynchronous Bit bang Mode enabled
}
else {
// FT_SetBitMode FAILED!
}
设置MCU Host Bus Emulation mode
...
```## Reset IO Bit Mode
```Reset IO Bit Mode
HANDLE ftHandle; // valid handle returned from FT_Open or FT_W32_CreateFile
FT_STATUS ftStatus;
UCHAR Mask = 0x07; // set bits 0, 1 and 2 to output
UCHAR Mode = 0x8; // set MCU Host Bus Emulation mode
ftStatus = FT_SetBitMode(ftHandle,Mask,Mode);
if (ftStatus == FT_OK) {
// Asynchronous Bit bang Mode enabled
}
else {
// FT_SetBitMode FAILED!
}
FT_GetBitMode
获取IO Bit Mode状态
FT_STATUS FT_GetBitMode (FT_HANDLE ftHandle, PUCHAR pucMode)
参数
ftHandle:器件句柄
pucMode:指针,用于存储Bit Mode值
FT_GetBitMode 例程
HANDLE ftHandle; // valid handle returned from FT_Open or FT_W32_CreateFile
UCHAR BitMode;
FT_STATUS ftStatus;
ftStatus = FT_GetBitMode(ftHandle,&BitMode);
if (ftStatus == FT_OK) {
// BitMode contains current value
}
else {
// FT_GetBitMode FAILED!
}
|