Break device mode class driver interfaces into seperate config and state structs...
[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 elapses */
75 } USB_ClassInfo_HID_Device_State_t;
76
77 /** Class state structure. An instance of this structure should be made for each HID interface
78 * within the user application, and passed to each of the HID class driver functions as the
79 * HIDInterfaceInfo parameter. This stores each HID interface's configuration and state information.
80 */
81 typedef struct
82 {
83 const USB_ClassInfo_HID_Device_Config_t Config; /**< Config data for the USB class interface within
84 * the device. All elements in this section
85 * <b>must</b> be set or the interface will fail
86 * to enumerate and operate correctly.
87 */
88
89 USB_ClassInfo_HID_Device_State_t State; /**< State data for the USB class interface within
90 * the device. All elements in this section
91 * <b>may</b> be set to initial values, but may
92 * also be ignored to default to sane values when
93 * the interface is enumerated.
94 */
95 } USB_ClassInfo_HID_Device_t;
96
97 /* Function Prototypes: */
98 /** Configures the endpoints of a given HID interface, ready for use. This should be linked to the library
99 * \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration
100 * containing the given HID interface is selected.
101 *
102 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
103 *
104 * \return Boolean true if the endpoints were sucessfully configured, false otherwise
105 */
106 bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
107
108 /** Processes incomming control requests from the host, that are directed to the given HID class interface. This should be
109 * linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
110 *
111 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
112 */
113 void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
114
115 /** General management task for a given HID class interface, required for the correct operation of the interface. This should
116 * be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
117 *
118 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
119 */
120 void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
121
122 /** HID class driver callback for the user creation of a HID input report. This callback may fire in response to either
123 * HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback the
124 * user is responsible for the creation of the next HID input report to be sent to the host.
125 *
126 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
127 * \param ReportID If preset to a non-zero value, this is the report ID being requested by the host. If zero, this should
128 * be set to the report ID of the generated HID input report. If multiple reports are not sent via the
129 * given HID interface, this parameter should be ignored.
130 * \param ReportData Pointer to a buffer where the generated HID report should be stored.
131 *
132 * \return Number of bytes in the generated input report, or zero if no report is to be sent
133 */
134 uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
135
136 /** HID class driver callback for the user processing of a received HID input report. This callback may fire in response to
137 * either HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback
138 * the user is responsible for the processing of the received HID output report from the host.
139 *
140 * \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
141 * \param ReportID Report ID of the received output report. If multiple reports are not received via the given HID
142 * interface, this parameter should be ignored.
143 * \param ReportData Pointer to a buffer where the received HID report is stored.
144 * \param ReportSize Size in bytes of the received report from the host.
145 */
146 void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID, void* ReportData,
147 uint16_t ReportSize);
148
149 /* Disable C linkage for C++ Compilers: */
150 #if defined(__cplusplus)
151 }
152 #endif
153
154 #endif
155
156 /** @} */