
68
www.xilinx.com
Spartan-3A/3AN FPGA Starter Kit Board User Guide
UG334 (v1.1) June 19, 2008
Chapter 8:
PS/2 Mouse/Keyboard Port
R
The keyboard sends data to the host in 11-bit words that contain a ‘0’ start bit, followed by
eight bits of scan code (LSB first), followed by an odd parity bit and terminated with a ‘1’
stop bit. When the keyboard sends data, it generates 11 clock transitions at around 20 to
30 kHz, and data is valid on the falling edge of the clock as shown in
Figure 8-2
.
Mouse
PS/2-compatible mice potentially support two modes. In polled mode, the host controller
interrogates the mouse for activity. In streaming mode, the mouse reports any movement
or key presses. Streaming mode is the default operating mode.
To specifically enter streaming mode, the FPGA host must transmit a “Set Stream Mode”
command (0xEA) to the mouse. The mouse then generates a clock and data signal when
moved or when one or more keys are pressed; otherwise, these signals remain High,
indicating the Idle state. Each time the mouse is moved, the mouse sends three 11-bit
words to the host. Each of the 11-bit words contains a ‘0’ start bit, followed by 8 data bits
(LSB first), followed by an odd parity bit, and terminated with a ‘1’ stop bit. Each data
transmission contains 33 total bits, where bits 0, 11, and 22 are ‘0’ start bits, and bits 10, 21,
and 32 are ‘1’ stop bits. The three eight-bit data fields contain movement data as shown in
Figure 8-4
. Data is valid at the falling edge of the clock, and the clock period is 20 to 30 kHz.
A PS/2-style mouse employs a relative coordinate system (see
Figure 8-5
), wherein
moving the mouse to the right generates a positive value in the X field, and moving to the
left generates a negative value. Likewise, moving the mouse up generates a positive value
in the Y field, and moving it down represents a negative value. The XS and YS bits in the
status byte define the sign of each value, where a ‘1’ indicates a negative value.
Figure 8-4:
PS/2 Mouse Transaction
L
R
C 1 XS YS XV YV P
X0 X1 X2 X3 X4 X5 X6 X7 P
Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7 P
1
0
1
0
0
1
1
Idle state
Idle state
Start bit
Start bit
Stop bit
Stop bit
Stop bit
Start bit
Mouse status byte
X direction byte
Y direction byte
UG330_c8_04_032007
Figure 8-5:
The Mouse Uses a Relative Coordinate System to Track Movement
(YS=0)
-Y values
+Y values
(YS=1)
+X values
-X values
(XS=1)
(XS=0)
UG230_c8_05_021806