SDL_hid.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifndef SDL_hid_h_
  20. #define SDL_hid_h_
  21. #include "SDL_windows.h"
  22. typedef LONG NTSTATUS;
  23. typedef USHORT USAGE;
  24. typedef struct _HIDP_PREPARSED_DATA *PHIDP_PREPARSED_DATA;
  25. typedef struct _HIDD_ATTRIBUTES
  26. {
  27. ULONG Size;
  28. USHORT VendorID;
  29. USHORT ProductID;
  30. USHORT VersionNumber;
  31. } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
  32. typedef enum
  33. {
  34. HidP_Input = 0,
  35. HidP_Output = 1,
  36. HidP_Feature = 2
  37. } HIDP_REPORT_TYPE;
  38. typedef struct
  39. {
  40. USAGE UsagePage;
  41. UCHAR ReportID;
  42. BOOLEAN IsAlias;
  43. USHORT BitField;
  44. USHORT LinkCollection;
  45. USAGE LinkUsage;
  46. USAGE LinkUsagePage;
  47. BOOLEAN IsRange;
  48. BOOLEAN IsStringRange;
  49. BOOLEAN IsDesignatorRange;
  50. BOOLEAN IsAbsolute;
  51. ULONG Reserved[10];
  52. union
  53. {
  54. struct
  55. {
  56. USAGE UsageMin;
  57. USAGE UsageMax;
  58. USHORT StringMin;
  59. USHORT StringMax;
  60. USHORT DesignatorMin;
  61. USHORT DesignatorMax;
  62. USHORT DataIndexMin;
  63. USHORT DataIndexMax;
  64. } Range;
  65. struct
  66. {
  67. USAGE Usage;
  68. USAGE Reserved1;
  69. USHORT StringIndex;
  70. USHORT Reserved2;
  71. USHORT DesignatorIndex;
  72. USHORT Reserved3;
  73. USHORT DataIndex;
  74. USHORT Reserved4;
  75. } NotRange;
  76. };
  77. } HIDP_BUTTON_CAPS, *PHIDP_BUTTON_CAPS;
  78. typedef struct
  79. {
  80. USAGE UsagePage;
  81. UCHAR ReportID;
  82. BOOLEAN IsAlias;
  83. USHORT BitField;
  84. USHORT LinkCollection;
  85. USAGE LinkUsage;
  86. USAGE LinkUsagePage;
  87. BOOLEAN IsRange;
  88. BOOLEAN IsStringRange;
  89. BOOLEAN IsDesignatorRange;
  90. BOOLEAN IsAbsolute;
  91. BOOLEAN HasNull;
  92. UCHAR Reserved;
  93. USHORT BitSize;
  94. USHORT ReportCount;
  95. USHORT Reserved2[5];
  96. ULONG UnitsExp;
  97. ULONG Units;
  98. LONG LogicalMin;
  99. LONG LogicalMax;
  100. LONG PhysicalMin;
  101. LONG PhysicalMax;
  102. union
  103. {
  104. struct
  105. {
  106. USAGE UsageMin;
  107. USAGE UsageMax;
  108. USHORT StringMin;
  109. USHORT StringMax;
  110. USHORT DesignatorMin;
  111. USHORT DesignatorMax;
  112. USHORT DataIndexMin;
  113. USHORT DataIndexMax;
  114. } Range;
  115. struct
  116. {
  117. USAGE Usage;
  118. USAGE Reserved1;
  119. USHORT StringIndex;
  120. USHORT Reserved2;
  121. USHORT DesignatorIndex;
  122. USHORT Reserved3;
  123. USHORT DataIndex;
  124. USHORT Reserved4;
  125. } NotRange;
  126. };
  127. } HIDP_VALUE_CAPS, *PHIDP_VALUE_CAPS;
  128. typedef struct
  129. {
  130. USAGE Usage;
  131. USAGE UsagePage;
  132. USHORT InputReportByteLength;
  133. USHORT OutputReportByteLength;
  134. USHORT FeatureReportByteLength;
  135. USHORT Reserved[17];
  136. USHORT NumberLinkCollectionNodes;
  137. USHORT NumberInputButtonCaps;
  138. USHORT NumberInputValueCaps;
  139. USHORT NumberInputDataIndices;
  140. USHORT NumberOutputButtonCaps;
  141. USHORT NumberOutputValueCaps;
  142. USHORT NumberOutputDataIndices;
  143. USHORT NumberFeatureButtonCaps;
  144. USHORT NumberFeatureValueCaps;
  145. USHORT NumberFeatureDataIndices;
  146. } HIDP_CAPS, *PHIDP_CAPS;
  147. typedef struct
  148. {
  149. USHORT DataIndex;
  150. USHORT Reserved;
  151. union
  152. {
  153. ULONG RawValue;
  154. BOOLEAN On;
  155. };
  156. } HIDP_DATA, *PHIDP_DATA;
  157. #define HIDP_ERROR_CODES(p1, p2) ((NTSTATUS)(((p1) << 28) | (0x11 << 16) | (p2)))
  158. #define HIDP_STATUS_SUCCESS HIDP_ERROR_CODES(0x0, 0x0000)
  159. #define HIDP_STATUS_NULL HIDP_ERROR_CODES(0x8, 0x0001)
  160. #define HIDP_STATUS_INVALID_PREPARSED_DATA HIDP_ERROR_CODES(0xC, 0x0001)
  161. #define HIDP_STATUS_INVALID_REPORT_TYPE HIDP_ERROR_CODES(0xC, 0x0002)
  162. #define HIDP_STATUS_INVALID_REPORT_LENGTH HIDP_ERROR_CODES(0xC, 0x0003)
  163. #define HIDP_STATUS_USAGE_NOT_FOUND HIDP_ERROR_CODES(0xC, 0x0004)
  164. #define HIDP_STATUS_VALUE_OUT_OF_RANGE HIDP_ERROR_CODES(0xC, 0x0005)
  165. #define HIDP_STATUS_BAD_LOG_PHY_VALUES HIDP_ERROR_CODES(0xC, 0x0006)
  166. #define HIDP_STATUS_BUFFER_TOO_SMALL HIDP_ERROR_CODES(0xC, 0x0007)
  167. #define HIDP_STATUS_INTERNAL_ERROR HIDP_ERROR_CODES(0xC, 0x0008)
  168. #define HIDP_STATUS_I8042_TRANS_UNKNOWN HIDP_ERROR_CODES(0xC, 0x0009)
  169. #define HIDP_STATUS_INCOMPATIBLE_REPORT_ID HIDP_ERROR_CODES(0xC, 0x000A)
  170. #define HIDP_STATUS_NOT_VALUE_ARRAY HIDP_ERROR_CODES(0xC, 0x000B)
  171. #define HIDP_STATUS_IS_VALUE_ARRAY HIDP_ERROR_CODES(0xC, 0x000C)
  172. #define HIDP_STATUS_DATA_INDEX_NOT_FOUND HIDP_ERROR_CODES(0xC, 0x000D)
  173. #define HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE HIDP_ERROR_CODES(0xC, 0x000E)
  174. #define HIDP_STATUS_BUTTON_NOT_PRESSED HIDP_ERROR_CODES(0xC, 0x000F)
  175. #define HIDP_STATUS_REPORT_DOES_NOT_EXIST HIDP_ERROR_CODES(0xC, 0x0010)
  176. #define HIDP_STATUS_NOT_IMPLEMENTED HIDP_ERROR_CODES(0xC, 0x0020)
  177. extern bool WIN_LoadHIDDLL(void);
  178. extern void WIN_UnloadHIDDLL(void);
  179. typedef BOOLEAN (WINAPI *HidD_GetAttributes_t)(HANDLE HidDeviceObject, PHIDD_ATTRIBUTES Attributes);
  180. typedef BOOLEAN (WINAPI *HidD_GetString_t)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
  181. typedef NTSTATUS (WINAPI *HidP_GetCaps_t)(PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities);
  182. typedef NTSTATUS (WINAPI *HidP_GetButtonCaps_t)(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps, PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
  183. typedef NTSTATUS (WINAPI *HidP_GetValueCaps_t)(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
  184. typedef ULONG (WINAPI *HidP_MaxDataListLength_t)(HIDP_REPORT_TYPE ReportType, PHIDP_PREPARSED_DATA PreparsedData);
  185. typedef NTSTATUS (WINAPI *HidP_GetData_t)(HIDP_REPORT_TYPE ReportType, PHIDP_DATA DataList, PULONG DataLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
  186. extern HidD_GetAttributes_t SDL_HidD_GetAttributes;
  187. extern HidD_GetString_t SDL_HidD_GetManufacturerString;
  188. extern HidD_GetString_t SDL_HidD_GetProductString;
  189. extern HidP_GetCaps_t SDL_HidP_GetCaps;
  190. extern HidP_GetButtonCaps_t SDL_HidP_GetButtonCaps;
  191. extern HidP_GetValueCaps_t SDL_HidP_GetValueCaps;
  192. extern HidP_MaxDataListLength_t SDL_HidP_MaxDataListLength;
  193. extern HidP_GetData_t SDL_HidP_GetData;
  194. void WIN_InitDeviceNotification(void);
  195. Uint64 WIN_GetLastDeviceNotification(void);
  196. void WIN_QuitDeviceNotification(void);
  197. #endif // SDL_hid_h_