AN249 Silicon_Laboratories, AN249 Datasheet - Page 32

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
AN249
7.4. IN Report Handler
Since only one input report was defined in the Report Descriptor of this example, only one input report handler is
needed. This report will transfer mouse information stored the global variables Mouse_Button, Mouse_Vector,
and Mouse_Axis to the host.
The function prototype for the Report Handler, called IN_Report(), has been placed in the appropriate spot at
the top of the F3xx_USB0_ReportHandler.c file. IN_VectorTableSize is set to 1. The Report Handler is linked
to a Report ID of 0. In the case where only one report is defined in the Report Descriptor, no Report ID should be
defined, and 0 should be placed in the Report ID field of the Vector Table element.
The IN_Report() body takes the Mouse global variables and stores them in a buffer following the format defined
in the Report Descriptor. Bit 0 of byte 0 of the buffer is set to Mouse_Button state. The report handler examines
Mouse_Axis to determine whether the X-Axis or the Y-Axis is being manipulated, and then sets either byte 1 or
byte 2 of the buffer to Mouse_Vector, depending on whether the X-Axis or the Y-Axis is selected.
IN_Buffer.Ptr is set to the newly formatted buffer, and IN_Buffer.Length is set to “3”, following the Report
Descriptor’s definition of a 3-byte report.
This example does not require the use of any output reports. If it did, the function Setup_OUT_Buffer() would
need to set the OUT_Buffer struct elements so that the firmware would know where to store output reports.
Reports stored in this output buffer would then be processed by defined output report handlers. For an example of
how such a system could look, read the next section that describes the creation of an HID Blinky firmware and
software system.
7.5. Alterations to Main()
The main(void) function of the firmware template requires only a few modifications. After peripheral
initializations, the system enters a while(1) loop. Inside this loop, the SendPacket() function is repeatedly
called, with a Report ID of 0 passed in as the Report to transmit to the host.
SendReport(), a function found in the USB_ISR.c file, checks to see if the IN Endpoint is set to IDLE. If it is not,
meaning that another transfer is already in progress, SendReport exits with an error code of 0. If the IN Endpoint is
set to IDLE, a transmission of the report with ID “0” is initiated.
32
Rev. 0.2

Related parts for AN249