Remix.run Logo
parhamn 8 days ago

I've wondered how this works (and who wins).

scottapotamas 8 days ago | parent | next [-]

For two DRP (dual role) devices connected to each other, I believe in a default case the one that happens to advertise as a source first just becomes one.

The standard allows for a role swap at any point while connected, and if that’s triggered will be dependent on the firmware/config on one or both ends.

There’s probably more nuance hiding in the real world hardware too.

stephen_g 8 days ago | parent | next [-]

They can also prefer one role, with a mechanism called Try.SNK and Try.SRC (‘try sink’ / ‘try source’).

Basically DRPs toggle back and forth between sink and source until they happen to match up (one side has switched to source and one to sink). If it doesn’t prefer to do the role it’s resolved to randomly, it can switch to the other way and wait a bit - if the other side is fine with it then it will switch too and everyone is happy, if not you can switch back.

We use this for a device that can on-charge a device when it has external power plugged in (in which case we prefer source role) but not when running on battery (in which case we prefer sink but don’t actually pull any power because it’s self powered).

unsnap_biceps 8 days ago | parent | prev [-]

According to https://superuser.com/a/1773195

> Any DRP port must have pull-down 5k1 resistors on CC wires (as a sink), AND 10-22-56k pull-ups (as provider), but not at the same time. The DRP then alternates the sink advertising (5k1 pull-downs) with pull-ups (source advertising) about 10 to 20 times per second.

> If another DRP is connected, they both will toggle their advertising until a correct (pull-up - pull-down) combination occurs. Then CC controller(s) will stop toggling, and the end that happens to be in provider mode will provide +5VSAFE VBUS. The process will end in one or other direction, which will happen at random (since frequencies of toggling are independent).

franky47 8 days ago | parent [-]

A protocol designed on who wins an race condition? That's wild.

crote 8 days ago | parent | next [-]

It works surprisingly well in practice. The key thing to remember is that you rarely connect identical devices together.

A laptop and a power bank both support both modes, but the laptop will have a "prefer sink" policy and the power bank will have a "prefer source" policy. As long as you don't connect two laptops or two power banks, it'll work out just fine.

Moreover, it has an override mechanism in case you do connect two identical devices. If you do connect two laptops together for data transferring, the OS should be able to let the user override the power flow direction - or even disable charging altogether.

darkwater 8 days ago | parent | prev | next [-]

What are the alternatives, for a mass market standard like USB used literally by everything out there nowadays? Unplug it and plug it again until it works it's easier for everyone that going to some obscure menu (although maybe smartphones/laptop/console could just display a modal "do you want to charge or be charged?")

somat 8 days ago | parent | next [-]

Usb historically solved this with ended connectors It was why you had "A" and "B" sides. usb C has an awful lot of user hostile fallout considering it's stated goal of "a cable that just works for everything"

I think to solve it, while keeping all the other goals of usb C would be to orient the charging pins on the plug, not charging the direction you want? unplug then flip one side.

klausa 8 days ago | parent [-]

Having a plug that works differently based on the orientation it’s plugged in, feels like it would not quite be „keeping all the other goals of USB-C”.

bzzzt 8 days ago | parent | prev [-]

It could default to charging the device with the lowest battery level. Can't find it but I believe having read years ago Apple does something like that.

toast0 8 days ago | parent | prev [-]

Ethernet has been doing this kind of thing for four decades. With only two nodes and short cables, you'll rapidly converge.

8 days ago | parent | prev [-]
[deleted]