devlib icon indicating copy to clipboard operation
devlib copied to clipboard

Turning off USB charging of the target from the energy meter

Open joelagnel opened this issue 7 years ago • 4 comments

Can we instruct the target to turn off USB charging from the energy meter as a hint?

Currently this has to be done manually either from target.execute or from adb. Can we automate this by providing some per-device abstraction?

CC @bjackman @derkling

joelagnel avatar May 02 '17 20:05 joelagnel

AndroidTarget has a property for this: https://github.com/ARM-software/devlib/blob/master/devlib/target.py#L1092

As far as it's been tested, it currently only works on Google Pixel. However if another device has a different method for disabling charging then it should be possible to override the mechanism.

bjackman avatar May 03 '17 09:05 bjackman

Thanks @bjackman for pointing that out. Is it Ok if we provide a way to override the path from: libs/utils/platforms/pixel.json ? Also, since this is related to emeter usage, can we have emeter set this to False during start/reset and set to True after stop? Just want to avoid the possiblity that the user forgets to set it before emeter reset.

joelagnel avatar May 03 '17 17:05 joelagnel

Is it Ok if we provide a way to override the path from: libs/utils/platforms/pixel.

Maybe we can do that, but that means adding API surface so it musn't be a hack to solve a problem for a specific platform. How to dis/enable charging is really procedural information rather than data so I'd want to be conservative about designing a JSON interface for it (Even if we assume it's always a case of writing a sysfs file, we need to store the values to write. Do we assume that it's always the same file to enable and disable? Should we read the file back to check it was updated or is it write-only? What if there are multiple power sources to be dis/enabled?).

Also, that configuration isn't technically necessary, the problem could be solved in devlib by making the charging_enabled property implementation more generic - that's what I meant by "it should be possible to override the mechanism."

Also, since this is related to emeter usage, can we have emeter set this to False during start/reset and set to True after stop?

Yeah that sounds sensible, probably libs/utils/energy.py is the place to do that - patches welcome :grin:

bjackman avatar May 04 '17 10:05 bjackman

Turns out charging disable from target side is unreliable on devices. It seems to confuse the host-side, and if the host drops the USB connection, then there isn't any way to re-enable charging because that requires the USB connection to begin with. I think some USB host controllers do monitor VBUS current.

Considering the nature of doing this which platform-specific and the fact that its unreliable, I think we should just use something like USB passthrough where USB automatically disconnected externally by the emeter. I started a discussion here: https://github.com/ARM-software/devlib/issues/121

joelagnel avatar May 07 '17 20:05 joelagnel