FTDI Android Interface Solutions

作者:DigiKey Technical Content

投稿人:DigiKey

Towards the end of the ‘90s, a new connection scheme aimed to create one standard for connecting computing equipment. This standard was the Universal Serial Bus (USB). Just as the name implies, USB has become the de facto standard among computing devices. The USB specification defines a strict Host to Peripheral arrangement. It also allows multiple peripherals to connect to a given USB host through one or more hubs. In all cases, the host PC ultimately controls all the peripherals. Peripherals take on numerous forms such as digital cameras, biometric devices, sensors, and printers. With all of these peripherals, the control of the USB is left to the host PC. In 2007, Google, along with the Open Handset Alliance, publicly introduced the Android operating system which is a Linux-based operating system. About a year later, the first commercially available handset with an ARM CPU running the OS was introduced. This platform has evolved through the past few years and is now part of mobile phones, tablet computers, and numerous other embedded applications as shown in Figure 1.

Android Application Examples

Figure 1: Application Examples

FTDI offers the following three distinct options to connect via USB to the Android platforms.

  • Utilizing the Android Open Accessory mode on the Android platform
  • Utilizing the Android's USB host capabilities with FTDI's Android Java driver
  • Utilizing the Android's USB host capabilities with FTDI's legacy drivers

Each of these options contain benefits and disadvantages and there are three main factors to consider when deciding which interface option to use. Does the Android platform support USB host or device? Will the Android platform or the peripheral provide the USB power? Which version of Android is the platform using?

The first interface factor to consider is whether the Android platform supports USB host. Android smartphones always provide a USB device port but some Android tablets provide both USB host and USB device ports as shown in Figure 2. The USB device port is for connecting to a PC or embedded host to enable data transfer and battery charging. The USB host port is for connecting to USB peripheral hardware.

USB Host and USB Device

Figure 2: USB Host and USB Device

Many Android platforms, like the one shown in Figure 3, are now supplied with On-The-Go (OTG) USB ports, which allow for the USB port to be either a host or a device. Some of these OTG ports will be USB device only and some will offer both USB host and device capabilities. One way to determine if a user’s Android platform supports USB host and/or device is by the cable type. A Micro-AB cable will likely be both USB host and device whereas a Micro-B cable will indicate USB device only.

USB On-The-Go

Figure 3: USB On-The-Go. (Image source: Hosting Canada)

Another factor in determining which interface option to use is deciding whether the Android platform or the peripheral will provide the USB power. Per the USB specification, the USB host is required to provide the power to the downstream peripheral. It is important to keep in mind that even though the Android platform may provide USB host support, most Android devices are portable and require battery power to operate. Utilizing the USB client port on the Android platform eliminates the requirement for the Android platform to provide power along with the complex USB host connection and software stack. This results in reducing battery size and cost on the Android platform. The Android platform OS version also plays a role in determining which interface option to use as Android Open Accessories requires OS version 3.1 onward and the Java driver interface option requires Android OS version 3.2 onward.

Once the interface factors are determined, one of the three interface options can be used. The first interface option is using Android Open Accessory (AOA) mode (Figure 4).

Android Open Accessory (AOA) Mode

Figure 4: Android Open Accessory (AOA) Mode

Google introduced AOA in May 2011 to address the dilemma of wanting to control a much simpler peripheral from the Android platform using the USB device port. AOA allows peripherals to use the USB Embedded Host as their interface to the Android platform. At the physical layer and through the establishment of the USB connection (aka Enumeration), a traditional host-peripheral connection is made. The power arrangement is also maintained. The peripheral platform could provide the full 500 mA to the Android device. One can think of the two entities, Android host and AOA peripheral, as swapping logical functions. The Android platform (USB device) is now controlling the peripheral (USB host) through an installed application (APK). The only requirement to use AOA is that the Android platform be running OS version 3.1 onward.

A key advantage of using AOA to connect peripherals is that many Android platforms are only capable of acting as a USB device and not a USB Host. AOA overcomes this limitation by utilizing the Android’s USB device port which all Android platforms have. Since the Android acts as the USB device, it saves on battery size by not providing the power (Figure 5). It is not necessary to develop special drivers to be loaded on the Android platform and no rooting of the Android platform is required. Also, the complex USB host connection and software stack is not the responsibility of the Android platform.

Benefits of Using AOA

Figure 5: Benefits of Using AOA

To connect to an Android platform in Open Accessory Mode, the platform must first support the mode. This is true of OS version 3.1 onwards, but may also be available on OS versions as far back as 2.3.4 if the user has back ported the feature to this OS version. When an Open Accessory device is connected to the Android, it must send a vendor request to the Android to inquire if the device supports Open Accessory Mode.

Figure 6 below shows an example of this Get_Protocol command. The communication stops there if the reply is no. If the reply is yes, the peripheral sends its own unique descriptor strings to identify itself. There is then another USB vendor request to enable the Open Accessory Mode and re-enumerate the Android device in this configuration. When enumerated as an Open Accessory Mode device, there will be one USB BULK IN endpoint and one USB BULK OUT endpoint as well as the control endpoint. This interface will be full speed (12 Mbit/s) USB allowing for data transfer in and out.

