AN249 Silicon_Laboratories, AN249 Datasheet - Page 31

no-image

AN249

Manufacturer Part Number
AN249
Description
Human Interface Device Tutorial
Manufacturer
Silicon_Laboratories
Datasheet

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
AN2490NFHP
Manufacturer:
PANASONIC/松下
Quantity:
20 000
Part Number:
AN2491NFHP
Manufacturer:
PANASON
Quantity:
5 510
Part Number:
AN2491NFHP
Manufacturer:
MAXIM
Quantity:
5 510
These items describe the minimum and maximum values that the following data can take.
These items describe the data that follows as being two bytes (with 8 bits per byte).
This item tells the host about the data’s direction of flow, that the data can change in value, and that it is relative to
some axis. In this case, the data measured relative to the change in mouse position since the last measurement.
This item applies to both bytes of data.
These two items should be considered “closing parentheses” on the above-defined collections. The first End
Collection closes the physical collection containing information about the mouse data point, and the second End
Collection closes the top-level application collection.
7.3. Mouse Emulation Data Sampling
The routines that capture and save mouse-related data are found in the file Mouse.c, and some global variables
are included in the Mouse.h header file. In the C8051F320/1 build, the Mouse.c file contains two routines, the
“Timer 2 ISR” and the “ADC Sample Complete ISR”. In the C8051F326/7 build, the Mouse.c file contains only a
“Timer 2 ISR”.
Initialization routines, as well as port configuration, are also found in the Mouse.c file.
7.3.1. Timer 2 ISR
Once properly configured to overflow and enabled as an interrupt, Timer 2 is used to take readings from the two
switches on the ‘F320 target board. Inside Timer2_ISR(), both switch values are captured by saving the state of
the port pin connected to each switch. Timer overflows allow for switch “debouncing” by comparing switch values
across two consecutive Timer 2 ISR servicings. Switch states are saved in variables of Mouse.c file scope.
In the C8051F326/7 build of the project, the Timer 2 ISR also controls mouse movement by setting the
Mouse_Vector and Mouse_Axis to a pattern that causes the cursor to move on-screen.
7.3.2. Adc_ConvComplete_ISR
In the C8051F320/1 version of the build, the ADC is configured to take samples at the port pin connected to the
potentiometer. The captured value of the potentiometer is translated to relative mouse movement by first
converting the unsigned potentiometer value to a signed character value by subtracting 128. The value is then
divided by 16 to reduce the movement sensitivity of the potentiometer. Dividing by 16 makes cursor movement on-
screen smoother.
At this point, the potentiometer value has been centered around 0 and reduced so that the maximum value is
128/16 = 8. This value is then saved as relative X- or Y- Axis movement, depending on whether X-Axis or Y-Axis
movement is selected. Axis selection is accomplished by using one of the switches to toggle between the two axes.
Inside the ADC ISR, variables for the mouse button, mouse vector (relative movement), and active axis are saved
in the global variables Mouse_Button, Mouse_Vector, and Mouse_Axis, respectively. These variables will be
formatted into a report inside the Report Handler, which is discussed in the following section.
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8)
0x95, 0x02, // Report Count (2)
0x81, 0x06, // Input (Data, Variable, Relative)
0xC0,
0xC0
// End Collection (Physical)
// End Collection (Application)
Rev. 0.2
AN249
31

Related parts for AN249