Author Topic: [Project Idea] USB-only KVM type switch box, UPS PSU, mechanical relays or what  (Read 1399 times)

0 Members and 1 Guest are viewing this topic.

Offline faekjarzTopic starter

  • Regular Contributor
  • *
  • Posts: 57
  • Country: de
  • I'm half cat, half platypus, and half pink! :3
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 GNDserver with GNDworkstation with GNDlaptop with GNDhackedIOTbotnetZombie ...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 CHactive) 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 (CHactive) 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 CHactive 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 LEDs

Phew, this project might require a lot of MCU pins …unless someone persuades me to invest effort into familiarising myself with shift registers
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
I would probably use analog switch ICs, but you can already buy USB switchboxes, we used to have some of them around at work.
 

Offline faekjarzTopic starter

  • Regular Contributor
  • *
  • Posts: 57
  • Country: de
  • I'm half cat, half platypus, and half pink! :3
I would probably use analog switch ICs, but you can already buy USB switchboxes, we used to have some of them around at work.

Ohai James! Could you please post some links? What USB switch boxes might your work place have used?
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
I don't remember what brand they were, we don't have them anymore but they were simple passive switch boxes, mechanical buttons. They were similar to these:
https://www.amazon.com/ECore-Cables-Manual-Button-Switch/dp/B01M3293Z8/ref=sr_1_19?s=electronics&ie=UTF8&qid=1512166176&sr=1-19&keywords=usb+switch+box
 
The following users thanked this post: faekjarz

Offline faekjarzTopic starter

  • Regular Contributor
  • *
  • Posts: 57
  • Country: de
  • I'm half cat, half platypus, and half pink! :3
I don't remember what brand they were, we don't have them anymore but they were simple passive switch boxes, mechanical buttons. They were similar to these:
https://www.amazon.com/ECore-Cables-Manual-Button-Switch/dp/B01M3293Z8/ref=sr_1_19?s=electronics&ie=UTF8&qid=1512166176&sr=1-19&keywords=usb+switch+box

WOW, I didn't expect that such a switcher could be that bare bones, with mechanical switches!
I guess that price kills my DIY approach too, haha.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
There are some disadvantages to a passive switch though, each time you switch is like unplugging the device and plugging it into something else so it will re-enumerate each time. When you use a KVM it typically provides an abstraction layer of sorts so the devices on either end have no idea that the switch has taken place although I think that only works with HIDs like keyboards and mice.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf