Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ft4222/clibft4222.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,24 @@ cdef extern from "libft4222.h":
FT4222_STATUS FT4222_GetMaxTransferSize(FT_HANDLE ftHandle, uint16* pMaxSize)
FT4222_STATUS FT4222_SetEventNotification(FT_HANDLE ftHandle, DWORD mask, PVOID param)
FT4222_STATUS FT4222_GetVersion(FT_HANDLE ftHandle, FT4222_Version* pVersion)
# FT4222 I2C Functions
# FT4222 I2C Master Functions
FT4222_STATUS FT4222_I2CMaster_Read(FT_HANDLE ftHandle, uint16 deviceAddress, uint8* buffer, uint16 bufferSize, uint16* sizeTransferred)
FT4222_STATUS FT4222_I2CMaster_Write(FT_HANDLE ftHandle, uint16 deviceAddress, uint8* buffer, uint16 bufferSize, uint16* sizeTransferred)
FT4222_STATUS FT4222_I2CMaster_Init(FT_HANDLE ftHandle, uint32 kbps)
FT4222_STATUS FT4222_I2CMaster_ReadEx(FT_HANDLE ftHandle, uint16 deviceAddress, uint8 flag, uint8* buffer, uint16 bufferSize, uint16* sizeTransferred)
FT4222_STATUS FT4222_I2CMaster_WriteEx(FT_HANDLE ftHandle, uint16 deviceAddress, uint8 flag, uint8* buffer, uint16 bufferSize, uint16* sizeTransferred)
FT4222_STATUS FT4222_I2CMaster_Reset(FT_HANDLE ftHandle)
FT4222_STATUS FT4222_I2CMaster_GetStatus(FT_HANDLE ftHandle, uint8 *controllerStatus)
# FT4222 I2C Slave Functions
FT4222_STATUS FT4222_I2CSlave_Init(FT_HANDLE ftHandle);
FT4222_STATUS FT4222_I2CSlave_Reset(FT_HANDLE ftHandle);
FT4222_STATUS FT4222_I2CSlave_GetAddress(FT_HANDLE ftHandle, uint8*addr);
FT4222_STATUS FT4222_I2CSlave_SetAddress(FT_HANDLE ftHandle, uint8 addr);
FT4222_STATUS FT4222_I2CSlave_GetRxStatus(FT_HANDLE ftHandle, uint16*pRxSize);
FT4222_STATUS FT4222_I2CSlave_Read(FT_HANDLE ftHandle, uint8*buffer, uint16 bufferSize, uint16*sizeTransferred);
FT4222_STATUS FT4222_I2CSlave_Write(FT_HANDLE ftHandle, uint8*buffer, uint16 bufferSize, uint16*sizeTransferred);
FT4222_STATUS FT4222_I2CSlave_SetClockStretch(FT_HANDLE ftHandle, BOOL enable);
FT4222_STATUS FT4222_I2CSlave_SetRespWord(FT_HANDLE ftHandle, uint8 responseWord);
# FT4222 GPIO Functions
FT4222_STATUS FT4222_GPIO_Init(FT_HANDLE ftHandle, GPIO_Dir gpioDir[4])
FT4222_STATUS FT4222_GPIO_Read(FT_HANDLE ftHandle, GPIO_Port portNum, BOOL* value)
Expand All @@ -184,4 +194,3 @@ cdef extern from "libft4222.h":
FT4222_STATUS FT4222_SPISlave_GetRxStatus(FT_HANDLE ftHandle, uint16* pRxSize);
FT4222_STATUS FT4222_SPISlave_Read(FT_HANDLE ftHandle, uint8* buffer, uint16 bufferSize, uint16* sizeOfRead);
FT4222_STATUS FT4222_SPISlave_Write(FT_HANDLE ftHandle, uint8* buffer, uint16 bufferSize, uint16* sizeTransferred);
FT4222_STATUS FT4222_SPISlave_RxQuickResponse(FT_HANDLE ftHandle, BOOL enable);
149 changes: 149 additions & 0 deletions ft4222/ft4222.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ cdef class FT4222:
FT4222_UnInitialize(self._handle)
FT_Close(self._handle)

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
self.close()

