Author Topic: Hardware dev: USB -> KB+Mouse+Joystick adapter  (Read 457 times)

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Hardware dev: USB -> KB+Mouse+Joystick adapter
« on: May 25, 2018, 05:43:52 PM »
Hello friends!

I recently purchased an x68k, but I'm also cheap as heck so when I saw keyboards run $200+, I immediately looked for keyboard adapters. And they exist! But... most are ps/2, and they're all fairly expensive for a single use device. Considering you also need a mouse and joystick adapter, the costs of ownership for these old things really add up fast.

 ...So I designed this.....

It ain't pretty, but it works.

The pitch: It accepts a USB controller, keyboard, and mouse, at the same time, and connects them all to your 68k via two cables.

It supports:
  • Most standard USB hid keyboards
  • Most standard USB mice
  • Most USB composite devices (Such as a Logitech k400r keyboard+trackpad combo)
  • PS4 controller (wired)
  • PS3 controller (Wired)
  • Xbox one controller (wireless via dongle)
  • Xbox 360 controller (Wireless via dongle, or wired if you have one of those)

And I can probably add other stuff fairly easily. I'd also like to add support for bluetooth via USB dongles, but I need to find a reasonably easy to integrate BT stack for that. I should also be able to add Cyberstick emulation. Absolutely no ETA on that and consider it more of a wishlist item than a feature, but I can't see any obvious reason why it wouldn't be possible.

Right now:
It works. More or less. The joystick control seems to work fine in both two and 6 button modes without ghosting. Keyboard works as a proof of concept; I need to spend more time on the key mapping, but that's just code. The mouse also works, but jitters a lot. I believe this is also just software; I'm not sure I've encoded the data correctly on the wire. Again, software. At this point there's nothing to indicate there will be any roadblocks in the hardware design, so I'm about to start laying out a first rev PCB.

Cool but what will it cost?
That's where you come in! I have some options as to how I build this thing. One of the most expensive parts would be integrating a USB hub into the thing. I only need one USB host port. You could plug your own hub into it, and that greatly simplifies the circuit. I could also skimp out on some of the robustness and just assume users will know better than to plug in high current devices into it, or optimize the PCB for size above all else, eschewing the convenience of port locations. Another option is whether I should add a second joystick port. The software can probably support it, but it will add to the cost (larger PCB, which is the biggest cost, and an extra buck or so for the connector). I'd also like to use a small LCD for configuration and debugging, but a cheap $5 i2c oled should work fine. I suspect the fully featured robust unit should land under $150 and a cost stripped version may be as cheap as $70. This is all napkin math though, I won't know for sure until I have a finished design so I can figure out what the BOM is. That said, if someone is selling them, they're free to charge whatever for their own labor, so bear that in mind if you don't plan on building your own.

So, what do you want to see from this? Is a built-in USB hub essential for you, or are you OK using your own hub even if it makes cables messier? Do you prefer a cheaper, raw product, or something closer to a robust and durable consumer product? Do you want it to be easily configurable or are you OK re-flashing the firmware to make changes? How important is a second joystick port? I'm mostly making this for myself, but I don't really have any hard constraints; your feedback will help me design something people actually want.

Great! When can I buy one?
I have no interest in selling these directly. I plan to release both the hardware and software as open source, and hope some enterprising individual will build and sell them for people who lack the tools to do it themselves. Alternatively, anyone with a soldering iron can build their own. I'll include kicad files for the PCB, and STL files for the enclosure if I get around to making one. The board design will also be uploaded to oshpark so you can easily order one(three). I'll try to avoid leadless packages if possible to ensure it can be hand soldered, but I love surface mount stuff so you'll want a decent iron with some fine tips (it's also unavoidable if we do anything with USB, nobody makes through-hole usb hubs)

Offline leonk

  • BigMember
  • ***
  • Posts: 87
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #1 on: May 26, 2018, 04:18:09 AM »
WOW!  That looks awesome!  Can't wait to try it out and iron out the bugs!

I think a 1 joystick solution would be sufficient for the start.  Firmware upgrades is always great (allow people to write their own code if they see fit).


« Last Edit: May 26, 2018, 04:20:13 AM by leonk »

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #2 on: May 27, 2018, 10:47:26 AM »
Ok, I spent a few hours hacking together a schematic. This took longer than anticipated since I've never used Circuitmaker before, so years of Eagle muscle memory needed to die.

Updated BOM estimate below. Note these are all single run estimates, so they'll vary a lot based on vendor, and could come down a bit with scale. This is for the 4 port USB variant.  Cutting the USB hub would shave ~$10 off the BOM.

ComponentQuantityPrice
Teensy 3.61$30
TXS0104E1$1.35
TXB0108PWR1$1.55
MD-80S1$1.91
TE Connectivity 5747250-41$3.13
ZX62-B-5PA1$.84
XR22404CG28TR-F1$2.38
TE Connectivity 5787745-22$4.96
Abracon ABM3B-12.000MHZ-B2-T1$0.63
Various passives*~$5
PCB1~$9

Current estimated BOM: $61 + tax/shipping
Note this is NOT the final cost of the product, only a ballpark estimate of how much the individual parts will cost. I'll post an updated BOM when I finish routing the design and order parts. There's a good chance I'll realize I forgot something or add some new features. I kind of want to add a cheap little SSD1306 based oled panel for debugging; I'm using one in my prototype but it's not strictly necessary (adds ~$3 to the BOM depending on where you get from)

Populated board (unrouted)

You can see why adding a second joystick would be so expensive. They take up a lot of space! I can likely shave a few cm off both dimensions once I routed it, but I wanted to be conservative in my initial sizing. I also originally had one of those huge clunky USB B connectors on the back for power, but does literally anyone still use those things? I figured micro would be less hassle, but can change it back if needed. If nothing else they're capable of more current AFAIK.

One thing I'm thinking about is how I'm going to power it. Right now I've got a micro USB connector for external power, but it'd be kind of nice if it could self-power for simple low power applications. I think it'd only add a few bucks to the BOM to add power detection/switching, if I could be mega lazy and just slam a diode over the x68k's 5v rail and hope nothing complains.

Also before someone mentions it: yes, I know that's the wrong keyboard connector. Couldn't find the 7 pin variant in circuitmaker so I just pin swapped the 8. The footprint is identical other than the extra pin, and i'm lazy.

« Last Edit: May 27, 2018, 10:49:00 AM by Spitko »

Offline LowDefAl

  • SmallMember
  • **
  • Posts: 11
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #3 on: May 27, 2018, 10:48:27 PM »
I also originally had one of those huge clunky USB B connectors on the back for power, but does literally anyone still use those things? I figured micro would be less hassle, but can change it back if needed. If nothing else they're capable of more current AFAIK.
In terms of robustness, it's no contest, B all the way. Theres a reason why the music industry still uses B pretty much across the board unless dictated by footprint, although data is more of a concern there.

For a project like this with cables all over the place and the possibility of them getting pulled on, B makes the most sense to me. I think the cables are more reliable as well. The cables are also so cheap these days that I don't think they should determine the connector used.

Micro is more about footprint than anything else. That doesn't seem to be a concern here. Although a thought occurs, do the footprints allow you to put traces for both types? That way the builder can make the choice themselves.
« Last Edit: May 27, 2018, 10:56:42 PM by LowDefAl »

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #4 on: May 29, 2018, 04:12:11 AM »
I didn't think they would, but it turns out there's a style of B connector that puts the pins at the back (as opposed to the style I typically see with the pins more toward the middle). If I use that package, they both fit just fine. Circuitmaker is going to whine about it, but that can be ignored.


Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #5 on: May 31, 2018, 06:51:32 PM »
Board is routed. I need to do some final checks before I send it off to the fab, but should be this week.




Notable changes:
  • Supports both full size or micro USB connectors. I may remove the micro connector as I'm worried it may allow the shield of the full size connector to short 5v to ground. If there's significant demand I can always just spin a second board.
  • Improved the input side. Now features a PTC fuse, and some basic EMI defense to reduce the chance of cheap USB power supplies causing issues.
  • Added a 4 pin header for i2c (To be used for an optional LCD)

Left to do:
  • Add some status LEDs? They're cheap and could be useful for early stage debugging. If nothing else, add the pads and let the user decide.
  • Test points for 5v and 3v3 rails.
  • Move the i2c header down so it doesn't block the SD card slot. I'm not using it for anything now, but there's so much empty space below the header there's no reason not to move it.
  • Replace the ferrite bead with an 0805 package (Somehow an 0603 slipped in!). Also needs to be properly rated, the current part is only good for 1.2A
  • Find something to do with all that spare board space. Might add another header with pins for a second joystick so one could be added with a cheap daughter board, but probably not for the prototype since I'm too lazy to route all those pins.
  • Maybe tug that d-sub connector forward a bit. Right now the end of the housing is aligned with other connectors, but it seems like you really want the housings aligned.... maybe I'm overthinking this.

I decided to drop the dual/self power idea. TI makes a few power muxes that sort of do what I need, but I don't really know what the effect on the 68k would be if you put a significant load on it through the joystick/keyboard ports. Seems safer/cheaper to just stick with USB power than risk blowing up someone's computer because their USB supply croaked. Worth noting this board is specced for 2A (500mA per USB port). This is an incredibly unlikely load to see, but the USB spec shall not be trifled with. Also some wireless controllers decide to charge from USB ports so I'd rather over build than start fires.
« Last Edit: June 01, 2018, 04:23:09 AM by Spitko »

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #6 on: June 03, 2018, 11:10:30 AM »
PCB sent out to the fab.

I really missed the mark on the PCB cost. I somehow completely misremembered how OSH Park calculated their pricing, and it's actually $44! OSH tends to be optimized more for smaller boards anyway, so I'm running them through AllPCB. This'll be my first time using them, so we'll see how it goes; but $20 for 5 is acceptable. The tolerances on this board are pretty loose so it shouldn't matter even if things are a bit less accurate.

The only other changes were moving the connector, adding a couple of optional diagnostic LEDs, and nudging a few dimensions around to make it easier to plot the case in Fusion later. Updates will likely be slow for a bit until the boards+components arrive.

Edit: As a note, single run cost looks to be about ~$100 after tax and shipping for the parts. A bit higher than I was aiming for, but I'd still say it's a good deal compared to what's available on the market otherwise.

Assuming it, you know, works. ;D
« Last Edit: June 03, 2018, 11:57:20 AM by Spitko »

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #7 on: June 11, 2018, 05:54:24 AM »
Boards arrived.

Aaaand, I struck out pretty hard here.

1) USB circuit seems to be a write off. I followed the datasheet pretty closely, but the chip doesn't seem to want to boot. I can "kickstart" it by shunting the VBUS_SENSE resistor, which brings it online just long enough for the teensy to detect it, but it crashes as soon as it tries any kind of communication. With a few additional modifications I was able to get it to stay online a bit longer but then the teensy itself crashed, so I'm thinking it doesn't like negotiating USB full speed on its upstream port. I'll try again with the TI part I was going to use originally.

2) Joystick port doesn't work at all. I added a level shifter here for paranoia, since it's possible to set some of those pins as outputs, but there seems to be some kind of bug there.

3) Keyboard port almost works, I'm not yet convinced this isn't just a software bug, or an issue with my 68k; as I'm getting caps lock LED feedback, just no key presses.

I'll keep picking at it and start spinning up a v2.
« Last Edit: June 11, 2018, 06:03:04 AM by Spitko »

Offline DMR

  • Newbie
  • *
  • Posts: 1
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #8 on: June 14, 2018, 12:31:08 AM »
I ended up spending the $$$ for the extra converters, but, the more hardware projects for the x68000, the better.

