00d73a9a0e0827878883cf3afd0ad8da85e6113c
[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 /** \ingroup Group_USBClassHID
32 * @defgroup Group_USBClassHIDDevice HID Class Device Mode Driver
33 *
34 * \section Module Description
35 * Device Mode USB Class driver framework interface, for the HID USB Class driver.
36 *
37 * @{
38 */
39
40 #ifndef _HID_CLASS_DEVICE_H_
41 #define _HID_CLASS_DEVICE_H_
42
43 /* Includes: */
44 #include "../../USB.h"
45 #include "../Common/HID.h"
46
47 #include <string.h>
48
49 /* Enable C linkage for C++ Compilers: */
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
53
54 /* Public Interface - May be used in end-application: */
55 /* Type Defines: */
56 /** Configuration information structure for \ref USB_ClassInfo_HID_Device_t HID device interface structures. */
57 typedef struct
58 {
59 uint8_t InterfaceNumber; /**< Interface number of the HID interface within the device */
60
61 uint8_t ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */
62 uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */
63
64 uint8_t ReportINBufferSize; /**< Size of the largest possible report to send to the host, for
65 * buffer allocation purposes
66 */
67 } USB_ClassInfo_HID_Device_Config_t;
68
69 /** Current State information structure for \ref USB_ClassInfo_HID_Device_t HID device interface structures. */
70 typedef struct
71 {
72 bool UsingReportProtocol; /**< Indicates if the HID interface is set to Boot or Report protocol mode */
73 uint16_t IdleCount; /**< Report idle period, in ms, set by the host */
74 uint16_t IdleMSRemaining; /**< Total number of ms remaining before the idle period elapsed - this should be
75 * decremented by the user application if non-zero each millisecond */
76 } USB_ClassInfo_HID_Device_State_t;
77
78 /** Class state structure. An instance of this structure should be made for each HID interface
79 * within the user application, and passed to each of the HID class driver functions as the
80 * HIDInterfaceInfo parameter. This stores each HID interface's configuration and state information.
81 */
82 typedef struct
83 {
84 const USB_ClassInfo_HID_Device_Config_t Config; /**< Config data for the USB class interface within
85 * the device. All elements in this section
86 * <b>must</b> be set or the interface will fail
87 * to enumerate and operate correctly.
88 */
89
90 USB_ClassInfo_HID_Device_State_t State; /**< State data for the USB class interface within
91 * the device. All elements in this section
92 * <b>may</b> be set to initial values, but may
93 * also be ignored to default to sane values when
94 * the interface is enumerated.
95 */
96 } USB_ClassInfo_HID_Device_t;
97
98 /* Function Prototypes: */
99 /** Configures the endpoints of a given HID interface, ready for use. This should be linked to the library
100 * \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration
101 * containing the given HID interface is selected.
102 *
103 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
104 *
105 * \return Boolean true if the endpoints were sucessfully configured, false otherwise
106 */
107 bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
108
109 /** Processes incomming control requests from the host, that are directed to the given HID class interface. This should be
110 * linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
111 *
112 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
113 */
114 void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
115
116 /** General management task for a given HID class interface, required for the correct operation of the interface. This should
117 * be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
118 *
119 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
120 */
121 void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
122
123 /** HID class driver callback for the user creation of a HID input report. This callback may fire in response to either
124 * HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback the
125 * user is responsible for the creation of the next HID input report to be sent to the host.
126 *
127 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
128 * \param ReportID If preset to a non-zero value, this is the report ID being requested by the host. If zero, this should
129 * be set to the report ID of the generated HID input report. If multiple reports are not sent via the
130 * given HID interface, this parameter should be ignored.
131 * \param ReportData Pointer to a buffer where the generated HID report should be stored.
132 *
133 * \return Number of bytes in the generated input report, or zero if no report is to be sent
134 */
135 uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
136
137 /** HID class driver callback for the user processing of a received HID input report. This callback may fire in response to
138 * either HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback
139 * the user is responsible for the processing of the received HID output report from the host.
140 *
141 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
142 * \param ReportID Report ID of the received output report. If multiple reports are not received via the given HID
143 * interface, this parameter should be ignored.
144 * \param ReportData Pointer to a buffer where the received HID report is stored.
145 * \param ReportSize Size in bytes of the received report from the host.
146 */
147 void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID, void* ReportData,
148 uint16_t ReportSize);
149
150 /* Disable C linkage for C++ Compilers: */
151 #if defined(__cplusplus)
152 }
153 #endif
154
155 #endif
156
157 /** @} */