PS/2 keyboard hookup with microcontroller

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
xopr
Posts: 21
Joined: 05 Jun 2018, 12:05

Re: PS/2 keyboard hookup with microcontroller

Post by xopr »

marcelk wrote: 07 Jun 2018, 18:20... My ambition is that Snake, Racer and the setting of the clock in Mandelbrot should all work in this setup....
Maybe it's an idea to toggle between keypad/keyboard mode with the scroll-lock (or num-lock) key (since they also come with the led indicator).
In keypad mode, one could also send the terminal payload using the function keys.

I'm definitely going to build a similar adapter when my Gigatron arrives :)
WattSekunde
Posts: 24
Joined: 22 May 2018, 10:25

Re: PS/2 keyboard hookup with microcontroller

Post by WattSekunde »

Very nice! The parts drawer looks very familiar to me :) .

In my first design I thought I need a dedicated bit to show that a key is pressed and the keycode is valid. But after my positive experience with your little terminal program I think I don't need to waste the bit any more. I can use it as a second function key. To obtain most compatibility I would like to use the shift key bit in ASCII shift bit position 5 = 00s0.0000 and the special function key bit on bit position 7 = f000.0000.

And it's getting even better :lol:. The famicom controller is active low and the keyboard interface is active high. Now it's easy for the software to differentiate between the presence of a keyboard or a controller.
What do you think?

My next step, beside dig deeper into GCL, is to wire up a <=64 key keyboard prototype with two special shift keys. In my case I love to have a custom TTL Keyboard on the Gigatron with a lot of special keys. ;)
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: PS/2 keyboard hookup with microcontroller

Post by marcelk »

Until I am get into GCL I tried to compile and transfer your little Terminal App called Main.gcl
The issue with compiling Main.gcl (now renamed to Terminal.gcl) should be fixed with this: #26
With this, GCL programs can start at addresses other than $0200 again, and the "Loader patch" is only applied if the program seems to require it.
walter
Site Admin
Posts: 160
Joined: 13 May 2018, 08:00

Re: PS/2 keyboard hookup with microcontroller

Post by walter »

Cool. I just built my own. I found some old serial plugs (DB9-RJ45) of which I sacrifised one. I just added some sugru to fill the small gap next to the PS/2 connector and it looks pretty nice.
plug1.jpg
plug1.jpg (493.18 KiB) Viewed 3771 times
plug1.jpg
plug1.jpg (493.18 KiB) Viewed 3771 times
Attachments
plug2.jpg
plug2.jpg (635.24 KiB) Viewed 3771 times
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: PS/2 keyboard hookup with microcontroller

Post by marcelk »

My ambition is that Snake, Racer and the setting of the clock in Mandelbrot should all work in this setup. I don't know if that is all realistic, and it very likely requires total assimilation of the PS2keyboard module.
I finally got around to work on this. PS/2 support in BabelFish was completely rewritten and I have just pushed all changes. I hope I didn't break something for the Nano and Micro configurations. Please let me know.

1. PS/2 iterface updates:
  • Parity checks on the keyboard data, and properly lowering the PS/2 clock line when busy talking to the Gigatron.
  • Better mapping of arrow keys to game controller signals. Support long presses, and holding more than one down at the same time.
  • The A button can be activated as [Delete] or [BackSpace] or [End]
  • The B button can be activated as [Insert] or [Home]
  • The Select button can be activated as [PageDown]
  • The Start button can be activated as [PageUp]. So if you press [PageUp] for >2 seconds, the Gigatron resets
  • Simply hitting [Ctrl]+[Alt]+[Delete] will conveniently do this tedious holding down for you :-)
  • Regular keys are sent as ASCII codes to the Gigatron for 3 consecutive frames (about 50 ms)
  • The function keys are mapped to non-ASCII codes $C1..$CC (F1..F12)
  • [Ctrl] + function key will send one of the built-in applications to Loader, see below (this used to be the [Escape] key)
Nine GT1 files, all from Apps/ and Contrib/, are stored in the BabelFish memory for immediate sending to Loader. (I will certainly add Gigatris and frogstroll to the list once they appear in the repo...)
  1. Tiny BASIC
  2. WozMon
  3. Terminal (TV Typewriter)
  4. Blinky
  5. Bricks game [xbx]
  6. Lines demo [at67]
  7. Game of Life demo [at67]
  8. Starfield demo [at67]
  9. Tetris game [at67]
For example, to start Tetris, first start Loader and then hit [Ctrl] + [F9].

Of these, 6-9 are absent in the ATtiny85 configuration because it doesn't have sufficient non-volatile memory.

What is not in there:
  • Switching between key maps. It (still) defaults to the US layout. The tables are still compatible with the Arduino PS2Keyboard library however.
  • Sending PS/2 commands back into the keyboard (so the keyboard leds, caps lock, num lock etcetera all do nothing)
  • Actual handling of parity errors by requesting the keyboard to resend (mind that, in reality, parity errors don't really happen...)
PS/2 support is now good enough that typing seems quite reliable, you can get high scores in Snake, Racer is more or less playable, you can set the clock in Mandelbrot and force a Gigatron reset. So in principle the keyboard can take over all game controller functions.

2. The USB serial interface commands were a bit expanded as well:

Code: Select all

:Commands are
: V        Show configuration
: H        Show this help
: R        Reset Gigatron
: L        Start Loader
: P[<n>]   Transfer object file from PROGMEM slot <n> [1..12]
: U        Transfer object file from USB
: .<text>  Send text line as ASCII key strokes
: C        Toggle echo mode (default off)
: T        Enter terminal mode
: W/A/S/D  Up/left/down/right arrow
: Z/X      A/B button 
: Q/E      Select/start button
'P' now takes an optional argument to specify the program slot. (Same as the function key number).

'.' sends the rest of the line directly to the Gigatron as ASCII (handy for sending BASIC programs?)

'T' enters terminal mode. This sends all key strokes from your computer directly into the Gigatron. With this you can connect using a terminal program and type directly from your PC/laptop into the Gigatron. For example to type BASIC or even play Snake. Use a true terminal program for the best experience, such as PuTTY, screen or picocom. This doesn't work with the Arduino IDE Serial Monitor, because it doesn't have a "raw" mode. Hit [Ctrl]+[D] to leave the terminal mode and go back to the BabelFish command prompt.

For example, this is how I connect to BabelFish with a terminal program:

Code: Select all

screen /dev/tty.usbmodem1411 115200

Code: Select all

picocom -b 115200 /dev/tty.usbmodem1411 
115200 is the baud rate that BabelFish uses. The /dev/tty* name can be a bit different for your computer and operating system. By default there is no echoing of the characters you typed. With the 'C' command you can toggle echo mode ON and OFF. You have to leave terminal mode first to give this command. Echo is useful when typing in BASIC, and a bit annoying when playing Snake.

'V' now also shows the echo status and some useful information about the configuration, such as pin assignment:

Code: Select all

:BabelFish platform=ArduinoUno
:Pins:
: Gigatron data=13 latch=12 pulse=11
: Keyboard clock=3 data=4
: Controller data=-1
:PROGMEM slots:
: 1) Tiny BASIC

[... snip ...]

:Echo off
:Type 'H' for help
:Gigatron OK
With all this, the 'W', 'A', 'S', 'D', 'Z', 'X', 'Q' and 'E' commands are less useful now, but we kept them in anyway.

3. Finally sendGt1.py got a small update

Sending files over USB should be more reliable for platforms that intercept the XOFF character. sendGt1.py detects when it is talking to an updated BabelFish, and then will escape these characters.
Post Reply