Get_Protocol Command

Figure 6: Get_Protocol Command

To utilize the Android Open Accessories, FTDI has released the FT311D. This is a hard-coded USB Android Host IC dedicated to accessing the AOA mode on Android platforms. This IC allows designers to bridge an interface on their peripheral hardware to an Android tablet or smartphone platform over the Android USB device port. The FT311D will enumerate the Android platform and provide an interface via GPIO, UART, PWM, I2C Master, SPI Slave or SPI Master between a customer’s Android platform and their peripheral hardware. Simply select the interface mode with pull up/pull down resistors on the FT311D mode select pins and plug into an Android (3.1 or later) platform to access peripheral hardware over USB via Androids’ Open Accessory Mode.

The FT311D system allows providers to enhance connectivity to the mobile ecosystem with the ability to create applications that capitalize on the Android platform's resources such as high-performance processing, accelerometers, and touchscreen interfaces.

The FT311D features include: Interface configuration via three mode select pins; Basic UART function of Rx, Tx, RTS, CTS with Tx Active; four PWM channels; Host stack, class driver, Open Accessory driver, and IP bridging functionality; 3.3 V single supply with 5 V tolerant I/O; 32 pin LQFP or QFN footprint; and an extended temperature range of -40oC to +85oC. In addition, extensive FT311D development support is available, including development hardware, applications, white-paper, and datasheets.

The UMFT311EV is a development module for the FT311D. The module allows for selection of each of the FT311D interfaces: GPIO, UART, PWM, I2C Master, SPI Slave, or SPI Master. The module provides a USB type A connector with power switch to control the 5 V supply to the USB port. The UMFT311GP is a PCB with eight buttons and eight LEDs. It may be plugged into a FT311D development board to test GPIO operation. The module also has a power socket to accept 5 VDC, allowing power for the FT311D via an onboard 3.3 V regulator and the connected Android device

Another FTDI solution that also uses the Android Open Accessory mode is FTDI's Vinculum-II (VNC2) family of ICs and modules. This is a single-chip embedded host which can be programmed to include the AOA support. In addition to the interfaces available with the FT311D IC, the Vinculum-II also includes a second USB port that can be configured as a USB host or USB device. With the second USB port of the Vinculum-II configured for host, it is possible to add USB support for traditional USB peripherals such as a barcode scanner that already uses an FTDI peripheral IC or connects as a HID peripheral.

Vinculum-II is a second generation product building on FTDI’s USB experience and customer requests. It has a custom designed CPU with increased processing capability over FTDI's first generation USB Host Controller, Vinculum-I. Building on FTDI's competitive advantage by delivering a complete solution, Vinculum-II enhances the initial member of the Vinculum family, the Vinculum-I, by reducing the device cost. The Vinculum-II supports full-speed and low speed Control, Bulk, Isochronous, and Interrupt mode data transfers. In addition, the IC supports three power modes, one suspend mode, and comes in six different packages. Included at no charge is FTDI’s IDE design tool for developers that want to create their own firmware.

As with FTDI's Vinculum-I IC, precompiled firmware is available to allow quick and easy development. The IDE and precompiled firmware is available at http://www.ftdichip.com/Products/ICs/VNC2.htm.

Development platforms and modules are also available for the Vinculum-II. The V2-Eval board is a complete evaluation module with a prototyping area available. The V2DIP modules are compact, easy-to-integrate, and include a USB connector. The Vinco development platform is compatible with Arduino shields.

The second FTDI interface available is FTDI's Java D2xx driver, supporting the USB host class library. This interface requires the Android platform to support USB host and be running OS version 3.2 onward. The Java driver supports FTDI's full complement of USB bridge slave chips including R Chips (232R/245R), H- Series (USB2.0 Hi-Speed), and the X-Chip Series. The Vinculum-II is also supported when one of its USB device ports is configured for FT232 emulation. This library requires no special root access privileges to load the driver and can be easily adapted into applications by developers.

The API is packaged in d2xx.jar and is distributed with demo application source code available online at http://www.ftdichip.com/Android.htm. With this interface option, the Android platform is responsible for providing the USB power.

The key benefits to using FTDI's JAVA Class driver are that installing the driver does not require rooting permissions to be used on the Android platform. As a result, applications and drivers can be made available on the Google Play Store. Rather than requiring FTDI's USB host based chips (FT311D and Vinculum-II) by using FTDI's Java driver, the Android platform can integrate with FTDI's broader range of existing based "bridge" chips.

