安卓USB开发教程 六 安卓 AOA 2.0

Android Open Accessory Protocol 2.0

  • 目录
  • Detecting AOAv2 support
  • Audio support
  • HID support
  • Interoperability with AOAv1
  • Connecting AOAv2 without an Android app

This document describes changes in the Android Open Accessory (AOA) protocol since its initial release and supplements AOA 1.0 documentation. AOAv2 adds the following features:

1. Audio output (from the Android device to the accessory).

2. Support for the accessory acting as one or more Human Interface Devices (HID) to the Android device.

Android SDK APIs available to Android application developers are unchanged.

Detecting AOAv2 support

To determine if a connected Android device supports accessories and the supported protocol version, an accessory must send a getProtocol() command and check the result. Android devices that support only the feautures in AOAv1 must return 1 as the protocol version; devices that support the additional feautres in AOAv2 must return 2 as the protocol version. AOAv2 is backward-compatible with AOAv1, so accessories designed for the original accessory protocol continue to work with newer Android devices.

The following example from the Accessory Development Kit 2011 source code (<adk-src>/adk1/board/AndroidAccessory/AndroidAccessory.cpp) library demonstrates this protocol check:

bool AndroidAccessory::switchDevice(byte addr)
{int protocol = getProtocol(addr);if (protocol >= 1) {Serial.print("device supports protocol 1 or higher\n");} else {Serial.print("could not read device protocol version\n");return false;}sendString(addr, ACCESSORY_STRING_MANUFACTURER, manufacturer);sendString(addr, ACCESSORY_STRING_MODEL, model);sendString(addr, ACCESSORY_STRING_DESCRIPTION, description);sendString(addr, ACCESSORY_STRING_VERSION, version);sendString(addr, ACCESSORY_STRING_URI, uri);sendString(addr, ACCESSORY_STRING_SERIAL, serial);usb.ctrlReq(addr, 0, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_VENDOR |USB_SETUP_RECIPIENT_DEVICE, ACCESSORY_START, 0, 0, 0, 0, NULL);return true;
}

AOAv2 includes new USB product IDs for each combination of USB interfaces available in accessory mode:

Version Product ID Communication Description
AOAv1 0x2D00 accessory Provides two bulk endpoints for communicating with an Android application.
0x2D01 accessory + adb For debugging purposes during accessory development. Available only if the user has enabled USB Debugging in the Android device settings.
AOAv2 0x2D02 audio For streaming audio from an Android device to an accessory.
0x2D03 audio + adb  
0x2D04 accessory + audio  
0x2D05 accessory + audio + adb  

Product IDs used in AOAv1 (0x2D00and 0x2D01) continue to be supported in AOAv2.

Audio support

AOAv2 includes support for audio output from an Android device to an accessory via a standard USB audio class interface capable of 2 channel, 16-bit PCM audio with a bit rate of 44100 Khz (additional audio modes may be added in the future).

To enable audio support, the accessory must send a new USB control request:

**SET_AUDIO_MODE**
requestType:    USB_DIR_OUT | USB_TYPE_VENDOR
request:        58
value:          0 for no audio (default),1 for 2 channel, 16-bit PCM at 44100 KHz
index:          0
data            none

This command must be sent before sending the ACCESSORY_START command for entering accessory mode.

HID support

AOAv2 allows accessories to register one or more USB Human Interface Devices (HID) with an Android device. This approach reverses the direction of communication for typical USB HID devices such as USB mice and keyboards. Normally, the HID device is a peripheral connected to a USB host (i.e. a personal computer), but in AOA the USB host can act as one or more input devices to a USB peripheral.

HID support is a proxy for standard HID events; the implementation makes no assumptions about the content or type of events and simply passes it through to the input system, enabling an AOAv2 accessory to act as any HID device (mouse, keyboard, game controller, etc.). You can use HID support to provide basic functionality, such as a play/pause button on a media dock, or for advanced functionality such as a docking station with a mouse and full QWERTY keyboard.

AOAv2 adds new USB control requests that allow the accessory to act as one or more HID input devices to the Android device. HID support is handled entirely through control requests on endpoint zero, so no new USB interface is needed. The four new control requests are:

1. ACCESSORY_REGISTER_HID registers a new HID device with the Android device. The accessory provides an ID used to identify the HID device for the other three calls. This ID is valid until USB disconnects or until the accessory sends ACCESSORY_UNREGISTER_HIDto unregister the HID device.

2. ACCESSORY_UNREGISTER_HID unregisters a HID device previously registered with ACCESSORY_REGISTER_HID.

3. ACCESSORY_SET_HID_REPORT_DESC sends a report descriptor for a HID device to the Android device. This request is used to describe the capabilities of the HID device and must be sent before reporting any HID events to the Android device. If the report descriptor is larger than the maximum packet size for endpoint zero, multiple ACCESSORY_SET_HID_REPORT_DESC are sent to transfer the entire descriptor.

4. ACCESSORY_SEND_HID_EVENT sends input events from the accessory to the Android device.

The code definitions for the new control requests are:

/* Control request for registering a HID device.* Upon registering, a unique ID is sent by the accessory in the* value parameter. This ID will be used for future commands for* the device**  requestType:    USB_DIR_OUT | USB_TYPE_VENDOR*  request:        ACCESSORY_REGISTER_HID_DEVICE*  value:          Accessory assigned ID for the HID device*  index:          total length of the HID report descriptor*  data            none*/
#define ACCESSORY_REGISTER_HID         54/* Control request for unregistering a HID device.**  requestType:    USB_DIR_OUT | USB_TYPE_VENDOR*  request:        ACCESSORY_REGISTER_HID*  value:          Accessory assigned ID for the HID device*  index:          0*  data            none*/
#define ACCESSORY_UNREGISTER_HID         55/* Control request for sending the HID report descriptor.* If the HID descriptor is longer than the endpoint zero max packet size,* the descriptor will be sent in multiple ACCESSORY_SET_HID_REPORT_DESC* commands. The data for the descriptor must be sent sequentially* if multiple packets are needed.**  requestType:    USB_DIR_OUT | USB_TYPE_VENDOR*  request:        ACCESSORY_SET_HID_REPORT_DESC*  value:          Accessory assigned ID for the HID device*  index:          offset of data in descriptor*                      (needed when HID descriptor is too big for one packet)*  data            the HID report descriptor*/
#define ACCESSORY_SET_HID_REPORT_DESC         56/* Control request for sending HID events.**  requestType:    USB_DIR_OUT | USB_TYPE_VENDOR*  request:        ACCESSORY_SEND_HID_EVENT*  value:          Accessory assigned ID for the HID device*  index:          0*  data            the HID report for the event*/
#define ACCESSORY_SEND_HID_EVENT         57

Interoperability with AOAv1

The original protocol (AOAv1) provides support for an Android application to communicate directly with a USB host (accessory) over USB. AOAv2 continues this support and adds new features to allow the accessory to communicate with the Android operating system itself (specifically the audio and input systems). The design of AOAv2 makes it possible to build an accessory that uses the new audio and HID support in addition to the original feature set. Simply use the new features along with the original features.

Connecting AOAv2 without an Android app

You can design an accessory (such as an audio dock) that uses audio and HID support but does not communicate with an application on the Android device. For these accessories, users do not need to receive dialog prompts for finding and associating the newly attached accessory with an Android application that can communicate with it.

To suppress such dialogs after an accessory connects, the accessory can choose not to send the manufacturer and model names to the Android device. When these strings are not provided to the Android device:

1. The system does not attempt to find an application to communicate with the accessory.

2. The accessory USB interface is not present in the Android device USB configuration after the device enters accessory mode.


为了方便开发者阅读,格式被我重新排版。内容比较简单,我就不通篇翻译了,有疑问可以给我留言或者评论哦:-D


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/403054.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux 驱动编译报错:error: macro __DATE__ might prevent reproducible builds [-Werror=date-time]

