低电时限制USB反向充电

如何识别当前的USB连接是向别的设备充电?

       最好的方式是获取USB的供电电流,如果当前低电量,而且供电电流太大,则对USB总线断电。但是在USB服务上没法似乎无法获得供电电流。按功能是否可行?如果USB没有配置音频、视频、录音、录像、拍照, otg存储等功能,也就是没有常用的defined codes, 则掐断电源。

场景modepowerdataclasssub-c组合备注
pc  充电ufpsinkdevice//2[source:host, sink:device]
pc  mtpufpsinkdevice//2
pc ptpufpsinkdevice//2
pc cdromufpsinkdevice//2
pc rndis//////不支持rndis
充电头dfpsinkhost//3[source:host, sink:host, sink:device]
充电头ufpsinkdevice//2[source:host, sink:device]
headsetdfpsourcehost612
otg udisksourcehost2
printersourcehost2
y31s 充电dfpsourcehost862
790 充电ufpsinkdevice4[source:host, source:device, sink:host, sink:device]
790 mtpufpsinkdevice4
790 ptpufpsinkdevice4
790cdromufpsinkdevice4
790 充电sinkhost2552554受电方可以弹起连接选择框,虽可以
790 mtpsinkhost614弹起,但是如果切换连接方式,则虽配置
790 ptpsinkhost614成功,但连接会失败的,因为一个主设备
790cdromsinkhost864企图gadget连接从设备,是不允许的。
790 充电ufpsourcedevice4供电方不能弹起连接选择框,但是可以
790 mtpsourcedevice4通过svc usb setFunctions mtp等命令切换
790 ptpsourcedevice4连接方式
790cdromsourcedevice4
790 充电dfpsourcehost2552554
790 mtpsourcehost614
790 ptpsourcehost614
790cdromsourcehost864

Defined Class Codes 类型

Base Class

Descriptor Usage

Description

00h

Device

Use class information in the Interface Descriptors

01h

Interface

Audio

02h

Both

Communications and CDC Control

03h

Interface

HID (Human Interface Device)

05h

Interface

Physical

06h

Interface

Image

07h

Interface

Printer

08h

Interface

Mass Storage

09h

Device

Hub

0Ah

Interface

CDC-Data

0Bh

Interface

Smart Card

0Dh

Interface

Content Security

0Eh

Interface

Video

0Fh

Interface

Personal Healthcare

10h

Interface

Audio/Video Devices

11h

Device

Billboard Device Class

12h

Interface

USB Type-C Bridge Class

3ChInterfaceI3C Device Class

DCh

Both

Diagnostic Device

E0h

Interface

Wireless Controller

EFh

Both

Miscellaneous

FEh

Interface

Application Specific

FFh

Both

Vendor Specific

USB 耳机

07-14 15:34:06.836  1091  2461 I android.hardware.usb@1.2-service-qti: auto suspend usb interfaces /sys/devices/platform/soc/a600000.ssusb/a600000.dwc3/xhci-hcd.2.auto/usb2/2-1
07-14 15:33:51.712 21715 21715 I [21715:kworker/0:3]input: bestechnic HUAWEI USB-C HEADSET as /devices/platform/soc/a600000.ssusb/a600000.dwc3/xhci-hcd.2.auto/usb2/2-1/2-1:1.3/0003:12D1:3A07.0001/input/input6
07-14 15:33:51.784 21715 21715 I [21715:kworker/0:3]hid-generic 0003: 12D1:3A07.0001: input,hidraw0: USB HID v1.11 Device [bestechnic HUAWEI USB-C HEADSET] on usb-xhci-hcd.2.auto-1/input3
07-14 15:34:06.941 12615 12821 D EventHub: No input device configuration file found for device 'bestechnic HUAWEI USB-C HEADSET'.
07-14 15:34:06.947  1091  2461 I android.hardware.usb@1.2-service-qti: auto suspend usb interfaces /sys/devices/platform/soc/a600000.ssusb/a600000.dwc3/xhci-hcd.2.auto/usb2/2-1
07-14 15:34:06.950 12615 12939 D UsbHostManager: USB device attached: vidpid 12d1:3a07 mfg/product/ver/serial bestechnic/HUAWEI USB-C HEADSET/0.24/0296A100000000000000000000000 hasAudio/HID/Storage: true/true/false
07-14 15:34:06.955 12615 12939 D UsbDeviceDescriptor:   1 configs
07-14 15:34:06.958 12615 12939 D UsbHostManager: Added device UsbDevice[mName=/dev/bus/usb/002/002,mVendorId=4817,mProductId=14855,mClass=0,mSubclass=0,mProtocol=0,mManufacturerName=bestechnic,mProductName=HUAWEI USB-C HEADSET,mVersion=0.24,mSerialNumberReader=com.android.server.usb.UsbSerialReader@fb536d0, mHasAudioPlayback=true, mHasAudioCapture=true, mHasMidi=false, mHasVideoCapture=false, mHasVideoPlayback=false, mConfigurations=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbConfiguration[mId=1,mName=null,mAttributes=160,mMaxPower=50,mInterfaces=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=1,mSubclass=1,mProtocol=0,mEndpoints=[]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=0,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=1,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=131,mAttributes=13,mMaxPacketSize=192,mInterval=1]]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=2,mAlternateSetting=0,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=2,mAlternateSetting=1,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=3,mAttributes=13,mMaxPacketSize=384,mInterval=1]]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=2,mAlternateSetting=2,mName=null,mClass=1,mSubclass=2,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=3,mAttributes=13,mMaxPacketSize=576,mInterval=1]]
07-14 15:34:06.958 12615 12939 D UsbHostManager: UsbInterface[mId=3,mAlternateSetting=0,mName=null,mClass=3,mSubclass=0,mProtocol=0,mEndpoints=[
07-14 15:34:06.958 12615 12939 D UsbHostManager:

UsbEndpoint[mAddress=132,mAttributes=3,mMaxPacketSize=3,mInterval=1]]]]

对端是 DRP端口的手机,仅充电config

07-14 17:59:40.935 11994 11994 I [11994:kworker/u16:2]hub 3-0: 1.0: 1 port detected
07-14 17:59:41.488  1091  2461 I android.hardware.usb@1.2-service-qti: uevent received change@/devices/platform/soc/soc:qcom,pmic_glink/soc:qcom,pmic_glink:qcom,ucsi/typec/port0
07-14 17:59:41.496  1091  2461 I android.hardware.usb@1.2-service-qti: port0
07-14 17:59:41.499  1091  2461 I android.hardware.usb@1.2-service-qti: connected:1 canChangeMode:1 canChagedata:1 canChangePower:1
07-14 17:59:41.501 12615 12911 I UsbPortManager: ClientCallback V1_2: port0
07-14 17:59:41.502 12615 12648 I UsbPortManager: USB port changed: port=UsbPort{id=port0, supportedModes=dual, audio_accsupportedContaminantProtectionModes=5supportsEnableContaminantPresenceProtection=falsesupportsEnableContaminantPresenceDetection=false, status=UsbPortStatus{connected=true, currentMode=dfp, currentPowerRole=source, currentDataRole=host, supportedRoleCombinations=[source:host, source:device, sink:host, sink:device], contaminantDetectionStatus=2, contaminantProtectionStatus=1}, canChangeMode=true, canChangePowerRole=true, canChangeDataRole=true, connectedAtMillis=14369516, lastConnectDurationMillis=0
07-14 17:59:41.504 12615 12615 I UsbDeviceManager: updateHostState UsbPort{id=port0, supportedModes=dual, audio_accsupportedContaminantProtectionModes=5supportsEnableContaminantPresenceProtection=falsesupportsEnableContaminantPresenceDetection=false status=UsbPortStatus{connected=true, currentMode=dfp, currentPowerRole=source, currentDataRole=host, supportedRoleCombinations=[source:host, source:device, sink:host, sink:device], contaminantDetectionStatus=2, contaminantProtectionStatus=1}
07-14 17:59:41.341 31352 31352 I [31352:kworker/0:2]usb 2-1: new high-speed USB device number 2 using xhci-hcd
07-14 17:59:41.500 31352 31352 I [31352:kworker/0:2]usb 2-1: New USB device found, VID=109b, PID=90be
07-14 17:59:42.011 12615 12939 D UsbHostManager: USB device attached: vidpid 109b:90be mfg/product/ver/serial Android/Android/5.04/ABCDEFGH hasAudio/HID/Storage: false/false/false
07-14 17:59:42.020 12615 12939 D UsbDeviceDescriptor:   1 configs
07-14 17:59:42.038 12615 12939 D UsbHostManager: Added device UsbDevice[mName=/dev/bus/usb/002/002,mVendorId=4251,mProductId=37054,mClass=0,mSubclass=0,mProtocol=0,mManufacturerName=Android,mProductName=Android,mVersion=5.04,mSerialNumberReader=com.android.server.usb.UsbSerialReader@c9820d6, mHasAudioPlayback=false, mHasAudioCapture=false, mHasMidi=false, mHasVideoCapture=false, mHasVideoPlayback=false, mConfigurations=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbConfiguration[mId=1,mName=diag_adb,mAttributes=192,mMaxPower=0,mInterfaces=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=255,mSubclass=255,mProtocol=48,mEndpoints=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=1,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=129,mAttributes=2,mMaxPacketSize=512,mInterval=0]]
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=0,mName=ADB Interface,mClass=255,mSubclass=66,mProtocol=1,mEndpoints=[
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=2,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 17:59:42.038 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=130,mAttributes=2,mMaxPacketSize=512,mInterval=0]]]]
07-14 17:59:42.047 12615 12615 D AS.AudioService: onReceive()  action= android.hardware.usb.action.USB_DEVICE_ATTACHED

