com.ftdi.j2xx.ft4222

## Class FT_4222_Spi_Master

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

- All Implemented Interfaces:
    SpiMaster

      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);

  }

  Version:
    1.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FT_4222_Spi_Master(FT_4222_Device pDevice)`

  - ### Method Summary

    Methods
    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.

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

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

- - ### Constructor Detail

    - #### FT_4222_Spi_Master

          public FT_4222_Spi_Master(FT_4222_Device pDevice)

  - ### Method Detail

    - #### init

          public int init(int ioLine,
                 int clock,
                 int cpol,
                 int cpha,
                 byte ssoMap)

      Initialize FT4222H as an SPI master. In order to support various types of SPI slave devices, FT4222H SPI master is configurable using the following parameters: IO lines: SPI transmission lines. FT4222H SPI supports single, dual, or quad transmission mode. Clock divider: SPI clock rate is subject to system clock. FT4222H SPI clock cloud be 1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, or 1/512 system clock rate. Clock polarity: Active high or active low. Clock phase: Data is sampled on the leading (first) or trailing (second) clock edge. Slave selection output pins: Select slave devices by ss0o, ss1o, ss2o, ss3o.
      Specified by:
        `init` in interface `SpiMaster`
      Parameters:
        `ioLine` - SPI transmission lines
        `clock` - Clock divider
        `cpol` - Clock polarity
        `cpha` - Clock phase
        `ssoMap` - Slave selection output pins
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### setLines

          public int setLines(int spiMode)

      Switch FT4222H SPI master to single, dual, or quad lines.
      Specified by:
        `setLines` in interface `SpiMaster`
      Parameters:
        `spiMode` - SPI mode could be: SPI_IO_SINGLE , SPI_IO_DUAL, SPI_IO_QUAD
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### singleWrite

          public int singleWrite(byte[] writeBuffer,
                        int sizeToTransfer,
                        int[] sizeTransferred,
                        boolean isEndTransaction)

      Under SPI single mode, write data to an SPI slave.
      Specified by:
        `singleWrite` in interface `SpiMaster`
      Parameters:
        `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 transaction
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### singleRead

          public int singleRead(byte[] readBuffer,
                       int sizeToTransfer,
                       int[] sizeOfRead,
                       boolean isEndTransaction)

      Under SPI single mode, read data from an SPI slave.
      Specified by:
        `singleRead` in interface `SpiMaster`
      Parameters:
        `readBuffer` - buffer that receives the data from 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 transaction
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### singleReadWrite

          public 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.
      Specified by:
        `singleReadWrite` in interface `SpiMaster`
      Parameters:
        `readBuffer` - buffer that receives the data from the device
        `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 transaction
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### multiReadWrite

          public 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. The dual-SPI protocol supported by the FT4222H SPI master. It is a mixed protocol initiated with single write transmission, which may be an SPI command and dummy cycles, and followed by dual-write and dual-read transmission that use 2 signals in parallel for the data.
      Specified by:
        `multiReadWrite` in interface `SpiMaster`
      Parameters:
        `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.
      Returns:
        FT4222_OK if successful, otherwise the return value is an FT error code.

    - #### reset

          public int reset()

      Reset the SPI master device.
      Specified by:
        `reset` in interface `SpiMaster`
      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 master, 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.

About FTDI | FTDI Licence Terms