SlideShare a Scribd company logo
Android Accessory Protocol
FTF2014
04/10/2014
Gary Bisson
Embedded Software Engineer
SESSION OVERVIEW
1. Introduction
2. Protocol Specifications
3. Accessory Development Kit
4. Software Implementation
5. Demonstrations
6. Conclusion
ABOUT THE PRESENTER
• Embedded Software Engineer at Adeneo Embedded
(Bellevue, WA)
Linux / Android
♦ BSP Adaptation
♦ Driver Development
♦ System Integration
Partners with Freescale
Introduction
Android Accessory Protocol Introduction
INTRODUCTION TO AOA
• Allows USB hardware to interact with an Android-powered
device
No need for the Android device to act as USB Host
Standard API
• Introduced in Android 3.1 (API level 12)
Backported to Android 2.3.4 (API level 10)
• Version 2.0 released with Android 4.1
5
Android Accessory Protocol Introduction
INTRODUCTION TO AOA
6
Protocol Specifications
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
• Android Open Accessory 1.0 is a protocol that allows an
Android device to interact with an Android USB
Accessory in a special accessory mode.
• Basically there are four steps to initiate the
communication.
8
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
1. Wait for and detect connected devices
9
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
2. Determine the device’s accessory mode support
10
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
• The accessory must check the Vendor & Product ID’s of
the connected device
Possibility to target some devices
Detection of devices already in Accessory mode
• If it is already in accessory mode then:
Vendor ID = 0x18D1 (Google)
Product ID = 0x2D00 || 0x2D01
11
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
• Accessory mode product IDs
0x2D00 – Supports Accessory Mode
♦ 1 interface with 2 bulk endpoints
0x2D01 – Supports Accessory Mode + ADB
♦ 2 interfaces with 2 bulk endpoints each
• If it is not in accessory mode then Accessory mode support
can be asked:
Send a “Get Protocol” request (51) on endpoint 0
♦ AOA Version (1.0 or 2.0) is returned by Android
device
12
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
3. Attempt to start the device in accessory mode
13
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
• If the AOA Version # is okay, then send string’s identifying
our ADK to the device
Send “Identity” request (52) for each identifier:
♦ Manufacturer
♦ Model Name
♦ Description
♦ Version
♦ URL
♦ Serial Number
Send “Start Accessory” request (53) to request the
Android device re-introduce itself on the bus in
accessory mode
14
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
4. Establish communications
15
Android Accessory Protocol Protocol Specifications
AOA 1.0 PROTOCOL
• The accessory must obtain the Bulk endpoints and be
prepared to initiate communication with the device
From this point the communication is defined by the ADK
Developer
16
Android Accessory Protocol Protocol Specifications
AOA 2.0 PROTOCOL
• AOA 2.0 was released at Google I/O end of June 2012
alongside Jelly Bean
• Two new features:
Audio Output
Accessory as HID
17
Android Accessory Protocol Protocol Specifications
AOA 2.0 PROTOCOL
• Audio output:
From an Android device to an accessory
Standard USB audio class interface (ISO)
Only supports 2 Channel, 16-bit PCM @ 44100KHz
• To enable the audio support, the accessory must send a
new USB control request:
“Audio Support” request (58)
18
Android Accessory Protocol Protocol Specifications
AOA 2.0 PROTOCOL
• HID support:
Registers one or more USB HID with to the Android
device.
Reverses the direction of communication for typical
USB HID (Host <-> Device).
Uses USB control requests:
♦ ACCESSORY_REGISTER_HID
♦ ACCESSORY_UNREGISTER_HID
♦ ACCESSORY_SET_HID_REPORT_DESC
♦ ACCESSORY_SEND_HID_EVENT
19
Android Accessory Protocol Protocol Specifications
AOA 2.0 PROTOCOL
• Compatible with original AOA 1.0 protocol
• Also adds Bluetooth support
Not the focus of this presentation...
Example available in ADK source code
20
Android Accessory Protocol Protocol Specifications
AOA 2.0 PROTOCOL
• New Product ID’s
0x2D02 – Supports Audio
♦ 2 Audio interfaces (control + streaming)
0x2D03 – Supports Audio + ADB
♦ 3 interfaces: 2 Audio + 1 Bulk
0x2D04 – Supports AOA 1.0 + Audio
♦ 3 interfaces: 2 Audio + 1 Bulk
0x2D05 – Supports AOA 1.0 + Audio + ADB
♦ 4 interfaces: 2 Audio + 2 Bulk
21
Accessory Development Kit
Android Accessory Protocol Accessory Development Kit
GOOGLE ADK
• Hardware for ADK 2011 is based on a Arduino Mega2560
• Hardware for the ADK 2012 is based on an ARM
Cortex-M3
• ADK 2012 Guide
23
Android Accessory Protocol Accessory Development Kit
WHAT PART OF AOA DO YOU CONTROL?
• ADK HW
Schematics provided for the alarm clock
24
Android Accessory Protocol Accessory Development Kit
WHAT PART OF AOA DO YOU CONTROL?
• Other solutions?
Any USB Host capable device that can provide power
to the Android device.
This is what makes it easy to port the ADK SW to any
ARM-based board
♦ e.g. i.MX SoCs,Kinetis MCU
♦ Brings more capabilities (video control...)
25
Android Accessory Protocol Accessory Development Kit
WHAT PART OF AOA DO YOU CONTROL?
• ADK SW
Developer controls what runs on the ADK HW and
what runs on the Android device
• Google provides sample software:
Source code repo:
♦ android.googlesource.com/accessories/manifest
Android device application can apply on any device
with API level > 10
♦ Android Application presents UI for control, and
communication
26
Android Accessory Protocol Accessory Development Kit
ADK SOFTWARE
• Accessory side:
Full-featured:
♦ Accessory
Basic controls (LEDs, GPIOs)
♦ Audio
♦ Bluetooth
Code is Arduino-specific
♦ For other solutions, need for a “portable”
Accessory sample code
27
Android Accessory Protocol Accessory Development Kit
ADK SOFTWARE
• Android device side:
Hardware control
28
Software Implementation
Android Accessory Protocol Software Implementation
SOFTWARE IMPLEMENTATION
1. Software on the ADK HW
Handles communication with Android device
Controls sensors, displays, etc. on the ADK HW
2. Software on the Android device
Can be installed automatically via pop-up URL on
connection
Handles communication with ADK HW
Presents a GUI for control, data input/output from ADK
30
Android Accessory Protocol Software Implementation
SOFTWARE INSTALLATION
In case the software is not already installed:
31
Android Accessory Protocol Software Implementation
FIRST USE
Otherwise the user must authorize the execution of the
Accessory app:
32
Android Accessory Protocol Software Implementation
ANDROID APPLICATION
• Must discover the accessory when it is attached
• Communicate with the accessory via ADK Developer
defined commands over USB
• Utilizes the USB API in Android
33
Android Accessory Protocol Software Implementation
ANDROID APPLICATION
• Android contains two different packages to support AOA
protocol:
android.hardware.usb
♦ Works with no add-on library for Android 3.1 or
higher
com.android.future.usb
♦ From Google API add-on library for Android 2.3.4
or higher
♦ Wrapper around android.hardware.usb
♦ Better choice to support the widest range of
devices
34
Android Accessory Protocol Software Implementation
ANDROID APPLICATION
• First add an intent-filter to the application’s manifest
(manifest.xml)
1 <intent-filter >
2 <action android:name="android.intent.action.MAIN" />
3 <category android:name="android.intent.category.LAUNCHER" />
4 <action
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
5 </intent-filter>
6 <meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
7 android:resource="@xml/device_filter" />
35
Android Accessory Protocol Software Implementation
ANDROID APPLICATION
• Then define a resource file that details which USB
Accessory this Application communicates with
(accessory_filter.xml)
1 <?xml version="1.0" encoding="utf-8"?>
2 <resources>
3 <usb-accessory
4 manufacturer="Google, Inc."
5 model="DemoKit"
6 version="2.0" />
7 </resources>
36
Android Accessory Protocol Software Implementation
COMMUNICATION WITH THE ACCESSORY
• Grab the UsbAccessory handle from the Intent received
• Open up input/output file streams with the Accessory
1 if (UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(action)) {
2 UsbAccessory accessory = UsbManager.getAccessory(intent);
3 if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED
, false)) {
4 mAccessory = accessory;
5 fd = UsbManager.getInstance(getApplicationContext()).
openAccessory(accessory).getFileDescriptor();
6 mFout = new FileOutputStream(fd);
7 mFin = new FileInputStream(fd);
8 }
9 }
37
Android Accessory Protocol Software Implementation
ACCESSORY APPLICATION
• Control transfers for initialization
• Bulk transfers for custom com
MCU sample code:
1 res = usbh_check_transfer(outpipe);
2 if (res != PIPE_RESULT_NOT_QUEUED)
3 return -1;
4 usbh_queue_transfer(outpipe, buf, len);
Linux sample code:
1 ret = libusb_bulk_transfer(acc->handle,
2 AOA_ACCESSORY_EP_IN, acc_buf,
3 sizeof(acc_buf), &transferred,
4 200);
38
Android Accessory Protocol Software Implementation
ACCESSORY APPLICATION
• Audio streaming
Arduino ADK or MCU:
♦ DMA to DAC
♦ Simple solution
Linux implementation:
♦ ALSA sound card
♦ Custom ISO implementation
39
Android Accessory Protocol Software Implementation
ACCESSORY APPLICATION
40
Android Accessory Protocol Software Implementation
ACCESSORY APPLICATION
• HID support:
4-step process
♦ Register HID device
♦ Set HID report (defines capabilities)
♦ Send HID reports
♦ Unregister HID device
41
Android Accessory Protocol Software Implementation
ACCESSORY APPLICATION
• Tool to create your HID report structure:
HID Descriptor Tool
42
Demonstrations
Android Accessory Protocol Demonstrations
HARDWARE SELECTION
• Android Device
Stock Nexus 7 Tablet running Android KitKat (v4.4.2)
• Custom ARM-based accessory
i.MX6 SabreLite
GNU/Linux
44
Android Accessory Protocol Demonstrations
HARDWARE SELECTION
• Why were these particular platforms chosen?
i.MX6: powerful & famous nowadays
Show ease of using libusb-based code
Nexus 7: stock device that needs no modification
♦ Any Android device would work the same
45
Android Accessory Protocol Demonstrations
DEMONSTRATION #1
• Create an accessory device that:
Displays pictures
Allows control of the slideshow from Android
• Shows AOA v1.0 capabilities
46
Android Accessory Protocol Demonstrations
DEMONSTRATION #2
• Create an accessory device that:
Get ADK app data
Plays audio
• Shows AOA v2.0 capabilities
Audio streaming
47
Android Accessory Protocol Demonstrations
DEMONSTRATION #3
• Create an accessory device that:
Requires no app
Plays audio
Send HID events
• Shows AOA v2.0 capabilities
HID device
48
Android Accessory Protocol Demonstrations
MUSIC
• Moby - Innocents
Open-source tracks
Available on SoundCloud
More on mobygratis
• Blend.io
GitHub for Music
Pull entire project
Ableton / Logic /
GarageBand
49
Conclusion
Android Accessory Protocol Conclusion
CONCLUSION
• Interesting standard
Great flexibility
Can overcome HW access issues
Compatibility v2.0 / v1.0
• Limitations
• Code source of Linux ADK available:
https://github.com/gibsson/linux-adk
51
Android Accessory Protocol Conclusion
QUESTIONS?
52
Android Accessory Protocol Conclusion
REFERENCES
• Di Cerbo, Manuel: “Turn your Linux computer into a huge
Android USB Accessory”
http://android.serverbox.ch/?p=262
• libusb: http://www.libusb.org/
• Android Developers:
http://developer.android.com/index.html
• Jesse Dannenbring: AOA presentation
53

