1
COMP541COMP541
Input Devices: Keyboards, Input Devices: Keyboards, Mice and JoysticksMice and Joysticks
Montek SinghMontek Singh
Apr 16, 2012Apr 16, 2012
Keyboard InterfaceKeyboard Interface
3
PS/2 KeyboardPS/2 Keyboard Uses a synchronous serial protocolUses a synchronous serial protocol
What does that mean?What does that mean? Each symbol is transmitted bit-by-bitEach symbol is transmitted bit-by-bit
8 data bits + 3 control bits8 data bits + 3 control bits
4
Physical InterfacePhysical Interface Two linesTwo lines
Clock (15-20KHz)Clock (15-20KHz) DataData Normally high, asserted Normally high, asserted
lowlow
Read:Read: pp 13-14 of Nexys 3 pp 13-14 of Nexys 3
manualmanual
5
ProtocolProtocol BidirectionalBidirectional
Kybd-to-host and host-to-kybd on same wiresKybd-to-host and host-to-kybd on same wiresCAPS LOCK light for exampleCAPS LOCK light for example
Assert lowAssert low To send, keyboard starts clockingTo send, keyboard starts clocking
sends successive bit on positive edge of clocksends successive bit on positive edge of clockhost reads bits on negative edges of clockhost reads bits on negative edges of clock
You shouldnYou shouldn’’t need to send to kybdt need to send to kybd
ProtocolProtocol 11 bits11 bits
a start bit: always 0a start bit: always 0 8 bits of data8 bits of data
lsb firstlsb first one parity bit (odd)one parity bit (odd) a stop bit: always 1a stop bit: always 1
Clocked by keyboardClocked by keyboard Value should be latched by FPGA on neg edge of Value should be latched by FPGA on neg edge of
keyboard clockkeyboard clock
6Illustration from http://www.beyondlogic.org/keyboard/keybrd.htm
7
What is SentWhat is Sent ASCII is not sent!ASCII is not sent! Scan codes for keysScan codes for keys
Most keys have an 8-bit (single byte) scancodeMost keys have an 8-bit (single byte) scancode Some have two bytesSome have two bytes A few have even more!A few have even more! Most (not all, be careful!) keyboards use these Most (not all, be careful!) keyboards use these
scancodes:scancodes:
Illustration from Nexys 3 manual
8
Scan CodesScan Codes Normally translated by softwareNormally translated by software
You remap your keys, for exampleYou remap your keys, for example
Software takes care ofSoftware takes care of Shift, caps lock, controlShift, caps lock, control
9
Some Scan Codes LongSome Scan Codes Long Two code sequence commonTwo code sequence common
Have a look at Break key!Have a look at Break key!
10
Even More ComplicatedEven More Complicated Scan code generated when you pressScan code generated when you press And when you releaseAnd when you release
Two bytes: F0 followed by key scan codeTwo bytes: F0 followed by key scan code Example:Example:
Space pressed, 29 sentSpace pressed, 29 sentSpace released, F0 29 sentSpace released, F0 29 sent
If you hold key, scan code repeatedIf you hold key, scan code repeated
11
ResourcesResources InformationInformationhttp://www.beyondlogic.org/keyboard/keybrd.htm
Scan codesScan codeshttp://www.barcodeman.com/altek/mule/scandoc.php
My Verilog for keyboard is on the class websiteMy Verilog for keyboard is on the class website
12
My VerilogMy Verilog Have Verilog for keyboardHave Verilog for keyboard Have tested it with the FPGA kit; seems to Have tested it with the FPGA kit; seems to
work finework fine To use:To use:
You should memory-map the character code registerYou should memory-map the character code registergive the keyboard a memory address so the CPU can read give the keyboard a memory address so the CPU can read
it using it using lwlw instructions instructions Handle presses and releases appropriately in softwareHandle presses and releases appropriately in software
maybe add another register to indicate that a new maybe add another register to indicate that a new character has arrived..??character has arrived..??
MiceMice
13
MouseMouse Very similar interface (clk & data)Very similar interface (clk & data)
But: 3 words sent w/ mouse movement or button But: 3 words sent w/ mouse movement or button presspress
ReadRead pp 14-15 of Nexys 3 manualpp 14-15 of Nexys 3 manual
14
MovementMovement Movement is relativeMovement is relative
XS, YS are sign (+ is up/right)XS, YS are sign (+ is up/right) XV, YV are overflow (too fast)XV, YV are overflow (too fast) L, R are buttonsL, R are buttons
15
Scroll Wheel, etc.Scroll Wheel, etc. Extensions to original 2 button PS/2 mouseExtensions to original 2 button PS/2 mouse
See See http://www.computer-engineering.org/ps2mouse/
16
JoystickJoystick
(Courtesy Anselmo Lastra)(Courtesy Anselmo Lastra)
Atari 2600 Joystick (we only have Atari 2600 Joystick (we only have 2-3)2-3)
18
http://www.atariarchives.org
We Have Sega Joypads (we have We Have Sega Joypads (we have 5-6)5-6) Enhanced version with Enhanced version with
more buttonsmore buttons Has muxHas mux Select pin chooses first or Select pin chooses first or
second set of buttons, second set of buttons, L/RL/R
19http://pinouts.ru/data/genesiscontroller_pinout.shtml
Six Button UseSix Button Use SeeSee
http://www.cs.cmu.edu/~chuck/infopg/segasix.txthttp://www.cs.cmu.edu/~chuck/infopg/segasix.txt
Use select to use buttons B & CUse select to use buttons B & C To use X, Y, Z, need to pulse selectTo use X, Y, Z, need to pulse select
20
NEXYS Mappings (PMOD JA)NEXYS Mappings (PMOD JA) We have to connect them using wires…We have to connect them using wires…
21
Signal FPGA Pin DB-9 10-Pin
Up M15 1 4
Down L17 2 3
Left L16 3 8
Right K12 4 2
Btn A/B M14 6 9
Start/C L15 9 1
Select M16 7 10
Ground - 8 5
Power - 5 6PMOD JA is 10-pin connector nearest VGA connector
SuggestionSuggestion Create FF for SelectCreate FF for Select
Memory map so you can set from CPUMemory map so you can set from CPU
Memory map the input signalsMemory map the input signals I would not latch themI would not latch them
Please power off when plugging or unplugging Please power off when plugging or unplugging Sega joypads!Sega joypads! Careful when plugging in PCBCareful when plugging in PCB
22
23
LinksLinks http://pinouts.ru/data/JoystickAtari2600_pinout.shtmlhttp://pinouts.ru/data/JoystickAtari2600_pinout.shtml http://pinouts.ru/data/genesiscontroller_pinout.shtmlhttp://pinouts.ru/data/genesiscontroller_pinout.shtml http://www.epanorama.net/documents/joystick/ataristick.htmlhttp://www.epanorama.net/documents/joystick/ataristick.html http://www.epanorama.net/documents/joystick/tvgames.htmlhttp://www.epanorama.net/documents/joystick/tvgames.html
http://www.cs.cmu.edu/~chuck/infopg/segasix.txthttp://www.cs.cmu.edu/~chuck/infopg/segasix.txt