HID.h 8.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
             LUFA Library
     Copyright (C) Dean Camera, 2009.
              
  dean [at] fourwalledcubicle [dot] com
      www.fourwalledcubicle.com
*/

/*
  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)

  Permission to use, copy, modify, and distribute this software
  and its documentation for any purpose and without fee is hereby
  granted, provided that the above copyright notice appear in all
  copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaim all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

31
32
/** \ingroup Group_USBClassHID
 *  @defgroup Group_USBClassHIDDevice HID Class Device Mode Driver
33
 *
34
35
36
37
 *  \section Sec_Dependencies Module Source Dependencies
 *  The following files must be built with any user project that uses this module:
 *    - LUFA/Drivers/USB/Class/Device/HID.c
 *
38
 *  \section Module Description
39
 *  Device Mode USB Class driver framework interface, for the HID USB Class driver.
40
41
42
43
 *
 *  @{
 */
 
44
45
#ifndef _HID_CLASS_DEVICE_H_
#define _HID_CLASS_DEVICE_H_
46
47
48

	/* Includes: */
		#include "../../USB.h"
49
		#include "../Common/HID.h"
50
51
52

		#include <string.h>

53
54
55
56
57
	/* Enable C linkage for C++ Compilers: */
		#if defined(__cplusplus)
			extern "C" {
		#endif

58
	/* Public Interface - May be used in end-application: */
59
60
61
62
63
64
65
66
67
68
69
		/* Macros: */
			#if !defined(HID_MAX_REPORT_SIZE)
				/** Maximum size of an IN report which can be generated by the device and sent to the host, in bytes.
				 *
				 *  \note If larger reports than the default specified here are to be generated by the device, this
				 *        value can be overridden by defining this token to the required value in the project makefile
				 *        and passing it to the compiler via the -D switch.
				 */
				#define HID_MAX_REPORT_SIZE     16
			#endif
	
70
71
72
73
74
75
76
		/* Type Defines: */
			/** Class state structure. An instance of this structure should be made for each HID interface
			 *  within the user application, and passed to each of the HID class driver functions as the
			 *  HIDInterfaceInfo parameter. This stores each HID interface's configuration and state information.
			 */
			typedef struct
			{
77
78
79
80
81
				const struct
				{
					uint8_t  InterfaceNumber; /**< Interface number of the HID interface within the device */

					uint8_t  ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */
82
					uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */					
83
84
85
86
87
88
				} Config; /**< Config data for the USB class interface within the device. All elements in this section
				           *   <b>must</b> be set or the interface will fail to enumerate and operate correctly.
				           */										 
				struct
				{
					bool     UsingReportProtocol; /**< Indicates if the HID interface is set to Boot or Report protocol mode */
89
90
					uint16_t IdleCount; /**< Report idle period, in mS, set by the host */
					uint16_t IdleMSRemaining; /**< Total number of mS remaining before the idle period elapsed - this should be
91
92
93
											   *   decremented by the user application if non-zero each millisecond */	

					uint8_t PreviousReportINData[HID_MAX_REPORT_SIZE]; /**< Previously generated report from the HID interface */
94
				} State; /**< State data for the USB class interface within the device. All elements in this section
95
				          *   are reset to their defaults when the interface is enumerated.
96
				          */
97
98
			} USB_ClassInfo_HID_Device_t;
	
99
100
101
102
103
		/* Function Prototypes: */
			/** Configures the endpoints of a given HID interface, ready for use. This should be linked to the library
			 *  \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration
			 *  containing the given HID interface is selected.
			 *
104
			 *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.
105
106
107
			 *
			 *  \return Boolean true if the endpoints were sucessfully configured, false otherwise
			 */
108
			bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
109
110
111
112
			
			/** Processes incomming control requests from the host, that are directed to the given HID class interface. This should be
			 *  linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
			 *
113
			 *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.
114
			 */		
115
			void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
116

117
118
119
			/** General management task for a given HID class interface, required for the correct operation of the interface. This should
			 *  be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
			 *
120
			 *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.
121
			 */
122
			void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
123
			
124
125
126
127
128
129
130
			/** Indicates that a millisecond of idle time has elapsed on the given HID interface, and the interface's idle count should be
			 *  decremented. This should be called once per millisecond so that hardware key-repeats function correctly.
			 *
			 *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.
			 */
			void HID_Device_MillisecondElapsed(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
			
131
132
133
134
			/** HID class driver callback for the user creation of a HID input report. This callback may fire in response to either
			 *  HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback the
			 *  user is responsible for the creation of the next HID input report to be sent to the host.
			 *
135
136
137
138
139
			 *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.
			 *  \param[in,out] ReportID  If preset to a non-zero value, this is the report ID being requested by the host. If zero, this should
			 *                 be set to the report ID of the generated HID input report. If multiple reports are not sent via the
			 *                 given HID interface, this parameter should be ignored.
			 *  \param[out] ReportData  Pointer to a buffer where the generated HID report should be stored.
140
141
142
			 *
			 *  \return  Number of bytes in the generated input report, or zero if no report is to be sent
			 */
143
			uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
144

145
146
147
148
			/** HID class driver callback for the user processing of a received HID input report. This callback may fire in response to
			 *  either HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback
			 *  the user is responsible for the processing of the received HID output report from the host.
			 *
149
150
			 *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.
			 *  \param[in] ReportID  Report ID of the received output report. If multiple reports are not received via the given HID
151
			 *                   interface, this parameter should be ignored.
152
153
			 *  \param[in] ReportData  Pointer to a buffer where the received HID report is stored.
			 *  \param[in] ReportSize  Size in bytes of the received report from the host.
154
			 */
155
156
			void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID,
			                                          const void* ReportData, const uint16_t ReportSize);
157

158
159
160
161
162
	/* Disable C linkage for C++ Compilers: */
		#if defined(__cplusplus)
			}
		#endif
		
163
#endif
164
165

/** @} */