AN249 Silicon_Laboratories, AN249 Datasheet - Page 37

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
The rest of the Report Descriptor is composed of similarly worded information describing each report used in this
example. Each Report description begins with a Report ID, which is defined in the F3xx_Blink_Control.h file. The
next item tells the number of data items contained in this particular report. This value is also defined in the
F3xx_Blink_Control.h file. The next item tells the host that each data item will be 1 byte in size. The two next items
indicate that these data bytes can contain any value from 0 to 0xFF. The Usage item tags the data that follows as
vendor-defined with the same Usage as the rest of the data. The last item of each report description tells the host
whether data contained in this report is input or output.
8.2.2. Data Capture and Processing Routines
The data capture and storage of this system takes place inside the BlinkControl.c file and its associated header file
F3xx_Blink_Control.h. In the C8051F320/1 and C8051F34x versions of the build, the potentiometer’s value is
captured by saving the high byte of the ADC0 during an ADC Complete ISR servicing. In the C8051F326/7 version
of the build, switch 1’s state is saved instead. This value is sent to the host program, which uses it to select a
blinking pattern. Effectively, the user will be able to scroll through LED lighting sequence choices on-screen using
the potentiometer.
To optimize USB bandwidth usage, the firmware system transmits a report containing the potentiometer’s value
only if the value has changed since the last transmitted report. The ADC ISR sets a global variable called
Blink_SelectorUpdate whenever the new ADC value does not match the next value. The firmware system’s
foreground while(1) loop polls Blink_SelectorUpdate and when it finds the variable set, the foreground
initiates a transfer of potentiometer information.
The host application transmits the lighting pattern, and the device saves this pattern in the Blink_Pattern array.
The host transmits a blinking rate to the device and the device saves it to variable Blink_Rate. For a detailed
discussion on these data transfers, read the next subsection.
The firmware system configures Timer 0 ISR to interrupt at a rate of 0.5 ms. Inside the ISR, Blink_Rate
multiplies this interrupt rate by being used in a comparison with a counter that is incremented once every interrupt
servicing. For example, if Blink_Rate is equal to 2000, the LED pattern will be updated at a rate of 0.5 ms x 2000
or 1 s.
The Timer 0 ISR measures the percentage of time each LED is active during the sequence. The ISR stores these
measurements in the global variables Blink_Led1Active and Blink_Led2Active. The host has access to
these variables through the use of the Control data pipe.
The Timer 0 ISR updates the lighting pattern by checking the lower two bits of an element of the Blink_Pattern
array, where bit 0 controls Led1 and bit 1 controls Led2. The ISR increments an index variable used to access the
Blink_Pattern array after every LED pattern update. When the element selected by the incremented index
equals 0xFF, the index is reset to 0 and the pattern repeats.
8.2.3. Report Handler Creation
The five reports defined in the Report Descriptor each need a Report Handler. Prototypes for each handler have
been added to the F3xx_USB0_ReportHandler.c file as follows:
Each of these functions corresponds to one of the reports. The IN and OUT Vector tables establish a link between
these handlers and their associated reports.
void IN_Blink_Selector(void);
void OUT_Blink_Enable(void);
void OUT_Blink_Pattern(void);
void OUT_Blink_Rate(void);
void IN_Blink_Stats(void);
void FEATURE_Blink_Dimmer_Input(void);
void FEATURE_Blink_Dimmer_Output(void);
Rev. 0.2
AN249
37

Related parts for AN249