编译驱动时遇到这个错误提示&#xff0c;表示当前编译环境中将关于 DATE 以及 TIME 的警告也作为错误来进行处理的。有如下几种方法可以参考&#xff1a; 1. 在编译驱动的相应 Makefile 中增加一行&#xff1a;CFLAGS -Wno-errordate-time&#xff0c;然后保存重新 make&…

Java 结构体之 JavaStruct 使用教程一 初识 JavaStruct

Javastruct 是什么 简而言之&#xff0c;Javastruct 是一个第三方库&#xff0c;用于像处理 C 或者 C 结构体那样处理 java 对象。也即利用 Javastruct 可以在 java 上实现类似于结构体的功能和操作。 Javastruct 的用途 在 java 或者 Android 应用程序与一些嵌入式设备通讯…

Java 结构体之 JavaStruct 使用教程二 JavaStruct 用例分析

使用环境 前一篇在介绍 JavaStruct 类时指定了使用库使用环境为 Java 5 及以上&#xff0c;也即开发我们使用的 JDK 版本为1.5及以上就可以了。以下讲解的用例可以直接将 code 直接粘贴到 java 的 main 函数中执行就可以了&#xff0c;后面会给出测试用例和结果。 使用方法 Jav…

Java 结构体之 JavaStruct 使用教程三 JavaStruct 数组进阶

经过前面两篇博客的介绍&#xff0c;相信对于 JavaStruct 的认识以及编程使用&#xff0c;读者已经有一定的基础了。只要理解和实践结合起来&#xff0c;掌握还是很容易的。下面进行一些数组使用方面的实例说明及演示。 在结构体类中使用数组有几种方式&#xff0c;可以使用静…

Android开发如何使用JNA

1. JNA&#xff08;Java Native Access&#xff09;项目已经迁移到 github&#xff0c;最新的项目链接&#xff1a;https://github.com/java-native-access/jna 。首先前往该地址下载使用 JNA 需要的两个 jar 库文件&#xff0c;jna.jar&#xff0c;jna-platform.jar 。 2. 在…

JAVA循环队列

关于自定义循环队列的实现原理和要点可以参见之前的博文系列&#xff1a;循环队列及C语言实现。这里主要对JAVA下的具体实现方式与原理进行说明。 一、JAVA 中已经自带了 Queue、DQueue、ArrayList、LinkedList 等常用的数据结构&#xff0c;为什么还要单独实现循环队列&#…

VMware 虚拟机占用磁盘空间

使用VMware创建的虚拟机尽管已经设定分配的磁盘大小&#xff0c;但仍然会发现虚拟机占用的磁盘空间会越来越大&#xff0c;而直观体现就是虚拟机系统文件 vmdk 不断增大。因此下面介绍一个简单的方法&#xff0c;使用 VMware 自带的工具对 vmdk 文件进行压缩以节省磁盘空间。拿…

frameworks/av/media/CedarX-Projects/CedarAndroidLib/LIB_KK44_/Android.mk: No such file or directory

在安卓系统编译过程中如果遇到上述或者与之类似的错误&#xff0c;可以采取相同的处理方法进行解决。直接进入到 CedarAndroidLib 目录下&#xff0c;也即此例中的 frameworks/av/media/CedarX-Projects/CedarAndroidLib。看一下当前文件&#xff1a; 注意第9行为包含标题中报错…

《言简意赅之Linux设备驱动编程》 前言

linux 内核与驱动开发是一门很深的学问&#xff0c;主要是由于覆盖知识面较广、内核架构设计层级较深、软硬件知识要兼具。因此自己在学习理解时会经常遇到某一章节需要反复阅读理解多次。所以&#xff0c;我想用一种言简意赅的方式讲述 Linux 内核与设备驱动开发。我认为把一个…

Windows与Linux下tftp服务的使用

tftp 协议是基于 udp 的&#xff0c;轻量小巧&#xff0c;用在局域网和嵌入式上很顺手。大部分帖子把在 linux 上配置的过程描述的过于复杂&#xff0c;其实只是个工具而已。研究协议抓下包对比协议内容也可以满足需求了&#xff0c;下面进入正文。分别讲下在 linux 以及 windo…

Vmware提示:the operation was canceled by the user

