An 357 Android Java D2xx Demo Application For FT4222
An 357 Android Java D2xx Demo Application For FT4222
AN_357
This document provides the application programming interface (API) for the Java
D2xx for Android library.
Use of FTDI devices in life support and/or safety applications is entirely at the user’s risk, and the user agrees to
defend, indemnify and hold harmless FTDI from any and all damages, claims, suits or expense resulting from such
use.
Android Java D2xx Demo Application for FT4222
Version: 1.0
Document Reference No.FT_001142
Clearance No.:FTDI# 437
Table of Contents
1 Introduction .................................................................... 2
1.1 Android Support ........................................................................ 2
1.2 Prerequisites............................................................................. 2
2 Using the FTDI Java D2xx for Android Library................. 3
2.1 Introduction and Usage ............................................................ 3
3 Demo Application ............................................................ 6
3.1 Information .............................................................................. 6
3.2 SPI ............................................................................................ 7
3.3 I2C ............................................................................................ 9
3.4 GPIO ....................................................................................... 11
4 Appendix A – References............................................... 13
4.1 Acronyms and Abbreviations................................................... 13
5 Appendix B – List of figures .......................................... 14
6 Appendix C – Revision History....................................... 15
7 Contact Information ...................................................... 16
1 Introduction
FTDI provides a proprietary D2XX interface for easy communication with FTxxxx devices. The D2XX API
is common across several operating systems supported by FTDI, namely Windows, Windows CE, Linux,
Mac OS X and Android. This document explains how to operate the FT4222H demo APK and the functions
of all available UI in the FT4222H demo APK.
A Java class library supporting a USB Host is available and applicable to Android v3.2 or any later series.
This library requires no special root access privileges.
1.2 Prerequisites
The Android device should also have USB Debugging enabled to allow access using the ADB utility. To
accomplish this, navigate to Settings > Applications > Development and check the USB debugging
option.
A summary of the required configuration is provided in the diagram below.
To support versatile tablet usage scenarios, Google has included a USB Host API in Android since version
3.1. Before version 3.1, an Android application could not access USB devices attached to a system
naturally without root access rights. The Android USB Host API removes this limitation, allowing users to
utilize the USB gadgets attached to an Android Host or OTG port.
FTDI provides a Java class library that adapts to applications so that the developer can focus on the
desired input and output data. The design goal of the class library is to provide access to all the D2XX
functions including, EEPROM functions.
The D2xx library can be included in an Android application project in Eclipse. First, copy the library file,
d2xx.jar, to the folder of the project, and add it in “Project”–“Properties”. Refer to Figure 2 ~ Figure 4,
which show how to add the library file from the “\libs” sub-folder of the project folder.
The D2xx Java library is fully documented using Javadoc. For information on the D2xx Android library
methods, constants and sub-classes, please consult the corresponding Javadoc entry in the sample
project’s /doc directory.
A sample application demonstrating how to use various methods in the D2xx Java library is shown in
section 3 Demo Application.
3 Demo Application
3.1 Information
This demo application contains a Refresh button. Tap Refresh to access information about the
connected device.
3.2 SPI
This demo application contains Config, Master Read, Master Write, Slave Read and Slave Write
buttons .
The first row contains a Config button to set the SPI configuration with several selectable setting items.
The SPI configuration settings allow the Polarity / Phase to be set for CPOL = 0 or 1, CPHA = 0 or 1.
System clock may be set to 24, 48, 60 or 80 Mhz.
Divider may be set to a value between 1/2 and 1/512.These parameters are used to generate the SPI
clock and to sample data for SPI read/write functions. For instance, with an 80 MHz system clock and
1/2 divider, the SPI clock will be 40 MHz. The polarity and phase are the sampling trigger to read data
from the input pin.
The Config button has to be pressed before sending data.
From the second row to the last row are the control fields for transmitting and receiving data; data
exchanging functions are divided into Master Write, Master Read, Slave Write, and Slave Read fields.
The Master Write field:
The Write Data is an editable text widget which allows any text data to be transmitted to the SPI slave.
The Transmit Bytes widget is a message box which shows the total number of bytes that the master
has successfully transmitted.
The Master Write is a button widget for triggering write operation.
3.3 I2C
This demo application contains Config, Master Read, Master Write, Slave Read and Slave Write
buttons.
The first row contains a Config button to set the I2C configuration with several selectable setting items.
The I2C configuration settings allow the Frequency to be set for 60K, 100K, 400K, 1M or 3.4MHz.
Device Address(HEX) allow the user to input the I2C address between 0x00~ 0x7F.
From the second row to the last row are the control fields for transmitting and receiving data; data
exchanging functions are divided into Master Write, Master Read, Slave Write, and Slave Read fields.
3.4 GPIO
FT4222H
USB
(GPIO) GPIO3
GPIO2
GPIO1
GPIO0
The GPIO demo application provides four configurable GPIO pins and they are listed in four columns.
Each column has Input, Output, High and Low fields to control the GPIO’s direction and signal level.
From figure 8, the demo is hardwired with GPIO0 to GPIO1 and GPIO2 to GPIO3. Based on the hardware
setting, GPIO0/GPIO1 GPIO2/GPIO3 directions are mutually exclusive. In other words, changing the
GPIO0 to the output direction will automatically set GPIO1 to the input direction and vice versa. In
addition, by changing the output port signal level, the input port will automatically respond to the signal
level change. With this functional demonstration, GPIOs can be proven to work correctly on triggering bi-
directional signals.
4 Appendix A – References
http://developer.Android.com/index.html
http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT4222H.pdf
http://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_147_Java_D2xx_for_Android.pdf
Terms Description
D2xx FTDI’s proprietary “direct” user space driver interface running on-
top of Android USB Host API
OS Operating System
USB Universal Serial Bus
BSP Board Supporting Package
API Application Programming Interface
OTG On The Go
SDK Software Development Kit
ADT Android Development Tools
IDE Integrated Development Environment
ADB Android Debug Bridge
SPI Serial Peripheral Interface
I 2C Inter-Integrated Circuit
GPIO General Purpose Input/Output
7 Contact Information
System and equipment manufacturers and designers are responsible to ensure that their systems, and
any Future Technology Devices International Ltd (FTDI) devices incorporated in their systems, meet all
applicable safety, regulatory and system-level performance requirements. All application-related
information in this document (including application descriptions, suggested FTDI devices and other
materials) is provided for reference only. While FTDI has taken care to assure it is accurate, this
information is subject to customer confirmation, and FTDI disclaims all liability for system designs and for
any applications assistance provided by FTDI. Use of FTDI devices in life support and/or safety
applications is entirely at the user’s risk, and the user agrees to defend, indemnify and hold harmless
FTDI from any and all damages, claims, suits or expense resulting from such use. This document is
subject to change without notice. No freedom to use patents or other intellectual property rights is
implied by the publication of this document. Neither the whole nor any part of the information contained
in, or the product described in this document, may be adapted or reproduced in any material or electronic
form without the prior written consent of the copyright holder. Future Technology Devices International
Ltd, Unit 1, 2 Seaward Place, Centurion Business Park, Glasgow G41 1HH, United Kingdom. Scotland
Registered Company Number: SC136640