WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Software "switch"--or query--for USB power?  (Read 1666 times)

Offline ladnar

  • Newbie
  • *
  • Posts: 47
Software "switch"--or query--for USB power?
« on: October 05, 2020, 12:28:04 AM »
I could probably find this answer on my own through two methods (1) dig through raspberypi.org official documentation and my McDowell/Sayer book about USB and a million google searches, or (2) I could ask, here. I am afraid I chose the latter.

(3) Buy another USB voltmeter-ammeter, and plug both ri-pi zero USB micros through those, giving realtime readouts of amperage and voltage running host to device; or from wall to host ; or wall to device.  I will do this eventually, but I am in a new town and don't know the electronics stores yet. And the slow boat from china (ebay) ... well nevermind. I chose Number 2 method. (You know, at that price on ebay, I should buy twelve of them, one for each r-pi!)

What command or series of commands would tell me who is sourcing and who is sinking power? I am specifically thinking of during utilization of rpiboot and/ or g-ether USB gadget, and raspberry pi zero bramble clusters.

(I remember reading that USB hubs and "power strips" can act funny sometimes, regarding power? Backfeed?  Hopefully the USB standard can tolerate shoddy workmanship and thoughtless hardware hackers (i.e me!)? I sometimes plug in, before I think!)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11048
Re: Software "switch"--or query--for USB power?
« Reply #1 on: October 05, 2020, 02:51:24 AM »
I don't think those measurements are available via software, at least never heard of it.
The only barriers that can stop you are the ones you create yourself.

Offline ladnar

  • Newbie
  • *
  • Posts: 47
Re: Software "switch"--or query--for USB power?
« Reply #2 on: October 05, 2020, 11:13:00 PM »
I think you are might be right. I consulted my McDowell and Sayer book "USB Explained".

However, I think such an EFFECT could be CAUSED by a well written program? Maybe? (I am a VERY newbie programmer!).

Buying 10 USB voltammeters @ 1.87 a piece, could "size up" my raspberry pi bramble bush, in a hardware way. But it seems kind of silly.

A software way might be to use something called "power-switching". Some hubs support it (I don't know if this includes "root USB hubs"; the host controller.). McDowell and Sayer only had one paragraph on the subject? Perhaps its not popular? Perhaps its an old part of the standard. I could dig through the USB official documentation. I have it on pdf somewhere, but I could just find it online again.

According to McDowell an Sayer, downstream hubs have one of five states: (1) Powered off, (2) Disconnected, (3) Disabled, (2) Enabled, or (5) Suspended.

Devices have six possible states: (1)Attached, (2) Powered, (3) Suspended, (4) Default, (5) Address (6) Configured.

Hubs plugged into other hubs, are configured as devices.

Maybe a shell script could use cat and grep could glean from lsusb and dmesg and other common linux utilities (maybe "port" identification; Linux-port, not USB-port numbers. netstat, lsof, ss, and/or nmap.) what devices are present.

And maybe, by this "word" identification (mouse, keyboard, etc), and the possible states for devices and/or hubs, one could send a series of simple "enable" or "disable" queries, until the state becomes known? And some "power-switching" commands could be floated to the hubs to try them, on and off?

The only problem with this, I think, is turning somethings off might make it so they can't be turned on again, by CPU signal ove rthe bus? Is this right?

And Disconnecting a hub might make it unable to reconnect... or "enable"? Maybe?

So maybe, after this proposed software runs its course, the user should be prompted to reboot the computer, so that USB devices will all power on again?

I thought I understood this well enough to give a meticulous description of what to write; but unfortunately, looking at it, it is more than I can handle. I will leave it here as a "half thought", "half program".

With bus enumeration taking place every time a USB device is plugged or unplugged, you'd think there'd be an easier query for most of this information? There probably is, I just don't know it. Maybe that info is in proprietary drivers, in Windows and Apple, and that info in Linux, is just to "complex" for a Noob?

Offline ladnar

  • Newbie
  • *
  • Posts: 47
Re: Software "switch"--or query--for USB power?
« Reply #3 on: October 05, 2020, 11:32:24 PM »
Here is pg 69 of Macdowell and Sayer:

"Powered Off State:

Some ports on a hub have support for power switching, and some do not. Power switching means that the hub can selectively apply or remove power from each port. This switching is done because there is only a certain amount of bus power available, and intelligent hubs and devices can limit the amount of power they consume in order to give more power to other devices."