一般遇到这种情况是由于当前虚拟机资源中的资源文件被其他进程占用导致的。如果你的系统中有 DAEMON Tools Lite 软件&#xff0c;那么多半是因为这个原因。因此下面针对此情况提出两种解决办法&#xff1a; 1. 检查有无安装 DAEMON Tools Lite 软件&#xff0c;若安装此程序&a…

USB OTG 的进一步理解

一直以来在做安卓系统相关的嵌入式通讯&#xff08;USB、BLE、网络、串口等&#xff09;&#xff0c;最近在讨论 OTG 问题的时候&#xff0c;对该规范又重新理解了一次&#xff0c;这里仅做一些概要和核心点说明&#xff0c;下方会给出具体 OTG 包含协议的参考链接&#xff0c;…

中标麒麟/NeoKylin U盘安装系统

这里以 NeoKylin6 为例&#xff0c;其他版本与此相类似大同小异。但是下载指定版本的镜像时要注意配合该版本的软件包是否充足&#xff0c;不然就会遇到安装好系统很多软件无法安装或更新的情况。 1. 官方下载地址&#xff1a;http://download.cs2c.com.cn/neokylin/desktop/re…

中标麒麟/NeoKylin 安装QT开发环境

1. 如果你对中标麒麟系统安装有疑问&#xff0c;请阅读上一篇文章&#xff1a;《中标麒麟/NeoKylin U盘安装系统》。 2. 进入系统打开终端&#xff0c;以 root 模式操作。 <1> yum install gstream* libXext-devel libX11-devel<2> ln -s /usr/lib64/libXrender.so…

饥荒Mod 开发(二二):显示物品信息

饥荒Mod 开发(二一)&#xff1a;超大便携背包&#xff0c;超大物品栏&#xff0c;永久保鲜 饥荒中的物品没有详细信息&#xff0c;基本上只有一个名字&#xff0c;所以很多物品的功能都不知道&#xff0c;比如浆果吃了也不知道恢复什么&#xff0c; 采集的胡萝卜也不知道什么功…

解决 Windows Update 更新错误/无法创建还原点 代码 0x80246008

这个问题在我的电脑上由来已久&#xff0c;但是大部分的更新工作可以由其他第三方软件来完成&#xff0c;所有有时候得过且过。但同时&#xff0c;有一些棘手的问题&#xff0c;会提示系统进行 Windows Update&#xff0c;只有硬着头皮解决了。如果你遇到了“系统无法创建还原点…

安卓App报错:android.os.FileUriExposedException

安卓7.0开始&#xff0c;不再允许在App中把 file://Uri 暴露给其他App&#xff0c;因此在代码中需要做下版本判断&#xff0c;在7.0版本及以上需要使用 FileProvider 生成 content://Uri 来代替 file://Uri。同时安卓工程需要做以下调整&#xff1a; 1、在 AndroidManifest.xml…

Android/Linux 系统添加对多点触摸屏的支持

含有 HID 多点触摸控制器的触摸屏、触摸板在 Android 和 Linux 内核中都是由 "hid-multitouch" 驱动进行支持的。因此如果你的系统连接触摸屏没有反应&#xff0c;问题基本都出于驱动未加载或者与触摸屏的 VID 与 PID 不适配。以下分情形讨论&#xff1a; 1、系统中已…

安卓获取屏幕最大(绝对)分辨率

安卓开发时&#xff0c;在很多应用场景需要获取手机屏幕的真实分辨率&#xff0c;然而查阅了大部分博客提供的获取方法发现获取方法并不对。下面几种常用的方法&#xff08;错误&#xff09;和最终正确获取的方法均会展示在下面。 实验场景&#xff1a;Activity&#xff08;隐…

安卓BLE开发教程(一) BLE基础

我试图以一种简单的方式去把重要的事情讲清楚。目的是希望BLE协议栈和基础概念简单化&#xff0c;让自己及类似的安卓开发者可以在较短的时间内把握住BLE的核心及使用方法。BLE本身很复杂&#xff0c;但对于安卓开发而言只要抓住一些核心点&#xff0c;便已足够。如果你想全面了…