72
CY4636 WirelessUSB™ LP Keyboard Mouse Reference Design Kit User Guide, Doc. # 001-70355 Rev. *A
Code Examples
When the macro DEBUG_INDEX is defined, code is generated to move the mouse pointer to the
right and back again without the pen down. This is done in an incrementing fashion so that when
observing packet data on a Listener, a correlation can be made with a USB protocol analyzer. This is
useful for debugging data loss since the test mode guarantees packet delivery.
Entry to this test mode can be changed by modifying the macro TESTMODE_BUTTONS in the test-
mode c file. The button macros are defined in the buttons.h file.
Buttons Module.
The buttons module provides an API for handling the Bind button and the mouse
buttons. This module must be changed when adding or removing buttons for a new mouse design.
The button portion of the packet payload is formatted by this module and will need to change if more
buttons are added.
See the mouse module for a definition of the packet payload format.
This module manages power configurations that may be implemented to conserve power related to
button presses. For example, button polling is turned off and interrupts are used to detect button
presses in the idle state. It also manages the acquisition of button information depending on the
implementation: interrupts or polling.
When changes in button state are detected, the mouse module is notified for collection and reporting
of the data. Note: it is important for the buttons module to always report the button state when a but-
ton is pressed. This condition frequently occurs when the mouse is moved with the button held
down.
Mfgtest Module.
The manufacturing test module may be optionally compiled in, at the expense of
code space, by defining the macro MFG_TEST_CODE. In addition, a more complete version may be
compiled in by defining MFG_TX_MODES. The TX modes include code to perform a carrier test as
well as a random data test.
The manufacturing test code is designed to be compatible with the CY3631 Manufacturing Test Kit
Tester. Entry into this mode on the mouse is performed by placing a shorting block over pins four and
five of the ISSP programming header and then inserting the batteries. The test mode may only be
exited by removing the batteries and shorting block. For more information on how to use this test
mode, refer to the CY3631 Manufacturing Test Kit documentation. It is recommended that you not
make changes to this module unless similar changes are made to the CY3631 Tester.
Wheel Module.
The wheel module implements the functionality of the z-wheel. It is responsible for
power modes associated with the z-wheel, polling, z-wheel interrupts, wheel position tracking, and
partial packet formatting for z-wheel reports.
When the z-wheel is being polled, the GPIO pins are turned on with internal pull up resistors just
long enough to read the state. This is done to conserve power when the mouse is active. When the
polling timer has been turned off the wheel_poll_sleep() function is called which only looks for
change from the last state; it does not keep track of wheel position.
Z-wheel position tracking is done by comparing debounced wheel input to the previous two states.
Depending upon the wheel input phase transition the direction of the wheel can be determined. The
poll rate must be frequent enough to debounce and catch these transitions for a smooth response.
The RDK mouse is shipped with a mechanical encoder. It is typical for this decoder to rest on a
detent such that the z-wheel inputs are either both high or both low, hence the reason for only turning
on the pull ups when polling the input. Transition from one of these states to the other is reported as
a +/-1 motion. Note: sometimes the mechanical detents don't align with the high-high or low-low
state and movement may not be seen every time from detent to detent. When z-wheel motion is
detected, the mouse module is notified for collection and reporting of the data.