Do you have a PayPal donate button or Patreon to cover your R&D costs? I'd love to see you formalize this,
maybe do a run of 10 a month that you auction off to keep interest going.
If the prices get outrageous, it creates incentive for others to manufacture the open source schematics (if you decide to go the open source route).





Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #9 on: June 15, 2018, 04:42:52 AM »
I'm honestly way too lazy to manufacture these things. I'm happy to support someone else who wants to, but they're not coming from me. I'm doing this for fun/as a hobby, so I'm not really interested in the work involved in selling these things at any kind of scale.

After debugging the circuit, I realized the bidirectional shift registers are picky about pullup size, and the x68k has relatively low value pulls that confuse the heck out of them. I got the joystick "working" but it's very unstable as the registers see noise on the line as signals and switch directions. Serial is a similar story; the shifters don't know who's driving who and freak out long before any kind of data can make it across the bus.

Progress report:
- Dropped the bidirectional level shifters. Using unidirectional stuff instead as there are only two pins (PC6/7) which can be used mixed mode. This DOES mean any joystick that uses PC6/7 in these modes no longer works, but I can't find an example of this. I originally thought the cyber stick might, but it only requires PC4 (the same mux pin 6 button controllers use).

Todo:
- Change USB part to TUSB2046B

Offline neko68k

  • MassiveMember
  • ****
  • Posts: 355
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #10 on: June 15, 2018, 09:51:02 AM »
Sega MegaTap uses PC7 but basically nothing supports it anyway.

Offline SuperDeadite

  • MassiveMember
  • ****
  • Posts: 398
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #11 on: June 16, 2018, 08:34:28 PM »
Sega MegaTap uses PC7 but basically nothing supports it anyway.

Actually, Eternal World does support the MegaTap.
Neat little tech demo for conventions.
https://youtu.be/QZmDa4kH7tM

Offline neko68k

  • MassiveMember
  • ****
  • Posts: 355
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #12 on: June 18, 2018, 01:19:08 AM »
FWIW there are a half dozen or so games with patches to support MegaTap. Surprisingly Bomberman isn't one of them O.o I can't remember which Dennou they're on. 60 something, 62 or 63 maybe. There's source too IIRC.

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #13 on: June 18, 2018, 04:52:45 AM »
Rev 2 is routed.



I dropped the USB hub for now, it's going be a thorn in my side for a while I suspect, so I'll hork up a little test board on the side and play with that, once I figure out all the quirks to the chipset I'll re-integrate it as a feature for rev 3. For now you'll just have to use an off the shelf USB hub.

There's a bit of wasted space here I could optimize out for cost, but since it's a stepping stone, I'm not too worried about it. Need to add some mounting holes and tweak a few questionably spaced traces, then off to the fab again

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #14 on: June 24, 2018, 10:44:06 AM »
rev 2 arrived and soldered.

Bugs so far:
  • TX and RX are swapped on the keyboard connector. I should have pulled the pinout from Outside x68000 and not some random google image search result... Need to cut/bodge this, but a temporary patch shows the keyboard appears to work as expected through the level shifters.
  • Joystick port sees full ghosting across high/low bits, dpad doesn't seem to work. I suspect PC4 is either wired wrong, or bridge somewhere.
  • I somehow forgot to add the USB host connector to my digikey order? Guess I'll keep using the dorky 5 pin breakout cable :'(

It doesn't look like there's anything here I can't bodge into submission, so I should be able to focus on software and the USB hub microcircuit soon.

I also noticed the USB hub I ordered off amazon hangs the processor as soon as I connect something to it... it might be due to the hub being bus powered and the inrush current pulling vin too low... or just a software bug.

Offline Spitko

  • SmallMember
  • **
  • Posts: 26
Re: Hardware dev: USB -> KB+Mouse+Joystick adapter
« Reply #15 on: June 24, 2018, 03:55:34 PM »
Hardware development in a nutshell



Only took four mod wires ::)

Edit: If any particularly adventurous persons want to build one of these to test and maybe help debug the software, let me know. I can whip up a quick v2.1 with the corrected pinouts and upload gerbers. It'll be up to you to source the parts though. allpcb will cut you a set of boards for about $20 shipped to the states.
« Last Edit: June 24, 2018, 04:27:51 PM by Spitko »