More Related Content

PDF
Headless Android Strikes Back!
PDF
Adopting agile in an embedded platform Suryakiran Kasturi & Akhil Kumar
PDF
LTE Broadcast/Multicast for Live Events & More
PDF
Android OS Porting: Introduction
PPTX
Introductory webinar on iRidium
PPTX
Android Flash Development
PDF
Customize and control connected devices
Headless Android Strikes Back!
Adopting agile in an embedded platform Suryakiran Kasturi & Akhil Kumar
LTE Broadcast/Multicast for Live Events & More
Android OS Porting: Introduction
Introductory webinar on iRidium
Android Flash Development
Customize and control connected devices

What's hot (20)

PDF
Android Things - The IoT platform for everyone.
PPT
Android OS
PPT
Maddy android
PPTX
Embedded Fest 2019. Іван Пустовіт. From AOSP to Android powered device
PDF
Kubernetes Robotics Edge Cluster System
PDF
Sony robotics overview
PDF
Samsung Indonesia: Tizen Platform Overview and IoT
PPT
Enhancing and modifying_the_core_android_os
PPTX
Android ppt
PPTX
Tizen introduction & architecture
PPT
Mobile Security Assessment: 101
PPTX
Mec 2015 - Windows developer program for IoT
PPTX
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019
PDF
Android Internals and Toolchain
PPTX
Tehran's 1st Android bootcamp - Part1
KEY
I/O 2011 報告会 ADKで遊んでみた
PPTX
Android session-1-sajib
PPTX
Zero to one with Android Things - Hieu Hua
PPTX
Firefox operating system
Android Things - The IoT platform for everyone.
Android OS
Maddy android
Embedded Fest 2019. Іван Пустовіт. From AOSP to Android powered device
Kubernetes Robotics Edge Cluster System
Sony robotics overview
Samsung Indonesia: Tizen Platform Overview and IoT
Enhancing and modifying_the_core_android_os
Android ppt
Tizen introduction & architecture
Mobile Security Assessment: 101
Mec 2015 - Windows developer program for IoT
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019
Android Internals and Toolchain
Tehran's 1st Android bootcamp - Part1
I/O 2011 報告会 ADKで遊んでみた
Android session-1-sajib
Zero to one with Android Things - Hieu Hua
Firefox operating system
Ad

