TLDR
在USB首选项中连接两个USB-C Android手机时,我可以通过“电荷连接的设备”选项加热功率角色。
我如何在连接在一起的两个Android手机之外复制此功能(即连接自己的自定义第三方硬件时)?我了解我将必须在第三方硬件方面实现或使用一些USB堆栈硬件/固件,但是我不确定确切的标准是必需的。例如 digi-key < /a>制作了一篇不错的文章,描述了各种USB规格。因此,对于Android功率交换可比性,我是否需要USB PD 3.0,还是USB Type-C 1.2工作,或USB BC 1.2等?
另外,我想链接一些官方确认,即Android Open配件不是当前处理Android手机从外部设备供电的方法,尽管官方开发文档。取而代之的是,似乎USB-PD或其他一些具有Android的USB类型C标准保留数据主机,而外部设备是电源源是当前这样做的标准方法。到目前为止,我在Android Dev文档中还没有发现任何有关此事的信息,对我来说似乎很奇怪,自2012年以来,他们还没有更新的东西仍然是官方文档是做事的唯一方法。
看来我能找到的Android开发文档中未列出此USB功率交换功能,但是您可以找到负责功率角色热交换的源代码
usb_use_poper_poper_poper_only
我有一个项目,需要通过外部电池供电MCU为Android手机供电。根据 android dev docs 在USB连接上,我应该已经有了我的MCU充当主机并实施Android开放配件协议(AOA)。
寻找如何做的事实证明是一个相当深的兔子洞,但简而言之“ nofollow noreferrer”> ftdi 使专用IC用于处理AOA协议,但是自2012年以来,他们的示例尚未更新,AOA是硬编码的,因此该协议的未来更改都需要制作新硬件。
我还曾在 ioio board 中回购一点(来自Android side)在PIC24F上使用的固件中,看起来原始开发人员创建了一个自定义的USB-host堆栈,该堆栈实现了AOA,并在Repo Wiki中发表了一些评论,以了解这非常困难。
最后,我找到了在a max3421e 的回购。看来,这可能已经消失或与2011/2012年其他项目有关的AOA,例如现在已经过时了。
总而言之,它似乎围绕AOA或“ ADK”的任何内容都是完全用户或第三方驱动的,而Android/Google则没有正式支持。例如,在 docs 有一个链接到查看“”“”源代码“对于ADK,但是此链接将您重定向到同一文档(不是源代码)。我实际上发现了提到的源代码>源代码由一个12岁的孩子与正式仓库链接。您可以自由查看此代码,但是它是旧的,并且无法与当前的Android构建系统一起使用,并且您会发现USB_HOST_SHIELD_2.0项目的井井有条和易于理解,这是基于的从我了解的硬件上。
由于似乎很少支持Android的支持,因此自2011年推出了2012年以来,它几乎是自2012年以来就被放弃了。因此,我正在寻找一种更具未来的解决方案来为Android设备供电外部控制器。从我可以告诉现代方法的方法中,使用USB-PD控制器来允许从数据角色中独立选择功率角色。例如,如果我使用USB-C电缆连接到Android手机,则插头/电缆的方向似乎确定了主机/附件的角色,默认电源为附件。 (IE从屏幕截图之前,这是主机,因为“设置为“此设备”的“ USB控制器”,并且电源源是相反的电话,因为此处禁用了“电荷连接的设备”(并在另一个设备上启用)。
TLDR
When I connect two USB-C Android phones together in the USB Preferences I can hot swap the power roles via the "Charge connected device" option.

How can I duplicate this functionality outside of two Android phones connecting together (i.e. when I connect my own custom 3rd party hardware)? I understand I will have to implement or make use of some USB stack hardware/firmware on the 3rd party hardware side, but I'm not sure exactly what standards are necessary. For example Digi-key produced a nice article describing the various USB specifications. So for Android Power Swapping comparability, do I need USB PD 3.0, or would USB Type-C 1.2 work, or USB BC 1.2, etc.?
Also I would like a link to some official confirmation that Android Open Accessory is NOT the current way to handle powering an Android phone from an external device despite what is suggested by the official dev docs. Instead it appears that USB-PD, or some other USB type C standard with Android remaining the DATA Host, while the external device being the POWER SOURCE is the current standard way of doing this. I haven't found anything about this in the Android dev docs so far and it seems very strange to me that something they haven't updated since 2012 is still in the official docs as the ONLY way of doing things.
It appears this USB Power Swapping functionality is not listed in the Android dev docs that I could find, but you can find the source code responsible for the hot swapping of power roles here
Detailed Background
I have a project where I need to power an Android phone via an external battery powered MCU. According to the android dev docs on usb connectivity, I'm supposed to have my MCU act as a host and implement the Android Open Accessory Protocol (AOA).
Looking for how to do so turned out to be a fairly deep rabbit hole, but in short I found manufacturers like FTDI that make dedicated ICs for handling AOA protocol, but their examples haven't been updated since 2012 and the AOA is hardcoded so any future changes to the protocol would require making new hardware.
I also have worked on the IOIO Board repo a bit (from the Android side), but looking into the firmware used on the PIC24F it looks like the original developer created a custom USB-Host stack that implemented the AOA and makes several comments in the repo wiki about how this is VERY hard.
Finally, I found repo that implements AOA on a MAX3421E. It appears this may have stemmed off or related to other projects in 2011/2012 surrounding the AOA like the Arduino ADK which is now obsolete.
It summary it appears anything surrounding the AOA or "ADK" is completely user or 3rd-party driven and nothing officially supported by Android/Google. For example, in the docs there is a link to viewing the "source code" for the ADK, but this link redirects you back to the same documentation (not the source code). I actually found the mentioned source code from a copy of it on an Instructables page by a 12 year kid with a link to the official repo. You're free to have a look at this code, but it is OLD and does not work with the current Android build system and you'd find the USB_Host_Shield_2.0 project to be much more well organized and easy to understand, which is based on the hardware from what I understand.
With how little support Android appears to be providing for this, it looks like it was all but abandoned since 2012 a year after it was introduced in 2011. Thus, I was looking for a more future-proof solution to power the Android device from an external controller. From what I can tell the modern way to approach this is to use a USB-PD controller to allow power roles to be independently selected from the data roles. For example, if I connect to Android phones with a USB-C cable, it appears the orientation of the plug/cable determines the Host/Accessory role with the default Power Source being the accessory. (i.e. from the screenshot before, this is the Host since "USB Controller By" set to "This device" and the Power Source is the opposite phone since "Charge connected device" is disabled here (and enabled on the other device).
发布评论
评论(1)
我将继续一个潜在的答案,尽管我希望有一些正式答案来覆盖我的假设和猜测。
从源代码处理此功能,{power_role_none,power_role_none,power_role_sink,power_role_sink,power_role_sour_source}有三个势力。
遵循这些导入,我可以看到在这里,功率角色和数据角色之间存在明显的分离。
如果我将手机插入不支持USB PD的USB端口,则此“电荷连接设备”选项会消失。将手机连接到USB-PD充电器时也不会出现。因此,我假设连接的设备必须显示这是双重角色UFP | DFP以使此选项出现。
如果有人可以添加任何官方文档,以及必要的USB标准(3.0、3.1、3.2、4.0等),以及该功能支持哪些Android版本的内容等等,这将覆盖此答案。
I'll go ahead an post a potential answer, though I'm hoping for some official answer to override my assumptions and guesses.
From what I can see in the source code handling this functionality, there are three power roles of {POWER_ROLE_NONE, POWER_ROLE_SINK, POWER_ROLE_SOURCE}.
Following these imports, I can see here that there is a clear separation between power roles and data roles.
If I plug in the phone to a USB port not supporting USB-PD, this "Charge connected device" option disappears. It also does not appear when connecting the phone to a USB-PD charger. So I'm assuming the connected device has to show that is a Dual Role UFP | DFP in order for this option to appear.
If anyone can add any official documentation on this, and what USB standard (3.0, 3.1, 3.2, 4.0, etc.) is necessary and how this relates to which Android versions are supported for this functionality, etc., this would override this answer.