I have an interesting problem that I'd like some input on. It's a bit complex, so I'll do my best to explain it clearly.
I have a connector with 4 pins arranged in a square pattern. The pins are designated as +, -, D1, and D2 (where D1/D2 is I2C). The challenge is that the solution must work regardless of the connector's orientation when it is plugged in (i.e., it must be position-agnostic).
I know this is a easy fix by just using a correct plug, but this is not what I'm asking. Question isn't really about the plug, but how to solve the problem for the plug I'm describing below.
Layout of pins can be changed to whatever could best solve the problem.
Here is a visualisation of the connection I have so far:
I have to make it so that no matter what way I attach a plug it will work. I can use a microcontroller and anything else I wan't.
I came up with a solution, but would like to see if I can get some better ideas or improvements.
If I add a bridge in this configuration I will get power no matter what direction the plug has connected:
Next I would cut the signal for A or B lines using P-MOSFET and note in my microcontroller memory what line I am cutting:
If my microcontroller is still working after a few milliseconds, it means it has correctly identified the power and data pairs. It then triggers switches to route the data lines appropriately. If it guessed wrong and cuts off the power pair, the system will reset, turning off the microcontroller and MOSFETs. On reset, the microcontroller will try again with the opposite pair, remembering the last state it tried.
Here is a quick sketch of the configuration I imagine:
On a side note here is my first iteration I came up with that had 4 pins in a line. Left side is signal source and right side is slave device:
While this works it has some issues, and is not ideal because of some other constraints that I don't wan't to go into. Ideally I wan't to solve this for the 4 corner configuration.
Another thought was adding clock and data to the power rail with some opamp magic and then decoding it on the other side. But it probably is a lot more complicated than I imagine, considering noise, power draw etc.