Move Set Feature and Clear Feature control request feature selector values into their...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Common / HID.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all 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 /** \file
32 * \brief Common definitions and declarations for the library USB HID Class driver.
33 *
34 * Common definitions and declarations for the library USB HID Class driver.
35 *
36 * \note This file should not be included directly. It is automatically included as needed by the USB module driver
37 * dispatch header located in LUFA/Drivers/USB.h.
38 */
39
40 /** \ingroup Group_USBClassHID
41 * @defgroup Group_USBClassHIDCommon Common Class Definitions
42 *
43 * \section Module Description
44 * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
45 * HID Class.
46 *
47 * @{
48 */
49
50 #ifndef _HID_CLASS_COMMON_H_
51 #define _HID_CLASS_COMMON_H_
52
53 /* Includes: */
54 #include "../../HighLevel/StdDescriptors.h"
55
56 #include <string.h>
57
58 /* Preprocessor Checks: */
59 #if !defined(__INCLUDE_FROM_HID_DRIVER)
60 #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
61 #endif
62
63 /* Macros: */
64 /** \name Keyboard Standard Report Modifier Masks */
65 //@{
66 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left control key is currently pressed. */
67 #define HID_KEYBOARD_MODIFER_LEFTCTRL (1 << 0)
68
69 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left shift key is currently pressed. */
70 #define HID_KEYBOARD_MODIFER_LEFTSHIFT (1 << 1)
71
72 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left alt key is currently pressed. */
73 #define HID_KEYBOARD_MODIFER_LEFTALT (1 << 2)
74
75 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left GUI key is currently pressed. */
76 #define HID_KEYBOARD_MODIFER_LEFTGUI (1 << 3)
77
78 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right control key is currently pressed. */
79 #define HID_KEYBOARD_MODIFER_RIGHTCTRL (1 << 4)
80
81 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right shift key is currently pressed. */
82 #define HID_KEYBOARD_MODIFER_RIGHTSHIFT (1 << 5)
83
84 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right alt key is currently pressed. */
85 #define HID_KEYBOARD_MODIFER_RIGHTALT (1 << 6)
86
87 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right GUI key is currently pressed. */
88 #define HID_KEYBOARD_MODIFER_RIGHTGUI (1 << 7)
89 //@}
90
91 /** \name Keyboard Standard Report LED Masks */
92 //@{
93 /** Constant for a keyboard output report LED byte, indicating that the host's NUM LOCK mode is currently set. */
94 #define HID_KEYBOARD_LED_NUMLOCK (1 << 0)
95
96 /** Constant for a keyboard output report LED byte, indicating that the host's CAPS LOCK mode is currently set. */
97 #define HID_KEYBOARD_LED_CAPSLOCK (1 << 1)
98
99 /** Constant for a keyboard output report LED byte, indicating that the host's SCROLL LOCK mode is currently set. */
100 #define HID_KEYBOARD_LED_SCROLLLOCK (1 << 2)
101
102 /** Constant for a keyboard output report LED byte, indicating that the host's KATANA mode is currently set. */
103 #define HID_KEYBOARD_LED_KATANA (1 << 3)
104 //@}
105
106 /* Type Defines: */
107 /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the HID
108 * device class.
109 */
110 enum HID_Descriptor_ClassSubclassProtocol_t
111 {
112 HID_CSCP_HIDClass = 0x03, /**< Descriptor Class value indicating that the device or interface
113 * belongs to the HID class.
114 */
115 HID_CSCP_NonBootSubclass = 0x00, /**< Descriptor Subclass value indicating that the device or interface
116 * does not implement a HID boot protocol.
117 */
118 HID_CSCP_BootSubclass = 0x01, /**< Descriptor Subclass value indicating that the device or interface
119 * implements a HID boot protocol.
120 */
121 HID_CSCP_NonBootProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
122 * does not belong to a HID boot protocol.
123 */
124 HID_CSCP_KeyboardBootProtocol = 0x01, /**< Descriptor Protocol value indicating that the device or interface
125 * belongs to the Keyboard HID boot protocol.
126 */
127 HID_CSCP_MouseBootProtocol = 0x02, /**< Descriptor Protocol value indicating that the device or interface
128 * belongs to the Mouse HID boot protocol.
129 */
130 };
131
132 /** Enum for the HID class specific control requests that can be issued by the USB bus host. */
133 enum HID_ClassRequests_t
134 {
135 HID_REQ_GetReport = 0x01, /**< HID class-specific Request to get the current HID report from the device. */
136 HID_REQ_GetIdle = 0x02, /**< HID class-specific Request to get the current device idle count. */
137 HID_REQ_SetReport = 0x09, /**< HID class-specific Request to set the current HID report to the device. */
138 HID_REQ_SetIdle = 0x0A, /**< HID class-specific Request to set the device's idle count. */
139 HID_REQ_GetProtocol = 0x03, /**< HID class-specific Request to get the current HID report protocol mode. */
140 HID_REQ_SetProtocol = 0x0B, /**< HID class-specific Request to set the current HID report protocol mode. */
141 };
142
143 /** Enum for the HID class specific descriptor types. */
144 enum HID_DescriptorTypes_t
145 {
146 HID_DTYPE_HID = 0x21, /**< Descriptor header type value, to indicate a HID class HID descriptor. */
147 HID_DTYPE_Report = 0x22, /**< Descriptor header type value, to indicate a HID class HID report descriptor. */
148 };
149
150 /** Enum for the different types of HID reports. */
151 enum HID_ReportItemTypes_t
152 {
153 HID_REPORT_ITEM_In = 0, /**< Indicates that the item is an IN report type. */
154 HID_REPORT_ITEM_Out = 1, /**< Indicates that the item is an OUT report type. */
155 HID_REPORT_ITEM_Feature = 2, /**< Indicates that the item is a FEATURE report type. */
156 };
157
158 /** \brief HID class-specific HID Descriptor (LUFA naming conventions).
159 *
160 * Type define for the HID class-specific HID descriptor, to describe the HID device's specifications. Refer to the HID
161 * specification for details on the structure elements.
162 *
163 * \see \ref USB_HID_StdDescriptor_HID_t for the version of this type with standard element names.
164 */
165 typedef struct
166 {
167 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
168
169 uint16_t HIDSpec; /**< BCD encoded version that the HID descriptor and device complies to. */
170 uint8_t CountryCode; /**< Country code of the localized device, or zero if universal. */
171
172 uint8_t TotalReportDescriptors; /**< Total number of HID report descriptors for the interface. */
173
174 uint8_t HIDReportType; /**< Type of HID report, set to \ref HID_DTYPE_Report. */
175 uint16_t HIDReportLength; /**< Length of the associated HID report descriptor, in bytes. */
176 } USB_HID_Descriptor_HID_t;
177
178 /** \brief HID class-specific HID Descriptor (USB-IF naming conventions).
179 *
180 * Type define for the HID class-specific HID descriptor, to describe the HID device's specifications. Refer to the HID
181 * specification for details on the structure elements.
182 *
183 * \see \ref USB_HID_Descriptor_HID_t for the version of this type with non-standard LUFA specific
184 * element names.
185 */
186 typedef struct
187 {
188 uint8_t bLength; /**< Size of the descriptor, in bytes. */
189 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
190 * given by the specific class.
191 */
192
193 uint16_t bcdHID; /**< BCD encoded version that the HID descriptor and device complies to. */
194 uint8_t bCountryCode; /**< Country code of the localized device, or zero if universal. */
195
196 uint8_t bNumDescriptors; /**< Total number of HID report descriptors for the interface. */
197
198 uint8_t bDescriptorType2; /**< Type of HID report, set to \ref HID_DTYPE_Report. */
199 uint16_t wDescriptorLength; /**< Length of the associated HID report descriptor, in bytes. */
200 } USB_HID_StdDescriptor_HID_t;
201
202 /** \brief Standard HID Boot Protocol Mouse Report.
203 *
204 * Type define for a standard Boot Protocol Mouse report
205 */
206 typedef struct
207 {
208 uint8_t Button; /**< Button mask for currently pressed buttons in the mouse. */
209 int8_t X; /**< Current delta X movement of the mouse. */
210 int8_t Y; /**< Current delta Y movement on the mouse. */
211 } USB_MouseReport_Data_t;
212
213 /** \brief Standard HID Boot Protocol Keyboard Report.
214 *
215 * Type define for a standard Boot Protocol Keyboard report
216 */
217 typedef struct
218 {
219 uint8_t Modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of
220 * HID_KEYBOARD_MODIFER_* masks).
221 */
222 uint8_t Reserved; /**< Reserved for OEM use, always set to 0. */
223 uint8_t KeyCode[6]; /**< Key codes of the currently pressed keys. */
224 } USB_KeyboardReport_Data_t;
225
226 /** Type define for the data type used to store HID report descriptor elements. */
227 typedef uint8_t USB_Descriptor_HIDReport_Datatype_t;
228
229 #endif
230
231 /** @} */
232