PS/2 Keyboard Musings

Nagging hardware related question? Post here!
handyandy69
ROM Dongle
Posts: 10
Joined: Sun Feb 08, 2015 5:05 pm

PS/2 Keyboard Musings

Post by handyandy69 »

I mentioned on Tetroid's keyboard post below that I wondered whether it was possible to connect a PS/2 keyboard to a QL using an Arduino as a bridge. Please accept my ramblings as a method of getting my thoughts down. As someone who has only a small amount of knowledge on these topics (always dangerous), I apologise if what i'm about to write is absolute rubbish or has been covered elsewhere.

A bit of background. My QL came with a SPEM mechanical keyboard which has suffered over the years with failing key switches to the point that it became unusable. I mused that it must be possible to convert what a standard keyboard output to what the QL needed. This could be achieved by an arduino or something similar, I thought. This has nagged away for the last couple of years but I've yet to do anything about it. The idea came up again after seeing a video by Adrian Black on how he build a arduino converter so he could use an PS/2 keyboard on a Tandy 1000 computer. This however used a stream of data detailing the keystrokes, rather than the pin selection type the QL uses.

I found a keyboard matrix diagram online that identified which pins are required to be connected for each key. These were labelled J11 & J12. I have the ribbon cable off the old SPEM keyboard that i'd planned to connect between the arduino and the QL.

This raises a few questions:

1) Am I correct in thinking that the power would be provided to the J11(9 pin) socket and the current membrane will connect to the appropriate pin on the J12 (11 pin) socket?

2) Assuming 1 is correct. If I have the J11 connected to the Arduino Inputs and the J12 connected to the outputs, how would I be able to let the QL know that say pin 5 on the J11 connector and pin 7 on the J12 connector are being connected by the keyboard? I had planned to use Adrian's keyboard reading code and adapt it to fulfil the QL requirements.

3) Would the QL be able to provide enough power to supply the arduino and PS/2 keyboard?, or would this need to be externally powered?

4) Could a USB keyboard also be used, preferably wireless to make it a bit more practical?

5) The matrix diagram seems to miss off the up arrow key. Does anyone know which address this uses?

Thanks in advance for any help you are able to provide. As I said my technical knowledge is limited so I may need any advice in the simplest terms as possible.

Cheers,


Andy.


User avatar
Pr0f
QL Wafer Drive
Posts: 1306
Joined: Thu Oct 12, 2017 9:54 am

Re: PS/2 Keyboard Musings

Post by Pr0f »

Let's keep it simple and start with the PS/2 to QL matrix idea:

Tasks you would have to do:

1) Send some codes to the keyboard to set it up - the routine you have from Adrian Black may be able to do this already.

2) Listen for keys on the PS/2 keyboard - the keyboard will generate a 'key down' and 'key up' scan code - different for each key - it is I believe possible to turn off the key up code - you may want to do that to make your code easier - but check out what you have from Adrian

3) Once you have decoded the key(s) - there may be more than one - you need to emulate the pressing of a key on the matrix keyboard of the QL

4) The internal chip on the QL motherboard known as the IPC actually understand the keyboard as an 8 x 8 matrix, some additional diodes are used to separate out certain keys so they can be pressed in combination - this is why the keyboard connectors are 9 and 11 pins.

5) The IPC chip regularly scans through the 8 columns of keys and looks for a response back on the rows, it does this by keeping one of the lines high (+5 Volts) and the others all low (0 Volts). When one or more of the keys is pressed in the current column being scanned - the IPC can read the key data and work out which key is pressed.

6) Special consideration is given for the Shift ALT and CTRL keys (remember those diodes back in 4) above. This is so that the decision made in step 5) can be modified if necessary.

7) You would need to mimic this behavior by keeping track of when any of the special keys in step 6) are pressed, and also which other keys - you would read in to your arduino the column being scanned, and if you saw that your key from the PS/2 routine was a match for that column, you would make the appropriate row on the QL matrix high (+5 volts)


