68
CY4636 WirelessUSB™ LP Keyboard Mouse Reference Design Kit User Guide, Doc. # 001-70355 Rev. *A
Code Examples
■
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 and timer module for more details.
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 hardware 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 would be about 2.5 ms.
Refer to contact-debouncing algorithm emulates Schmitt trigger on
http://www.edn.com
for more
details on the operation of this algorithm.
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 inter-
facing with the radio. The enCoRe III LV SPI Master module does not manage the selection of slave
devices. This module 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.
Radio Driver.
The radio driver module is a low level module providing basic radio communication
and configuration. Its general application is such that it is likely not to be changed by the firmware
developer. It provides an interface for reading/writing radio registers, setting PN codes and initializa-
tion of the radio and transmitting or receiving packets. See the WirelessUSB LP Radio Driver docu-
mentation for details.
Protocol Module.
The protocol module defines and implements the layer used to deliver packets
from the device to the bridge. It manages the binding of devices to a bridge as well as the connection
and interference immunity by channel hopping. This module has a dependency on the radio driver
for sending formatted packets and the flash module for storing the manufacturing ID of the bridge the
device is bound to.
Flash Module.
The flash module is a smaller version of E2PROM module provided in PSoC
Designer. It is limited in functionality and only implements the read/write routines required by the
device. The
flashsecurity.txt
file must be modified so that the block being modified by this module is
given read/write privilege, that is, unprotected. Currently the topmost block in flash is used for this
module.
Port Module.
GPIO pins on the enCoRe III LV microcontroller ports can be configured as outputs
with a pull up resistor. This is the case for mouse buttons and the Bind button. In order to activate the
pull up a data value of one must be written to the port data latch for the pin. This feature presents a
problem when performing a read-modify-write on the port. For example, if a button is pressed
(grounding the pin), a zero would be read and written back out on the read-modify-write operation.
This turns off the pull-up for the button thereby essentially disabling the button. The port module pro-
vides an interface to treat ports, using the pull up feature, in a special way by caching the drive data
for the port.