1
0

usb_hid.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers
  2. *
  3. * Copyright ©2016 Dmitry Filimonchuk <dmitrystu[at]gmail[dot]com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _USB_HID_H_
  16. #define _USB_HID_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**\addtogroup USB_HID USB HID class
  21. * \brief This module contains USB Human Interface Devices class definitions
  22. * \details This module based on
  23. * + [Device Class Definition for Human Interface Devices (HID) Version 1.11](https://www.usb.org/sites/default/files/documents/hid1_11.pdf)
  24. * + [LUFA - the Lightweight USB Framework for AVRs.](https://github.com/abcminiuser/lufa)
  25. *
  26. * \par Control usage types
  27. * Type | Logical min | Logical max | Flags | Signal | Operation
  28. *-------------------------|-------------|-------------|---------------------------|--------|----------------
  29. *[LC] Linear control | -1 | 1 | Relative, Preferred state | Edge | Inc / Dec value
  30. * || -Min | Max | Relative, Preferred state | Level | Inc / Dec value by n
  31. * || Min | Max | Absolute, Preferred state | N/A | Absolute value
  32. *[OOC] ON/OFF control | -1 | 1 | Relative, No preferred | Edge | 1 asserts ON; -1 assertsOFF
  33. * || 0 | 1 | Relative, Preferred state | Edge | 0->1 toggles ON/OFF
  34. * || 0 | 1 | Absolute, No preferred | Level | 0 asserts ON; 1 asserts OFF
  35. *[MC] Momentary control | 0 | 1 | Absolute, Preferred state | Level | 0 asserts, 1 deasserts condition
  36. *[OSC] One shot control | 0 | 1 | Relative, Preferred state | Edge | 0->1 triggers an event
  37. *[RTC] Re-trigger control | 0 | 1 | Absolute, Preferred state | Level | 1 trigger an event
  38. *
  39. *\par Data usage types
  40. *Type | Flgs | Description
  41. *-------------------|------------------------------|------------------------
  42. *[SEL] Selector | Array | Contained a Named Array
  43. *[SV] Static value | Constant, Variable, Absolute | Read-only multiple-bit value
  44. *[SF] Static flag | Constant, Variable, Absolute | Read-only single-bit value
  45. *[DV] Dynamic value | Data, Variable, Absolute | Read-write multiple-bit value
  46. *[DF] Dynamic flag | Data, Variable, Absolute | Read-write single-bit value
  47. *
  48. * @{ */
  49. /**\name USB HID class code */
  50. #define USB_CLASS_HID 0x03 /**<\brief Interface belongs to the Human Interface device class.*/
  51. /**\name USB HID subclass codes
  52. * @{ */
  53. #define USB_HID_SUBCLASS_NONBOOT 0x00 /**<\brief Nonboot subclass.*/
  54. #define USB_HID_SUBCLASS_BOOT 0x01 /**<\brief Boot subclass.*/
  55. /** @} */
  56. /**\name USB HID protocol codes
  57. * @{ */
  58. #define USB_HID_PROTO_NONBOOT 0x00 /**<\brief Nonboot protocol.*/
  59. #define USB_HID_PROTO_KEYBOARD 0x01 /**<\brief Keyboard boot protocol.*/
  60. #define USB_HID_PROTO_MOUSE 0x02 /**<\brief Mouse boot protocol.*/
  61. /** @} */
  62. #define USB_HID_REPORT_IN 0x01 /**<\brief Indicates that the item is an IN report type.*/
  63. #define USB_HID_REPORT_OUT 0x02 /**<\brief Indicates that the item is an OUT report type.*/
  64. #define USB_HID_REPORT_FEATURE 0x03 /**<\brief Indicates that the item is a FEATURE report type.*/
  65. /**\name USB HID class-specified requests
  66. * @{ */
  67. #define USB_HID_GETREPORT 0x01 /**<\brief Request to get the current HID report from the device.*/
  68. #define USB_HID_GETIDLE 0x02 /**<\brief Request to get the current device idle count.*/
  69. #define USB_HID_GETPROTOCOL 0x03 /**<\brief Request to get the current HID report protocol mode.*/
  70. #define USB_HID_SETREPORT 0x09 /**<\brief Request to set the current HID report to the device.*/
  71. #define USB_HID_SETIDLE 0x0A /**<\brief Request to set the device's idle count.*/
  72. #define USB_HID_SETPROTOCOL 0x0B /**<\brief Request to set the current HID report protocol mode.*/
  73. /** @} */
  74. /**\name USB HID class-specified descriptor types
  75. * @{ */
  76. #define USB_DTYPE_HID 0x21 /**<\brief HID class HID descriptor type.*/
  77. #define USB_DTYPE_HID_REPORT 0x22 /**<\brief HID class HID report descriptor type.*/
  78. /** @} */
  79. /**\name USB HID country codes
  80. * @{ */
  81. #define USB_HID_COUNTRY_NONE 0 /**<\brief Not supported */
  82. #define USB_HID_COUNTRY_AR 1 /**<\brief Arabic */
  83. #define USB_HID_COUNTRY_BE 2 /**<\brief Belgian */
  84. #define USB_HID_COUNTRY_CA_BI 3 /**<\brief Canadian-Bilingual */
  85. #define USB_HID_COUNTRY_CA_FR 4 /**<\brief Canadian-French */
  86. #define USB_HID_COUNTRY_CZ 5 /**<\brief Czech Republic */
  87. #define USB_HID_COUNTRY_DK 6 /**<\brief Danish */
  88. #define USB_HID_COUNTRY_FI 7 /**<\brief Finnish */
  89. #define USB_HID_COUNTRY_FR 8 /**<\brief French */
  90. #define USB_HID_COUNTRY_DE 9 /**<\brief German */
  91. #define USB_HID_COUNTRY_GR 10 /**<\brief Greek */
  92. #define USB_HID_COUNTRY_HEB 11 /**<\brief Hebrew */
  93. #define USB_HID_COUNTRY_HU 12 /**<\brief Hungary */
  94. #define USB_HID_COUNTRY_ISO 13 /**<\brief International (ISO) */
  95. #define USB_HID_COUNTRY_IT 14 /**<\brief Italian */
  96. #define USB_HID_COUNTRY_JP 15 /**<\brief Japan (Katakana) */
  97. #define USB_HID_COUNTRY_KR 16 /**<\brief Korean */
  98. #define USB_HID_COUNTRY_LAT 17 /**<\brief Latin American */
  99. #define USB_HID_COUNTRY_NL 18 /**<\brief Netherlands/Dutch */
  100. #define USB_HID_COUNTRY_NO 19 /**<\brief Norwegian */
  101. #define USB_HID_COUNTRY_PER 20 /**<\brief Persian (Farsi) */
  102. #define USB_HID_COUNTRY_PL 21 /**<\brief Poland */
  103. #define USB_HID_COUNTRY_PO 22 /**<\brief Portuguese */
  104. #define USB_HID_COUNTRY_RU 23 /**<\brief Russia */
  105. #define USB_HID_COUNTRY_SK 24 /**<\brief Slovakia */
  106. #define USB_HID_COUNTRY_ES 25 /**<\brief Spanish */
  107. #define USB_HID_COUNTRY_SE 26 /**<\brief Swedish */
  108. #define USB_HID_COUNTRY_CH_FR 26 /**<\brief Swiss-French */
  109. #define USB_HID_COUNTRY_CH_DE 27 /**<\brief Swiss-German */
  110. #define USB_HID_COUNTRY_CH 29 /**<\brief Switzerland */
  111. #define USB_HID_COUNTRY_TW 30 /**<\brief Taiwan */
  112. #define USB_HID_COUNTRY_TR_Q 31 /**<\brief Turkish-Q */
  113. #define USB_HID_COUNTRY_UK 32 /**<\brief United Kingdom */
  114. #define USB_HID_COUNTRY_US 33 /**<\brief United States */
  115. #define USB_HID_COUNTRY_YU 34 /**<\brief Yugoslavia */
  116. #define USB_HID_COUNTRY_TR_F 35 /**<\brief Turkish-F */
  117. /** @} */
  118. /**\name HID Collections types
  119. * @{ */
  120. #define HID_PHYSICAL_COLLECTION 0x00 /**<\brief A physical collection of items.*/
  121. #define HID_APPLICATION_COLLECTION 0x01 /**<\brief Applies a name to a top level collection which the operating
  122. * system uses to identify a device and possibly remap to a legacy API.*/
  123. #define HID_LOGICAL_COLLECTION 0x02 /**<\brief A logical collection of items.*/
  124. #define HID_REPORT_COLLECTION 0x03
  125. #define HID_NARY_COLLECTION 0x04 /**<\brief A collection that encompasses an array definition, naming
  126. * the array set or the field created by the array.*/
  127. #define HID_USAGE_SWITCH_COLLECTION 0x05 /**<\brief Modifies the purpose or function of the usages (controls) that it contains. */
  128. #define HID_USAGE_MODIFIER_COLLECTION 0x06 /**<\brief Modifies the purpose or function of the usages (controls) that contains it.*/
  129. /** @} */
  130. /**\brief USB HID functional descriptor */
  131. struct usb_hid_descriptor {
  132. uint8_t bLength; /**<\brief Size of the descriptor, in bytes. */
  133. uint8_t bDescriptorType; /**<\brief Type of the descriptor, set to \ref USB_DTYPE_HID */
  134. uint16_t bcdHID; /**<\brief BCD encoded version that the HID descriptor and device complies to. */
  135. uint8_t bCountryCode; /**<\brief Country code of the localized device, or zero if universal. */
  136. uint8_t bNumDescriptors; /**<\brief Total number of HID report descriptors for the interface. */
  137. uint8_t bDescriptorType0; /**<\brief 1'st HID report descriptor type, set to \ref USB_DTYPE_HID_REPORT */
  138. uint16_t wDescriptorLength0; /**<\brief 1'sr HID report descriptor length in bytes. */
  139. } __attribute__((packed));
  140. /**\brief USB HID functional descriptor header */
  141. struct usb_hid_descriptor_header {
  142. uint8_t bLength; /**<\brief Size of the descriptor, in bytes. */
  143. uint8_t bDescriptorType; /**<\brief Type of the descriptor, set to \ref USB_DTYPE_HID */
  144. uint16_t bcdHID; /**<\brief BCD encoded version that the HID descriptor and device complies to. */
  145. uint8_t bCountryCode; /**<\brief Country code of the localized device, or zero if universal. */
  146. uint8_t bNumDescriptors; /**<\brief Total number of HID report descriptors for the interface. */
  147. } __attribute__((packed));
  148. /**\brief USB HID report descriptor */
  149. struct usb_hid_report_descriptor {
  150. uint8_t bDescriptorType; /**<\brief Type of HID report, set to \ref USB_DTYPE_HID_REPORT */
  151. uint16_t wDescriptorLength; /**<\brief Length of the associated HID report descriptor, in bytes. */
  152. } __attribute__((packed));
  153. /**\brief Helper macro for the multireport hid descriptor */
  154. #define DECLARE_USB_HID_DESCRIPTOR(p) \
  155. struct usb_hid_descriptor_##p { \
  156. uint8_t bLength; \
  157. uint8_t bDescriptorType; \
  158. uint16_t bcdHID; \
  159. uint8_t bCountryCode; \
  160. uint8_t bNumDescriptors; \
  161. struct usb_hid_report_descriptor report[p]; \
  162. } __attribute__((packed));
  163. /* Private Interface - For use in library only: */
  164. #if !defined(__DOXYGEN__)
  165. /* Macros: */
  166. #define CONCAT(x, y) x ## y
  167. #define CONCAT_EXPANDED(x, y) CONCAT(x, y)
  168. #define HID_RI_DATA_SIZE_MASK 0x03
  169. #define HID_RI_TYPE_MASK 0x0C
  170. #define HID_RI_TAG_MASK 0xF0
  171. #define HID_RI_TYPE_MAIN 0x00
  172. #define HID_RI_TYPE_GLOBAL 0x04
  173. #define HID_RI_TYPE_LOCAL 0x08
  174. #define HID_RI_DATA_BITS_0 0x00
  175. #define HID_RI_DATA_BITS_8 0x01
  176. #define HID_RI_DATA_BITS_16 0x02
  177. #define HID_RI_DATA_BITS_32 0x03
  178. #define HID_RI_DATA_BITS(DataBits) CONCAT_EXPANDED(HID_RI_DATA_BITS_, DataBits)
  179. #define _HID_RI_ENCODE_0(Data)
  180. #define _HID_RI_ENCODE_8(Data) , (Data & 0xFF)
  181. #define _HID_RI_ENCODE_16(Data) _HID_RI_ENCODE_8(Data) _HID_RI_ENCODE_8(Data >> 8)
  182. #define _HID_RI_ENCODE_32(Data) _HID_RI_ENCODE_16(Data) _HID_RI_ENCODE_16(Data >> 16)
  183. #define _HID_RI_ENCODE(DataBits, ...) CONCAT_EXPANDED(_HID_RI_ENCODE_, DataBits(__VA_ARGS__))
  184. #define _HID_RI_ENTRY(Type, Tag, DataBits, ...) (Type | Tag | HID_RI_DATA_BITS(DataBits)) _HID_RI_ENCODE(DataBits, (__VA_ARGS__))
  185. #endif
  186. /* Public Interface - May be used in end-application: */
  187. /* Macros: */
  188. /** \name HID Input, Output and Feature Report Descriptor Item Flags */
  189. //@{
  190. #define HID_IOF_CONSTANT (1 << 0) /**<Item is a static read-only field in a report and cannot be modified.*/
  191. #define HID_IOF_DATA (0 << 0) /**<Item contains a modifiable device data.*/
  192. #define HID_IOF_VARIABLE (1 << 1) /**<Each field represents data from a physical control.*/
  193. #define HID_IOF_ARRAY (0 << 1) /**<Array returns an index in each field that corresponds to the pressed button.*/
  194. #define HID_IOF_RELATIVE (1 << 2) /**<Data is relative (indicating the change in value from the last report).*/
  195. #define HID_IOF_ABSOLUTE (0 << 2) /**<Data is absolute (based on a fixed origin).*/
  196. #define HID_IOF_WRAP (1 << 3) /**<Data “rolls over” when reaching either the extreme high or low value.*/
  197. #define HID_IOF_NO_WRAP (0 << 3) /**<Data not “rolls over” when reaching either the extreme high or low value. */
  198. #define HID_IOF_NON_LINEAR (1 << 4) /**<Noninear relationship between logical and physical units.*/
  199. #define HID_IOF_LINEAR (0 << 4) /**<Linear relationship between logical and physical units.*/
  200. #define HID_IOF_NO_PREFERRED_STATE (1 << 5) /**<Control has no preferred state.*/
  201. #define HID_IOF_PREFERRED_STATE (0 << 5) /**<Control has a preferred state to which it will return when the user is
  202. * not physically interacting with the control. */
  203. #define HID_IOF_NULLSTATE (1 << 6) /**<Control has a state in which it is not sending meaningful data.*/
  204. #define HID_IOF_NO_NULL_POSITION (0 << 6) /**<Control has no nullstate.*/
  205. #define HID_IOF_VOLATILE (1 << 7) /**<Data may be changed by device itself. (Output and Feature) */
  206. #define HID_IOF_NON_VOLATILE (0 << 7) /**<Data can be changed by host only. (Output and Feature) */
  207. #define HID_IOF_BUFFERED_BYTES (1 << 8) /**<Indicates that the control emits a fixed-size stream of bytes.*/
  208. #define HID_IOF_BITFIELD (0 << 8) /**<Data is a fixed bitfield.*/
  209. //@}
  210. /** \name HID Report Descriptor Main items */
  211. //@{
  212. /** Describes information about the data provided by one or more physical controls. */
  213. #define HID_RI_INPUT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0x80, DataBits, __VA_ARGS__)
  214. /** similar to an Input item except it describes data sent to the device—for example, LED states. */
  215. #define HID_RI_OUTPUT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0x90, DataBits, __VA_ARGS__)
  216. /** identifies a relationship between two or more data (Input, Output, or Feature.) */
  217. #define HID_RI_COLLECTION(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0xA0, DataBits, __VA_ARGS__)
  218. /** describe device configuration information that can be sent to the device. */
  219. #define HID_RI_FEATURE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0xB0, DataBits, __VA_ARGS__)
  220. /** closes a collection */
  221. #define HID_RI_END_COLLECTION(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0xC0, DataBits, __VA_ARGS__)
  222. //@}
  223. /** \name HID Report Descriptor Global items */
  224. //@{
  225. /** Unsigned integer specifying the current Usage Page. */
  226. #define HID_RI_USAGE_PAGE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x00, DataBits, __VA_ARGS__)
  227. /** Defines a minimum value that a variable or array item will report. */
  228. #define HID_RI_LOGICAL_MINIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x10, DataBits, __VA_ARGS__)
  229. /** Defines a maximum value that a variable or array item will report. */
  230. #define HID_RI_LOGICAL_MAXIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x20, DataBits, __VA_ARGS__)
  231. /** Defines a minimum value for the physical extent of a variable item */
  232. #define HID_RI_PHYSICAL_MINIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x30, DataBits, __VA_ARGS__)
  233. /** Defines a maximum value for the physical extent of a variable item */
  234. #define HID_RI_PHYSICAL_MAXIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x40, DataBits, __VA_ARGS__)
  235. /** Value of the unit exponent in base 10.
  236. * \note The USB-HID specification is unclear about Unit exponent usage. Practically it's limited by 1 nibble.
  237. */
  238. #define HID_RI_UNIT_EXPONENT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x50, DataBits, __VA_ARGS__)
  239. /** Encoded unit value \see \ref HID_UNITS_ENCODE */
  240. #define HID_RI_UNIT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x60, DataBits, __VA_ARGS__)
  241. /** Unsigned integer specifying the size of the report fields in bits. */
  242. #define HID_RI_REPORT_SIZE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x70, DataBits, __VA_ARGS__)
  243. /** Unsigned value that specifies the Report ID. */
  244. #define HID_RI_REPORT_ID(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x80, DataBits, __VA_ARGS__)
  245. /** Unsigned integer specifying the number of data fields for the item */
  246. #define HID_RI_REPORT_COUNT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x90, DataBits, __VA_ARGS__)
  247. /** Places a copy of the global item state table on the stack. */
  248. #define HID_RI_PUSH(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0xA0, DataBits, __VA_ARGS__)
  249. /** Replaces the item state table with the top structure from the stack. */
  250. #define HID_RI_POP(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0xB0, DataBits, __VA_ARGS__)
  251. //@}
  252. /** \name HID Report Descriptor Local items */
  253. //@{
  254. /** Represents a suggested usage for the item or collection. */
  255. #define HID_RI_USAGE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x00, DataBits, __VA_ARGS__)
  256. /** Defines the starting usage associated with an array or bitmap */
  257. #define HID_RI_USAGE_MINIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x10, DataBits, __VA_ARGS__)
  258. /** Defines the ending usage associated with an array or bitmap. */
  259. #define HID_RI_USAGE_MAXIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x20, DataBits, __VA_ARGS__)
  260. /** Determines the body part used for a control. */
  261. #define HID_RI_DESIGNATOR_INDEX(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x30, DataBits, __VA_ARGS__)
  262. /** Defines the index of the starting designator associated with an array or bitmap. */
  263. #define HID_RI_DESIGNATOR_MIN(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x40, DataBits, __VA_ARGS__)
  264. /** Defines the index of the ending designator associated with an array or bitmap. */
  265. #define HID_RI_DESIGNATOR_MAX(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x50, DataBits, __VA_ARGS__)
  266. /** String index for a String descriptor; allows a string to be associated with a particular item or control. */
  267. #define HID_RI_STRING_INDEX(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x70, DataBits, __VA_ARGS__)
  268. /** Specifies the first string index when assigning a group of sequential strings to controls in an array or bitmap. */
  269. #define HID_RI_STRING_MINIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x80, DataBits, __VA_ARGS__)
  270. /** Specifies the last string index when assigning a group of sequential strings to controls in an array or bitmap. */
  271. #define HID_RI_STRING_MAXIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x90, DataBits, __VA_ARGS__)
  272. /** Defines the beginning or end of a set of local items (1 = open set, 0 = close set). */
  273. #define HID_RI_DELIMITER(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0xA0, DataBits, __VA_ARGS__)
  274. //@}
  275. /** \name HID Report Descriptor for most common cases */
  276. //@{
  277. #define HID_INPUT(data) HID_RI_INPUT(8, data) /**<\copydoc HID_RI_INPUT */
  278. #define HID_OUTPUT(data) HID_RI_OUTPUT(8, data) /**<\copydoc HID_RI_OUTPUT */
  279. #define HID_COLLECTION(data) HID_RI_COLLECTION(8, data) /**<\copydoc HID_RI_COLLECTION */
  280. #define HID_FEATURE(data) HID_RI_FEATURE(8, data) /**<\copydoc HID_RI_FEATURE */
  281. #define HID_END_COLLECTION HID_RI_END_COLLECTION(0) /**<\copydoc HID_RI_END_COLLECTION */
  282. #define HID_USAGE_PAGE(data) HID_RI_USAGE_PAGE(8, data) /**<Range [0; 0xFF]; \copydoc HID_RI_USAGE_PAGE */
  283. #define HID_LOGICAL_MINIMUM(data) HID_RI_LOGICAL_MINIMUM(8, data) /**<Range [-127; 127]; \copydoc HID_RI_LOGICAL_MINIMUM */
  284. #define HID_LOGICAL_MAXIMUM(data) HID_RI_LOGICAL_MAXIMUM(8, data) /**<Range [-127; 127]; \copydoc HID_RI_LOGICAL_MAXIMUM */
  285. #define HID_PHYSICAL_MINIMUM(data) HID_RI_PHYSICAL_MINIMUM(16, data) /**<Range [-32767; 32767]; \copydoc HID_RI_PHYSICAL_MINIMUM */
  286. #define HID_PHYSICAL_MAXIMUM(data) HID_RI_PHYSICAL_MAXIMUM(16, data) /**<Range [-32767; 32767]; \copydoc HID_RI_PHYSICAL_MAXIMUM */
  287. #define HID_UNIT_EXPONENT(data) HID_RI_UNIT_EXPONENT(8, data) /**<Range [-127; 127]; \copydoc HID_RI_UNIT_EXPONENT */
  288. #define HID_UNIT(bits, data) HID_RI_UNIT(bits, data) /**<\copydoc HID_RI_UNIT */
  289. #define HID_REPORT_SIZE(data) HID_RI_REPORT_SIZE(8, data) /**<Range [0; 0xFF]; \copydoc HID_RI_REPORT_SIZE */
  290. #define HID_REPORT_ID(data) HID_RI_REPORT_ID(8, data) /**<Range [0; 0xFF]; \copydoc HID_RI_REPORT_ID */
  291. #define HID_REPORT_COUNT(data) HID_RI_REPORT_COUNT(8, data) /**<Range [0; 0xFF]; \copydoc HID_RI_REPORT_COUNT */
  292. #define HID_PUSH HID_RI_PUSH(0) /**<\copydoc HID_RI_PUSH */
  293. #define HID_POP HID_RI_POP(0) /**<\copydoc HID_RI_POP */
  294. #define HID_USAGE(data) HID_RI_USAGE(8, data) /**<Range [0; 0xFF]; \copydoc HID_RI_USAGE */
  295. #define HID_USAGE_MINIMUM(data) HID_RI_USAGE_MINIMUM(8, data) /**<Range [0; 0xFF]; \copydoc HID_RI_USAGE_MINIMUM */
  296. #define HID_USAGE_MAXIMUM(data) HID_RI_USAGE_MAXIMUM(8, data) /**<Range [0; 0xFF]; \copydoc HID_RI_USAGE_MAXIMUM */
  297. //@}
  298. /**\name Macros for the units encoding
  299. * \anchor HID_UNITS_ENCODE */
  300. //@{
  301. #define HID_UNIT_NONE 0x00 /**<No system. */
  302. #define HID_UNIT_CGS_LINEAR 0x01 /**<Centimeter-Gram-Second metric linear system. \note USB-HID defines this as SI linear.*/
  303. #define HID_UNIT_CGS_ROTATION 0x02 /**<Centimeter-Gram-Second metric rotation system. \note USB-HID defines this as SI rotation.*/
  304. #define HID_UNIT_IMPERIAL_LINEAR 0x03 /**<Imperial linear system.*/
  305. #define HID_UNIT_IMPERIAL_ROTATION 0x04 /**<Imperial rotation system.*/
  306. #define HID_UNIT_LENGTH(exp) ((exp & 0x0F) << 4) /**<Length, position, distance unit. cm (CGS), inch (Imperial) */
  307. #define HID_UNIT_ANGLE(exp) ((exp & 0x0F) << 4) /**<Angle unit. radians(CGS), degree (Imperial) */
  308. #define HID_UNIT_MASS(exp) ((exp & 0x0F) << 8) /**<Mass unit. gram (CGS), slug (Imperial) */
  309. #define HID_UNIT_TIME(exp) ((exp & 0x0F) << 12) /**<Time unit. secound. */
  310. #define HID_UNIT_TEMPERATURE(exp) ((exp & 0x0F) << 16) /**<Temperature unit. Kelvin (CGS), Fahrenheit (Imperial) */
  311. #define HID_UNIT_CURRENT(exp) ((exp & 0x0F) << 20) /**<Current unit. Ampere */
  312. #define HID_UNIT_LUMINOUS(exp) ((exp & 0x0F) << 24) /**<Luminous intensity unit. Candela */
  313. //@}
  314. /**\name Macros for the some SI named units */
  315. //@{
  316. /** SI length. m = 1E2 * cm */
  317. #define HID_UNIT_METER(exp) \
  318. HID_UNIT(8, HID_UNIT_CGS_LINEAR | HID_UNIT_LENGTH(1)), \
  319. HID_UNIT_EXPONENT(exp + 2)
  320. /** SI mass. kg = 1E3 * g */
  321. #define HID_UNIT_KG(exp) \
  322. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1), \
  323. HID_UNIT_EXPONENT(exp + 3)
  324. /** SI time. 1s */
  325. #define HID_UNIT_SECOND(exp) \
  326. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_TIME(1), \
  327. HID_UNIT_EXPONENT(exp + 0)
  328. /** SI velocity. m/s = 1E2 * cm/s */
  329. #define HID_UNIT_MPS(exp) \
  330. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_LENGTH(1) | HID_UNIT_TIME(-1)), \
  331. HID_UNIT_EXPONENT(exp + 2)
  332. /** SI acceleration. m/s^2 = 1E2 * cm/s^2*/
  333. #define HID_UNIT_MPS2(exp) \
  334. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_LENGTH(1) | HID_UNIT_TIME(-2)), \
  335. HID_UNIT_EXPONENT(exp + 2)
  336. /** SI force. N = 1E5 * g * cm / s^2 */
  337. #define HID_UNIT_NEWTON(exp) \
  338. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_LENGTH(1) | HID_UNIT_TIME(-2)), \
  339. HID_UNIT_EXPONENT(exp + 5)
  340. /** SI energy. J = 1E7 * g * cm^2 / s^2 */
  341. #define HID_UNIT_JOULE(exp) \
  342. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_LENGTH(2) | HID_UNIT_TIME(-2)), \
  343. HID_UNIT_EXPONENT(exp + 7)
  344. /** SI power. W = 1E7 * g * cm^2 / s^3 */
  345. #define HID_UNIT_WATT(exp) \
  346. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_LENGTH(2) | HID_UNIT_TIME(-3)), \
  347. HID_UNIT_EXPONENT(exp + 7)
  348. /** SI pressure. Pa = 1E1 * g / (cm * s^2) */
  349. #define HID_UNIT_PASCAL(exp) \
  350. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_LENGTH(-1) | HID_UNIT_TIME(-2)), \
  351. HID_UNIT_EXPONENT(exp + 1)
  352. /** SI frequency. Hz = 1 / s */
  353. #define HID_UNIT_HERTZ(exp) \
  354. HID_UNIT(16, HID_UNIT_CGS_LINEAR | HID_UNIT_TIME(-1)), \
  355. HID_UNIT_EXPONENT(exp + 0)
  356. /** SI current. A */
  357. #define HID_UNIT_AMPERE(exp) \
  358. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_CURRENT(1)), \
  359. HID_UNIT_EXPONENT(exp)
  360. /** SI voltage. V = W / A = 1E7 * g * cm^2 / (s^3 * A) */
  361. #define HID_UNIT_VOLT(exp) \
  362. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_LENGTH(2) | HID_UNIT_TIME(-3) | HID_UNIT_CURRENT(-1)), \
  363. HID_UNIT_EXPONENT(exp + 7)
  364. /** SI resistance. Ohm = 1E7 * g * cm^2 / (s^3 * A^2) */
  365. #define HID_UNIT_OHM(exp) \
  366. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_LENGTH(2) | HID_UNIT_TIME(-3) | HID_UNIT_CURRENT(-2)), \
  367. HID_UNIT_EXPONENT(exp + 7)
  368. /** SI inductance. H = 1E7 * g * cm^2 / (s^2 * A^2) */
  369. #define HID_UNIT_HENRY(exp) \
  370. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_LENGTH(2) | HID_UNIT_TIME(-2) | HID_UNIT_CURRENT(-2)), \
  371. HID_UNIT_EXPONENT(exp + 7)
  372. /** SI capacitance. F = 1E-7 * s^4 * A^2 / (cm^2 * g) */
  373. #define HID_UNIT_FARAD(exp) \
  374. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(-1) | HID_UNIT_LENGTH(-2) | HID_UNIT_TIME(4) | HID_UNIT_CURRENT(2)), \
  375. HID_UNIT_EXPONENT(exp - 7)
  376. /** SI electric charge. C = s * A */
  377. #define HID_UNIT_COULOMB(exp) \
  378. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_TIME(1) | HID_UNIT_CURRENT(1)), \
  379. HID_UNIT_EXPONENT(exp)
  380. /** SI magnetic flux density. T = 1E3 * g / (s^2 * A) */
  381. #define HID_UNIT_TESLA(exp) \
  382. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_MASS(1) | HID_UNIT_TIME(-2) | HID_UNIT_CURRENT(-1)), \
  383. HID_UNIT_EXPONENT(exp)
  384. /** SI illuminance. lx = 1E4 * cd / cm^2 */
  385. #define HID_UNIT_LUX(exp) \
  386. HID_UNIT(32, HID_UNIT_CGS_LINEAR | HID_UNIT_LENGTH(-1) | HID_UNIT_LUMINOUS(1)), \
  387. HID_UNIT_EXPONENT(exp)
  388. //@}
  389. /** @} */
  390. #ifdef __cplusplus
  391. }
  392. #endif
  393. #endif