Hi!
I'm thinking about a KVM type USB switch box, but without the V (as in Video) ...USB-only. Basically not even limited to Keyboards and Mice (HID input), how about USB-Storage, UAS or UVC, but a KVM type switching scenario is what i have in mind. Implementing such a little box should be fairly straight forward, even for a novice like me, with limited Arduino / AVR experience. It's just wiring and switches, right?
Here's my Plan A:Mimic the physical connection sequence of a USB plug, which has staggered PWR and DATA pins (the longer outer PWR pins connect first, when plugged in). I'd basically have to recreate the unplug-and-plug-into-other-port sequence, without actually touching any plugs or cables - the whole point is to only press channel select buttons (yes plural, in
my project i want one select button per channel). And i want at least 3 channels.
Sequence draft A:
fn onCHselectEvent()
if CHselected equals CHactive
noop("do nothing"); // no need to change state, because you selected the same channel, duh
else
open_data(CHactive); // pull the plug, data pins are short, sever 1st
sleep(0.25s); // mimic staggered USB plug pins
open_power(CHactive); // still pulling plug, long power pins sever last
sleep(0.25s) // just for good measure
close_power(CHselected); // connect long pins first
sleep(0.25s) // mimic staggered USB plug pins
close_data(CHselected); // connect short pins last
Questions:My quarter of a second sleep() may be a bit too generous, but i guess .05 would be too fast. (I'm sure there's an actual value in the USB spec, but tl;dr) …Comments?
Should i switch GND too? I mean, i could save one relay (switching component) per channel, but putting all the GNDs onto the same conductor would basically connect GND
server with GND
workstation with GND
laptop with GND
hackedIOTbotnetZombie ...and so on …all via somewhat thin wires. I'd better isolate those too, right?
Relays are nice and fairly easy to use; juice on one end causes closed circuit on the other end, done …those are fairly cheap too, <5€$ delivered, for ~12 (3 channels) 5V clackers from AliExpress.
UPS type Control Circuit Power Supply Lego Bricks:Since there are only USB
devices (leaf nodes, in bus topology nomenclature) connected to the
input channel (as in KVM nomenclature), i need to source the power supply to
the switching control circuitry, as well as the devices, from any of the output channels. My idea is similar to a seamless UPS (Uninterruptible Power Supply) type fail-over circuit. I'd rather fancy a somewhat "active" approach, with a sufficiently dimensioned capacitor to overcome short power outages, while failing over, in case the active (from the UPS point of view, not necessarily the CH
active) channel host shuts down or reboots / resets. Up to 5 seconds backup power would be nice, in order to keep the current MCU runtime state (not rebooting, due to power loss / hard reset). And yes, there should be a BACKUP_POWER_ONLY emergency kind of flag somewhere, in order to immediately open / sever power rails to all input side devices (which could be a very "thirsty" 2.5 inch bus-powered HDD) …just keep the control logic running for a few seconds
I'm sure there are 5V "Lego Brick" type (ready-made) circuits, are there? Comments?
Weird machines:I remember that one talk at one of the CCCs (Chaos Communication Congress), a few years ago, about weird machines, overly complicated, hardly debugable, machines; the gist was "Don't create weird machines!" …so, i think i should compartmentalise and constrain my UPS PSU idea. I really want to keep the MCU and its state running, as long as possible, while there's power supplied via any of the "outputs". But i don't want to supply power to any of the "input" devices, via a non-active channel. In short, when the selected channel (CH
active) is powered off, the input device(s) should be in the same state too. And if there's power supplied from another channel, the MCU keeps running, until the last power supplying host is powered off.
the Train Of Thought steams on, and on:…if there's no power on any of the output channels, than there'd be absolutely no need to …urgh, nevermind, that's rather obvious ;-)
…but what if the CH
active setting is being stored in some kind of non-volatile memory, and...restored...on boot...? …do AVRs / ATtiny / ATmega have integrated nv-mem? Alternatives?
…mechanical relays and a big cap are the obvious choice for a novice like me …comments?
Oh, by the way, i want CHactive indicator LEDsPhew, this project might require a lot of MCU pins …unless someone persuades me to invest effort into familiarising myself with shift registers