* commit 'f3cdea937b8b659f959d5e77f4a17f749f85c6ae': doc change: adding link to pic board
This commit is contained in:
@@ -1,90 +1,136 @@
|
|||||||
page.title=Android Open Accessory Development Kit
|
page.title=Android Open Accessory Development Kit
|
||||||
@jd:body
|
@jd:body
|
||||||
|
|
||||||
<div id="qv-wrapper">
|
<div id="qv-wrapper">
|
||||||
<div id="qv">
|
<div id="qv">
|
||||||
<h2>In this document</h2>
|
<h2>In this document</h2>
|
||||||
<ol>
|
|
||||||
<li><a href="#getting-started">Getting Started with the ADK</a>
|
|
||||||
<ol>
|
|
||||||
<li><a href="#installing">Installing the Arduino software and necessary libraries</a></li>
|
|
||||||
<li><a href="#installing-firmware">Installing the firmware to the ADK board</a></li>
|
|
||||||
<li><a href="#running-demokit">Running the DemoKit Android application</a></li>
|
|
||||||
<li><a href="#monitoring">Monitoring the ADK board</a></li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
<li><a href="#how">How an Accessory Communicates with an Android-powered Device
|
|
||||||
in Accessory Mode</a>
|
|
||||||
<ol>
|
|
||||||
<li><a href="#wait">Wait for and detect connected devices</a></li>
|
|
||||||
<li><a href="#determine">Determine the connected device's accessory mode support</a></li>
|
|
||||||
<li><a href="#start">Attempt to start the device in accessory mode</a></li>
|
|
||||||
<li><a href="#establish">Establish communication with the device</a></li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
<li><a href="#firmware">How the ADK board communicates with an Android-powered Device
|
|
||||||
in Accessory Mode</a>
|
|
||||||
<ol>
|
|
||||||
<li><a href="#wait-adk">Wait for and detect connected devices</a></li>
|
|
||||||
<li><a href="#determine-adk">Determine the connected device's accessory mode support</a></li>
|
|
||||||
<li><a href="#start-adk">Attempt to start the device in accessory mode</a></li>
|
|
||||||
<li><a href="#establish-adk">Establish communication with the device</a></li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>The Android 3.1 platform (also backported to Android 2.3.4) introduces Android Open Accessory support, which allows external USB hardware (an Android USB accessory)
|
<ol>
|
||||||
to interact with an Android-powered device in a special "accessory" mode. When an Android-powered powered device is in accessory mode,
|
<li>
|
||||||
the connected accessory acts as the USB host (powers the bus and enumerates devices) and the Android-powered device acts as the device.
|
<a href="#getting-started">Getting Started with the ADK</a>
|
||||||
Android USB accessories are specifically designed to attach to Android-powered devices and
|
|
||||||
adhere to a simple protocol (Android accessory protocol) that allows them to detect Android-powered devices that support accessory mode. Accessories must also provide
|
|
||||||
500mA at 5V for charging power. Many previously released
|
|
||||||
Android-powered devices are only capable of acting as a USB device and cannot initiate connections with external USB devices. Android Open Accessory support
|
|
||||||
overcomes this limitation and allows you to build accessories that can interact with an assortment of Android-powered devices by allowing the accessory
|
|
||||||
initiate the connection.</p>
|
|
||||||
|
|
||||||
<p class="note"><strong>Note:</strong> Accessory mode is ultimately dependent on the device's hardware
|
<ol>
|
||||||
and not all devices will support accessory mode. Devices that support accessory mode can be filtered using a <code><uses-feature></code>
|
<li><a href="#installing">Installing the Arduino software and necessary
|
||||||
element in your corresponding application's Android manifest. For more information, see the <a href="{@docRoot}guide/topics/usb/accessory.html#manifest">USB Accessory</a> Developer
|
libraries</a></li>
|
||||||
Guide.</p>
|
|
||||||
|
|
||||||
<p>The Android Open Accessory Development Kit (ADK) provides an implementation of an Android USB accessory that is based on the
|
<li><a href="#installing-firmware">Installing the firmware to the ADK board</a></li>
|
||||||
<a href="http://www.arduino.cc/">Arduino open source electronics prototyping platform</a>, the accessory's hardware design files,
|
|
||||||
code that implements
|
<li><a href="#running-demokit">Running the DemoKit Android application</a></li>
|
||||||
the accessory's firmware, and the Android application that interacts with the
|
|
||||||
accessory. The hardware design files and code are contained in the <a href="https://dl-ssl.google.com/android/adk/adk_release_0506.zip">ADK package download</a>.
|
<li><a href="#monitoring">Monitoring the ADK board</a></li>
|
||||||
You can <a href="http://www.rt-net.jp/products/rt-adk">buy the hardware components</a> of the ADK if you do not already have them.
|
</ol>
|
||||||
The main hardware and software components of the ADK include:</p>
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<a href="#how">How an Accessory Communicates with an Android-powered Device in Accessory
|
||||||
|
Mode</a>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li><a href="#wait">Wait for and detect connected devices</a></li>
|
||||||
|
|
||||||
|
<li><a href="#determine">Determine the connected device's accessory mode
|
||||||
|
support</a></li>
|
||||||
|
|
||||||
|
<li><a href="#start">Attempt to start the device in accessory mode</a></li>
|
||||||
|
|
||||||
|
<li><a href="#establish">Establish communication with the device</a></li>
|
||||||
|
</ol>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<a href="#firmware">How the ADK board communicates with an Android-powered Device in
|
||||||
|
Accessory Mode</a>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li><a href="#wait-adk">Wait for and detect connected devices</a></li>
|
||||||
|
|
||||||
|
<li><a href="#determine-adk">Determine the connected device's accessory mode
|
||||||
|
support</a></li>
|
||||||
|
|
||||||
|
<li><a href="#start-adk">Attempt to start the device in accessory mode</a></li>
|
||||||
|
|
||||||
|
<li><a href="#establish-adk">Establish communication with the device</a></li>
|
||||||
|
</ol>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<h2>Where to Buy</h2>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li><a href=
|
||||||
|
"http://www.rt-shop.sakura.ne.jp/rt-shop/index.php?main_page=product_info&products_id=2731&language=en">
|
||||||
|
RT Corp</a></li>
|
||||||
|
|
||||||
|
<li><a href=
|
||||||
|
"http://www.microchip.com/android">
|
||||||
|
Microchip</a></li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>The Android 3.1 platform (also backported to Android 2.3.4) introduces Android Open Accessory
|
||||||
|
support, which allows external USB hardware (an Android USB accessory) to interact with an
|
||||||
|
Android-powered device in a special "accessory" mode. When an Android-powered powered device is
|
||||||
|
in accessory mode, the connected accessory acts as the USB host (powers the bus and enumerates
|
||||||
|
devices) and the Android-powered device acts as the device. Android USB accessories are
|
||||||
|
specifically designed to attach to Android-powered devices and adhere to a simple protocol
|
||||||
|
(Android accessory protocol) that allows them to detect Android-powered devices that support
|
||||||
|
accessory mode. Accessories must also provide 500mA at 5V for charging power. Many previously
|
||||||
|
released Android-powered devices are only capable of acting as a USB device and cannot initiate
|
||||||
|
connections with external USB devices. Android Open Accessory support overcomes this limitation
|
||||||
|
and allows you to build accessories that can interact with an assortment of Android-powered
|
||||||
|
devices by allowing the accessory initiate the connection.</p>
|
||||||
|
|
||||||
|
<p class="note"><strong>Note:</strong> Accessory mode is ultimately dependent on the device's
|
||||||
|
hardware and not all devices will support accessory mode. Devices that support accessory mode can
|
||||||
|
be filtered using a <code><uses-feature></code> element in your corresponding application's
|
||||||
|
Android manifest. For more information, see the <a href=
|
||||||
|
"{@docRoot}guide/topics/usb/accessory.html#manifest">USB Accessory</a> Developer Guide.</p>
|
||||||
|
|
||||||
|
<p>The Android Open Accessory Development Kit (ADK) provides an implementation of an Android USB
|
||||||
|
accessory that is based on the <a href="http://www.arduino.cc/">Arduino open source electronics
|
||||||
|
prototyping platform</a>, the accessory's hardware design files, code that implements the
|
||||||
|
accessory's firmware, and the Android application that interacts with the accessory. The hardware
|
||||||
|
design files and code are contained in the <a href=
|
||||||
|
"https://dl-ssl.google.com/android/adk/adk_release_0506.zip">ADK package download</a>. You can
|
||||||
|
<a href=
|
||||||
|
"http://www.rt-shop.sakura.ne.jp/rt-shop/index.php?main_page=product_info&products_id=2731&language=en">buy
|
||||||
|
the hardware components</a> of the ADK if you do not already have them. There is also a <a href=
|
||||||
|
"http://www.microchip.com/android">
|
||||||
|
PIC based USB microcontroller</a> that is not based on the ADK design, but that you can still use
|
||||||
|
to create your own Android open accessories. We expect more hardware distributers to create a
|
||||||
|
variety of kits, so please stay tuned for further developments.</p>
|
||||||
|
|
||||||
|
<p>The main hardware and software components of the ADK include:</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>A USB micro-controller board that is based on the Arduino Mega2560 and Circuits@Home USB Host
|
<li>A USB micro-controller board that is based on the Arduino Mega2560 and Circuits@Home USB
|
||||||
Shield designs (now referred to as the ADK board), which you will later implement as an Android USB accessory.
|
Host Shield designs (now referred to as the ADK board), which you will later implement as an
|
||||||
The ADK board provides input and output pins that you can implement through the use of attachments called "shields."
|
Android USB accessory. The ADK board provides input and output pins that you can implement
|
||||||
Custom firmware, written in C++, is installed on the board to define the board's functionality and interaction with
|
through the use of attachments called "shields." Custom firmware, written in C++, is installed
|
||||||
the attached shield and Android-powered device. The hardware design files for the
|
on the board to define the board's functionality and interaction with the attached shield and
|
||||||
board are located in <code>hardware/</code> directory.</li>
|
Android-powered device. The hardware design files for the board are located in
|
||||||
|
<code>hardware/</code> directory.</li>
|
||||||
|
|
||||||
<li>An Android Demo Shield (ADK shield) that affixes atop the ADK board implements the
|
<li>An Android Demo Shield (ADK shield) that affixes atop the ADK board implements the input
|
||||||
input and output points on the board. These implementations include a joystick, LED
|
and output points on the board. These implementations include a joystick, LED outputs, and
|
||||||
outputs, and temperature and light sensors. You can create or buy your own shields or wire
|
temperature and light sensors. You can create or buy your own shields or wire your own features
|
||||||
your own features to the ADK board to implement custom functionality.
|
to the ADK board to implement custom functionality. The hardware design files for the shield
|
||||||
The hardware design files for the shield are located in <code>hardware/</code>.</li>
|
are located in <code>hardware/</code>.</li>
|
||||||
|
|
||||||
<li>A library based on the <a href=
|
<li>A library based on the <a href=
|
||||||
"http://www.circuitsathome.com/arduino_usb_host_shield_projects">Arduino USB Host Shield</a>
|
"http://www.circuitsathome.com/arduino_usb_host_shield_projects">Arduino USB Host Shield</a>
|
||||||
library provides the logic for the USB micro-controller board to act as a USB Host. This allows
|
library provides the logic for the USB micro-controller board to act as a USB Host. This allows
|
||||||
the board to initiate transactions with USB devices. Describing how to
|
the board to initiate transactions with USB devices. Describing how to use this entire library
|
||||||
use this entire library is out of the scope of this document. Where needed, this document
|
is out of the scope of this document. Where needed, this document points out important
|
||||||
points out important interactions with the library. For more information, see the source code
|
interactions with the library. For more information, see the source code for the Arduino USB
|
||||||
for the Arduino USB Host Shield library in the
|
Host Shield library in the <code>firmware/arduino_libs/USB_Host_Shield</code> directory.</li>
|
||||||
<code>firmware/arduino_libs/USB_Host_Shield</code> directory.</li>
|
|
||||||
|
|
||||||
<li>An Arduino sketch, <code>firmware/demokit/demokit.pde</code>, defines the firmware that
|
<li>An Arduino sketch, <code>firmware/demokit/demokit.pde</code>, defines the firmware that
|
||||||
runs on the ADK board and is written in C++. The sketch calls the Android accessory protocol library
|
runs on the ADK board and is written in C++. The sketch calls the Android accessory protocol
|
||||||
to interact with the Android-powered device. It also sends data from the ADK board and shield to the Android application
|
library to interact with the Android-powered device. It also sends data from the ADK board and
|
||||||
and receives data from the Android application and outputs it to the ADK board and shield.</li>
|
shield to the Android application and receives data from the Android application and outputs it
|
||||||
|
to the ADK board and shield.</li>
|
||||||
|
|
||||||
<li>The Android accessory protocol library, which is located in the
|
<li>The Android accessory protocol library, which is located in the
|
||||||
<code>firmware/arduino_libs/AndroidAccessory</code> directory. This library defines how to
|
<code>firmware/arduino_libs/AndroidAccessory</code> directory. This library defines how to
|
||||||
@@ -113,9 +159,10 @@ page.title=Android Open Accessory Development Kit
|
|||||||
|
|
||||||
<h2 id="getting-started">Getting Started with the ADK</h2>
|
<h2 id="getting-started">Getting Started with the ADK</h2>
|
||||||
|
|
||||||
<p>The following sections describe how to install the Arduino software on your computer, use the Arduino software
|
<p>The following sections describe how to install the Arduino software on your computer, use the
|
||||||
to install the ADK board's firmware, and install and run the accompanying Android application for the ADK board.
|
Arduino software to install the ADK board's firmware, and install and run the accompanying
|
||||||
Before you begin, download the following items to set up your development environment:</p>
|
Android application for the ADK board. Before you begin, download the following items to set up
|
||||||
|
your development environment:</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="http://www.arduino.cc/en/Main/software">Arduino Software</a>: contains libraries
|
<li><a href="http://www.arduino.cc/en/Main/software">Arduino Software</a>: contains libraries
|
||||||
@@ -125,28 +172,34 @@ page.title=Android Open Accessory Development Kit
|
|||||||
libraries to sense human capacitance. This is needed for the capacative button that is located
|
libraries to sense human capacitance. This is needed for the capacative button that is located
|
||||||
on the ADK shield.</li>
|
on the ADK shield.</li>
|
||||||
|
|
||||||
<li><a href="">The ADK package</a>: contains the firmware for the ADK board and
|
<li><a href="">The ADK package</a>: contains the firmware for the ADK board and hardware design
|
||||||
hardware design files for the ADK board and shield.</li>
|
files for the ADK board and shield.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3 id="installing">Installing the Arduino software and necessary libraries</h3>
|
<h3 id="installing">Installing the Arduino software and necessary libraries</h3>
|
||||||
<p>To install the Arduino software:</p>
|
|
||||||
<ol>
|
|
||||||
<li><a href="http://arduino.cc/en/Guide/HomePage">Download and install</a> the Arduino Software
|
|
||||||
as described on the Arduino website.
|
|
||||||
|
|
||||||
<p class="note"><strong>Note:</strong> If you are on a Mac, install the FTDI USB Serial Driver
|
<p>To install the Arduino software:</p>
|
||||||
that is included in the Arduino package,
|
|
||||||
even though the installation instructions say otherwise.</p>
|
<ol>
|
||||||
|
<li>
|
||||||
|
<a href="http://arduino.cc/en/Guide/HomePage">Download and install</a> the Arduino Software
|
||||||
|
as described on the Arduino website.
|
||||||
|
|
||||||
|
<p class="note"><strong>Note:</strong> If you are on a Mac, install the FTDI USB Serial
|
||||||
|
Driver that is included in the Arduino package, even though the installation instructions say
|
||||||
|
otherwise.</p>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li><a href="https://dl-ssl.google.com/android/adk/adk_release_0506.zip">Download</a> and extract the ADK package to a directory of your choice. You should have
|
<li><a href="https://dl-ssl.google.com/android/adk/adk_release_0506.zip">Download</a> and
|
||||||
an <code>app</code>, <code>firmware</code>, and <code>hardware</code> directories.</li>
|
extract the ADK package to a directory of your choice. You should have an <code>app</code>,
|
||||||
|
<code>firmware</code>, and <code>hardware</code> directories.</li>
|
||||||
|
|
||||||
<li>Extract the CapSense download to a directory of your choice.</li>
|
<li>Extract the CapSense download to a directory of your choice.</li>
|
||||||
|
|
||||||
<li>Install the necessary libraries:
|
<li>Install the necessary libraries:
|
||||||
|
|
||||||
<p>On Windows:</p>
|
<p>On Windows:</p>
|
||||||
|
|
||||||
<ol type="a">
|
<ol type="a">
|
||||||
<li>Copy the <code>firmware/arduino_libs/AndroidAccessory</code> and
|
<li>Copy the <code>firmware/arduino_libs/AndroidAccessory</code> and
|
||||||
<code>firmware/arduino_libs/USB_Host_Shield</code> directories (the complete directories,
|
<code>firmware/arduino_libs/USB_Host_Shield</code> directories (the complete directories,
|
||||||
@@ -161,28 +214,30 @@ page.title=Android Open Accessory Development Kit
|
|||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<p>On Mac:</p>
|
<p>On Mac:</p>
|
||||||
|
|
||||||
<ol type="a">
|
<ol type="a">
|
||||||
<li>Right-click on the Arduino application in Finder and select <strong>Show Package
|
<li>Right-click on the Arduino application in Finder and select <strong>Show Package
|
||||||
Contents</strong>.</li>
|
Contents</strong>.</li>
|
||||||
|
|
||||||
<li>Copy the <code>firmware/arduino_libs/AndroidAccessory</code> and
|
<li>Copy the <code>firmware/arduino_libs/AndroidAccessory</code> and
|
||||||
<code>firmware/arduino_libs/USB_Host_Shield</code> directories (the complete directories,
|
<code>firmware/arduino_libs/USB_Host_Shield</code> directories (the complete directories,
|
||||||
not just the files within) to the <code>Contents/Resources/Java/libraries</code>
|
not just the files within) to the <code>Contents/Resources/Java/libraries</code> directory
|
||||||
directory inside the Arduino application.</li>
|
inside the Arduino application.</li>
|
||||||
|
|
||||||
<li>Create a <code>CapSense</code> directory in the
|
<li>Create a <code>CapSense</code> directory in the
|
||||||
<code>Contents/Resources/Java/libraries</code> directory.</li>
|
<code>Contents/Resources/Java/libraries</code> directory.</li>
|
||||||
|
|
||||||
<li>Copy <code>CapSense.cpp</code> and <code>CapSense.h</code> from the unzipped CapSense
|
<li>Copy <code>CapSense.cpp</code> and <code>CapSense.h</code> from the unzipped CapSense
|
||||||
download to the <code>CapSense</code> directory.</li>
|
download to the <code>CapSense</code> directory.</li>
|
||||||
|
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<p>On Linux (Ubuntu):</p>
|
<p>On Linux (Ubuntu):</p>
|
||||||
<ol type="a">
|
|
||||||
|
<ol type="a">
|
||||||
<li>Copy the <code>firmware/arduino_libs/AndroidAccessory</code> and
|
<li>Copy the <code>firmware/arduino_libs/AndroidAccessory</code> and
|
||||||
<code>firmware/arduino_libs/USB_Host_Shield</code> directories (the complete directories,
|
<code>firmware/arduino_libs/USB_Host_Shield</code> directories (the complete directories,
|
||||||
not just the files within) to the <code><arduino_installation_root>/libraries/</code> directory.</li>
|
not just the files within) to the <code><arduino_installation_root>/libraries/</code>
|
||||||
|
directory.</li>
|
||||||
|
|
||||||
<li>Create a <code>CapSense</code> directory in the
|
<li>Create a <code>CapSense</code> directory in the
|
||||||
<code><arduino_installation_root>/libraries/</code> directory.</li>
|
<code><arduino_installation_root>/libraries/</code> directory.</li>
|
||||||
@@ -190,35 +245,42 @@ page.title=Android Open Accessory Development Kit
|
|||||||
<li>Copy <code>CapSense.cpp</code> and <code>CapSense.h</code> from the unzipped CapSense
|
<li>Copy <code>CapSense.cpp</code> and <code>CapSense.h</code> from the unzipped CapSense
|
||||||
download to the <code>CapSense</code> directory.</li>
|
download to the <code>CapSense</code> directory.</li>
|
||||||
|
|
||||||
<li>Install the avr-libc library by entering <code>sudo apt-get install avr-libc</code> from a shell prompt.</li>
|
<li>Install the avr-libc library by entering <code>sudo apt-get install avr-libc</code>
|
||||||
|
from a shell prompt.</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
</li>
|
<p>You should now have three new directories in the Arduino libraries directory:
|
||||||
</ol>
|
<code>AndroidAccessory</code>, <code>USB_Host_Shield</code>, and <code>CapSense</code>.</p>
|
||||||
<p>You should now have three new directories in the Arduino libraries directory:
|
|
||||||
<code>AndroidAccessory</code>, <code>USB_Host_Shield</code>, and <code>CapSense</code>.</p>
|
|
||||||
|
|
||||||
<h3 id="installing-firmware">Installing the firmware to the ADK board</h3>
|
<h3 id="installing-firmware">Installing the firmware to the ADK board</h3>
|
||||||
<p>To install the firmware to the ADK board:</p>
|
|
||||||
<ol>
|
<p>To install the firmware to the ADK board:</p>
|
||||||
<li>Connect the ADK board to your computer using the micro-USB port, which allows two-way communication and provides power to the ADK board.</li>
|
|
||||||
|
<ol>
|
||||||
|
<li>Connect the ADK board to your computer using the micro-USB port, which allows two-way
|
||||||
|
communication and provides power to the ADK board.</li>
|
||||||
|
|
||||||
<li>Launch Arduino.</li>
|
<li>Launch Arduino.</li>
|
||||||
|
|
||||||
<li>Click <strong>Tools > Board > Arduino Mega 2560</strong> to specify the ADK board's type.</li>
|
<li>Click <strong>Tools > Board > Arduino Mega 2560</strong> to specify the ADK board's
|
||||||
|
type.</li>
|
||||||
|
|
||||||
<li>Select the appropriate USB port:
|
<li>Select the appropriate USB port:
|
||||||
<ul>
|
|
||||||
<li>On Windows: click <strong>Tools > Serial Port > COM#</strong> to specify the port of
|
|
||||||
communication. The COM port number varies depending on your computer. COM1 is usually reserved for serial port
|
|
||||||
connections. You most likely want COM2 or COM3. </li>
|
|
||||||
|
|
||||||
<li>On Mac: Click <strong>Tools > Serial Port > dev/tty.usbserial-###</strong> to specify the
|
<ul>
|
||||||
port of communication.</li>
|
<li>On Windows: click <strong>Tools > Serial Port > COM#</strong> to specify the port
|
||||||
|
of communication. The COM port number varies depending on your computer. COM1 is usually
|
||||||
|
reserved for serial port connections. You most likely want COM2 or COM3.</li>
|
||||||
|
|
||||||
<li>On Linux (Ubuntu): Click <strong>Tools > Serial Port > dev/ttyUSB#</strong> to specify the
|
<li>On Mac: Click <strong>Tools > Serial Port > dev/tty.usbserial-###</strong> to
|
||||||
port of communication.</li>
|
specify the port of communication.</li>
|
||||||
</ul></li>
|
|
||||||
|
<li>On Linux (Ubuntu): Click <strong>Tools > Serial Port > dev/ttyUSB#</strong> to
|
||||||
|
specify the port of communication.</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li>To open the firmware code (a sketch), click <strong>File > Open</strong> and select
|
<li>To open the firmware code (a sketch), click <strong>File > Open</strong> and select
|
||||||
<code>firmware/demokit/demokit.pde</code>.</li>
|
<code>firmware/demokit/demokit.pde</code>.</li>
|
||||||
@@ -226,13 +288,11 @@ page.title=Android Open Accessory Development Kit
|
|||||||
<li>Click <strong>Sketch > Compile/Verify</strong> to ensure that the sketch has no
|
<li>Click <strong>Sketch > Compile/Verify</strong> to ensure that the sketch has no
|
||||||
errors.</li>
|
errors.</li>
|
||||||
|
|
||||||
<li>Select <strong>File > Upload to I/O Board</strong>. When Arduino outputs <strong>Done uploading.</strong>, the board
|
<li>Select <strong>File > Upload to I/O Board</strong>. When Arduino outputs <strong>Done
|
||||||
is ready to communicate with your Android-powered device.</li>
|
uploading.</strong>, the board is ready to communicate with your Android-powered device.</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
</ol>
|
<h3 id="running-demokit">Running the DemoKit Android application</h3>
|
||||||
|
|
||||||
|
|
||||||
<h3 id="running-demokit">Running the DemoKit Android application</h3>
|
|
||||||
|
|
||||||
<p>The DemoKit Android application runs on your Android-powered device and communicates with the
|
<p>The DemoKit Android application runs on your Android-powered device and communicates with the
|
||||||
ADK board. The ADK board receives commands such as lighting up the board's LEDs or sends data
|
ADK board. The ADK board receives commands such as lighting up the board's LEDs or sends data
|
||||||
@@ -241,53 +301,68 @@ page.title=Android Open Accessory Development Kit
|
|||||||
<p>To install and run the application in Eclipse:</p>
|
<p>To install and run the application in Eclipse:</p>
|
||||||
|
|
||||||
<ol>
|
<ol>
|
||||||
<li><a href="http://code.google.com/android/add-ons/google-apis/installing.html">Install the Google APIs API Level 10 add-on library</a>,
|
<li><a href="http://code.google.com/android/add-ons/google-apis/installing.html">Install the
|
||||||
which includes the Open Accessory library for 2.3.4 devices that support accessory mode.
|
Google APIs API Level 10 add-on library</a>, which includes the Open Accessory library for
|
||||||
This library is also forward compatible with Android 3.1 or newer devices that support accessory mode. If you only care
|
2.3.4 devices that support accessory mode. This library is also forward compatible with Android
|
||||||
about Android 3.1 or newer devices, all you need is API Level 12. For more information
|
3.1 or newer devices that support accessory mode. If you only care about Android 3.1 or newer
|
||||||
on deciding which API level to use, see the <a href="{@docRoot}guide/topics/USB/accessory.html#choosing">USB Accessory</a> documentation.</li>
|
devices, all you need is API Level 12. For more information on deciding which API level to use,
|
||||||
<li>Click <strong>File > New > Project...</strong>, then select <strong>Android > Android Project</strong></li>
|
see the <a href="{@docRoot}guide/topics/USB/accessory.html#choosing">USB Accessory</a>
|
||||||
<li>In the <strong>Project name:</strong> field, type DemoKit.
|
documentation.</li>
|
||||||
<li>Choose <strong>Create project from existing source</strong>, click <strong>Browse</strong>, select the
|
|
||||||
<code>app</code> directory, and click <strong>Finish</strong>.</li>
|
<li>Click <strong>File > New > Project...</strong>, then select <strong>Android >
|
||||||
|
Android Project</strong></li>
|
||||||
|
|
||||||
|
<li>In the <strong>Project name:</strong> field, type DemoKit.</li>
|
||||||
|
|
||||||
|
<li>Choose <strong>Create project from existing source</strong>, click <strong>Browse</strong>,
|
||||||
|
select the <code>app</code> directory, and click <strong>Finish</strong>.</li>
|
||||||
|
|
||||||
<li>For Build Target, select <strong>Google APIs</strong> (Platform 2.3.3, API Level 10).
|
<li>For Build Target, select <strong>Google APIs</strong> (Platform 2.3.3, API Level 10).
|
||||||
<p class="note"><strong>Note:</strong> Even though the add-on is labeled as
|
|
||||||
<strong>2.3.3</strong>, the newest Google API add-on library for API level 10 adds
|
<p class="note"><strong>Note:</strong> Even though the add-on is labeled as
|
||||||
USB Open Accessory API support for 2.3.4 devices.</li>
|
<strong>2.3.3</strong>, the newest Google API add-on library for API level 10 adds USB Open
|
||||||
|
Accessory API support for 2.3.4 devices.</p>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li>Click <strong>Finish</strong>.</li>
|
<li>Click <strong>Finish</strong>.</li>
|
||||||
|
|
||||||
<li>Install the application to your device.</li>
|
<li>Install the application to your device.</li>
|
||||||
|
|
||||||
<li>Connect the ADK board (USB-A) to your Android-powered device (micro-USB). Ensure that the power cable to the
|
<li>Connect the ADK board (USB-A) to your Android-powered device (micro-USB). Ensure that the
|
||||||
accessory is plugged in or that the micro-USB port on the accesory is connected to your computer
|
power cable to the accessory is plugged in or that the micro-USB port on the accesory is
|
||||||
for power (this also allows you to <a href="monitoring">monitor the ADK board</a>). When
|
connected to your computer for power (this also allows you to <a href="monitoring">monitor the
|
||||||
connected, accept the prompt that asks for whether or not to open the
|
ADK board</a>). When connected, accept the prompt that asks for whether or not to open the
|
||||||
DemoKit application to connect to the accessory. If the prompt does not show up, connect and reconnect the accessory.</li>
|
DemoKit application to connect to the accessory. If the prompt does not show up, connect and
|
||||||
|
reconnect the accessory.</li>
|
||||||
</ol>
|
</ol>
|
||||||
<p>You can now interact with the ADK board by moving the color LED or servo sliders (make sure the servos are connected)
|
|
||||||
or by pressing the relay buttons in the application. On the ADK shield, you can press the
|
|
||||||
buttons and move the joystick to see their outputs displayed in the application.</p>
|
|
||||||
|
|
||||||
<h3 id="monitoring">Monitoring the ADK Board</h3>
|
<p>You can now interact with the ADK board by moving the color LED or servo sliders (make sure
|
||||||
<p>The ADK firmware consists of a few files that you should be looking at if you want to build your own accessory.
|
the servos are connected) or by pressing the relay buttons in the application. On the ADK shield,
|
||||||
The files in the <code>firmware/arduino_libs/AndroidAccessory</code> directory are the most important files and have the logic to detect and connect
|
you can press the buttons and move the joystick to see their outputs displayed in the
|
||||||
to Android-powered devices that support accessory mode. Feel free to add debug statements (Arduino <code>Serial.print()</code> statements) to the code located in the
|
application.</p>
|
||||||
<code>arduino_libraries_directory/AndroidAccessory</code> directory and <code>firmware/demokit/demokit.pde</code> sketch and re-upload the sketch to the ADK board to discover more
|
|
||||||
about how the firmware works.</p>
|
|
||||||
|
|
||||||
<p>You can view the debug statements in the Arduino Serial Monitor by clicking
|
<h3 id="monitoring">Monitoring the ADK Board</h3>
|
||||||
<strong>Tools > Serial Monitor</strong> and setting the baud to 115200.
|
|
||||||
The following sections about how accessories communicate with Android-powered
|
<p>The ADK firmware consists of a few files that you should be looking at if you want to build
|
||||||
devices describe much of what you should be doing in your own accessory.</p>
|
your own accessory. The files in the <code>firmware/arduino_libs/AndroidAccessory</code>
|
||||||
</p>
|
directory are the most important files and have the logic to detect and connect to
|
||||||
|
Android-powered devices that support accessory mode. Feel free to add debug statements (Arduino
|
||||||
|
<code>Serial.print()</code> statements) to the code located in the
|
||||||
|
<code>arduino_libraries_directory/AndroidAccessory</code> directory and
|
||||||
|
<code>firmware/demokit/demokit.pde</code> sketch and re-upload the sketch to the ADK board to
|
||||||
|
discover more about how the firmware works.</p>
|
||||||
|
|
||||||
|
<p>You can view the debug statements in the Arduino Serial Monitor by clicking <strong>Tools >
|
||||||
|
Serial Monitor</strong> and setting the baud to 115200. The following sections about how
|
||||||
|
accessories communicate with Android-powered devices describe much of what you should be doing in
|
||||||
|
your own accessory.</p>
|
||||||
|
|
||||||
<h2 id="how">How an Accessory Communicates with an Android-powered Device in Accessory Mode</h2>
|
<h2 id="how">How an Accessory Communicates with an Android-powered Device in Accessory Mode</h2>
|
||||||
|
|
||||||
<p>When you connect an accessory to an Android-powered device, the accessory's firmware must
|
<p>When you connect an accessory to an Android-powered device, the accessory's firmware must
|
||||||
carry out some standard steps to set up communication with the Android-powered device. If you are building an
|
carry out some standard steps to set up communication with the Android-powered device. If you are
|
||||||
accessory along with an application, this section goes over some general steps that your firmware
|
building an accessory along with an application, this section goes over some general steps that
|
||||||
should carry out.</p>
|
your firmware should carry out.</p>
|
||||||
|
|
||||||
<p>In general, an accessory should carry out the following steps:</p>
|
<p>In general, an accessory should carry out the following steps:</p>
|
||||||
|
|
||||||
@@ -301,27 +376,31 @@ devices describe much of what you should be doing in your own accessory.</p>
|
|||||||
<li>Establish communication with the device if it supports the Android accessory protocol</li>
|
<li>Establish communication with the device if it supports the Android accessory protocol</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<h3 id="wait"><p>Wait for and detect connected devices</h3>Your accessory should have logic to
|
<h3 id="wait">Wait for and detect connected devices</h3>
|
||||||
continuously check for connected Android-powered devices. When a device is connected, your accessory should
|
|
||||||
|
<p>Your accessory should have logic to continuously check
|
||||||
|
for connected Android-powered devices. When a device is connected, your accessory should
|
||||||
determine if the device supports accessory mode.</p>
|
determine if the device supports accessory mode.</p>
|
||||||
|
|
||||||
<h3 id="determine"><p>Determine the device's accessory mode support</h3>
|
<h3 id="determine">Determine the device's accessory mode support</h3>
|
||||||
|
|
||||||
|
|
||||||
<p>When an Android-powered device is connected, it can be in one of three states:</p>
|
<p>When an Android-powered device is connected, it can be in one of three states:</p>
|
||||||
|
|
||||||
<ol type="a">
|
<ol type="a">
|
||||||
|
|
||||||
<li>The attached device supports Android accessory mode and is already in accessory mode.</li>
|
<li>The attached device supports Android accessory mode and is already in accessory mode.</li>
|
||||||
|
|
||||||
<li>The attached device supports Android accessory mode, but it is not in accessory mode.</li>
|
<li>The attached device supports Android accessory mode, but it is not in accessory mode.</li>
|
||||||
|
|
||||||
<li>The attached device does not support Android accessory mode.</li>
|
<li>The attached device does not support Android accessory mode.</li>
|
||||||
|
|
||||||
|
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<p>During the initial connection, the accessory should check the vendor and product IDs of the connected device's USB
|
<p>During the initial connection, the accessory should check the vendor and product IDs of the
|
||||||
device descriptor. The vendor ID should match Google's ID (0x18D1) and the product ID should be
|
connected device's USB device descriptor. The vendor ID should match Google's ID (0x18D1) and the
|
||||||
0x2D00 or 0x2D01 if the device is already in accessory mode (case A). If so, the accessory can now <a href=
|
product ID should be 0x2D00 or 0x2D01 if the device is already in accessory mode (case A). If so,
|
||||||
"#establish">establish communication with the device</a> through bulk transfer endpoints with its
|
the accessory can now <a href="#establish">establish communication with the device</a> through
|
||||||
own communication protocol. There is no need to start the device in accessory mode.</p>
|
bulk transfer endpoints with its own communication protocol. There is no need to start the device
|
||||||
|
in accessory mode.</p>
|
||||||
|
|
||||||
<p class="note"><strong>Note:</strong> 0x2D00 is reserved for Android-powered devices that
|
<p class="note"><strong>Note:</strong> 0x2D00 is reserved for Android-powered devices that
|
||||||
support accessory mode. 0x2D01 is reserved for devices that support accessory mode as well as the
|
support accessory mode. 0x2D01 is reserved for devices that support accessory mode as well as the
|
||||||
@@ -331,37 +410,39 @@ devices describe much of what you should be doing in your own accessory.</p>
|
|||||||
implementing a passthrough to ADB on the device.</p>
|
implementing a passthrough to ADB on the device.</p>
|
||||||
|
|
||||||
<p>If the vendor and product ID do not match, there is no way to distinguish between states b and
|
<p>If the vendor and product ID do not match, there is no way to distinguish between states b and
|
||||||
c, so the accessory <a href="#start">attempts to start the device in accessory mode</a> to
|
c, so the accessory <a href="#start">attempts to start the device in accessory mode</a> to figure
|
||||||
figure out if the device is supported.</p>
|
out if the device is supported.</p>
|
||||||
|
|
||||||
<h3 id="start">Attempt to start the device in accessory mode</h3>
|
<h3 id="start">Attempt to start the device in accessory mode</h3>
|
||||||
|
|
||||||
<p>If the vendor and product IDs do not correspond to an Android-powered device in accessory mode, the accessory
|
<p>If the vendor and product IDs do not correspond to an Android-powered device in accessory
|
||||||
cannot discern whether the device supports accessory mode and is not in that state, or if the
|
mode, the accessory cannot discern whether the device supports accessory mode and is not in that
|
||||||
device does not support accessory mode at all. This is because devices that support accessory mode but aren't in it
|
state, or if the device does not support accessory mode at all. This is because devices that
|
||||||
initially report the device's manufacturer vendor ID and product ID, and not the special Google ones.
|
support accessory mode but aren't in it initially report the device's manufacturer vendor ID and
|
||||||
In either case, the accessory should try to start the device
|
product ID, and not the special Google ones. In either case, the accessory should try to start
|
||||||
into accessory mode to figure out if the device supports it. The following steps explain how to do this:</p>
|
the device into accessory mode to figure out if the device supports it. The following steps
|
||||||
|
explain how to do this:</p>
|
||||||
|
|
||||||
<ol>
|
<ol>
|
||||||
<li>Send a 51 control request ("Get Protocol") to figure out if the device supports
|
<li>Send a 51 control request ("Get Protocol") to figure out if the device supports the Android
|
||||||
the Android accessory protocol. A non-zero number is returned if the protocol is supported, which
|
accessory protocol. A non-zero number is returned if the protocol is supported, which
|
||||||
represents the version of the protocol that the device supports (currently, only version 1
|
represents the version of the protocol that the device supports (currently, only version 1
|
||||||
exists). This request is a control request on endpoint 0 with the following characteristics:
|
exists). This request is a control request on endpoint 0 with the following characteristics:
|
||||||
<pre>
|
<pre>
|
||||||
requestType: USB_DIR_IN | USB_TYPE_VENDOR
|
requestType: USB_DIR_IN | USB_TYPE_VENDOR
|
||||||
request: 51
|
request: 51
|
||||||
value: 0
|
value: 0
|
||||||
index: 0
|
index: 0
|
||||||
data: protocol version number (16 bits little endian sent from the device to the accessory)
|
data: protocol version number (16 bits little endian sent from the device to the accessory)
|
||||||
</pre>
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>If the device returns a proper protocol version, send identifying string information to the device.
|
<li>If the device returns a proper protocol version, send identifying string information to the
|
||||||
This information allows the device to figure out an appropriate application for this accessory and also present the user
|
device. This information allows the device to figure out an appropriate application for this
|
||||||
with a URL if an appropriate application does not exist. These requests
|
accessory and also present the user with a URL if an appropriate application does not exist.
|
||||||
are control requests on endpoint 0 (for each string ID) with the following characteristics:
|
These requests are control requests on endpoint 0 (for each string ID) with the following
|
||||||
<pre>
|
characteristics:
|
||||||
|
<pre>
|
||||||
requestType: USB_DIR_OUT | USB_TYPE_VENDOR
|
requestType: USB_DIR_OUT | USB_TYPE_VENDOR
|
||||||
request: 52
|
request: 52
|
||||||
value: 0
|
value: 0
|
||||||
@@ -369,9 +450,9 @@ index: string ID
|
|||||||
data zero terminated UTF8 string sent from accessory to device
|
data zero terminated UTF8 string sent from accessory to device
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>The following string IDs are supported, with a maximum size of 256 bytes for each string (must
|
<p>The following string IDs are supported, with a maximum size of 256 bytes for each string
|
||||||
be zero terminated with \0).</p>
|
(must be zero terminated with \0).</p>
|
||||||
<pre>
|
<pre>
|
||||||
manufacturer name: 1
|
manufacturer name: 1
|
||||||
model name: 2
|
model name: 2
|
||||||
description: 3
|
description: 3
|
||||||
@@ -379,67 +460,73 @@ version: 4
|
|||||||
URI: 5
|
URI: 5
|
||||||
serial number: 6
|
serial number: 6
|
||||||
</pre>
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>When the identifying strings are sent, request the device start up in accessory mode.
|
<li>When the identifying strings are sent, request the device start up in accessory mode. This
|
||||||
This request is a control request on endpoint 0 with the following
|
request is a control request on endpoint 0 with the following characteristics:
|
||||||
characteristics:
|
<pre>
|
||||||
<pre>
|
|
||||||
requestType: USB_DIR_OUT | USB_TYPE_VENDOR
|
requestType: USB_DIR_OUT | USB_TYPE_VENDOR
|
||||||
request: 53
|
request: 53
|
||||||
value: 0
|
value: 0
|
||||||
index: 0
|
index: 0
|
||||||
data: none
|
data: none
|
||||||
</pre>
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
<p>After sending the final control request, the connected USB device should re-introduce itself on the bus
|
|
||||||
in accessory mode and the accessory can re-enumerate the connected devices. The algorithm jumps back to
|
<p>After sending the final control request, the connected USB device should re-introduce itself
|
||||||
<a href="#determine">determining the device's accessory mode support</a> to check for the
|
on the bus in accessory mode and the accessory can re-enumerate the connected devices. The
|
||||||
vendor and product ID. The vendor ID and product ID of the device will be different if the device
|
algorithm jumps back to <a href="#determine">determining the device's accessory mode support</a>
|
||||||
successfully switched to accessory mode and will now correspond to Google's vendor and product
|
to check for the vendor and product ID. The vendor ID and product ID of the device will be
|
||||||
IDs instead of the device manufacturer's IDs. The accessory can now <a href="#establish">establish communication with the device</a>.</p>
|
different if the device successfully switched to accessory mode and will now correspond to
|
||||||
|
Google's vendor and product IDs instead of the device manufacturer's IDs. The accessory can now
|
||||||
|
<a href="#establish">establish communication with the device</a>.</p>
|
||||||
|
|
||||||
<p>If at any point these steps fail, the device does not support Android accessory mode and the
|
<p>If at any point these steps fail, the device does not support Android accessory mode and the
|
||||||
accessory should wait for the next device to be connected.</p>
|
accessory should wait for the next device to be connected.</p>
|
||||||
|
|
||||||
|
|
||||||
<h3 id="establish">Establish communication with the device</h3>
|
<h3 id="establish">Establish communication with the device</h3>
|
||||||
|
|
||||||
<p>If an Android-powered device in accessory mode is detected, the accessory can query the device's interface and
|
<p>If an Android-powered device in accessory mode is detected, the accessory can query the
|
||||||
endpoint descriptors to obtain the bulk endpoints to communicate with the device. An
|
device's interface and endpoint descriptors to obtain the bulk endpoints to communicate with the
|
||||||
Android-powered device that has a product ID of 0x2D00 has one interface with two bulk endpoints for
|
device. An Android-powered device that has a product ID of 0x2D00 has one interface with two bulk
|
||||||
input and output communication. A device with product ID of 0x2D01 has two interfaces with two bulk endpoints
|
endpoints for input and output communication. A device with product ID of 0x2D01 has two
|
||||||
each for input and output communication. The first interface is for standard communication while the second
|
interfaces with two bulk endpoints each for input and output communication. The first interface
|
||||||
interface is for ADB communication. To communicate on an interface, all you need to do is find the first bulk input and output endpoints,
|
is for standard communication while the second interface is for ADB communication. To communicate
|
||||||
set the device's configuration to a value of 1 with a SET_CONFIGURATION (0x09) device request, then communicate using the endpoints.</p>
|
on an interface, all you need to do is find the first bulk input and output endpoints, set the
|
||||||
|
device's configuration to a value of 1 with a SET_CONFIGURATION (0x09) device request, then
|
||||||
|
communicate using the endpoints.</p>
|
||||||
|
|
||||||
|
<h2 id="firmware">How the ADK board communicates with an Android-powered Device in Accessory
|
||||||
|
Mode</h2>
|
||||||
|
|
||||||
|
<p>If you have access to the ADK board and shield, the following sections describe the firmware
|
||||||
|
code that you installed onto the ADK board. The firmware demonstrates a practical example of how
|
||||||
|
to communicate with an Android-powered device. Even if you do not have the ADK board and shield,
|
||||||
|
reading through how the hardware detects and interacts with devices in accessory mode is still
|
||||||
|
useful if you want to port the code over for your own accessories.</p>
|
||||||
|
|
||||||
<h2 id="firmware">How the ADK board communicates with an Android-powered Device in Accessory Mode</h2>
|
<p>The important pieces of the firmware are the
|
||||||
|
<code>accessory/demokit/demokit/demokit.pde</code> sketch, which is the code that receives and
|
||||||
|
sends data to the DemoKit application running on the Android-powered device. The code to detect
|
||||||
|
and set up communication with the Android-powered device is contained in the
|
||||||
|
<code>accessory/arduino_libs/AndroidAccessory/AndroidAccessory.h</code> and
|
||||||
|
<code>accessory/arduino_libs/AndroidAccessory/AndroidAccessory.cpp</code> files. This code
|
||||||
|
includes most of the logic that will help you implement your own accessory's firmware. It might
|
||||||
|
be useful to have all three of these files open in a text editor as you read through these next
|
||||||
|
sections.</p>
|
||||||
|
|
||||||
<p>If you have access to the ADK board and shield, the following sections describe the firmware code that you installed onto the ADK board. The firmware demonstrates a practical
|
<p>The following sections describe the firmware code in the context of the algorithm described in
|
||||||
example of how to communicate with an Android-powered device. Even if you do not have the ADK board and shield, reading through how the hardware detects
|
<a href="#how">How an Accessory Communicates with an Android-powered Device in Accessory
|
||||||
and interacts with devices in accessory mode is still useful if you want to port the code over for your own accessories.</p>
|
Mode</a>.</p>
|
||||||
|
|
||||||
<p>The important pieces of the firmware are the <code>accessory/demokit/demokit/demokit.pde</code> sketch, which is the code that
|
|
||||||
receives and sends data to the DemoKit application running on the Android-powered device. The
|
|
||||||
code to detect and set up communication with the Android-powered device is contained in the
|
|
||||||
<code>accessory/arduino_libs/AndroidAccessory/AndroidAccessory.h</code> and <code>accessory/arduino_libs/AndroidAccessory/AndroidAccessory.cpp</code>
|
|
||||||
files. This code includes most of the logic that will help you implement your own accessory's firmware.
|
|
||||||
It might be useful to have all three of these files open in a text editor as you read through these next sections.</p>
|
|
||||||
|
|
||||||
<p>The following sections describe the firmware code in the context of the
|
|
||||||
algorithm described in <a href="#how">How an Accessory Communicates with an Android-powered
|
|
||||||
Device in Accessory Mode</a>.</p>
|
|
||||||
|
|
||||||
<h3 id="wait-adk">Wait for and detect connected devices</h3>
|
<h3 id="wait-adk">Wait for and detect connected devices</h3>
|
||||||
|
|
||||||
<p>In the firmware code (<code>demokit.pde</code>), the
|
<p>In the firmware code (<code>demokit.pde</code>), the <code>loop()</code> function runs
|
||||||
<code>loop()</code> function runs repeatedly and calls
|
repeatedly and calls <code>AndroidAccessory::isConnected()</code> to check for any connected
|
||||||
<code>AndroidAccessory::isConnected()</code> to check for any connected devices. If there is a
|
devices. If there is a connected device, it continuously updates the input and output streams
|
||||||
connected device, it continuously updates the input and output streams going to and from the
|
going to and from the board and application. If nothing is connected, it continuously checks for
|
||||||
board and application. If nothing is connected, it continuously checks for a device to be connected:</p>
|
a device to be connected:</p>
|
||||||
<pre>
|
<pre>
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -466,16 +553,16 @@ void loop()
|
|||||||
|
|
||||||
<h3 id="determine-adk">Determine the connected device's accessory mode support</h3>
|
<h3 id="determine-adk">Determine the connected device's accessory mode support</h3>
|
||||||
|
|
||||||
<p>When a device is connected to the ADK board, it can already be in accessory mode,
|
<p>When a device is connected to the ADK board, it can already be in accessory mode, support
|
||||||
support accessory mode and is not in that mode, or does not support accessory mode. The
|
accessory mode and is not in that mode, or does not support accessory mode. The
|
||||||
<code>AndroidAccessory::isConnected()</code> method checks for these cases and responds
|
<code>AndroidAccessory::isConnected()</code> method checks for these cases and responds
|
||||||
accordingly when the <code>loop()</code> function calls it. This function first checks to see if
|
accordingly when the <code>loop()</code> function calls it. This function first checks to see if
|
||||||
the device that is connected hasn't already been handled. If not, it gets the connected device's
|
the device that is connected hasn't already been handled. If not, it gets the connected device's
|
||||||
device descriptor to figure out if the device is already in accessory mode by calling
|
device descriptor to figure out if the device is already in accessory mode by calling
|
||||||
<code>AndroidAccessory::isAccessoryDevice()</code>. This method checks the vendor and product ID
|
<code>AndroidAccessory::isAccessoryDevice()</code>. This method checks the vendor and product ID
|
||||||
of the device descriptor. A device in accessory mode has a vendor ID of 0x18D1 and a product ID
|
of the device descriptor. A device in accessory mode has a vendor ID of 0x18D1 and a product ID
|
||||||
of 0x2D00 or 0x2D01. If the device is in accessory mode, then the ADK board can
|
of 0x2D00 or 0x2D01. If the device is in accessory mode, then the ADK board can <a href=
|
||||||
<a href="#establish-a">establish communication with the device</a>. If not, the board <a href=
|
"#establish-a">establish communication with the device</a>. If not, the board <a href=
|
||||||
"start-a">attempts to start the device in accessory mode</a>.</p>
|
"start-a">attempts to start the device in accessory mode</a>.</p>
|
||||||
<pre>
|
<pre>
|
||||||
bool AndroidAccessory::isConnected(void)
|
bool AndroidAccessory::isConnected(void)
|
||||||
@@ -516,14 +603,13 @@ bool AndroidAccessory::isConnected(void)
|
|||||||
|
|
||||||
<h3 id="start-adk">Attempt to start the device in accessory mode</h3>
|
<h3 id="start-adk">Attempt to start the device in accessory mode</h3>
|
||||||
|
|
||||||
<p>If the device is not already in accessory mode, then the ADK board must
|
<p>If the device is not already in accessory mode, then the ADK board must determine whether or
|
||||||
determine whether or not it supports it by sending control request 51 to check the version of the
|
not it supports it by sending control request 51 to check the version of the USB accessory
|
||||||
USB accessory protocol that the device supports (see
|
protocol that the device supports (see <code>AndroidAccessory::getProtocol()</code>). Protocol
|
||||||
<code>AndroidAccessory::getProtocol()</code>). Protocol version 1 is the only version for now, but this can
|
version 1 is the only version for now, but this can be an integer greater than zero in the
|
||||||
be an integer greater than zero in the future. If
|
future. If the appropriate protocol version is returned, the board sends control request 52 (one
|
||||||
the appropriate protocol version is returned, the board sends control request 52 (one for each
|
for each string with <code>AndroidAcessory:sendString()</code>) to send it's identifying
|
||||||
string with <code>AndroidAcessory:sendString()</code>) to send it's identifying information, and
|
information, and tries to start the device in accessory mode with control request 53. The
|
||||||
tries to start the device in accessory mode with control request 53. The
|
|
||||||
<code>AndroidAccessory::switchDevice()</code> method takes care of this:</p>
|
<code>AndroidAccessory::switchDevice()</code> method takes care of this:</p>
|
||||||
<pre>
|
<pre>
|
||||||
bool AndroidAccessory::switchDevice(byte addr)
|
bool AndroidAccessory::switchDevice(byte addr)
|
||||||
@@ -555,9 +641,9 @@ re-enumerates the bus. When the device is in accessory mode, the accessory then
|
|||||||
<h3 id="establish-adk">Establish communication with the device</h3>
|
<h3 id="establish-adk">Establish communication with the device</h3>
|
||||||
|
|
||||||
<p>If a device is detected as being in accessory mode, the accessory must find the proper bulk
|
<p>If a device is detected as being in accessory mode, the accessory must find the proper bulk
|
||||||
endpoints and set up communication with the device. When the ADK board detects an
|
endpoints and set up communication with the device. When the ADK board detects an Android-powered
|
||||||
Android-powered device in accessory mode, it calls the
|
device in accessory mode, it calls the <code>AndroidAccessory::configureAndroid()</code>
|
||||||
<code>AndroidAccessory::configureAndroid()</code> function:</p>
|
function:</p>
|
||||||
<pre>
|
<pre>
|
||||||
...
|
...
|
||||||
if (isAccessoryDevice(devDesc)) {
|
if (isAccessoryDevice(devDesc)) {
|
||||||
@@ -581,16 +667,16 @@ bool AndroidAccessory::configureAndroid(void)
|
|||||||
...
|
...
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>The <code>AndroidAccessory::findEndpoints()</code> function queries the Android-powered device's
|
<p>The <code>AndroidAccessory::findEndpoints()</code> function queries the Android-powered
|
||||||
configuration descriptor and finds the bulk data endpoints in which to communicate with the USB
|
device's configuration descriptor and finds the bulk data endpoints in which to communicate with
|
||||||
device. To do this, it first gets the device's first four bytes of the configuration
|
the USB device. To do this, it first gets the device's first four bytes of the configuration
|
||||||
descriptor (only need descBuff[2] and descBuff[3]), which contains the information about the
|
descriptor (only need descBuff[2] and descBuff[3]), which contains the information about the
|
||||||
total length of data returned by getting the descriptor. This data is used to determine whether
|
total length of data returned by getting the descriptor. This data is used to determine whether
|
||||||
or not the descriptor can fit in the descriptor buffer. This descriptor also contains information
|
or not the descriptor can fit in the descriptor buffer. This descriptor also contains information
|
||||||
about all the interfaces and endpoint descriptors. If the descriptor is of appropriate size, the
|
about all the interfaces and endpoint descriptors. If the descriptor is of appropriate size, the
|
||||||
method reads the entire configuration descriptor and fills the entire descriptor buffer with this
|
method reads the entire configuration descriptor and fills the entire descriptor buffer with this
|
||||||
device's configuration descriptor. If for some reason the descriptor is no longer attainable,
|
device's configuration descriptor. If for some reason the descriptor is no longer attainable, an
|
||||||
an error is returned.</p>
|
error is returned.</p>
|
||||||
<pre>
|
<pre>
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -626,12 +712,11 @@ bool AndroidAccessory::findEndpoints(byte addr, EP_RECORD *inEp, EP_RECORD *outE
|
|||||||
<p>Once the descriptor is in memory, a pointer is assigned to the first position of the buffer
|
<p>Once the descriptor is in memory, a pointer is assigned to the first position of the buffer
|
||||||
and is used to index the buffer for reading. There are two endpoint pointers (input and output)
|
and is used to index the buffer for reading. There are two endpoint pointers (input and output)
|
||||||
that are passed into <code>AndroidAccessory::findEndpoints()</code> and their addresses are set
|
that are passed into <code>AndroidAccessory::findEndpoints()</code> and their addresses are set
|
||||||
to 0, because the code hasn't found any suitable bulk endpoints yet. A loop reads the buffer, parsing
|
to 0, because the code hasn't found any suitable bulk endpoints yet. A loop reads the buffer,
|
||||||
each configuration, interface, or endpoint descriptor. For each descriptor,
|
parsing each configuration, interface, or endpoint descriptor. For each descriptor, Position 0
|
||||||
Position 0 always contains the size of the descriptor in bytes and position 1 always contains the
|
always contains the size of the descriptor in bytes and position 1 always contains the descriptor
|
||||||
descriptor type. Using these two values, the loop skips any configuration and interface
|
type. Using these two values, the loop skips any configuration and interface descriptors and
|
||||||
descriptors and increments the buffer with the <code>descLen</code> variable to get to the next
|
increments the buffer with the <code>descLen</code> variable to get to the next descriptor.</p>
|
||||||
descriptor.</p>
|
|
||||||
|
|
||||||
<p class="note"><strong>Note:</strong> An Android-powered device in accessory mode can
|
<p class="note"><strong>Note:</strong> An Android-powered device in accessory mode can
|
||||||
potentially have two interfaces, one for the default communication to the device and the other
|
potentially have two interfaces, one for the default communication to the device and the other
|
||||||
@@ -642,8 +727,8 @@ bool AndroidAccessory::findEndpoints(byte addr, EP_RECORD *inEp, EP_RECORD *outE
|
|||||||
|
|
||||||
<p>When it finds the first input and output endpoint descriptors, it sets the endpoint pointers
|
<p>When it finds the first input and output endpoint descriptors, it sets the endpoint pointers
|
||||||
to those addresses. If the findEndpoints() function finds both an input and output endpoint, it
|
to those addresses. If the findEndpoints() function finds both an input and output endpoint, it
|
||||||
returns true. It ignores any other endpoints that it finds (the endpoints for the ADB interface, if
|
returns true. It ignores any other endpoints that it finds (the endpoints for the ADB interface,
|
||||||
present).</p>
|
if present).</p>
|
||||||
<pre>
|
<pre>
|
||||||
...
|
...
|
||||||
p = descBuff;
|
p = descBuff;
|
||||||
@@ -701,10 +786,10 @@ bool AndroidAccessory::findEndpoints(byte addr, EP_RECORD *inEp, EP_RECORD *outE
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>Back in the <code>configureAndroid()</code> function, if there were endpoints found, they are
|
<p>Back in the <code>configureAndroid()</code> function, if there were endpoints found, they are
|
||||||
appropriately set up for communication. The device's configuration is set to 1 and the state of the device is set to "running", which
|
appropriately set up for communication. The device's configuration is set to 1 and the state of
|
||||||
signifies that the device is properly set up to communicate with your USB accessory. Setting this
|
the device is set to "running", which signifies that the device is properly set up to communicate
|
||||||
status prevents the device from being re-detected and re-configured in the
|
with your USB accessory. Setting this status prevents the device from being re-detected and
|
||||||
<code>AndroidAccessory::isConnected()</code> function.</p>
|
re-configured in the <code>AndroidAccessory::isConnected()</code> function.</p>
|
||||||
<pre>
|
<pre>
|
||||||
bool AndroidAccessory::configureAndroid(void)
|
bool AndroidAccessory::configureAndroid(void)
|
||||||
{
|
{
|
||||||
@@ -745,11 +830,11 @@ bool AndroidAccessory::configureAndroid(void)
|
|||||||
|
|
||||||
<p>Lastly, methods to read and write to the appropriate endpoints are needed. The
|
<p>Lastly, methods to read and write to the appropriate endpoints are needed. The
|
||||||
<code>demokit.pde</code> sketch calls these methods depending on the data that is read from the
|
<code>demokit.pde</code> sketch calls these methods depending on the data that is read from the
|
||||||
Android-powered device or sent by the ADK board. For instance, moving the joystick
|
Android-powered device or sent by the ADK board. For instance, moving the joystick on the ADK
|
||||||
on the ADK shield writes data that is read by the DemoKit application running on the
|
shield writes data that is read by the DemoKit application running on the Android-powered device.
|
||||||
Android-powered device. Moving sliders on the DemoKit application is read by the
|
Moving sliders on the DemoKit application is read by the <code>demokit.pde</code> sketch and
|
||||||
<code>demokit.pde</code> sketch and changes the state of the accessory, such as lighting up or
|
changes the state of the accessory, such as lighting up or changing the color of the LED
|
||||||
changing the color of the LED lights.</p>
|
lights.</p>
|
||||||
<pre>
|
<pre>
|
||||||
int AndroidAccessory::read(void *buff, int len, unsigned int nakLimit) {
|
int AndroidAccessory::read(void *buff, int len, unsigned int nakLimit) {
|
||||||
return usb.newInTransfer(1, in, len, (char *)buff, nakLimit); }
|
return usb.newInTransfer(1, in, len, (char *)buff, nakLimit); }
|
||||||
@@ -760,4 +845,5 @@ int AndroidAccessory::write(void *buff, int len) {
|
|||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>See the <code>firmware/demokit/demokit.pde</code> file for information about how the Demo Shield reads and writes data.</p>
|
<p>See the <code>firmware/demokit/demokit.pde</code> file for information about how the ADK board
|
||||||
|
reads and writes data.</p>
|
||||||
Reference in New Issue
Block a user