To develop applications using the FTDI Java D2XX for Android driver, the development machine needs the Eclipse IDE and an up-to-date Android SDK, including the ADB program and the ADT plug-in for Eclipse. Installation and configuration of these tools is outlined on the Android developer web site. Please see (http://developer.android.com/sdk/index.html). The Android device should also have USB Debugging enabled to allow access using the ADB utility. To accomplish this on the Android platform, navigate to Settings > Applications > Development and select the USB debugging option.

Developing Applications w/ FTDI Java D2xx Driver

Figure 7: Developing Application w/ FTDI Java D2xx Driver

To support versatile tablet usage scenarios, Google has included a USB Host API in Android since version 3.2. Before version 3.2, 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 utilization of the USB gadgets attached to Android Host or OTG port.

FTDI provides a Java class library that adapts to applications, so 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 easily. To do so, first copy the library file (d2xx.jar) to the folder of the project and add it by going to "Project"–"Properties".

Adding a Java D2xx Library Step 1

Figure 8: Adding a Java D2xx Library Step 1

Next, select "Java Build Path" from the list on the left hand side. Then, select the "Libraries" tab and click the "Add JARs…" button (Figure 9).

Adding a Java D2xx Library Step 2

Figure 9: Adding a Java D2xx Library Step 2

Choose the library file "d2xx.jarr". The D2xxManager class allows access to driver-wide information such as the VID and PID combinations to match with the device information list, and provides APIs to open target devices returning corresponding FT_Device objects. The FT_Device object can perform UART, EEPROM, and Bit mode-related operations to control device status or read/write data. When the device is no longer required, the FT_Device object can be closed with the close() method. The D2xx Java library is fully documented using Javadoc. Information on the D2xx Android library methods, constants, and sub-classes is available in the corresponding Javadoc entry in the sample project's /doc directory.

Adding a Java D2xx Library Step 3

Figure 10: Adding a Java D2xx Library Step 3

FTDI's Java D2xx driver can be used with FTDI's USB to Serial bridge chips, including the X Chip Series. The X Chip devices offer low power, low pin count, and a feature set that makes bridging from a USB ports to UART, I2C, enhanced SPI or FIFO interfaces easy to design and implement.

Key features include:

  • A battery charger detection to enable higher current and faster charging
  • Extensive clocking capabilities which include internal clock generation and external clock out
  • An internal 3.3 V regulator
  • An integrated crystal and Multi-Time –Programmable (MTP) memory to save board space and maximize flexibility

FTDI's Java driver can also be used with FTDI's legacy chips such as FTDI's FT2232D and R chip series. In addition, FTDI's USB Hi-Speed single, dual, and quad channel chips can be used. This will provide USB to a variety of industry standard or parallel interfaces. All of the ICs listed also have accompanied development modules available.

In addition to supporting FTDI's ICs and modules, FTDI's Java D2xx driver can interface with any of FTDI's Instant USB Full-Speed to Serial cables. These include USB to RS232, RS422, RS485, and TTL level UART cables. All of these are available in a large array of configurations, including power outputs, wire lengths, and serial side terminations.

FTDI's Hi-Speed USB to digital cables are also available for use with the Java D2xx driver.

Since the Vinculum-II has two USB ports that can be independently configured for host or device, it is possible to combine both interface options 1 and 2 through a single chip. AOA support is available on the USB host port. Java D2xx is available through FT232 emulation on the USB device port. This solution now provides support for all Android devices, regardless of the type of USB port or power configurations. The interface on the USB device port can support a traditional PC environment, enhancing the peripheral's usefulness even more.

The third integration option is to use FTDI's legacy drivers. FTDI's VCP driver provides a virtual com port and the standard D2xx driver provides direct access to the USB device through a DLL. Both of these drivers are mutually exclusive and cannot be used at the same time. Like the Java D2xx driver option, the Android platform must have USB host, provide the USB power and will work with FTDI's existing bridge chips, modules and cables. Unlike the Java D2xx driver option, the Android Platform must be "rooted" to install the VCP and legacy D2xx driver. Although available to all Android versions, use of the legacy drivers is only recommended for Android Platform OS before version 3.2. Interface Option 1, Option 2, AOA, and Java driver are suggested for current Android Platform OS versions.

In summary, FTDI offers three different options for interfacing with an Android platform via USB. Those options are:

  • Utilizing Android Open Accessories with FTDI's FT311D or Vinculum-II ICs
  • Utilizing FTDI's Java D2xx driver with the Android USB Host
  • Utilizing FTDI's legacy drivers with the Android USB Host

The complete Android USB ecosystem is supported through these FTDI solutions.

References:

  1. FTDI's Android Interface Solutions Product Training Module

免责声明:各个作者和/或论坛参与者在本网站发表的观点、看法和意见不代表 DigiKey 的观点、看法和意见,也不代表 DigiKey 官方政策。

关于此作者

DigiKey Technical Content

关于此出版商

DigiKey

DigiKey 总部设在美国明尼苏达州锡夫里弗福尔斯市,是一个同时针对原型开发/设计提供小批量供应、针对生产提供大批量供应的全球电子元件综合服务提供商,在 DigiKey 上提供 750 多家优质制造商品牌、六百多万种产品。