对端是手机且设置为mtp

07-14 18:10:49.967 12615 12939 D UsbHostManager: USB device attached: vidpid 109b:9135 mfg/product/ver/serial Android/Android/5.04/ABCDEFGH hasAudio/HID/Storage: false/false/false
07-14 18:10:49.972 12615 12939 D UsbDeviceDescriptor:   1 configs
07-14 18:10:49.991 12615 12939 D UsbHostManager: Added device UsbDevice[mName=/dev/bus/usb/002/003,mVendorId=4251,mProductId=37173,mClass=0,mSubclass=0,mProtocol=0,mManufacturerName=Android,mProductName=Android,mVersion=5.04,mSerialNumberReader=com.android.server.usb.UsbSerialReader@6872391, mHasAudioPlayback=false, mHasAudioCapture=false, mHasMidi=false, mHasVideoCapture=false, mHasVideoPlayback=false, mConfigurations=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbConfiguration[mId=1,mName=mtp_adb,mAttributes=192,mMaxPower=0,mInterfaces=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbInterface[mId=0,mAlternateSetting=0,mName=MTP,mClass=6,mSubclass=1,mProtocol=1,mEndpoints=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=129,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=1,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=130,mAttributes=3,mMaxPacketSize=28,mInterval=6]]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbInterface[mId=1,mAlternateSetting=0,mName=ADB Interface,mClass=255,mSubclass=66,mProtocol=1,mEndpoints=[
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=2,mAttributes=2,mMaxPacketSize=512,mInterval=0]
07-14 18:10:49.991 12615 12939 D UsbHostManager: UsbEndpoint[mAddress=131,mAttributes=2,mMaxPacketSize=512,mInterval=0]]]]

Version: 2.15.0 (2020-09-28) Keil.STM32F4xx_DFP.2.15.0.pack Download Updated Pack to STM32Cube_FW_F4 Firmware Package version V1.25.1 using HAL Drivers V1.7.9. STM32CubeMX integration (Version 6.0.1): Added support for Timebase Source TIMx (FrameworkCubeMX_gpdsc.ftl). Removed non-existent include path. CMSIS Flash Algorithm: Corrected STM32F42xxx_43xxx_OPT Algorithm. CMSIS SVD: Updated STM32F42*.svd, STM32F43*.svd files. CMSIS-Driver: I2C: Corrected 2 byte reception in master mode. MCI: Replaced empty delay loops with _NOP(). SPI: Corrected PowerControl function (to return error if Initialize was not called, to abort active transfer if power off was requested). Updated GetDataCount function to give accurate count in DMA mode. Corrected Control function (abort in DMA mode, software controlled slave select in slave mode, TI Frame Format selection, ignore bus speed for slave mode). Corrected Uninitialize function (to power off the peripheral if it is powered). Corrected SPI3_SCK pin configuration. Corrected DMA MemDataAlignment configuration. USART: Corrected DMA MemDataAlignment configuration. USBD_HS/USBH_HS: OTG_HS ULPI clock disabled in low power if internal PHY is used to enable proper operation of OTG_HS port in FS mode during CPU sleep. CAN/EMAC/USBD/USBH: Removed macros already provided by cmsis_compiler.h. Updated Boards Examples: Migrated CubeMX projects to V6.0.1 and updated config files. Changed variant selection to "MDK-Plus" where possible. Updated all USB Host/Device examples with user templates from MDK-Middleware v7.11.1. Terminating app_main thread with osThreadExit() to avoid endless loop Updated MS Windows UBS driver files.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值