Uzebox Keyboard Interface

From Uzebox Wiki
Jump to navigation Jump to search
Uzebox Keyboard Interface embedded in a PS/2 keyboard
SNES-to-PS/2 keyboard adapter
Interface embedded in SNES plug


The Uzebox Keyboard interface allows any PS/2 keyboard to be connected to the Uzebox via the Player 2 SNES port. The interface is made of a single ATtiny25/45/85 8-pins microcontroller and four resistors. With the use of a SNES controller cord, the interface is so small that it can be easily embedded into the keyboard itself.

The latest revision is 1.2. Changes includes:

  • Added pullups on the PS/2 lines since the internal AVR pullups would not work when the tiny85 wanted to send commands to the keyboard.
  • Added series resistors on the SNES lines to avoid interfering with ISP programming. Added for development and firmware updates.
  • Revamped the PCB design and labeled all components
  • Support sending host commands to the keyboard. Implemented to support keyboard that requires the host to send any command right after a reset/BAT. Otherwise the keyboard re-enters BAT (self-test) endlessly sending 0xAA on the bus. This allows the support of PS/2 Perixx keyboards.


Hardware Interface Schematic

Kb-interface-v1.2b.png


Firmware

Protocol

The interface is connected to SNES P2 port and uses a protocol similar to SPI. The following pins are used:

  • Latch -> Data Out to keyboard
  • Clock -> Clock
  • P2 Data -> Data In from Keyboard

Since the latch and clock lines are shared with the P1 port, they are constantly being toggled when reading P1 buttons. A special state is required to begin a "transaction" (one or more consecutive transfers) with the keyboard:

  • The Clock line is held low and Latch line high simultaneously for at least 1uS.
  • Then Clock is set high and Latch low and a 1us delay is observed.

Then a SPI-like transfer(s) can begin by clocking out a command byte on the Latch/Data Out line while reading the next available character on the P2 data line. If no characters are available, a value of zero is received. When done transferring data, you must send a command to close the transaction.

Commands can be sent to the firmware to perform certain actions or return other data than pressed keys. Currently only two command are supported:

  • KB_SEND_KEY (0x00): Indicate that the host intends to read another key.
  • KB_SEND_END (0x01): Indicates that this is the last character to be returned in this transaction. This command should always be sent when done to perform cleanup and close the ATtiny SPI port. Otherwise the firmware will get confused when the next P1 polling happens.

The data received are PS/2 scan codes as returned by the keyboard without any transformation. This include key codes (key down) and break codes (key up).

The firmware has a 32 bytes buffer to store key presses from the keyboard.

Download

Latest version 1.2 can be downloaded here: Download Section

The package contains:

  • Eagle file schematic and PCB files
  • GERBER files for manufacturing the PCB
  • Schematic PDF
  • Bill of Material
  • Precompiled firmware in .HEX format supporting AtTiny25/45/85 MCUs.

Sources

The firmware sources are available here: KeyboardFirmware V1.2

Test ROM

Demo ROM to test the keyboard. Requires Uzem v1.20 for emulation. [1] [2]

Emulator support

Uzem automatically detects when the game uses the keyboard protocol and captures the PC keyboard input for it. P2 port is always used for the Uzebox keyboard. Naturally that means you can't also use the keyboard as a joystick at the same time. But you can use a regular pc jopystick/joypad for P1. CUzebox does not currently support the keyboard interface.

Assembly Guide

This section details how to assemble the interface based on the lastest v1.2 PCB. To start, insure you have all the required parts.

Component Image Schematic Reference Description
Parts-keyboard-pcb-v1 2.jpg N/A Printed Circuit Board V1.2
Part-midi-din-6.jpg PS2 Midi DIN 6-pins Connector
Part-dip8-socket.JPG N/A DIP-8 Socket
Part-ATtiny85.jpg U1 ATtiny85 Microcontroller
Part-header-2x3.JPG J1 ISP header
Part-resistor-1k-5pct.JPG R1,R2 Resistor 1KΩ (Brown, black, red, gold,

brown)

Part-resistor-10k-5pct.JPG R3,R4 Resistor 10KΩ (Brown, black, orange, gold,

brown)

To be continued.

Flashing the firmware

If you build a complete kit, the ATtiny was already flashed and ready to go. If not, follow the following procedure to program your chip.

The default firwmware is targeting the AtTiny85. You must set the fuses to these settings before use. This allows the clock to run at the maximum speed (16Mhz).

  • EXTENDED: 0xFF
  • HIGH: 0xDF
  • LOW: 0xE1

From AtmelStudio's Device Programming window:

Tiny85fuses4kb.JPG

Todo: Add or reference programming tools