CY4636 WirelessUSB™ LP Keyboard Mouse Reference Design Kit User Guide, Doc. # 001-70355 Rev. *A
69
Code Examples
Poll Module.
The poll module manages the timing, enabling/disabling and polling of the mouse but-
tons and zwheel inputs. When the mouse is active, polling is enabled and occurs at a rate of about
250 µs for the z-wheel (see the timer module) and a rate of about 3 ms for the mouse buttons. When
the mouse is inactive, the buttons are changed to interrupt mode and the z-wheel is polled for
change only when the sleep timer expires; see button/wheel modules.
Timer Module.
The enCoRe III LV has an ILO that is used for generating a clock to a PWM User
Module. This clock is affected by voltage and temperature and may drift over time. This module pro-
vides an interface to periodically calibrate the PWM to the system clock. The PWM period is cali-
brated to be approximately 250 µs. Care must be taken when changing this period since the poll/
debounce modules are coupled to this time value. Calibration of the ILO is done by placing it in a sin-
gle power mode. Since the ILO configuration register is read-only, the fastest frequency is set for a
more precise calibration. Typical frequencies tend to be in the 90-100 kHz range. Because the ILO is
adjusted this way, it also affects the sleep timer. Setting the sleep timer to 1 second in the device edi-
tor actually results in a sleep timeout in the order of one quarter of a second.
The timer module also provides a set of functions for performing busy waits in the microsecond res-
olution. For more coarse timing requirements an API is provided for millisecond delays. The millisec-
ond delay routines should be used as often as possible to provide for better power consumption
since the microcontroller sleep feature is used. When polling is enabled, it is performed as a back-
ground task during the millisecond delay.
This module also adjusts the tick advancement based upon the sleep resolution selected as a global
parameter in the Device Editor when the timer is disabled. Turning off the timer provides for more
power savings, yet a sense of time is still preserved for non critical timing.
Note:
When using the ICE-Cube, define the macro PSOC_ICE so that busy waits are used instead
of the sleep instruction. Using the sleep instruction with the ICE-Cube generates errors due to syn-
chronization issues between the OCD part and the emulator.
ISR Module.
This module provides an interface to enable/disable individual GPIO interrupts. It also
provides the top level GPIO interrupt handler for the application. It does not handle User Module
specific interrupts; those are handled by specific routines provided in each module.
Due to compiler inefficiencies and the desire to maintain modularity with interrupt handlers, the top
level handler isr_gpio() calls a routine in the GPIO interrupt User Module. The parameter passed is a
pointer to another C function that has been declared as an interrupt handler. This is done in order to
preserve the registers used in the handler. The gpio_isr_redirector() function manipulates the stack,
preparing it for the interrupt handler being called. The rule is that the module routine being called
may not call any other functions and it must be declared with the #pragma interrupt_handler. For
example, the interrupt handler in the optical module to handle detection of optical motion does not
call any other C functions. Instead, it uses a macro provided by the mouse module to post an event
flag. See the optical/mouse modules. This method prevents the compiler from pushing all of its vir-
tual registers onto the stack when a function is called at interrupt context.