public class FT_4222_Spi_Master extends java.lang.Object implements SpiMaster
FDI SPI master support library
Example (Single Read Write)
-----------------------------------------
FTDevice mFTDevice0 = m_pFtD2xx.openByIndex(m_pActivity, 0, params);
if(mFTDevice0 != null)
{
mFT4222Device0 = new FT_4222_Device(mFTDevice0);
mFT4222Device0.init();
mFT4222Device0.setClock((byte)FT4222_ClockRate.SYS_CLK_80); //80 MHZ
mSPIMaster = m_FT4222Device0.getSpiMasterDevice();
mSPIMaster.init(FT4222_SPIMode.SPI_IO_SINGLE, FT4222_SPIClock.CLK_DIV_4, FT4222_SPICPOL.CLK_ACTIVE_LOW, FT4222_SPICPHA.CLK_LEADING, 1);
mSPIMaster.singleReadWrite(rd_buf, wr_buf, wr_buf.length, sizeTransferred, false);
}
Example (Multi Read Write)
-----------------------------------------
mFTDevice0 = m_pFtD2xx.openByIndex(m_pActivity, 0, params);
if(mFTDevice0 != null)
{
mFT4222Device0 = new FT_4222_Device(mFTDevice0);
mFT4222Device0.init();
mFT4222Device0.setClock((byte)FT4222_ClockRate.SYS_CLK_80); //80 MHZ
mSPIMaster = mFT4222Device0.getSpiMasterDevice();
mSPIMaster.init(FT4222_SPIMode.SPI_IO_SINGLE, FT4222_SPIClock.CLK_DIV_4, FT4222_SPICPOL.CLK_ACTIVE_LOW, FT4222_SPICPHA.CLK_LEADING, 1);
FT_4222_Spi_Master ft4222_spi_ext = (FT_4222_Spi_Master) mSPIMaster;
if(ft4222_spi_ext != null)
ft4222_spi_ext.setDrivingStrength(SPI_DrivingStrength.DS_8MA, SPI_DrivingStrength.DS_8MA, SPI_DrivingStrength.DS_8MA);
mSPIMaster.setLines(FT4222_SPIMode.SPI_IO_QUAD);
byte[] readBuffer = new byte[32];
int [] sizeOfRead = new int[1];
ftStatus = mSPIMaster.multiReadWrite(readBuffer, eeCmd, 1, 6, readBuffer.length, sizeOfRead);
}
Constructor and Description |
---|
FT_4222_Spi_Master(FT_4222_Device pDevice) |
Modifier and Type | Method and Description |
---|---|
int |
init(int ioLine,
int clock,
int cpol,
int cpha,
byte ssoMap)
Initialize FT4222H as an SPI master.
|
int |
multiReadWrite(byte[] readBuffer,
byte[] writeBuffer,
int singleWriteBytes,
int multiWriteBytes,
int multiReadBytes,
int[] sizeOfRead)
Under SPI dual or quad mode, write data to and read data from an SPI slave.
|
int |
reset()
Reset the SPI master device.
|
int |
setDrivingStrength(int clkStrength,
int ioStrength,
int ssoStregth)
For the FT4222H SPI master, set the driving strength of clk, io, and sso pins.
|
int |
setLines(int spiMode)
Switch FT4222H SPI master to single, dual, or quad lines.
|
int |
singleRead(byte[] readBuffer,
int sizeToTransfer,
int[] sizeOfRead,
boolean isEndTransaction)
Under SPI single mode, read data from an SPI slave.
|
int |
singleReadWrite(byte[] readBuffer,
byte[] writeBuffer,
int sizeToTransfer,
int[] sizeTransferred,
boolean isEndTransaction)
Under SPI single mode, full-duplex write data to and read data from an SPI slave.
|
int |
singleWrite(byte[] writeBuffer,
int sizeToTransfer,
int[] sizeTransferred,
boolean isEndTransaction)
Under SPI single mode, write data to an SPI slave.
|
public FT_4222_Spi_Master(FT_4222_Device pDevice)
public int init(int ioLine, int clock, int cpol, int cpha, byte ssoMap)
public int setLines(int spiMode)
public int singleWrite(byte[] writeBuffer, int sizeToTransfer, int[] sizeTransferred, boolean isEndTransaction)
singleWrite
in interface SpiMaster
writeBuffer
- buffer that contains the data to be written to the device.sizeToTransfer
- The size of read and write buffer. They must be the same.sizeTransferred
- Pointer to a variable of type uint16 which receives the number of bytes read and written to the device.isEndTransaction
- TRUE to raise the pin of SS at the end of the transactionpublic int singleRead(byte[] readBuffer, int sizeToTransfer, int[] sizeOfRead, boolean isEndTransaction)
singleRead
in interface SpiMaster
readBuffer
- buffer that receives the data from the devicesizeToTransfer
- The size of read and write buffer. They must be the same.sizeTransferred
- Pointer to a variable of type uint16 which receives the number of bytes read and written to the device.isEndTransaction
- TRUE to raise the pin of SS at the end of the transactionpublic int singleReadWrite(byte[] readBuffer, byte[] writeBuffer, int sizeToTransfer, int[] sizeTransferred, boolean isEndTransaction)
singleReadWrite
in interface SpiMaster
readBuffer
- buffer that receives the data from the devicewriteBuffer
- buffer that contains the data to be written to the device.sizeToTransfer
- The size of read and write buffer. They must be the same.sizeTransferred
- Pointer to a variable of type uint16 which receives the number of bytes read and written to the device.isEndTransaction
- TRUE to raise the pin of SS at the end of the transactionpublic int multiReadWrite(byte[] readBuffer, byte[] writeBuffer, int singleWriteBytes, int multiWriteBytes, int multiReadBytes, int[] sizeOfRead)
multiReadWrite
in interface SpiMaster
readBuffer
- buffer that receives the data from the device.writeBuffer
- buffer that contains the data to be written to the device. .singleWriteBytes
- number of bytes in writeBuffer will be written as single-line.multiWriteBytes
- number of bytes in writeBuffer will be written as multi-line.multiReadBytes
- number of bytes to read as multi-line.sizeOfRead
- number of bytes read from the device.public int reset()
public int setDrivingStrength(int clkStrength, int ioStrength, int ssoStregth)
clkStrength
- The driving strength of the clk pinioStrength
- The driving strength of the io pinssoStregth
- The driving strength of the sso pin