Similar to FTF2014 - Android Accessory Protocol (20)

PDF
Leveraging the Android Open Accessory Protocol
PDF
aoa-adk-osidays-rajeshsola
PDF
Android Open Accessory Protocol - Turn Your Linux machine as ADK
PDF
Android 10-cdd
PDF
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
PDF
Introduction to Android App Development
PDF
Android のusb support
PPTX
Introduction to android applications stu
PDF
Accessing Hardware on Android
KEY
Android Workshop
PPTX
3. Android Architecture.pptx
PDF
Programming objects with android
PPTX
Manish Chasta - Securing Android Applications
PPTX
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
PPTX
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...
PPT
Introduction to Android, Architecture & Components
PPT
AndroidFragmentation.com – an open community project
PPTX
Android Things - The IoT platform from Google
PDF
Smart homes using android
PPTX
Mobile development
Leveraging the Android Open Accessory Protocol
aoa-adk-osidays-rajeshsola
Android Open Accessory Protocol - Turn Your Linux machine as ADK
Android 10-cdd
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Introduction to Android App Development
Android のusb support
Introduction to android applications stu
Accessing Hardware on Android
Android Workshop
3. Android Architecture.pptx
Programming objects with android
Manish Chasta - Securing Android Applications
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...
Introduction to Android, Architecture & Components
AndroidFragmentation.com – an open community project
Android Things - The IoT platform from Google
Smart homes using android
Mobile development
Ad

