User manual

40 CY4672 Reference Design Guide, Document # 001-16968 Revision **
Mouse
The mouse firmware is partitioned into two logical groups. The Common group is a collection of code
modules that provide the underlying support for the application. This group provides services such
as radio protocol, radio driver, timing, polling, flash access, contact debounce, SPI, and interrupts.
The Application group implements the core functionality and features of the PRoC LP RDK mouse.
This includes power management, optical sensor, button, z-wheel, packet formatting and reporting,
various test modes and battery level sensing. The code modules for each of these groups are
described below in further detail.
All of the following module descriptions have corresponding <module name>.c or <module
name>.asm and <module name>.h source code files. The module API and definitions are exported
in the header file while the module implementation and local definitions are contained in the C/
assembly file.
3.3.4 Common Code
The modules in the common code group are a combination of two sources. The first is PSoC
Designer generated files in the
lib directory that have been modified to support the application. The
second group is modules that are generally used by the application.
3.3.4.1 Generated Library Code
There is currently only one file, generated by PSoC Designer, that is modified for the use of the
application. A minimal amount of code has been added to this module in user protected areas that
are preserved across code generation.
3.3.4.1.1 Timer Interrupt Module
The timer interrupt module has been modified to provide a finer timing of 250 µs for the Poll Module
and course timing by providing a 1 ms tick. When the timer module has been turned off, it still pro-
vides a sense of time on the 1 ms tick by using the sleep timer. In this case polling is disabled to con-
serve power. See the Poll Module on page 41 and the Timer Module on page 41 for more details.
3.3.4.2 Debounce Module
The debounce module is an assembly coded routine to perform debounce on button presses as well
as z-wheel motion. The algorithm is one that was published in EDN article as a way to perform hard-
ware debounce in software.
The debounce is performed by polling the inputs at a fixed period and by adding a weighted value of
the input to an accumulated value carried from the previous poll. The output is then passed to
threshold logic, with built in hysteresis, and a logic value of one or zero is computed. The thresholds
can be changed to adjust the hysteresis crossings by setting SCHMITT_HIGH_THRESH and
SCHMITT_LOW_THRESH. Once an input has changed state, the output can be observed to
change approximately 10x the poll period later with the current threshold settings. With a poll period
of 250 µs the input latency is about 2.5 ms.
Refer to
Contact-debouncing algorithm emulates Schmitt trigger at http://www.edn.com for more
details on the operation of this algorithm.
3.3.4.3 SPI Module
This module provides an interface to the SPI bus for the optical sensor only. Physically the SPI bus is
connected to the radio and the optical sensor. The radio driver is responsible for interfacing with the
radio. The PRoC LP SPI Master module does not manage the selection of slave devices. This mod-
ule was created to provide that functionality. This module has a dependency on the instantiation of a
SPIM module in PSoC Designer that is properly connected to the devices.
[+] Feedback