def close(self):
"""Closes the device."""
status = FT4222_UnInitialize(self._handle)
Expand Down Expand Up @@ -608,6 +614,149 @@ cdef class FT4222:
return ControllerStatus(cs)
raise FT4222DeviceError, status

def i2cSlave_Init(self):
"""Initialize the FT4222H as an I2C slave.

Raises:
FT4222DeviceError: on error

"""
status = FT4222_I2CSlave_Init(self._handle)
if status != FT4222_OK:
raise FT4222DeviceError, status

def i2cSlave_Reset(self):
"""Reset i2c slave

Raises:
FT4222DeviceError: on error

"""
status = FT4222_I2CSlave_Reset(self._handle)
if status != FT4222_OK:
raise FT4222DeviceError, status

def i2cSlave_GetAddress(self):
"""Get address of slave device

Returns:
int: address of slave device

Raises:
FT4222DeviceError: on error

"""
cdef uint8 addr
status = FT4222_I2CSlave_GetAddress(self._handle, &addr)
if status == FT4222_OK:
return addr
raise FT4222DeviceError, status

def i2cSlave_SetAddress(self, addr):
"""Set address of slave device

Args:
addr(int): address of slave device

Raises:
FT4222DeviceError: on error

"""
status = FT4222_I2CSlave_SetAddress(self._handle, addr)
if status != FT4222_OK:
raise FT4222DeviceError, status

def i2cSlave_GetRxStatus(self):
"""Get rx byte count of slave device

Returns:
int: rx byte count of slave device

Raises:
FT4222DeviceError: on error

"""
cdef uint16 rxSize
status = FT4222_I2CSlave_GetRxStatus(self._handle, &rxSize)
if status == FT4222_OK:
return rxSize
raise FT4222DeviceError, status

def i2cSlave_Read(self, bytesToRead):
"""Read bytes from master device

Args:
bytesToRead (int): Number of bytes to read from master

Returns:
bytes: Bytes read from master

Raises:
FT4222DeviceError: on error

"""
cdef:
array[uint8] buf = array('B', [])
uint16 bytesRead
resize(buf, bytesToRead)
status = FT4222_I2CSlave_Read(self._handle, buf.data.as_uchars, bytesToRead, &bytesRead)
resize(buf, bytesRead)
if status == FT4222_OK:
return bytes(buf)
raise FT4222DeviceError, status

def i2cSlave_Write(self, data):
"""write data to master

Args:
data (int, bytes, bytearray): Data to write to master

Returns:
int: Bytes sent to master

Raises:
FT4222DeviceError: on error

"""
if isinstance(data, int):
data = bytes([data])
elif not isinstance(data, (bytes, bytearray)):
raise TypeError("the data argument must be of type 'int', 'bytes' or 'bytearray'")
cdef:
uint16 bytesSent
uint8* cdata = data
status = FT4222_I2CSlave_Write(self._handle, cdata, len(data), &bytesSent)
if status == FT4222_OK:
return bytesSent
raise FT4222DeviceError, status

def i2cSlave_SetClockStretch(self, enable):
"""Set clock stretch

Args:
enable (bool): True for enable, False for disable

Raises:
FT4222DeviceError: on error

"""
status = FT4222_I2CSlave_SetClockStretch(self._handle, enable)
if status != FT4222_OK:
raise FT4222DeviceError, status

def i2cSlave_SetRespWord(self, responseWord):
"""Set response word

Args:
enable (bool): True for enable, False for disable

Raises:
FT4222DeviceError: on error

"""
status = FT4222_I2CSlave_SetRespWord(self._handle, responseWord)
if status != FT4222_OK:
raise FT4222DeviceError, status

