Let's say you need to connect a Mac Plus keyboard connector to an ARM-based ST Discovery Board (because that's a normal thing to do). The Mac Plus uses a RJ11 cable for the keyboard, which has GND, CLK, DATA, and +5V, and connects to an RJ11 socket on an adapter board attached to the Discovery Board. Unfortunately the Mac isn't specced to provide enough current for the Discovery Board, so it's got its own power supply (from USB). The situation looks like this:
You can hard-wire A to the Discovery Board's +5V, D to its GND, and B and C to ARM I/O pins, and everything will be great until someone use a regular RJ11 phone cable instead of an actual Mac keyboard cable. Because the phone cable has the pins in reverse order from the keyboard cable, you'll end up with +5V and GND swapped, as well as CLK and DATA swapped.
Is there any simple way to prevent damage if the wrong cable is used? Even better, is there any simple way to detect when the lines are reversed, and make it auto-magically work anyway?
Am I correct in thinking that the grounds of the two systems need to be connected? Or is that not even necessary?
To simply prevent damage, you don't really need to connect +5V (pin A), since the systems have independent power supplies. So my first thought was to put a diode in the ground line of the adapter board, so that if +5V volts is connected to pin D, the diode will prevent current from flowing. But I think this would interfere with normal operation with the correct cable, and make the Discovery Board's ground 0.6V higher than the Mac's. Another thought was to put a polyfuse in the ground line of the adapter board, that would trip if too much current flows. But I'm not sure how much is "too much" or how much would flow under normal circumstances.
To go beyond damage prevention, and have the circuit actually work, I was imagining something with two transistors acting as switches between the Discovery Board's ground and A and D. If A is high, then ground should be connected with D, but if D is high, then ground should be connected with A. However, I think this may rely on an overly-simplistic view of a transistor as a switch. In reality I believe there is still a small voltage drop between collector and emitter even when a transistor is on, so two system grounds connected in this way aren't really directly connected. Worse, I believe the current in this shared ground connection could only flow in one direction.
Anyone see a simple path out of this mess?