converting USB HID devices (keyboard and mouse) to PS/2 - Page 1
Forum section: electronics / general

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 02:32:23 pm
content: In the retrocomputing field, a lot of computers are PS/2, some are ADB, and some are even weirder (e.g. DEC terminal have their own standard), and we are receiving a lot of requests about converting USB keyboards to PS/2, including those from lucky guys who are owners ofultimatehackingkeyboard, which is a USB device.USB(kb&mouse)-to-PS/2(host) adapters seem to be rare; we have already found just a couple of commercial products, but they are really expensive (150-180 euro).I am tempted to get a cheap Linux SBC (router), and using the USB-host to get HID stack handled and decoded so I can attach an MPU to the serial port of the router to provide the PS/2 out streaming.This costs 10 euro for the Chinese cheap router (DLINK and alike), and 10 euro for the MPU.But it's not a neat solution, so ... I wonder what do you think about/alternatives

author: hans
author_rank: Super Contributor
timestamp: February 01, 2019, 02:44:16 pm
content: There are many modern microcontrollers that support USB host through hardware.You'd need to check if they have a HID host driver, which you could use to poll for values from the USB keyboard/mice and send them out via an emulated PS2 port.I think many Microchip PIC controllers have USB OTG, which supports host/device & switching, but basically anything else with USB host support should work.Then of course is the question, if you really want to get that involved with controlling USB devices on such a low level to save 10$ of the hardware BOM.

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 03:57:45 pm
content: with ateensyMPU?

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 01, 2019, 03:58:38 pm
content: You can use an Arduino Pro Mini (I prefer Teensy or a Micro) with a Mini USB Host shield (based on MAX3421E; DuinoFun UHS clones are < $5 at fleabay). TheUSB Host Shield 2.0library works with those (including Teensies). Arduino Playgroundmentionsps2dev, which implements the device side of the PS/2 protocol.I haven't done this myself, but looking at the code, there shouldn't be much Arduino tinkering to get this working. Plus, you have a dozen or so I/O pins left, and plenty of processing power, to implement additional buttons or features. Maybe an optional I2C OLED display? I love those things.As a nice cherry on top, using the same libraries, but adding a BLE module, you can also implement a bluetooth device to PS/2 host keyboard/mouse bridge as well.

author: BloodyCactus
author_rank: Frequent Contributor
timestamp: February 01, 2019, 04:28:28 pm
content: I know Microchip have a USB HID stack in the MLA. But its more about if you need to attach more than 1 usb device or need to act as a hub or just a simple 1 port client.

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 04:48:57 pm
content: yup, Elisabeth is looking at the Maxim chip used in the USB-shield and she thinks it's a good idea. We have guys looking for an adapter for their usb-keyboards, and we are considering the purchase ofhappyhackingkeyboard for ourSonoko project, which is composed by two PowerPC405GP nodes using a PS/2 through a KVM interface.For sure we won't change the KVM, but we can add (and integrate) a USB-to-PS/2 adapter.Anyway, we are also evaluating other keyboards, some are natively PS/2, which is better for us, but other guys want USB keyboards and mouses so in a way or in another we have to satisfy the need for an adapter.

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 01, 2019, 05:40:20 pm
content: (Completely off topic, but if you think the gentoo irc ban is funky, just look at theDebian CTTE discussion on bug #919951, especially posts by Stéphane Glondu and Anil Madhavapeddy. They appropriated a binary without discussion, causing a package conflict, falsely claimed and keep claiming others have agreed to the change; and now complain that someone is suggesting they change the name/path again to fix the clash. "The tone of your message sounds like harassment to me." Apparently, redoing their earlier change is apparently too much work, because they'd have to run a singlefind . -type f -exec sed -e 's|/usr/bin/dune|/usr/bin/we-are-idiots|g' -i '{}' ';'stanza on their source archive to fix their changes.)Give me technical challenges every day, and I'll be happy as a clam. But these PC manipulations make Nominal Animal a very very unhappy boy.

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 06:09:54 pm
content: Quote from: Nominal Animal on February 01, 2019, 05:40:20 pmYup. Funny, summarizedhere.

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 06:21:23 pm
content: Quote from: Nominal Animal on February 01, 2019, 03:58:38 pmThe Keyboard Cherry's G81-8308 looks interesting since it implements "programmable keys".This can be replicated in some wayShown inthisvideo

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 01, 2019, 06:33:42 pm
content: Quote from: legacy on February 01, 2019, 02:32:23 pmOuch. Even though it may still be "cheap" for your intended target, I don't like this solution much. Not just because it's overkill (you may not care, and that could save a significant development time if I got you right). The main reason would be that as a Linux-based device, it will take a significant amount of time booting up every time it's powered on. That may be quite annoying for the end-user depending on how it's being used. Even if it's just a few seconds (and it could be much more than that, cheap routers sometime take almost 30s...), that's annoying IMO.

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 07:25:21 pm
content: Quote from: SiliconWizard on February 01, 2019, 06:33:42 pmyup, this is bad. Our Atheros9 chips take 12 sec for booting, plus 4 sec for loading the kernel into the ram.Anyway, sonoko takes longer for booting.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 01, 2019, 07:45:44 pm
content: Additionally, if using Linux, you should also consider using a read-only distribution if you can. Normal distributions tend to write to disk quite often, and that would only wear off the flash memory, and introduce the possibility of data corruption in case of a power supply problem... this fact in itself (finding the right distribution or tweaking it yourself to make it read-only) may take a significant dev. time...The most cost effective way of implementing this (and most 'simple' from a system pov) would be to use a small MCU with embedded USB host (like USB OTG), then decoding the keyboard input from there, translating it for PS/2 and then send it to PS/2, which is just a serial transmission (looks a bit like I2C IIRC.)If going for an STM32 MCU, you could start here:https://www.st.com/en/embedded-software/stsw-stm32046.html

author: Buriedcode
author_rank: Super Contributor
timestamp: February 01, 2019, 07:55:29 pm
content: Some keyboards still natively support PS/2 - the adapters are purely mechanical, but it is becoming less common. I'll second a PIC. Plenty of the PIC24 and PIC32 series have OTG/host capability and 5V operation for <$4. Seems like overkill to go for an SBC, and a USB host shield, whilst possibly cheap would be rather large.Also, Wikipedia mentions the PS/2 spec can supply max 275mA, vs USB's 2.0 500mA. Fancy keyboards with lots of LED's could draw more than this meaning you'll need an external supply. Although its probably not much I suspect the total current draw for an Arduino + USB host shield to be non-insignificant, where-as a single PIC MCU would be <10mA. Not to mention a low part count and size.

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 08:02:23 pm
content: yup, for sure we will go with the MPU approach. It's neat. Already ordered a couple of USB-shields

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 08:08:07 pm
content: Quote from: Buriedcode on February 01, 2019, 07:55:29 pmlike these?

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 01, 2019, 08:23:20 pm
content: Quote from: legacy on February 01, 2019, 07:25:21 pmI think I have a PCI G400 and a Rainbow Runner digitizer daughterboard lying around here somewhere..The G400 could be an AGP-bus'd G450, if I recall wrong, though. Have an use for those? I don't.

author: legacy
author_rank: Super Contributor
timestamp: February 01, 2019, 09:42:48 pm
content: it's funny because we have here a Microspeed trackball and it's serial RS232 with a built-in adapter that *magically* makes it a PS/2 deviceit's a real true good trackball, anyway!

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 01, 2019, 10:45:15 pm
content: Quote from: SiliconWizard on February 01, 2019, 06:33:42 pmOn some dedicated devices with a truly simple userspace (dumb init, eudev, and a custom binary service or application) you can wrap it all as an initrd, and run the thing without any userspace bootup. Most won't bother, because it is a lot of work and using a proper Linux machine with all the standard services is easier. But it can be done; I've done it for cluster node benchmarking. There, it did not really shorten the bootup time at all, because their BIOSes often take a minute or so before even reading any boot sector stuff. The real point there was to omit anything unnecessary and unrelated to the benchmarking, really.I backed the La Frite Kickstarter because its developerssaythey will try hard to get all support into the vanilla kernels. That is rare. When I get my mittens on it, I will probably look at minimal initrd-only booting on it (because it is pretty easy when the kernel has all the necessary support built-in). There are many embedded type tasks (like 3D printer control, dumb terminals, displays, media playback devices) that really do not need a full userspace, and cutting the bootup time to a minimum will mean a much better UX. I have no idea yet how fast I can make it, though.For retrocomputing, I could imagine using one as a peripheral, faking various interfaces via custom microcontrollers and such. For example, if I had an older one with composite or S-Video outputs (say, an original Playstation -- wait, I do have one), I could use one of those USB digitizer dongles to digitize that, and use the HDMI output to display it to a modern display, with an easy way to add my own custom graphical overlays (for whatever else I might need, like system configuration and such).Quote from: legacy on February 01, 2019, 09:42:48 pmThePS/2 port protocolis pretty simple, really; reminds me of I2C or SPI. It is no surprise that you only need a small bus driver chip, probably a 8-bit shift register based one, to implement a RS232-PS/2 bridge. But, bit-banging PS/2 on an MCU is not at all hard to do.If you want to do a proper professional board, look into FTDIVinculumchips. The VDIP2 development kit on Mouser looks to be around $30; it has two USB host ports you could use for HID devices. I haven't ever even seen FTDI's development tools, so I don't know whether this is a good approach; I'm only saying that if a professional packaged product is what is in your mind, it might be worth it to look into the FTDI offerings, starting with the VDIP2 development kit to see the Vinculum chip capabilities.

author: legacy
author_rank: Super Contributor
timestamp: February 02, 2019, 04:40:44 pm
content: it's also funny but in Japan, someone is making keyboards that are designed for being used with emacs. These keyboards are usually USB-device with a customkeybinding, optimized for bash, vi, or emacsvery expensive keyboards and some of them miss the arrow keys as well as the F{1..12} keys as well as other useful keys.In short, it seems they assume that one has to have several keyboards and input devices depending on the computing task.

author: legacy
author_rank: Super Contributor
timestamp: February 02, 2019, 04:51:11 pm
content: Foundthiswebsite with information about converting different protocols for old keyboards.

author: rstofer
author_rank: Super Contributor
timestamp: February 02, 2019, 11:20:05 pm
content: I'm not sure I followed the intent of the first posting...There have been adapters that take USB peripherals and connect them to PS2 ports - been around a very long time:https://www.amazon.com/USB-Female-Male-Adapter-Mouse/dp/B00HDGULP8Whether they work for any particular USB keyboard, I wonder. Nevertheless, I have used them with KVM switches that only accepted PS2 and I wanted to use a USB mouse/keyboard. Worked well.Other than that, I would use RawHID for the Teensy if I actually wanted a USB peripheral. I could take PS2 into the micro, do some kind of magic and output either USB HID or PS2. It might work out that I could take a USB peripheral, run it through the adapter to get PS2 and then mangle the PS2 output before sending it along as either PS2 or USB.A long time ago I connected knobs, switches and dials to Microsoft Flight Simulator using RawHID on one of the early Teensy devices. It used an Atmel ATmega something or other (I think, it's been a LONG time).

author: NiHaoMike
author_rank: Super Contributor
timestamp: February 03, 2019, 12:02:20 am
content: It shouldn't be too difficult to find a microcontroller that has USB host and a USART or two that can be used to output PS/2.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: February 03, 2019, 08:29:08 am
content: Quote from: Nominal Animal on February 01, 2019, 10:45:15 pmYes, the FTDI VNC2 series looks useful :https://www.ftdichip.com/Products/ICs/VNC2.htmAnother would be the Chinese CH554/ CH559I can find source code here, that mentions both USB Host and PS/2, so those might splice together ?https://github.com/zhuhuijia0001/ch559-usb-hostand eval boards herehttps://www.electrodragon.com/product-category/arduino-2/avr_pic_51/http://www.wch.cn/products/category/5.htmlThe CH549/CH548/CH547/CH546 look to be newer, with maybe better ADC, more peripherals, and could be between the 554 & 558/559 in price?

author: ebastler
author_rank: Super Contributor
timestamp: February 03, 2019, 08:44:32 am
content: Quote from: rstofer on February 02, 2019, 11:20:05 pm^^^ This. It seems that modern USB keyboards still support PS/2, with a simple passive adapter as shown in rstofer's link. At least the brand-name ones; just spot-checked a Cherry datasheet.

author: OwO
author_rank: Super Contributor
timestamp: February 03, 2019, 11:43:23 am
content: I'm glad I'm not the only weeb here

author: Doctorandus_P
author_rank: Super Contributor
timestamp: February 03, 2019, 11:57:36 am
content: Keyboards have a microcontroller in them and it's likely to be flash based.Ideally you can re program that microcontroller, cut of the USB cord and attach a PS/2 port to the keyboard.You can also replace the microcontroller with another and only use the case, keys, and PCB for the keys matrix.For a single board you can glue in an adapterboard and connect it with enamelled wire (burn through the isolation with a hot iron).For many keyboards you can design an adapter board and castellations on the side to solder it another keyboard if the original uC can not be reprogrammed.

author: legacy
author_rank: Super Contributor
timestamp: February 03, 2019, 12:32:02 pm
content: Quote from: Doctorandus_P on February 03, 2019, 11:57:36 amyup, excellent idea.some keyboards that I have inspected are ROM-masked based, some are based on Intel 8049, some are not clear what they are based on (cannot read anything on the chip), and some don't come with any flash.I have also found some keyboards based on AVR8 (so Yuuupeeee we have a flash here, and a simple reprogramming interface) but we are looking at "mini keyboards" and this kind doesn't usually have the internal space for a hack.

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 03, 2019, 10:49:07 pm
content: Quote from: rstofer on February 02, 2019, 11:20:05 pmThe Logitech ones I have even came with those, and I imagine it would be easier and cheaper to keep the support than remove it (because the USB HID protocol has not changed, nor PS/2, and both have a mechanism for supporting new keycodes and macros like those in "media keyboards").Quote from: rstofer on February 02, 2019, 11:20:05 pmATmega32u4 on the Teensy 2, AT90USB1286 on the Teensy 2++. Yes, Paul Stoffregen even provided a pre-Arduino library,RawHID(orUSB keyboardfor keyboards specifically), so all you need to implement it is those files, avr-gcc, and a Teensy (of the older variants; 2.0 or 2.0++). Stoffregen wrote the bootloader (HalfKay) in assembly, and it is smaller than the ones used in Arduinos (Pro Micro/Leonardo), so you can fit a bit more stuff on those compared to the Arduinos using the same chips. Teensy keyboard implementations abound if you look for them. I seem to recall that there is at least one commercial keyboard one, that has a Teensy inside (licensed from PJRC.com).The main reason the microcontroller approach appeals to me, is the adaptability (wired or BLE) and ease of mapping the keystrokes to whatever one wants. In fact, I'd wager that I would probably want to switch between some different layouts at run time. For playing games (via emulators thus far) I definitely want to change the mappings; that's why I designedthis Pro Micro gamepadfor use with Arduino Pro Micro (has the same ATmega32U4 core as Teensy 2.0, but an Arduino Leonardo bootloader (slightly bigger), but is dirt cheap and ubiquitous on fleabay). It's two 10cm × 5cm PCBs panelized as one 10cm × 10cm one for cheapness, the side-by-side images showing both sides. I designed it to be used with Flash games, Mame, and other emulators, with a large number of mappings built in to choose from. I like the problem-solving and planning part way too much, and haven't even ordered the boards.(I did use a Logitech Rumble 2 with an userspace uinput mapping daemon in Linux (for flash/web games), until I wore out the right-side buttons. Where do you get that graphite paint they use on the contact surfaces? It does not seem to be impregnated in the rubber button, just painted on. Or maybe glued from a sheet.)

author: legacy
author_rank: Super Contributor
timestamp: February 03, 2019, 11:40:46 pm
content: I have just found that we need PS/2 scan set3 for our Tektronix and HP Xterminals.We will have a couple of them for sale during the camping, so if people want a USB keyboard with the X11 terminal ... we have to support the proper scan setIf we will ever decide to design our own keyboard, we will go with the EMACS layout recommendations.Keyboards optimized for UNIX, VI, and Emacs have a different layout and a couple of keys have also different behavior.Having a customizable firmware will solve both these two needs.

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 04, 2019, 01:01:38 am
content: (You might find theHackaday article on turning ThinkPad T61 keyboard into an external keyboard using a Teensyinteresting. To add support for PS/2, you'll need to move two I/O pins, similar to how Teensy LC maps some of the keyboard pins as it has fewer I/O pins than the Teensy 3.2.)

author: PCB.Wiz
author_rank: Super Contributor
timestamp: February 04, 2019, 05:09:08 am
content: Further to the CH54x/CH55x parts I linked above, I find this linkhttp://www.wch.cn/downloads/CH549EVT_ZIP.htmlincludes USBHostHUB_KM.C code for creating a USB host device that checks for each ofloc = SearchTypeDevice( DEV_TYPE_MOUSE );loc = SearchTypeDevice( DEV_TYPE_KEYBOARD );loc = SearchTypeDevice( USB_DEV_CLASS_PRINTER );loc = SearchTypeDevice( USB_DEV_CLASS_HID );loc = SearchTypeDevice( DEF_AOA_DEVICE );I think AOA is Android Open Accessory ?