Specifications

Finally, to support boot protocol, the firmware will not transmit power key status on endpoint 2 when the boot protocol is
selected via the host command; instead, it reverts to transmitting a standard 2-axis mouse packet without the packet id
header: i.e., a three-byte packet consisting of button data, X, and Y coordinates. When report protocol is re-selected, the
packet structure is as described above.
Slave Mouse Support
The usb portion of the reference firmware includes optional support for a slave ps2 mouse. The firmware uses 2 port pins to
implement the clock/data interface to the mouse, reports data to the host via USB data endpoint 2. Commands to the
mouse are initiated by the main loop of the reference firmware and are sequenced to completion by subsequent GPIO
interrupts, which are generated by edge transitions of the mouses clock line. During normal execution, the firmware places
the ps2 mouse in polling mode (in which the mouse only transmits data packets upon request); at 4msec intervals the
firmware solicits mouse data and places it in USB endpoint 2s data buffer for transmission to the host.
Slave mouse support is optional. The usb reference firmware, by default, makes calls to subroutines that implement the
slave mouse interface. However, these calls can be stubbedand the slave mouse code removed. Two variants of the
reference firmware (usb.asm and usbps2.asm) are examples of code that disables mouse support; usbsmps2.asm is an
example of one that includes it.
To support the slave ps2 mouse, the usb reference firmware performs the following additional tasks, in addition to those
already described for normal usb operation :
Support for mouse packet transmission on endpoint 2. The report descriptor for endpoint 2 includes a mouse collection,
so that the host will detect the presence of a mouse and poll for its data accordingly. This additional support is handled
in the report descriptor tables and in the firmware that transmits the report descriptors to the host on the control
endpoint (endpoint 0).
Support for bit-level serial communications to/from the mouse. Serial communications are handled via a state machine
implemented in the function mouse_int, which is invoked from the GPIO ISR each time the mouse clock line transitions
to clock in or out the next bit of a transaction. mouse_int communicates the successful result of a data transfer to the
main loop via a set of status flags and a 3-byte data buffer.
Support for mouse plug n play. To insure that the ps2 mouse can be plugged/unplugged during operation, the firmware
calls the function MouseConnectTask periodically from the main loop. This function maintains the connect state of the
ps2 mouse by periodically verifying its operation. If the mouse is determined to be unplugged as a result of lost
communication, this function issues reset commands to the mouse each time it is invoked, until it receives a valid
response from the re-connected mouse. MouseConnectTask relies on the helper function mouse_1ms_int , which is
called from the 1msec ISR to monitor the elapsed time between mouse transactions. If the mouse is unplugged in the
middle of a transaction, this routine will flag a timeout, thus resetting the bit-level state machine in mouse_int so that a
fresh command can be re-initiated.
Support for periodic data collection from the mouse. The reference firmware calls the function MouseTask at 4 msec
intervals, to solicit a data packet from the mouse. This received packet is placed the data in endpoint 2s data buffer for
eventual transmission to the host.
Support for remote wakeup. Any mouse movement or button press is required to wake up the keyboard from suspend
(in addition to a key press from the keyboard itself or from the resumption of USB bus activity). To accomplish this, the
firmware temporarily places the mouse in data mode by calling mouse_suspend prior to suspending the
microcontroller. In this mode the mouse will automatically report data if its position or buttons change state. This
unsolicited mouse activity will generate a GPIO interrupt, which in turn causes the microcontroller to wake up from
suspend mode and resume operation. The firmware calls mouse_resume to restore the mouse to data polling mode
after returning from a suspend.
PS/2 Interface Reference Firmware
The PS/2 reference firmware is conceptually simple: all tasks are handled sequentially from a main loop. The 1msec ISR
merely increments a count variable to generate gross delays and to time the period between successive keyboard scans.
Since the USB D+ and D- lines are pressed into service as the PS/2 Clock and Data lines, rather than using GPIO lines,
changing the drive state for bit transitions of the PS/2 clock and data must be accomplished by modifying the control bits in
the USB Status and Control register. Remembering that the PS/2 clock and data are open-collector lines, the idle state of
the PS/2 interface is a setting of 111in Control Bits 2~0 of this register, placing both lines at Hi-Z. Neither the clock nor
data line are ever driven high. Each line is always either driven low or pulled high by the pullup resistors on the host. Driving