API¶
Control FTDI USB chips for I2C/SPI/GPIO.
Open a handle using one of the ft4222.openBy… functions and use the methods on the object thus returned.
- exception ft4222.FT2XXDeviceError(msgnum)¶
Exception class for status messages
- exception ft4222.FT4222DeviceError(msgnum)¶
Exception class for status messages
- class ft4222.SysClock(value)¶
Chip system clock
- CLK_60¶
60 MHz
- CLK_24¶
24 MHz
- CLK_48¶
48 MHz
- CLK_80¶
80 MHz
- ft4222.createDeviceInfoList()¶
Create the internal device info list and return number of entries
- ft4222.getDeviceInfoDetail(devnum=0, update=True)¶
Get an entry from the internal device info list. Set update to False to avoid a slow call to createDeviceInfoList.
- ft4222.openByDescription(desc)¶
Open a handle to a usb device by description
- Parameters:
- Returns:
Opened device
- Return type:
- Raises:
FT2XXDeviceError – on error
- ft4222.openByLocation(locId)¶
Open a handle to a usb device by location
- Parameters:
locId (int) – Location id
- Returns:
Opened device
- Return type:
- Raises:
FT2XXDeviceError – on error
- ft4222.openBySerial(serial)¶
Open a handle to a usb device by serial number
- Parameters:
- Returns:
Opened device
- Return type:
- Raises:
FT2XXDeviceError – on error
FT4222¶
- class ft4222.FT4222¶
- chipReset()¶
Software reset for device. This function is used to attempt to recover system after a failure. It is a software reset for device.
Re-opening the device may be needed after calling this function.
- Raises:
FT2XXDeviceError – on error
- chipRevision¶
The revision of the chip in human readable format
- chipVersion¶
Chip version as number
- close()¶
Closes the device.
- getClock()¶
Get the system clock
- Returns:
Clock
- Return type:
- Raises:
FT4222DeviceError – on error
- getLatencyTimer()¶
Get the current value of the latency timer.
- Returns:
Latency timer value in milliseconds
- Return type:
- Raises:
FT2XXDeviceError – on error
- getMaxTransferSize()¶
Get the maximum transfer size for the currently configured operating mode
- Returns:
Maximum number of bytes for each transfer.
- Return type:
- Raises:
FT4222DeviceError – on error
- gpio_GetTriggerStatus(portNum)¶
Get the size of trigger event queue.
- Parameters:
portNum (
ft4222.GPIO.Port
) – GPIO Port number- Returns:
Size of the trigger queue
- Return type:
- Raises:
FT4222DeviceError – on error
- gpio_Init(*args, gpio0=Dir.INPUT, gpio1=Dir.INPUT, gpio2=Dir.INPUT, gpio3=Dir.INPUT)¶
Initialize the GPIO interface.
- Parameters:
*args (
list
offt4222.GPIO.Dir
, optional) – List containing a direction for each port.gpio0 (
ft4222.GPIO.Dir
, optional) – Direction of gpio0gpio1 (
ft4222.GPIO.Dir
, optional) – Direction of gpio1gpio2 (
ft4222.GPIO.Dir
, optional) – Direction of gpio2gpio3 (
ft4222.GPIO.Dir
, optional) – Direction of gpio3
- Raises:
FT4222DeviceError – on error
- gpio_Read(portNum)¶
Read value from selected GPIO
- Parameters:
portNum (
ft4222.GPIO.Port
) – GPIO Port number- Returns:
True if high, False otherwise
- Return type:
- Raises:
FT4222DeviceError – on error
- gpio_ReadTriggerQueue(portNum, readSize=None)¶
Get events recorded in the trigger event queue.
- Parameters:
portNum (
ft4222.GPIO.Port
) – GPIO Port numberreadSize (
int
, optional) – Size of the queue,gpio_GetTriggerStatus()
gets called if omitted
- Returns:
Trigger queue as list
- Return type:
- Raises:
FT4222DeviceError – on error
- gpio_SetInputTrigger(portNum, trigger)¶
Set software trigger conditions on the specified GPIO pin.
- Parameters:
portNum (
ft4222.GPIO.Port
) – GPIO Port numbertrigger (
ft4222.GPIO.Trigger
) – Combination of trigger conditions
- Raises:
FT4222DeviceError – on error
- gpio_Wait(portNum, expectedValue, timeout=0, sleep=1)¶
Blocks until the selected GPIO reaches a certain value.
Will release the GIL while waiting.
- Parameters:
portNum (
ft4222.GPIO.Port
) – GPIO Port numberexpectedValue (bool) – True for high, False for low
timeout (int) – timeout in milliseconds, or 0 for no timeout
sleep (int) – sleep time in milliseconds between each polling attempt, or 0 for no sleep
- Raises:
FT4222DeviceError – on error
TimeoutError – when timeout is exceeded
- gpio_Write(portNum, value)¶
Write value to given GPIO
- Parameters:
portNum (
ft4222.GPIO.Port
) – GPIO Port numbervalue (bool) – True for high, False for low
- Raises:
FT4222DeviceError – on error
- i2cMaster_GetStatus()¶
Read the status of the I2C master controller.
This can be used to poll a slave until its write-cycle is complete.
- Returns:
Controller status
- Return type:
- Raises:
FT4222DeviceError – on error
- i2cMaster_Init(kbps=100)¶
Initialize the FT4222H as an I2C master with the requested I2C speed.
- Parameters:
kbps (int) – Speed in kb/s
- Raises:
FT4222DeviceError – on error
- i2cMaster_Read(addr, bytesToRead)¶
Read data from the specified I2C slave device with START and STOP conditions.
- Parameters:
- Returns:
Bytes read from slave
- Return type:
- Raises:
FT4222DeviceError – on error
- i2cMaster_ReadEx(addr, flag, bytesToRead)¶
Read data from the specified I2C slave device with the specified I2C condition.
- Parameters:
addr (int) – I2C slave address
flag (
ft4222.I2CMaster.Flag
) – Flag to control start- and stopbit generationbytesToRead (int) – Number of bytes to read from slave
- Returns:
Bytes read from slave
- Return type:
- Raises:
FT4222DeviceError – on error
- i2cMaster_Reset()¶
Reset the I2C master device.
If the I2C bus encounters errors or works abnormally, this function will reset the I2C device. It is not necessary to call I2CMaster_Init again after calling this reset function.
- Raises:
FT4222DeviceError – on error
- i2cMaster_Write(addr, data)¶
Write data to the specified I2C slave device with START and STOP conditions.
- i2cMaster_WriteEx(addr, flag, data)¶
Write data to the specified I2C slave device with the specified I2C condition.
- Parameters:
addr (int) – I2C slave address
flag (
ft4222.I2CMaster.Flag
) – Flag to control start- and stopbit generation
- Returns:
Bytes sent to slave
- Return type:
- Raises:
FT4222DeviceError – on error
- libVersion¶
Library version as number
- setClock(clk)¶
Set the system clock
- Parameters:
clk (
ft4222.SysClock
) – Desired clock- Raises:
FT4222DeviceError – on error
- setLatencyTimer(latency)¶
Set the current value of the latency timer.
- Parameters:
latency (int) – Latency timer value in milliseconds. Valid range is 2 - 255
- Raises:
FT2XXDeviceError – on error
- setSuspendOut(enable)¶
Enable or disable, suspend out, which will emit a signal when FT4222H enters suspend mode.
- Parameters:
enable (bool) – TRUE to enable suspend out and configure GPIO2 as an output pin for emitting a signal when suspended. FALSE to switch back to GPIO2
- Raises:
FT4222DeviceError – on error
- setTimeouts(read_timeout, write_timeout)¶
Set the read and write timeouts
- Parameters:
- Raises:
FT2XXDeviceError – on error
- setWakeUpInterrupt(enable)¶
Enable or disable the wakeup/interrupt
- Parameters:
enable (bool) – True to configure GPIO3 as an input pin for wakeup/interrupt. FALSE to switch back to GPIO3.
- Raises:
FT4222DeviceError – on error
- spiMaster_EndTransaction()¶
End the current SPI transaction.
- Raises:
FT4222DeviceError – on error
- spiMaster_Init(mode, clock, cpol, cpha, ssoMap)¶
Initialize as an SPI master under all modes.
- Parameters:
mode (
ft4222.SPIMaster.Mode
) – SPI transmission lines / modeclock (
ft4222.SPIMaster.Clock
) – Clock dividercpol (
ft4222.SPI.Cpol
) – Clock polaritycpha (
ft4222.SPI.Cpha
) – Clock phasessoMap (
ft4222.SPIMaster.SlaveSelect
) – Slave selection output pins
- Raises:
FT4222DeviceError – on error
- spiMaster_MultiReadWrite(singleWrite, multiWrite, bytesToRead)¶
Write and read data to and from a SPI slave in dual- or quad-mode (multi-mode).
- Parameters:
- Returns:
Bytes read from slave in multi-line mode
- Return type:
- Raises:
FT4222DeviceError – on error
- spiMaster_SetLines(mode)¶
Switch the FT4222H SPI master to single, dual, or quad mode.
This overrides the mode passed to FT4222_SPIMaster_init. This might be needed if a device accepts commands in single mode but data transfer is to use dual or quad mode.
- Parameters:
mode (
ft4222.SPIMaster.Mode
) – SPI transmission lines / mode- Raises:
FT4222DeviceError – on error
- spiMaster_SingleRead(bytesToRead, isEndTransaction)¶
Read data from a SPI slave in single mode
- Parameters:
- Returns:
Bytes read from slave
- Return type:
- Raises:
FT4222DeviceError – on error
- spiMaster_SingleReadWrite(data, isEndTransaction)¶
Write and read data to and from a SPI slave in single mode
- spiMaster_SingleWrite(data, isEndTransaction)¶
Write data to a SPI slave in single mode
- spiSlave_GetRxStatus()¶
Get number of bytes in the receive queue.
- Returns:
Number of bytes in the receive queue
- Return type:
pRxSize (uint16)
- Raises:
FT4222DeviceError – on error
- spiSlave_Init()¶
Initialize the FT4222H as an SPI slave. Default SPI_SlaveProtocol is SPI_SLAVE_WITH_PROTOCOL.
- Raises:
FT4222DeviceError – on error
- spiSlave_InitEx(proto)¶
Initialize as an SPI slave under all modes.
- Parameters:
mode (
ft4222.SPISlave.Protocol
) – SPI slave protocol- Raises:
FT4222DeviceError – on error
- spiSlave_Read(bytesToRead)¶
Read data from the receive queue of the SPI slave device.
- Parameters:
bytesToRead (int) – Number of bytes to read
- Returns:
Bytes read from slave
- Return type:
- Raises:
FT4222DeviceError – on error
- spiSlave_SetMode(cpol, cpha)¶
Set SPI slave cpol and cpha. The Default value of cpol is (
ft4222.SPI.Cpol.CLK_IDLE_LOW
) , default value of cpha is (ft4222.SPI.Cpol.CLK_LEADING
)- Parameters:
cpol (
ft4222.SPI.Cpol
) – Clock polaritycpha (
ft4222.SPI.Cpha
) – Clock phase
- Raises:
FT4222DeviceError – on error
- spiSlave_Write(data)¶
Write data to the transmit queue of the SPI slave device.
- Parameters:
- Returns:
Number of bytes written to the device.
- Return type:
sizeTransferred (uint16)
- Raises:
FT4222DeviceError – on error
- spi_Reset()¶
Reset the SPI master or slave device
- Raises:
FT4222DeviceError – on error
- spi_ResetTransaction(spiIdx)¶
Reset the SPI transaction
- Parameters:
spiIdx (int) – The index of the SPI transaction, which ranges from 0~3 depending on the mode of the chip.
- Raises:
FT4222DeviceError – on error
- spi_SetDrivingStrength(clkStrength, ioStrength, ssoStrength)¶
Reset the SPI master or slave device.
- Parameters:
clkStrength (
ft4222.SPI.DrivingStrength
) – Driving strength clock pin (master only)ioStrength (
ft4222.SPI.DrivingStrength
) – Driving strength io pinssoStrength (
ft4222.SPI.DrivingStrength
) – Driving strength sso pin (master only)
- Raises:
FT4222DeviceError – on error
- vendorCmdGet(req, bytesToRead)¶
Vendor get command
- vendorCmdSet(req, data)¶
Vendor set command
I2CMaster¶
I2C Master
Definitions to configure the I2C Master interface.
- class ft4222.I2CMaster.ControllerStatus(value)¶
I2CMaster controller Status
- BUSY¶
controller busy: all other status bits invalid
- ERROR¶
error condition
- ADDRESS_NACK¶
slave address was not acknowledged during last operation
- DATA_NACK¶
data not acknowledged during last operation
- ARB_LOST¶
arbitration lost during last operation
- IDLE¶
controller idle
- BUS_BUSY¶
bus busy
GPIO¶
GPIO
Definitions to configure the GPIO interface.
SPI¶
SPI
Definitions to configure either the SPI Master or Slave interface.
SPIMaster¶
SPI Master
Definitions to configure the SPI Master interface.
- class ft4222.SPIMaster.Clock(value)¶
SPIMaster Clock
- NONE¶
- DIV_2¶
1/2 System Clock
- DIV_4¶
1/4 System Clock
- DIV_8¶
1/8 System Clock
- DIV_16¶
1/16 System Clock
- DIV_32¶
1/32 System Clock
- DIV_64¶
1/64 System Clock
- DIV_128¶
1/128 System Clock
- DIV_256¶
1/256 System Clock
- DIV_512¶
1/512 System Clock
SPISlave¶
SPI Slave
Definitions to configure the SPI Slave interface.