Keyboards - Snial/FIGnition GitHub Wiki

This is a short document on how to add an external keyboard (e.g. a PS/2 keyboard) and interface it via J5-J6.

Hardware

If we term J5-J6 as J5top, J5bottom, J6top, J6bottom then you'll find that J5bottom is connected to PortC.0, J5top can be connected to PortC.1, J6top can be connected to PortC.2 and J6bottom is connected to PortC.3.

You don't need more than 4 connections to interface to a PS/2 keyboard (apart from power and ground). You'll need to actually solder bridge J5top and J6top. to the adjacent solder pads.

Software

To get an external keyboard to work you'll essentially need to rewrite the FigKeyDrv.c file. You'll need to provide an identical interface for the rest of the code; support the interrupt callback for keyscanning and actually do the correct keyscanning.

The basic idea for a PS/2 keyboard would involve suspending the PS/2 interface during the main video scanning and only reading the keyboard during the margin states (when there's hardly any interrupts going on). You can read Timer1's value to maintain timing. You'll probably find it best if you use the keyboard's internal buffer and only read keys when Key has actually been called.

You have a major constraint in that the FIGnition KeyDriver is currently about 716b long. If your code is significantly longer than that it won't fit in future Firmware revisions and you'll need an AVR chip with more Flash.

Interface

This is in FigKeyDrv.h

Initialisation

You need to support the function void KeyInit(void); to intialise PortC correctly.

Interrupt Callback.

The Keyboard interrupt is called twice from the Video generator. You can replace it with a dummy function:

void KeyScan(void) { }

Reading Keys

In your PS/2 interface it's probably just best to read keys when needed. It's safe to read keys when gFrameSyncState is =kFrameSyncBotMargin. This gives you about 64scans of * 64us = 4ms to read a key and this should be OK since the clock frequency is about 10 to 16KHz. Nevertheless, You'll still have to keep monitoring gFrameSync during keyboard communications.

PS/2 Protocol

The only keyboard function you need to support is byte KeyP(void), which is the Inkey function. Key itself uses KeyP, and expects 0 if there's no key.

You'll need to generate a pseudo keypad in gSysVars.gKScan, the keypad layout is given in the FIGnition documentation.

Keypad