230 likes | 254 Views
This article explains the interfaces for keyboards, mice, and joysticks. It covers the protocols, scan codes, and mappings for these input devices. It also provides resources and Verilog code for implementing the interfaces.
E N D
COMP541Input Devices: Keyboards, Mice and Joysticks Montek Singh Apr 16, 2012
PS/2 Keyboard • Uses a synchronous serial protocol • What does that mean? • Each symbol is transmitted bit-by-bit • 8 data bits + 3 control bits
Physical Interface • Two lines • Clock (15-20KHz) • Data • Normally high, asserted low • Read: • pp 13-14 of Nexys 3 manual
Protocol • Bidirectional • Kybd-to-host and host-to-kybd on same wires • CAPS LOCK light for example • Assert low • To send, keyboard starts clocking • sends successive bit on positive edge of clock • host reads bits on negative edges of clock • You shouldn’t need to send to kybd
Protocol • 11 bits • a start bit: always 0 • 8 bits of data • lsb first • one parity bit (odd) • a stop bit: always 1 • Clocked by keyboard • Value should be latched by FPGA on neg edge of keyboard clock Illustration from http://www.beyondlogic.org/keyboard/keybrd.htm
What is Sent • ASCII is not sent! • Scan codes for keys • Most keys have an 8-bit (single byte) scancode • Some have two bytes • A few have even more! • Most (not all, be careful!) keyboards use these scancodes: Illustration from Nexys 3 manual
Scan Codes • Normally translated by software • You remap your keys, for example • Software takes care of • Shift, caps lock, control
Some Scan Codes Long • Two code sequence common • Have a look at Break key!
Even More Complicated • Scan code generated when you press • And when you release • Two bytes: F0 followed by key scan code • Example: • Space pressed, 29 sent • Space released, F0 29 sent • If you hold key, scan code repeated
Resources • Information http://www.beyondlogic.org/keyboard/keybrd.htm • Scan codes http://www.barcodeman.com/altek/mule/scandoc.php • My Verilog for keyboard is on the class website
My Verilog • Have Verilog for keyboard • Have tested it with the FPGA kit; seems to work fine • To use: • You should memory-map the character code register • give the keyboard a memory address so the CPU can read it using lw instructions • Handle presses and releases appropriately in software • maybe add another register to indicate that a new character has arrived..??
Mouse • Very similar interface (clk & data) • But: 3 words sent w/ mouse movement or button press • Read • pp 14-15 of Nexys 3 manual
Movement • Movement is relative • XS, YS are sign (+ is up/right) • XV, YV are overflow (too fast) • L, R are buttons
Scroll Wheel, etc. • Extensions to original 2 button PS/2 mouse • See http://www.computer-engineering.org/ps2mouse/
Joystick (Courtesy Anselmo Lastra)
Atari 2600 Joystick (we only have 2-3) http://www.atariarchives.org
We Have Sega Joypads (we have 5-6) • Enhanced version with more buttons • Has mux • Select pin chooses first or second set of buttons, L/R http://pinouts.ru/data/genesiscontroller_pinout.shtml
Six Button Use • See • http://www.cs.cmu.edu/~chuck/infopg/segasix.txt • Use select to use buttons B & C • To use X, Y, Z, need to pulse select
NEXYS Mappings (PMOD JA) • We have to connect them using wires… PMOD JA is 10-pin connector nearest VGA connector
Suggestion • Create FF for Select • Memory map so you can set from CPU • Memory map the input signals • I would not latch them • Please power off when plugging or unplugging Sega joypads! • Careful when plugging in PCB
Links • http://pinouts.ru/data/JoystickAtari2600_pinout.shtml • http://pinouts.ru/data/genesiscontroller_pinout.shtml • http://www.epanorama.net/documents/joystick/ataristick.html • http://www.epanorama.net/documents/joystick/tvgames.html • http://www.cs.cmu.edu/~chuck/infopg/segasix.txt