COMP 541 Input Devices Keyboards Mice and Joysticks
COMP 541 Input Devices: Keyboards, Mice and Joysticks Montek Singh Nov 3, 2014 1
Keyboard Interface USB keyboard plugs into the USB port on Nexys 3 / Nexys 4 boards
USB to PS/2 emulation ã Host controller on Nexys boards l talks to USB keyboard on one side l speaks PS/2 protocol to the FPGA on the other side Ø PS/2 used to be the dominant keyboard protocol ã PS/2 = a synchronous serial protocol l What does that mean? l Each symbol is transmitted bit-by-bit Ø 8 data bits + 3 control bits Ø synchronized to the keyboard’s clock (slow) 3
Physical Interface ã Two lines l Clock (15 -20 KHz) l Data l Normally high, asserted low ã Read: l pp. 13 -14 of Nexys 3 manual l pg. 10 of Nexys 4 manual 4
Protocol ã Bidirectional l Kybd-to-host and host-to-kybd on same wires Ø CAPS LOCK light for example ã Assert low l To send, keyboard starts clocking Ø sends successive bit on positive edge of clock Ø host reads bits on negative edges of clock ã For your lab: l You shouldn’t need to send anything to keyboard 5
Protocol ã 11 bits l a start bit: always 0 l 8 bits of data Ø lsb first l one parity bit (odd) l a stop bit: always 1 ã Clocked by keyboard l Value should be latched by FPGA on neg edge of keyboard clock Illustration from http: //www. beyondlogic. org/keyboard/keybrd. htm 6
What is Sent ã ASCII is not sent! ã Scan codes for keys l Most keys have an 8 -bit (single byte) scancode l Some have two bytes l A few have even more! l Most (not all, be careful!) keyboards use these scancodes: Illustration from Nexys 3 manual 7
Scan Codes ã Normally translated by software l You remap your keys, for example ã Software takes care of l Shift, caps lock, control 8
Some Scan Codes Long ã Two code sequence common l Some special keys use even more… Ø …have a look at Break key! 9
Even More Complicated ã Scan code generated when you press ã And when you release l Two bytes: F 0 followed by key scan code l Example: Ø Space pressed, 29 sent Ø Space released, F 0 29 sent 10
Resources ã Information http: //www. beyondlogic. org/keyboard/keybrd. htm ã Scan codes http: //www. barcodeman. com/altek/mule/scandoc. php ã Available on the class website: l my Verilog for keyboard 11
My Verilog ã Have Verilog for keyboard l a test/demo which displays data from keyboard onto 7 - segment display l have tested it with the FPGA kit; seems to work fine ã To use: l You will memory-map the character code register Ø give the keyboard a memory address so the CPU can read it using lw instructions l Handle presses and releases appropriately in software Ø Either: Check for a key release before reading a new key press Ø OR: Delaying next key read (by, say, 1/4 th sec) – gives you automatic “key repeat” feature! 12
Mice 13
Mouse ã Very similar interface (clk & data) l But: 3 words sent w/ mouse movement or button press ã Read l pp. 14 -15 of Nexys 3 manual / pp. 12 -13 of Nexys 4 manual ã Verilog l I can guide you to modify keyboard. v to read 3 bytes 14
Movement ã Movement is relative l XS, YS are sign (+ is up/right) l XY, YY are overflow (too fast) l L, R are buttons 15
Scroll Wheel, etc. ã Extensions to original 2 button PS/2 mouse l See http: //www. computer-engineering. org/ps 2 mouse/ 16
Joystick
Joystick module ã 2 axes: x and y l 10 -bit position values ã On-board microprocessor l handles debouncing l communicates with host ã Info on class website l reference manual l Verilog code Ø demo: feeds joystick output to the 7 seg display Ø you will modify to feed the output into your memory-mapped I/O unit instead 18
Accelerometer Nexys 4 boards have built-in accelerometer For Nexys 3: read on… 19
Accelerometer module ã 3 -axis accelerometer l x, y, z components of gravity l helps determine Ø orientation and acceleration ã On-board microprocessor l communicates with host ã Info on class website l reference manual l Verilog code Ø demo: feeds accelerometer output to the 7 -seg display Ø you will modify to feed the output into your memorymapped I/O unit instead 20
Keypad 21
Keypad module ã 4 x 4 keypad l 0 -9, A-F l one hex character input ã Simple interface l 4 -bit row, 4 -bit column l a ‘ 0’ means pressed ã Info on class website l reference manual l Verilog code Ø demo: feeds keypad output to the 7 -seg display Ø you will modify to feed the output into your memorymapped I/O unit instead 22
Stereo Audio Amplifier Nexys 4 has mono amplified built-in Nexys 3/Nexys 4: you can attach a stereo module (read on…) 23
Amplifier module ã Stereo output l headphone jack compatible ã Very very low-level…! l expects analog waveform on input! l your design on FPGA will have to generate an analog value by rapidly toggling between 0 and 1 Ø e. g. , 60% of the time ‘ 1’ value will approximate an analog value of 0. 60 V (if range is 0 -1 V) ã Verilog code l I will post mine on the website 24
- Slides: 24