8fdeb064a0a1ac2cd8bcdcd84fb612cc37ca5df5
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / HID.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #ifndef _HID_CLASS_H_
32 #define _HID_CLASS_H_
33
34 /* Includes: */
35 #include "../../USB.h"
36
37 #include <string.h>
38
39 /* Macros: */
40 /** HID Class Specific Request to get the current HID report from the device. */
41 #define REQ_GetReport 0x01
42
43 /** HID Class Specific Request to get the current device idle count. */
44 #define REQ_GetIdle 0x02
45
46 /** HID Class Specific Request to set the current HID report to the device. */
47 #define REQ_SetReport 0x09
48
49 /** HID Class Specific Request to set the device's idle count. */
50 #define REQ_SetIdle 0x0A
51
52 /** HID Class Specific Request to get the current HID report protocol mode. */
53 #define REQ_GetProtocol 0x03
54
55 /** HID Class Specific Request to set the current HID report protocol mode. */
56 #define REQ_SetProtocol 0x0B
57
58 /** Descriptor header type value, to indicate a HID class HID descriptor. */
59 #define DTYPE_HID 0x21
60
61 /** Descriptor header type value, to indicate a HID class HID report descriptor. */
62 #define DTYPE_Report 0x22
63
64 /* Type Defines: */
65 /** Type define for the HID class specific HID descriptor, to describe the HID device's specifications. Refer to the HID
66 * specification for details on the structure elements.
67 */
68 typedef struct
69 {
70 USB_Descriptor_Header_t Header;
71
72 uint16_t HIDSpec;
73 uint8_t CountryCode;
74
75 uint8_t TotalReportDescriptors;
76
77 uint8_t HIDReportType;
78 uint16_t HIDReportLength;
79 } USB_Descriptor_HID_t;
80
81 /** Type define for the data type used to store HID report descriptor elements. */
82 typedef uint8_t USB_Descriptor_HIDReport_Datatype_t;
83
84 /** Class state structure. An instance of this structure should be made for each HID interface
85 * within the user application, and passed to each of the HID class driver functions as the
86 * HIDInterfaceInfo parameter. The contents of this structure should be set to their correct
87 * values when used, or ommitted to force the library to use default values.
88 */
89 typedef struct
90 {
91 uint8_t InterfaceNumber; /**< Interface number of the HID interface within the device */
92
93 uint8_t ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */
94 uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */
95
96 uint8_t ReportOUTEndpointNumber; /**< Endpoint number of the HID interface's OUT report endpoint, if used */
97 uint16_t ReportOUTEndpointSize; /**< Size in bytes of the HID interface's OUT report endpoint, if used */
98
99 uint8_t ReportBufferSize;
100
101 bool UsingReportProtocol; /**< Indicates if the HID interface is set to Boot or Report protocol mode */
102 uint16_t IdleCount; /**< Report idle period, in ms, set by the host */
103 uint16_t IdleMSRemaining; /**< Total number of ms remaining before the idle period elapses */
104 } USB_ClassInfo_HID_t;
105
106 /* Function Prototypes: */
107 bool USB_HID_ConfigureEndpoints(USB_ClassInfo_HID_t* HIDInterfaceInfo);
108 void USB_HID_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo);
109 void USB_HID_RegisterStartOfFrame(USB_ClassInfo_HID_t* HIDInterfaceInfo);
110 void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo);
111
112 uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
113 void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData, uint16_t ReportSize);
114
115 #endif