1 COMP541 Input Devices: Keyboards, Mice and Joysticks Montek Singh Apr 16, 2012
Keyboard Interface
3 PS/2 Keyboard Uses a synchronous serial protocol What does that mean? What does that mean? Each symbol is transmitted bit-by-bit Each symbol is transmitted bit-by-bit 8 data bits + 3 control bits
4 Physical Interface Two lines Clock (15-20KHz) Clock (15-20KHz) Data Data Normally high, asserted low Normally high, asserted low Read: pp of Nexys 3 manual pp of Nexys 3 manual
5Protocol Bidirectional Kybd-to-host and host-to-kybd on same wires Kybd-to-host and host-to-kybd on same wires CAPS LOCK light for example Assert low To send, keyboard starts clocking 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 a start bit: always 0 8 bits of data 8 bits of data lsb first one parity bit (odd) one parity bit (odd) a stop bit: always 1 a stop bit: always 1 Clocked by keyboard Value should be latched by FPGA on neg edge of keyboard clock Value should be latched by FPGA on neg edge of keyboard clock 6 Illustration from
7 What is Sent ASCII is not sent! Scan codes for keys Most keys have an 8-bit (single byte) scancode Most keys have an 8-bit (single byte) scancode Some have two bytes Some have two bytes A few have even more! A few have even more! Most (not all, be careful!) keyboards use these scancodes: Most (not all, be careful!) keyboards use these scancodes: Illustration from Nexys 3 manual
8 Scan Codes Normally translated by software You remap your keys, for example You remap your keys, for example Software takes care of Shift, caps lock, control Shift, caps lock, control
9 Some Scan Codes Long Two code sequence common Have a look at Break key! Have a look at Break key!
10 Even More Complicated Scan code generated when you press And when you release Two bytes: F0 followed by key scan code Two bytes: F0 followed by key scan code Example: Example: Space pressed, 29 sent Space released, F0 29 sent If you hold key, scan code repeated
11Resources Information Scan codes My Verilog for keyboard is on the class website
12 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 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 Handle presses and releases appropriately in software maybe add another register to indicate that a new character has arrived..??
Mice 13
Mouse Very similar interface (clk & data) But: 3 words sent w/ mouse movement or button press But: 3 words sent w/ mouse movement or button press Read pp of Nexys 3 manual pp of Nexys 3 manual 14
Movement Movement 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 buttons L, R are buttons 15
Scroll Wheel, etc. Extensions to original 2 button PS/2 mouse See See
Joystick (Courtesy Anselmo Lastra)
Atari 2600 Joystick (we only have 2-3) 18
We Have Sega Joypads (we have 5-6) Enhanced version with more buttons Has mux Has mux Select pin chooses first or second set of buttons, L/R Select pin chooses first or second set of buttons, L/R 19
Six Button Use See Use select to use buttons B & C To use X, Y, Z, need to pulse select 20
NEXYS Mappings (PMOD JA) We have to connect them using wires… 21 SignalFPGA PinDB-910- Pin UpM1514 DownL1723 LeftL1638 RightK1242 Btn A/BM1469 Start/CL1591 SelectM16710 Ground-85 Power-56 PMOD JA is 10-pin connector nearest VGA connector
Suggestion Create FF for Select Memory map so you can set from CPU Memory map so you can set from CPU Memory map the input signals I would not latch them I would not latch them Please power off when plugging or unplugging Sega joypads! Careful when plugging in PCB Careful when plugging in PCB 22
23Links