Recently uploaded (20)

PPTX
Sustainable Sites - Green Building Construction
PPTX
OOP with Java - Java Introduction (Basics)
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Welding lecture in detail for understanding
PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
composite construction of structures.pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
web development for engineering and engineering
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
Sustainable Sites - Green Building Construction
OOP with Java - Java Introduction (Basics)
Mechanical Engineering MATERIALS Selection
Welding lecture in detail for understanding
Structs to JSON How Go Powers REST APIs.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
CYBER-CRIMES AND SECURITY A guide to understanding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
composite construction of structures.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
web development for engineering and engineering
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
bas. eng. economics group 4 presentation 1.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Model Code of Practice - Construction Work - 21102022 .pdf
Foundation to blockchain - A guide to Blockchain Tech

FTF2014 - Android Accessory Protocol

  • 1. Android Accessory Protocol FTF2014 04/10/2014 Gary Bisson Embedded Software Engineer
  • 2. SESSION OVERVIEW 1. Introduction 2. Protocol Specifications 3. Accessory Development Kit 4. Software Implementation 5. Demonstrations 6. Conclusion
  • 3. ABOUT THE PRESENTER • Embedded Software Engineer at Adeneo Embedded (Bellevue, WA) Linux / Android ♦ BSP Adaptation ♦ Driver Development ♦ System Integration Partners with Freescale
  • 5. Android Accessory Protocol Introduction INTRODUCTION TO AOA • Allows USB hardware to interact with an Android-powered device No need for the Android device to act as USB Host Standard API • Introduced in Android 3.1 (API level 12) Backported to Android 2.3.4 (API level 10) • Version 2.0 released with Android 4.1 5
  • 6. Android Accessory Protocol Introduction INTRODUCTION TO AOA 6
  • 8. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL • Android Open Accessory 1.0 is a protocol that allows an Android device to interact with an Android USB Accessory in a special accessory mode. • Basically there are four steps to initiate the communication. 8
  • 9. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL 1. Wait for and detect connected devices 9
  • 10. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL 2. Determine the device’s accessory mode support 10
  • 11. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL • The accessory must check the Vendor & Product ID’s of the connected device Possibility to target some devices Detection of devices already in Accessory mode • If it is already in accessory mode then: Vendor ID = 0x18D1 (Google) Product ID = 0x2D00 || 0x2D01 11
  • 12. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL • Accessory mode product IDs 0x2D00 – Supports Accessory Mode ♦ 1 interface with 2 bulk endpoints 0x2D01 – Supports Accessory Mode + ADB ♦ 2 interfaces with 2 bulk endpoints each • If it is not in accessory mode then Accessory mode support can be asked: Send a “Get Protocol” request (51) on endpoint 0 ♦ AOA Version (1.0 or 2.0) is returned by Android device 12
  • 13. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL 3. Attempt to start the device in accessory mode 13
  • 14. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL • If the AOA Version # is okay, then send string’s identifying our ADK to the device Send “Identity” request (52) for each identifier: ♦ Manufacturer ♦ Model Name ♦ Description ♦ Version ♦ URL ♦ Serial Number Send “Start Accessory” request (53) to request the Android device re-introduce itself on the bus in accessory mode 14
  • 15. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL 4. Establish communications 15
  • 16. Android Accessory Protocol Protocol Specifications AOA 1.0 PROTOCOL • The accessory must obtain the Bulk endpoints and be prepared to initiate communication with the device From this point the communication is defined by the ADK Developer 16
  • 17. Android Accessory Protocol Protocol Specifications AOA 2.0 PROTOCOL • AOA 2.0 was released at Google I/O end of June 2012 alongside Jelly Bean • Two new features: Audio Output Accessory as HID 17
  • 18. Android Accessory Protocol Protocol Specifications AOA 2.0 PROTOCOL • Audio output: From an Android device to an accessory Standard USB audio class interface (ISO) Only supports 2 Channel, 16-bit PCM @ 44100KHz • To enable the audio support, the accessory must send a new USB control request: “Audio Support” request (58) 18
  • 19. Android Accessory Protocol Protocol Specifications AOA 2.0 PROTOCOL • HID support: Registers one or more USB HID with to the Android device. Reverses the direction of communication for typical USB HID (Host <-> Device). Uses USB control requests: ♦ ACCESSORY_REGISTER_HID ♦ ACCESSORY_UNREGISTER_HID ♦ ACCESSORY_SET_HID_REPORT_DESC ♦ ACCESSORY_SEND_HID_EVENT 19
  • 20. Android Accessory Protocol Protocol Specifications AOA 2.0 PROTOCOL • Compatible with original AOA 1.0 protocol • Also adds Bluetooth support Not the focus of this presentation... Example available in ADK source code 20
  • 21. Android Accessory Protocol Protocol Specifications AOA 2.0 PROTOCOL • New Product ID’s 0x2D02 – Supports Audio ♦ 2 Audio interfaces (control + streaming) 0x2D03 – Supports Audio + ADB ♦ 3 interfaces: 2 Audio + 1 Bulk 0x2D04 – Supports AOA 1.0 + Audio ♦ 3 interfaces: 2 Audio + 1 Bulk 0x2D05 – Supports AOA 1.0 + Audio + ADB ♦ 4 interfaces: 2 Audio + 2 Bulk 21
  • 23. Android Accessory Protocol Accessory Development Kit GOOGLE ADK • Hardware for ADK 2011 is based on a Arduino Mega2560 • Hardware for the ADK 2012 is based on an ARM Cortex-M3 • ADK 2012 Guide 23
  • 24. Android Accessory Protocol Accessory Development Kit WHAT PART OF AOA DO YOU CONTROL? • ADK HW Schematics provided for the alarm clock 24
  • 25. Android Accessory Protocol Accessory Development Kit WHAT PART OF AOA DO YOU CONTROL? • Other solutions? Any USB Host capable device that can provide power to the Android device. This is what makes it easy to port the ADK SW to any ARM-based board ♦ e.g. i.MX SoCs,Kinetis MCU ♦ Brings more capabilities (video control...) 25
  • 26. Android Accessory Protocol Accessory Development Kit WHAT PART OF AOA DO YOU CONTROL? • ADK SW Developer controls what runs on the ADK HW and what runs on the Android device • Google provides sample software: Source code repo: ♦ android.googlesource.com/accessories/manifest Android device application can apply on any device with API level > 10 ♦ Android Application presents UI for control, and communication 26
  • 27. Android Accessory Protocol Accessory Development Kit ADK SOFTWARE • Accessory side: Full-featured: ♦ Accessory Basic controls (LEDs, GPIOs) ♦ Audio ♦ Bluetooth Code is Arduino-specific ♦ For other solutions, need for a “portable” Accessory sample code 27
  • 28. Android Accessory Protocol Accessory Development Kit ADK SOFTWARE • Android device side: Hardware control 28
  • 30. Android Accessory Protocol Software Implementation SOFTWARE IMPLEMENTATION 1. Software on the ADK HW Handles communication with Android device Controls sensors, displays, etc. on the ADK HW 2. Software on the Android device Can be installed automatically via pop-up URL on connection Handles communication with ADK HW Presents a GUI for control, data input/output from ADK 30
  • 31. Android Accessory Protocol Software Implementation SOFTWARE INSTALLATION In case the software is not already installed: 31
  • 32. Android Accessory Protocol Software Implementation FIRST USE Otherwise the user must authorize the execution of the Accessory app: 32
  • 33. Android Accessory Protocol Software Implementation ANDROID APPLICATION • Must discover the accessory when it is attached • Communicate with the accessory via ADK Developer defined commands over USB • Utilizes the USB API in Android 33
  • 34. Android Accessory Protocol Software Implementation ANDROID APPLICATION • Android contains two different packages to support AOA protocol: android.hardware.usb ♦ Works with no add-on library for Android 3.1 or higher com.android.future.usb ♦ From Google API add-on library for Android 2.3.4 or higher ♦ Wrapper around android.hardware.usb ♦ Better choice to support the widest range of devices 34
  • 35. Android Accessory Protocol Software Implementation ANDROID APPLICATION • First add an intent-filter to the application’s manifest (manifest.xml) 1 <intent-filter > 2 <action android:name="android.intent.action.MAIN" /> 3 <category android:name="android.intent.category.LAUNCHER" /> 4 <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/> 5 </intent-filter> 6 <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" 7 android:resource="@xml/device_filter" /> 35
  • 36. Android Accessory Protocol Software Implementation ANDROID APPLICATION • Then define a resource file that details which USB Accessory this Application communicates with (accessory_filter.xml) 1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 <usb-accessory 4 manufacturer="Google, Inc." 5 model="DemoKit" 6 version="2.0" /> 7 </resources> 36
  • 37. Android Accessory Protocol Software Implementation COMMUNICATION WITH THE ACCESSORY • Grab the UsbAccessory handle from the Intent received • Open up input/output file streams with the Accessory 1 if (UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(action)) { 2 UsbAccessory accessory = UsbManager.getAccessory(intent); 3 if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED , false)) { 4 mAccessory = accessory; 5 fd = UsbManager.getInstance(getApplicationContext()). openAccessory(accessory).getFileDescriptor(); 6 mFout = new FileOutputStream(fd); 7 mFin = new FileInputStream(fd); 8 } 9 } 37
  • 38. Android Accessory Protocol Software Implementation ACCESSORY APPLICATION • Control transfers for initialization • Bulk transfers for custom com MCU sample code: 1 res = usbh_check_transfer(outpipe); 2 if (res != PIPE_RESULT_NOT_QUEUED) 3 return -1; 4 usbh_queue_transfer(outpipe, buf, len); Linux sample code: 1 ret = libusb_bulk_transfer(acc->handle, 2 AOA_ACCESSORY_EP_IN, acc_buf, 3 sizeof(acc_buf), &transferred, 4 200); 38
  • 39. Android Accessory Protocol Software Implementation ACCESSORY APPLICATION • Audio streaming Arduino ADK or MCU: ♦ DMA to DAC ♦ Simple solution Linux implementation: ♦ ALSA sound card ♦ Custom ISO implementation 39
  • 40. Android Accessory Protocol Software Implementation ACCESSORY APPLICATION 40
  • 41. Android Accessory Protocol Software Implementation ACCESSORY APPLICATION • HID support: 4-step process ♦ Register HID device ♦ Set HID report (defines capabilities) ♦ Send HID reports ♦ Unregister HID device 41
  • 42. Android Accessory Protocol Software Implementation ACCESSORY APPLICATION • Tool to create your HID report structure: HID Descriptor Tool 42
  • 44. Android Accessory Protocol Demonstrations HARDWARE SELECTION • Android Device Stock Nexus 7 Tablet running Android KitKat (v4.4.2) • Custom ARM-based accessory i.MX6 SabreLite GNU/Linux 44
  • 45. Android Accessory Protocol Demonstrations HARDWARE SELECTION • Why were these particular platforms chosen? i.MX6: powerful & famous nowadays Show ease of using libusb-based code Nexus 7: stock device that needs no modification ♦ Any Android device would work the same 45
  • 46. Android Accessory Protocol Demonstrations DEMONSTRATION #1 • Create an accessory device that: Displays pictures Allows control of the slideshow from Android • Shows AOA v1.0 capabilities 46
  • 47. Android Accessory Protocol Demonstrations DEMONSTRATION #2 • Create an accessory device that: Get ADK app data Plays audio • Shows AOA v2.0 capabilities Audio streaming 47
  • 48. Android Accessory Protocol Demonstrations DEMONSTRATION #3 • Create an accessory device that: Requires no app Plays audio Send HID events • Shows AOA v2.0 capabilities HID device 48
  • 49. Android Accessory Protocol Demonstrations MUSIC • Moby - Innocents Open-source tracks Available on SoundCloud More on mobygratis • Blend.io GitHub for Music Pull entire project Ableton / Logic / GarageBand 49
  • 51. Android Accessory Protocol Conclusion CONCLUSION • Interesting standard Great flexibility Can overcome HW access issues Compatibility v2.0 / v1.0 • Limitations • Code source of Linux ADK available: https://github.com/gibsson/linux-adk 51
  • 52. Android Accessory Protocol Conclusion QUESTIONS? 52
  • 53. Android Accessory Protocol Conclusion REFERENCES • Di Cerbo, Manuel: “Turn your Linux computer into a huge Android USB Accessory” http://android.serverbox.ch/?p=262 • libusb: http://www.libusb.org/ • Android Developers: http://developer.android.com/index.html • Jesse Dannenbring: AOA presentation 53