com.ftdi.j2xx.ft4222

## Class FT_4222_Spi_Slave

- java.lang.Object
- - com.ftdi.j2xx.ft4222.FT_4222_Spi_Slave

- All Implemented Interfaces:
    SpiSlave

      public class FT_4222_Spi_Slave
      extends java.lang.Object
      implements SpiSlave

  FTDI SPI Slave Interface

  Example:

  init

  ----------------------------------------------------

  mSPISlave = mFT4222Device0.getSpiSlaveDevice();

  mSPISlave.init();

  FT_4222_Spi_Slave ft4222_spi_ext = (FT_4222_Spi_Slave) mSPISlave;

  if(ft4222_spi_ext != null)

  ft4222_spi_ext.setDrivingStrength(SPI_DrivingStrength.DS_12MA, SPI_DrivingStrength.DS_16MA, SPI_DrivingStrength.DS_16MA);

  polling

  -----------------------------------------------------

  public void Slave_Poll()

  {

  String output = "";

  //byte [] rdBuf = mSPISlave.read();

  int [] rxStatus = new int[1];

  mSPISlave.getRxStatus(rxStatus);

  if(rxStatus[0] > 0)

  {

  byte [] rdBuf = new byte[rxStatus[0]];

  int [] rdSize = new int[1];

  mSPISlave.read(rdBuf, rdBuf.length, rdSize);

  String outputText = "";

  byte [] wrBuf = new byte[rdSize[0]];

  for(int i=0; i < wrBuf.length ; i++)

  {

  //wrBuf[i] = (byte)(i & 0xff);

  int val = (byte)(rdBuf[i] & 0xff);

  wrBuf[i] = rdBuf[i];

  }

  int ret = mSPISlave.write(wrBuf, wrBuf.length, rdSize);

  if(wrBuf.length != rdSize[0])

  Log.d("FTDI", "send ="+wrBuf.length+" tx="+rdSize[0]);

  }

  }

  Version:
    1.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FT_4222_Spi_Slave(FT_4222_Device pDevice)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getRxStatus(int[] pRxSize)` Get number of bytes in the receive queue.
    `int` | `init()` Initialize FT4222H as SPI slave.
    `int` | `read(byte[] buffer, int bufferSize, int[] sizeOfRead)` Get number of bytes in the receive queue.
    `int` | `reset()` Reset the SPI slave device.
    `int` | `setDrivingStrength(int clkStrength, int ioStrength, int ssoStregth)` For the FT4222H SPI Slave, set the driving strength of clk, io, and sso pins.
    `int` | `setMode(int cpol, int cpha)` Set SPI slave mode.
    `int` | `setRxQuickResponse(boolean enable)` Adjust SPI Slave RX response method.
    `int` | `write(byte[] buffer, int bufferSize, int[] sizeTransferred)` Write data to the transmit queue of the SPI slave device.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FT_4222_Spi_Slave

          public FT_4222_Spi_Slave(FT_4222_Device pDevice)

  - ### Method Detail

    - #### init

          public int init()

      Initialize FT4222H as SPI slave.
      Specified by:
        `init` in interface `SpiSlave`
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### getRxStatus

          public int getRxStatus(int[] pRxSize)

      Get number of bytes in the receive queue.
      Specified by:
        `getRxStatus` in interface `SpiSlave`
      Parameters:
        `iSpiIdx` - number of bytes in the receive queue.
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### read

          public int read(byte[] buffer,
                 int bufferSize,
                 int[] sizeOfRead)

      Get number of bytes in the receive queue.
      Specified by:
        `read` in interface `SpiSlave`
      Parameters:
        `buffer` - buffer that receives the data from the device.
        `bufferSize` - number of bytes to read from the device.
        `sizeOfRead` - number of bytes read from the device.
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### write

          public int write(byte[] buffer,
                  int bufferSize,
                  int[] sizeTransferred)

      Write data to the transmit queue of the SPI slave device.
      Specified by:
        `write` in interface `SpiSlave`
      Parameters:
        `buffer` - buffer that contains the data to be written to the device.
        `bufferSize` - number of bytes to read from the device.
        `sizeTransferred` - number of bytes written to the device.
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### reset

          public int reset()

      Reset the SPI slave device.
      Specified by:
        `reset` in interface `SpiSlave`
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### setDrivingStrength

          public int setDrivingStrength(int clkStrength,
                               int ioStrength,
                               int ssoStregth)

      For the FT4222H SPI Slave, set the driving strength of clk, io, and sso pins.
      Parameters:
        `clkStrength` - The driving strength of the clk pin
        `ioStrength` - The driving strength of the io pin
        `ssoStregth` - The driving strength of the sso pin
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### setMode

          public int setMode(int cpol,
                    int cpha)

      Description copied from interface: `SpiSlave`
      Set SPI slave mode. Clock polarity: Active high or active low. Clock phase: Data is sampled on the leading (first) or trailing (second) clock edge.
      Specified by:
        `setMode` in interface `SpiSlave`
      Parameters:
        `cpol` - Clock polarity
        `cpha` - Clock phase
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### setRxQuickResponse

          public int setRxQuickResponse(boolean enable)

      Adjust SPI Slave RX response method. There are three rules that SPI Slave device returns the RX data to USB Host through USB PIPE. Rule 1: SPI slave device does not receives USB maximum bulk size in specific time. The device returns all rx data in deviceĦĤs FIFO. ĦE The specific time is defined by FT_SetLatencyTimer. ĦE The full packet size , HS is 512 bytes, FS is 64 bytes. The device must response two status bytes at every bulk-in packet. So the actual size, HS is 510 bytes, FS is 62 bytes.These two bytes are filled by device automatically and does not affect any function. The user does not need to care about it. Rule 2: SPI slave device receives USB maximum bulk size in specific time. The device returns full packet data. Rule 3: The option only takes effect when FT4222_SPISlave_RxQuickResponse is on. ĦE When this option turns on, the device return the rx data when the transfer gap of two bytes is larger than 1000 MCU clock. Take an example ,the default MCU frequency is 80 MHZ. 1000MCU clock is equal to 12.5ns*1000 = 12.5us ĦE There is a constraint. The size of rx data is not the multiple of 16 bytes or data can not be returned so fast. Rule1 and Rule 2 are mandatory. Rule 3 is optional. If Rule 3 option turns on. The priority of rule 3 is highest. One thing needs to notice, do not enable FT4222_SPISlave_RxQuickResponse while the transaction rate below 2 Mbps or it may cause some data lost.
      Parameters:
        `enable` - enable quick response mode
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

About FTDI | FTDI Licence Terms