How to approach a USB KVM?

T

Hello all,

I hope this is the right sub for an issue like this. The situation is the following: I bought a KVM hub for my computer displays, which works fine for the keyboard and mouse input devices. However, it's an unreliable mess when it comes to the other USB 2.0 port that I used for my USB microphone.

I assume this is due to the way the switching is handled, and I heard about audio devices causing issues in this kind of setup. I also want to add a webcam that is incompatible with the KVM anyway, since it requires USB 3.0 or faster.

Since I'm somewhat interested, i electronics, but have no experience beyond frying a few LEDs with my Arduino. However, I did some research till this point and figured I may actually be able to pull this off given enough time and patience. One question that remains is: how would I implement the actual switching?

Conceptually, the idea is for it to look like this

​

Conceptual drawing on how the final wiring should look like

The idea is simple enough. A Wi-Fi connected microcontroller (wireless because the KVM is mounted under my desk) with a few photoresistors to detect the indicators on the front of the device, keeping track of the current state to account for external triggers. Via home assistant, the KVM can be switched using the keyboard shortcuts sent to the KVM via keyboard emulation. With some small delay, the state is synced to the USB KVM that is controlled by a small microcontroller (ATTiny?) via I2C.

Is there something dumb that I'm missing with my concept?

The specific implementation of the functionality of the USB KVM is where I'm struggling. My concerns start with the USB 3 protocol being fairly high bandwidth, which I presume requires some precise planning for the wiring? Is there a beginner-friendly source to read up on this? For the actual hub, I figured the TUSB8043 would be a good choice

Additionally, how would I reliably and safely switch between the two host PCS? Could I use transistors for that, or would they cause issues? What would be the best way to go about this.

For me, it's important that the hub actually disconnects the upstream USB device properly when not in use, since I assume this is the current source of most of my device swapping issues with the current hub.

​

I appreciate your input!

Posted Jul 24, 2023, 9:13 PM UTC

11
AutoModeratorMOD•

Not sure if this is the right subreddit for your post?
Not to worry, the mods have been contacted to check it over. The next time you are not sure, try the following before posting:

  • Read the sidebar and tag descriptions.
  • Check over the wiki pages for guidance - see the sidebar link.

After that, if you are still not sure, contact the mods using the link in the sidebar and we'll be happy to help!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1
AskElectronics-ModTeamMOD•

This submission has been allowed provisionally under an expanded focus of this sub (see column "G" in this table).

OP, also check if one of these other subs is more appropriate for your question. Downvote this comment to remove this entire submission.

1
PotatoPotato142•

Your method of detecting the lights from the kvm with LDRs seems reasonable enough to me but then taking that and passing it through home assistant and back seems convoluted. Why not just control the switching directly with a single micro? An attiny would be plenty to do the job, no wifi required. If you wanted wifi for some other purpose you could have an esp32 run the whole show, just make sure you code still works if it doesn't have an internet connection.

There are dedicated switch ics for usb. Simple transistors won't work. USB 3.0 is also not very beginninner friendly. I do a lot of designs with USB 3.0 and run into signal integrity problems all the time.

For a single chip mux look at HD3SS6126 or for a two chip solution you can use a pcie mux like PI3DBS16212ZBBEX and a USB 2.0 mux TMUXHS22. There are many other ics that will do this. The keywords you are looking for are USB and pcie mux.

I've also used the TUSB8041 before which is a two port version of the TUSB8031 and it's pretty easy to implement.

As for making the mux do a clean switch there are three ways I can see to make it work. The first is just a hard cutover using the select pin on the mux. The second is putting the hub in reset, changing the mux and then releasing reset. This will ensure a full reinitialization of the connected devices. The third method would be using the output enable pin on the mux. This could disable both upstreams for 100mS or so and then make the switch and reenable the mux. This would be akin to manually unplugging the cable and switching it over.

I would implement the ability to do all 3 in hardware and then leave it up to software later. You can try all 3 and see which works best.

Now, if all of this sounds too complicated, you could just buy an existing product that does this via a button press from Amazon and then rip it open and control the button with your own microcontroller.

1
mooo99OP•

Thank your for that detailed reply!

I don’t necessarily want to control the whole thing to home assistant, I just want to push the current state to MQTT so I can trigger some routines I use for work and specifically video calls automatically. It’s absolutely not a must have, but a nice to have.

Would definitely ensure it also works without network connectivity, but the software side of things is the part where I feel more confident than in the HW side.

Thank you for the details on the Mux! Triggering a full reinitialization would be exactly what I am looking for! It’s just a wild guess, but this seems to be exactly the issue with my current solution.

As for the difficulty, there seem to be a fair bit of resources out there when it comes to regular USB hubs. I‘ll do some more reading now that I know the general direction. If it turns out too difficult I can still resort to the DIY solution of ripping open an existing product and hoping it’ll work!

I’ll read some datasheets today after work!

1
mooo99OP•

Thank your for that detailed reply!

I don’t necessarily want to control the whole thing to home assistant, I just want to push the current state to MQTT so I can trigger some routines I use for work and specifically video calls automatically. It’s absolutely not a must have, but a nice to have.

Would definitely ensure it also works without network connectivity, but the software side of things is the part where I feel more confident than in the HW side.

Thank you for the details on the Mux! Triggering a full reinitialization would be exactly what I am looking for! It’s just a wild guess, but this seems to be exactly the issue with my current solution.

As for the difficulty, there seem to be a fair bit of resources out there when it comes to regular USB hubs. I‘ll do some more reading now that I know the general direction. If it turns out too difficult I can still resort to the DIY solution of ripping open an existing product and hoping it’ll work!

I’ll read some datasheets today after work!

1
HJ_wu•

There are advanced DDM-class KVM switches that already can meet all of the specs. and requirements listed with serial port control and hotkey commands control for the advanced KVM switches - so you don't need to divide video switching and USB switching into two different sets, but just all in one KVM switch.

1
mooo99OP•

Oh maybe I missed making that clear, I’ve had the video KVM switch for six months now, so what I’m describing is basically my retrofit approach.

Serial control sounds cool, but the switch that are anywhere near my price don’t seem to list that feature. Many of the standalone USB models even specifically list soundcard compatability (or rather the lack thereof) in their product section on Amazon.

1
HJ_wu•
1
HJ_wu•

There are dual audio I/O ports for each connected system. The shared audio devices via the audio connections from each system can be also using the hotkey commands or serial console to control or run custom-programing procedures for them.

1
mooo99OP•

That is a pretty close match to my current setup with the sole but important distinction that my KVM only has USB2 ports which are not sufficient for a modern Webcam and microphone combination, hence the wish for a DIY solution. (And the DDM solution implemented seems to mess with my keyboard unfortunately).

1
swdee•

If your experience is frying LED's with an Ardunio then the task far exceeds your ability, however even if this is something you could do it would be a waste of time as you can already buy quality KVM's.

1
mooo99OP•

Their products are not available on my country and with importing (shipping, duties, taxes) I would look at a pricetag of roughly 400€.

I also already own a video KVM that I would like to retrofit with said capabilities. While my practical soldering experience is very limited indeed, I’d like to think that I have a decent understanding of the basics of electronics. Besides that, I love to jump onto a learning opportunity, so I think I will stick to my plan and other commenters suggestions an learn something, even if the conclusion may be that there is no way I can pull that off :D

1