User avatar
bwinkel67
QL Wafer Drive
Posts: 1202
Joined: Thu Oct 03, 2019 2:09 am

Re: PS/2 Keyboard Musings

Post by bwinkel67 »

I did recently watch that same Adrian Black video on his PS/2 to Tandy 1000 converter in which he programs an arduino to parse PS/2 key codes and remap them to the Tandy 1000 key codes. He does seem to differentiate for keydown and then keyup (I think his code is a modification from a working project, not his, that he modified to get it to work for the Tandy 1000). He actually takes some time to go over the code that he modified explaining what it does, so it is a helpful reference.


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PS/2 Keyboard Musings

Post by tofro »

There is no way to get a working keyboard when you decide to ignore the PS/2 key release codes - you won't get the modifier keys (CTRL, ALT, SHIFT) working properly, and a held down key will either auto-repeat forever or not at all.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Ruptor
Gold Card
Posts: 418
Joined: Fri Dec 20, 2019 2:23 pm
Location: London

Re: PS/2 Keyboard Musings

Post by Ruptor »

handyandy69 wrote:4) Could a USB keyboard also be used, preferably wireless to make it a bit more practical?
I was reading the replacement QL CPU thread where they were discussing using a PS/2 to QL keymatrix. I found this article about PS/2 protocols and hardware with the thought it could easily be done on a PIC
http://www.tayloredge.com/reference/Int ... yboard.pdf
but now I think stuff that why use an obsolete complicated system when you can use USB. Is it complicated to create a USB keyboard interface? The matrix side on the QL seems straight forward.


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: PS/2 Keyboard Musings

Post by tofro »

Ruptor wrote:
handyandy69 wrote: but now I think stuff that why use an obsolete complicated system when you can use USB. Is it complicated to create a USB keyboard interface? The matrix side on the QL seems straight forward.
USB is about 2 magnitudes more complex than PS/2.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Ruptor
Gold Card
Posts: 418
Joined: Fri Dec 20, 2019 2:23 pm
Location: London

Re: PS/2 Keyboard Musings

Post by Ruptor »

tofro wrote:USB is about 2 magnitudes more complex than PS/2.
There is a lot of open source host side USB software that could be adapted or chopped down to use for a keyboard interface I think. We don't need to support everything just make a keyboard think it is connected to a host.


User avatar
Peter
Font of All Knowledge
Posts: 2004
Joined: Sat Jan 22, 2011 8:47 am

Re: PS/2 Keyboard Musings

Post by Peter »

Ruptor wrote:There is a lot of open source host side USB software that could be adapted or chopped down to use for a keyboard interface I think.
A lot? I know only one project that doesn't require a Linux-like OS underneath and seems relatively suitable. Needs a full ARM system, relatively time consuming to get the development platform up and a PCB designed.

And for what purpose? If one wants to type on a keyboard outside the QL anyway, why use the original box at all?
Ruptor wrote:We don't need to support everything just make a keyboard think it is connected to a host.
And probably also mouse.


User avatar
Ruptor
Gold Card
Posts: 418
Joined: Fri Dec 20, 2019 2:23 pm
Location: London

Re: PS/2 Keyboard Musings

Post by Ruptor »

Peter wrote:And for what purpose? If one wants to type on a keyboard outside the QL anyway, why use the original box at all?
Same applies to PS/2 port I think but people have done it. :?


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: PS/2 Keyboard Musings

Post by mk79 »

Peter wrote:A lot? I know only one project that doesn't require a Linux-like OS underneath and seems relatively suitable.
AT90USB1287 (8-bit processor!) with LUFA USB, many of the STM32 chips with STM32Cube USB host library and a bit more exotic but interesting the Vinculum II chips from FTDI. All provide relatively easy USB host support without any operating system.

I studied those mostly for mouse support, not keyboard, but the two are not that different from a complexity standpoint.

Another issue: all in all PC keyboards map relatively well to QL keyboards (though maybe needing different mappings for different languages), but a few keys probably would need tweaks to the operating system tables (possible with Minerva and SMSQ/E).

Cheers, Marcel


Post Reply