def spi_Reset(self):
"""Reset the SPI master or slave device
Expand Down
107 changes: 107 additions & 0 deletions linux/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@



libft4222 for Linux
-------------------

FTDI's libft4222 allows access to, and control of, the FT4222H.
Depending on configuration, the FT4222H presents 1, 2 or 4 interfaces
for I2C, SPI and GPIO functions. Please search ftdichip.com for the
FT4222H data sheet, and Application Note AN_329 which describes the
libft4222 API.

The Linux version of libft4222 includes (statically links to) FTDI's
libftd2xx which itself includes an unmodified version of libusb
(http://libusb.info) which is distributed under the terms of the GNU
Lesser General Public License (see http://www.gnu.org/licenses). Sources
for libusb, plus re-linkable object files are included in the libftd2xx
distribution, available from ftdichip.com.


Installing
----------

1. tar xfvz libft4222-1.4.4.44.tgz

This unpacks the archive, creating the following directory structure:

build-arm-v6
build-i386
build-x86_64
examples
libft4222.h
ftd2xx.h
WinTypes.h
install4222.sh

2. sudo ./install4222.sh

This copies the library (libft4222.so.1.4.4.44) and headers to
/usr/local/lib and /usr/local/include respectively. Also it creates a
version-independent symbolic link, libft4222.so.

Alternatively, you may manually copy the library and headers to a
custom location.


Building
--------

1. cd examples

2. cc get-version.c -lft4222 -Wl,-rpath,/usr/local/lib

With an FT4222H device connected to a USB port, try:

3. sudo ./a.out

You should see a message similar to this:

Chip version: 42220100, LibFT4222 version: 010200E5

If you see a message such as "No devices connected" or "No FT4222H detected",
this may indicate that:

a. There is no FT4222H connected. Check by running 'lsusb', which
should output something similar to:

Bus 001 Device 005: ID 0403:601c Future Technology Devices International, Ltd

b. Your program did not run with sufficient privileges to access USB.
Use 'sudo', or 'su', or run as root.

If you see an error message about libft4222.so having an invalid ABI, please
try to upgrade glibc to version 2.10 or above.

Release Notes
-------------

1.4.4.44
Fix issue. Frequency 100K~400K in I2C Master is not accurate.
Add Feature. Add API FT4222_I2CMaster_ResetBus. This function can reset i2c bus when it is abnormal.
Add Feature. Add API FT4222_SPIMaster_SetCS. It can determine the CS is high or low when SPI bus is active. The default value is active-low.
Remove Feature. Remove API FT4222_SPISlave_RxQuickResponse. It may cause data lost sometimes.
Add Feature. Add license announce in libft4222.h

1.4.4.9
Add i486 and Arm-V7-A83T support.
Fix potential FT4222_I2CMaster_Read and FT4222_I2CMaster_ReadEx data lost.
Fix issue. FT4222_I2CMaster_WriteEx does not return correct sizeTransferred.
Fix issue. FT4222_SPIMaster_MultiReadWrite does not return correct sizeOfRead when multiReadBytes equal to zero

1.4.2.184
New API gives SPI Slave protocol options.
Fixed potential SPI Slave data loss.
Fixed potential GPIO read error.
Fixed potential SPISlave_GetMaxTransferSize error.
Fixed potential inability for GPIO_Read to get interrupt status.

1.2.1.4
Added Linux support, extended I2C Master API.
Added portable C examples.

1.1.0.0
Added 64-bit Windows support.

1.0.0.0
Initial version. Windows only.
Binary file added linux/build-arm-hisiv300/libft4222.so.1.4.4.44
Binary file not shown.
Binary file added linux/build-arm-v5-sf/libft4222.so.1.4.4.44
Binary file not shown.
Binary file added linux/build-arm-v7-hf/libft4222.so
Binary file not shown.
Binary file added linux/build-arm-v7-hf/libft4222.so.1.4.4.44
Binary file not shown.
Binary file added linux/build-i486/libft4222.so.1.4.4.44
Binary file not shown.
Binary file added linux/build-mips-eglibc-hf/libft4222.so.1.4.4.44
Binary file not shown.
Binary file added linux/build-pentium/libft4222.so.1.4.4.44
Binary file not shown.
Loading