SlideShare a Scribd company logo
1 of 53
Download to read offline
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

What's hot

Embedded Fest 2019. Іван Пустовіт. From AOSP to Android powered device
Embedded Fest 2019. Іван Пустовіт. From AOSP to Android powered deviceEmbedded Fest 2019. Іван Пустовіт. From AOSP to Android powered device
Embedded Fest 2019. Іван Пустовіт. From AOSP to Android powered deviceEmbeddedFest
 
Kubernetes Robotics Edge Cluster System
Kubernetes Robotics Edge Cluster SystemKubernetes Robotics Edge Cluster System
Kubernetes Robotics Edge Cluster SystemTomoya Fujita
 
Sony robotics overview
Sony robotics overviewSony robotics overview
Sony robotics overviewTomoya Fujita
 
Samsung Indonesia: Tizen Platform Overview and IoT
Samsung Indonesia: Tizen Platform Overview and IoTSamsung Indonesia: Tizen Platform Overview and IoT
Samsung Indonesia: Tizen Platform Overview and IoTRyo Jin
 
Enhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osEnhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osArnav Gupta
 
Tizen introduction & architecture
Tizen introduction & architectureTizen introduction & architecture
Tizen introduction & architectureYoonsoo Kim
 
Mobile Security Assessment: 101
Mobile Security Assessment: 101Mobile Security Assessment: 101
Mobile Security Assessment: 101wireharbor
 
Mec 2015 - Windows developer program for IoT
Mec 2015 - Windows developer program for IoTMec 2015 - Windows developer program for IoT
Mec 2015 - Windows developer program for IoTMirco Vanini
 
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019
Eclipse Plugin for ESP-IDF -  EclipseCon Europe 2019Eclipse Plugin for ESP-IDF -  EclipseCon Europe 2019
Eclipse Plugin for ESP-IDF - EclipseCon Europe 2019Kondal Kolipaka
 
Android Internals and Toolchain
Android Internals and ToolchainAndroid Internals and Toolchain
Android Internals and ToolchainVladimir Kotov
 
Tehran's 1st Android bootcamp - Part1
Tehran's 1st Android bootcamp - Part1Tehran's 1st Android bootcamp - Part1
Tehran's 1st Android bootcamp - Part1Mohsen Mirhoseini
 
I/O 2011 報告会 ADKで遊んでみた
I/O 2011 報告会 ADKで遊んでみたI/O 2011 報告会 ADKで遊んでみた
I/O 2011 報告会 ADKで遊んでみたMakoto Yamazaki
 
Zero to one with Android Things - Hieu Hua
Zero to one with Android Things - Hieu HuaZero to one with Android Things - Hieu Hua
Zero to one with Android Things - Hieu HuaTu Le Dinh
 
Firefox operating system
Firefox operating systemFirefox operating system
Firefox operating systemNishant Mehare
 

What's hot (20)

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

Similar to Android Accessory Protocol Introduction

Leveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory ProtocolLeveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory ProtocolGary Bisson
 
Android Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADKAndroid Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADKRajesh Sola
 
aoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsolaaoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsolaRajesh Sola
 
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...Intel® Software
 
Introduction to Android App Development
Introduction to Android App DevelopmentIntroduction to Android App Development
Introduction to Android App DevelopmentAndri Yadi
 
Introduction to android applications stu
Introduction to android applications stuIntroduction to android applications stu
Introduction to android applications stucbashirmacalin
 
Accessing Hardware on Android
Accessing Hardware on AndroidAccessing Hardware on Android
Accessing Hardware on AndroidGary Bisson
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
3. Android Architecture.pptx
3. Android Architecture.pptx3. Android Architecture.pptx
3. Android Architecture.pptxHarshiniB11
 
Programming objects with android
Programming objects with androidProgramming objects with android
Programming objects with androidfirenze-gtug
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsPositive Hack Days
 
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArtAndroid Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArtAlina Vilk
 
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...Pietro F. Maggi
 
Introduction to Android, Architecture & Components
Introduction to  Android, Architecture & ComponentsIntroduction to  Android, Architecture & Components
Introduction to Android, Architecture & ComponentsVijay Rastogi
 
AndroidFragmentation.com – an open community project
AndroidFragmentation.com – an open community project AndroidFragmentation.com – an open community project
AndroidFragmentation.com – an open community project Joachim Ritter
 
Android Things - The IoT platform from Google
Android Things - The IoT platform from GoogleAndroid Things - The IoT platform from Google
Android Things - The IoT platform from GoogleEmmanuel Obot
 
Smart homes using android
Smart homes using androidSmart homes using android
Smart homes using androidDroidcon Berlin
 
Mobile development
Mobile developmentMobile development
Mobile developmentSayed Ahmed
 

Similar to Android Accessory Protocol Introduction (20)

Leveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory ProtocolLeveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory Protocol
 
Android Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADKAndroid Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADK
 
aoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsolaaoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsola
 
Android 10-cdd
Android 10-cddAndroid 10-cdd
Android 10-cdd
 
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
Accelerate Your IoT and Robotics Development Using Web Technology and Apache ...
 
Introduction to Android App Development
Introduction to Android App DevelopmentIntroduction to Android App Development
Introduction to Android App Development
 
Android のusb support
Android のusb supportAndroid のusb support
Android のusb support
 
Introduction to android applications stu
Introduction to android applications stuIntroduction to android applications stu
Introduction to android applications stu
 
Accessing Hardware on Android
Accessing Hardware on AndroidAccessing Hardware on Android
Accessing Hardware on Android
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
3. Android Architecture.pptx
3. Android Architecture.pptx3. Android Architecture.pptx
3. Android Architecture.pptx
 
Programming objects with android
Programming objects with androidProgramming objects with android
Programming objects with android
 
Manish Chasta - Securing Android Applications
Manish Chasta - Securing Android ApplicationsManish Chasta - Securing Android Applications
Manish Chasta - Securing Android Applications
 
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArtAndroid Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
 
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...
EMEA AppForum 2015 Android KitKat & Lollipop - new features for enterprise de...
 
Introduction to Android, Architecture & Components
Introduction to  Android, Architecture & ComponentsIntroduction to  Android, Architecture & Components
Introduction to Android, Architecture & Components
 
AndroidFragmentation.com – an open community project
AndroidFragmentation.com – an open community project AndroidFragmentation.com – an open community project
AndroidFragmentation.com – an open community project
 
Android Things - The IoT platform from Google
Android Things - The IoT platform from GoogleAndroid Things - The IoT platform from Google
Android Things - The IoT platform from Google
 
Smart homes using android
Smart homes using androidSmart homes using android
Smart homes using android
 
Mobile development
Mobile developmentMobile development
Mobile development
 

Recently uploaded

National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in projectDM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in projectssuserb6619e
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Sumanth A
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Romil Mishra
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptbibisarnayak0
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
chpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMM
chpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMMchpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMM
chpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMMNanaAgyeman13
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 

Recently uploaded (20)

National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in projectDM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.ppt
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
chpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMM
chpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMMchpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMM
chpater16.pptxMMMMMMMMMMMMMMMMMMMMMMMMMMM
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 

Android Accessory Protocol Introduction

  • 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