diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/hidapi/windows/hidapi_descriptor_reconstruct.h')
| -rw-r--r-- | contrib/SDL-3.2.8/src/hidapi/windows/hidapi_descriptor_reconstruct.h | 254 |
1 files changed, 254 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/hidapi/windows/hidapi_descriptor_reconstruct.h b/contrib/SDL-3.2.8/src/hidapi/windows/hidapi_descriptor_reconstruct.h new file mode 100644 index 0000000..0bfe72b --- /dev/null +++ b/contrib/SDL-3.2.8/src/hidapi/windows/hidapi_descriptor_reconstruct.h | |||
| @@ -0,0 +1,254 @@ | |||
| 1 | /******************************************************* | ||
| 2 | HIDAPI - Multi-Platform library for | ||
| 3 | communication with HID devices. | ||
| 4 | |||
| 5 | libusb/hidapi Team | ||
| 6 | |||
| 7 | Copyright 2022, All Rights Reserved. | ||
| 8 | |||
| 9 | At the discretion of the user of this library, | ||
| 10 | this software may be licensed under the terms of the | ||
| 11 | GNU General Public License v3, a BSD-Style license, or the | ||
| 12 | original HIDAPI license as outlined in the LICENSE.txt, | ||
| 13 | LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt | ||
| 14 | files located at the root of the source distribution. | ||
| 15 | These files may also be found in the public source | ||
| 16 | code repository located at: | ||
| 17 | https://github.com/libusb/hidapi . | ||
| 18 | ********************************************************/ | ||
| 19 | #include "SDL_internal.h" | ||
| 20 | |||
| 21 | #ifndef HIDAPI_DESCRIPTOR_RECONSTRUCT_H__ | ||
| 22 | #define HIDAPI_DESCRIPTOR_RECONSTRUCT_H__ | ||
| 23 | |||
| 24 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) | ||
| 25 | /* Do not warn about wcsncpy usage. | ||
| 26 | https://docs.microsoft.com/cpp/c-runtime-library/security-features-in-the-crt */ | ||
| 27 | #define _CRT_SECURE_NO_WARNINGS | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #include "hidapi_winapi.h" | ||
| 31 | |||
| 32 | #ifdef _MSC_VER | ||
| 33 | #pragma warning(push) | ||
| 34 | #pragma warning(disable: 4200) | ||
| 35 | #pragma warning(disable: 4201) | ||
| 36 | #pragma warning(disable: 4214) | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #include <windows.h> | ||
| 40 | |||
| 41 | #include "hidapi_hidsdi.h" | ||
| 42 | /*#include <assert.h>*/ | ||
| 43 | |||
| 44 | #define NUM_OF_HIDP_REPORT_TYPES 3 | ||
| 45 | |||
| 46 | typedef enum rd_items_ { | ||
| 47 | rd_main_input = 0x80, /* 1000 00 nn */ | ||
| 48 | rd_main_output = 0x90, /* 1001 00 nn */ | ||
| 49 | rd_main_feature = 0xB0, /* 1011 00 nn */ | ||
| 50 | rd_main_collection = 0xA0, /* 1010 00 nn */ | ||
| 51 | rd_main_collection_end = 0xC0, /* 1100 00 nn */ | ||
| 52 | rd_global_usage_page = 0x04, /* 0000 01 nn */ | ||
| 53 | rd_global_logical_minimum = 0x14, /* 0001 01 nn */ | ||
| 54 | rd_global_logical_maximum = 0x24, /* 0010 01 nn */ | ||
| 55 | rd_global_physical_minimum = 0x34, /* 0011 01 nn */ | ||
| 56 | rd_global_physical_maximum = 0x44, /* 0100 01 nn */ | ||
| 57 | rd_global_unit_exponent = 0x54, /* 0101 01 nn */ | ||
| 58 | rd_global_unit = 0x64, /* 0110 01 nn */ | ||
| 59 | rd_global_report_size = 0x74, /* 0111 01 nn */ | ||
| 60 | rd_global_report_id = 0x84, /* 1000 01 nn */ | ||
| 61 | rd_global_report_count = 0x94, /* 1001 01 nn */ | ||
| 62 | rd_global_push = 0xA4, /* 1010 01 nn */ | ||
| 63 | rd_global_pop = 0xB4, /* 1011 01 nn */ | ||
| 64 | rd_local_usage = 0x08, /* 0000 10 nn */ | ||
| 65 | rd_local_usage_minimum = 0x18, /* 0001 10 nn */ | ||
| 66 | rd_local_usage_maximum = 0x28, /* 0010 10 nn */ | ||
| 67 | rd_local_designator_index = 0x38, /* 0011 10 nn */ | ||
| 68 | rd_local_designator_minimum = 0x48, /* 0100 10 nn */ | ||
| 69 | rd_local_designator_maximum = 0x58, /* 0101 10 nn */ | ||
| 70 | rd_local_string = 0x78, /* 0111 10 nn */ | ||
| 71 | rd_local_string_minimum = 0x88, /* 1000 10 nn */ | ||
| 72 | rd_local_string_maximum = 0x98, /* 1001 10 nn */ | ||
| 73 | rd_local_delimiter = 0xA8 /* 1010 10 nn */ | ||
| 74 | } rd_items; | ||
| 75 | |||
| 76 | typedef enum rd_main_items_ { | ||
| 77 | rd_input = HidP_Input, | ||
| 78 | rd_output = HidP_Output, | ||
| 79 | rd_feature = HidP_Feature, | ||
| 80 | rd_collection, | ||
| 81 | rd_collection_end, | ||
| 82 | rd_delimiter_open, | ||
| 83 | rd_delimiter_usage, | ||
| 84 | rd_delimiter_close, | ||
| 85 | } rd_main_items; | ||
| 86 | |||
| 87 | typedef struct rd_bit_range_ { | ||
| 88 | int FirstBit; | ||
| 89 | int LastBit; | ||
| 90 | } rd_bit_range; | ||
| 91 | |||
| 92 | typedef enum rd_item_node_type_ { | ||
| 93 | rd_item_node_cap, | ||
| 94 | rd_item_node_padding, | ||
| 95 | rd_item_node_collection, | ||
| 96 | } rd_node_type; | ||
| 97 | |||
| 98 | struct rd_main_item_node { | ||
| 99 | int FirstBit; /* Position of first bit in report (counting from 0) */ | ||
| 100 | int LastBit; /* Position of last bit in report (counting from 0) */ | ||
| 101 | rd_node_type TypeOfNode; /* Information if caps index refers to the array of button caps, value caps, | ||
| 102 | or if the node is just a padding element to fill unused bit positions. | ||
| 103 | The node can also be a collection node without any bits in the report. */ | ||
| 104 | int CapsIndex; /* Index in the array of caps */ | ||
| 105 | int CollectionIndex; /* Index in the array of link collections */ | ||
| 106 | rd_main_items MainItemType; /* Input, Output, Feature, Collection or Collection End */ | ||
| 107 | unsigned char ReportID; | ||
| 108 | struct rd_main_item_node* next; | ||
| 109 | }; | ||
| 110 | |||
| 111 | typedef struct hid_pp_caps_info_ { | ||
| 112 | USHORT FirstCap; | ||
| 113 | USHORT NumberOfCaps; // Includes empty caps after LastCap | ||
| 114 | USHORT LastCap; | ||
| 115 | USHORT ReportByteLength; | ||
| 116 | } hid_pp_caps_info, *phid_pp_caps_info; | ||
| 117 | |||
| 118 | typedef struct hid_pp_link_collection_node_ { | ||
| 119 | USAGE LinkUsage; | ||
| 120 | USAGE LinkUsagePage; | ||
| 121 | USHORT Parent; | ||
| 122 | USHORT NumberOfChildren; | ||
| 123 | USHORT NextSibling; | ||
| 124 | USHORT FirstChild; | ||
| 125 | ULONG CollectionType : 8; | ||
| 126 | ULONG IsAlias : 1; | ||
| 127 | ULONG Reserved : 23; | ||
| 128 | // Same as the public API structure HIDP_LINK_COLLECTION_NODE, but without PVOID UserContext at the end | ||
| 129 | } hid_pp_link_collection_node, *phid_pp_link_collection_node; | ||
| 130 | |||
| 131 | // Note: This is risk-reduction-measure for this specific struct, as it has ULONG bit-field. | ||
| 132 | // Although very unlikely, it might still be possible that the compiler creates a memory layout that is | ||
| 133 | // not binary compatile. | ||
| 134 | // Other structs are not checked at the time of writing. | ||
| 135 | //static_assert(sizeof(struct hid_pp_link_collection_node_) == 16, | ||
| 136 | // "Size of struct hid_pp_link_collection_node_ not as expected. This might break binary compatibility"); | ||
| 137 | SDL_COMPILE_TIME_ASSERT(hid_pp_link_collection_node_, sizeof(struct hid_pp_link_collection_node_) == 16); | ||
| 138 | |||
| 139 | typedef struct hidp_unknown_token_ { | ||
| 140 | UCHAR Token; /* Specifies the one-byte prefix of a global item. */ | ||
| 141 | UCHAR Reserved[3]; | ||
| 142 | ULONG BitField; /* Specifies the data part of the global item. */ | ||
| 143 | } hidp_unknown_token, * phidp_unknown_token; | ||
| 144 | |||
| 145 | typedef struct hid_pp_cap_ { | ||
| 146 | USAGE UsagePage; | ||
| 147 | UCHAR ReportID; | ||
| 148 | UCHAR BitPosition; | ||
| 149 | USHORT ReportSize; // WIN32 term for this is BitSize | ||
| 150 | USHORT ReportCount; | ||
| 151 | USHORT BytePosition; | ||
| 152 | USHORT BitCount; | ||
| 153 | ULONG BitField; | ||
| 154 | USHORT NextBytePosition; | ||
| 155 | USHORT LinkCollection; | ||
| 156 | USAGE LinkUsagePage; | ||
| 157 | USAGE LinkUsage; | ||
| 158 | |||
| 159 | // Start of 8 Flags in one byte | ||
| 160 | BOOLEAN IsMultipleItemsForArray:1; | ||
| 161 | |||
| 162 | BOOLEAN IsPadding:1; | ||
| 163 | BOOLEAN IsButtonCap:1; | ||
| 164 | BOOLEAN IsAbsolute:1; | ||
| 165 | BOOLEAN IsRange:1; | ||
| 166 | BOOLEAN IsAlias:1; // IsAlias is set to TRUE in the first n-1 capability structures added to the capability array. IsAlias set to FALSE in the nth capability structure. | ||
| 167 | BOOLEAN IsStringRange:1; | ||
| 168 | BOOLEAN IsDesignatorRange:1; | ||
| 169 | // End of 8 Flags in one byte | ||
| 170 | BOOLEAN Reserved1[3]; | ||
| 171 | |||
| 172 | hidp_unknown_token UnknownTokens[4]; // 4 x 8 Byte | ||
| 173 | |||
| 174 | union { | ||
| 175 | struct { | ||
| 176 | USAGE UsageMin; | ||
| 177 | USAGE UsageMax; | ||
| 178 | USHORT StringMin; | ||
| 179 | USHORT StringMax; | ||
| 180 | USHORT DesignatorMin; | ||
| 181 | USHORT DesignatorMax; | ||
| 182 | USHORT DataIndexMin; | ||
| 183 | USHORT DataIndexMax; | ||
| 184 | } Range; | ||
| 185 | struct { | ||
| 186 | USAGE Usage; | ||
| 187 | USAGE Reserved1; | ||
| 188 | USHORT StringIndex; | ||
| 189 | USHORT Reserved2; | ||
| 190 | USHORT DesignatorIndex; | ||
| 191 | USHORT Reserved3; | ||
| 192 | USHORT DataIndex; | ||
| 193 | USHORT Reserved4; | ||
| 194 | } NotRange; | ||
| 195 | }; | ||
| 196 | union { | ||
| 197 | struct { | ||
| 198 | LONG LogicalMin; | ||
| 199 | LONG LogicalMax; | ||
| 200 | } Button; | ||
| 201 | struct { | ||
| 202 | BOOLEAN HasNull; | ||
| 203 | UCHAR Reserved4[3]; | ||
| 204 | LONG LogicalMin; | ||
| 205 | LONG LogicalMax; | ||
| 206 | LONG PhysicalMin; | ||
| 207 | LONG PhysicalMax; | ||
| 208 | } NotButton; | ||
| 209 | }; | ||
| 210 | ULONG Units; | ||
| 211 | ULONG UnitsExp; | ||
| 212 | |||
| 213 | } hid_pp_cap, *phid_pp_cap; | ||
| 214 | |||
| 215 | typedef struct hidp_preparsed_data_ { | ||
| 216 | UCHAR MagicKey[8]; | ||
| 217 | USAGE Usage; | ||
| 218 | USAGE UsagePage; | ||
| 219 | USHORT Reserved[2]; | ||
| 220 | |||
| 221 | // CAPS structure for Input, Output and Feature | ||
| 222 | hid_pp_caps_info caps_info[3]; | ||
| 223 | |||
| 224 | USHORT FirstByteOfLinkCollectionArray; | ||
| 225 | USHORT NumberLinkCollectionNodes; | ||
| 226 | |||
| 227 | #ifndef _MSC_VER | ||
| 228 | // MINGW fails with: Flexible array member in union not supported | ||
| 229 | // Solution: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html | ||
| 230 | union { | ||
| 231 | #ifdef HAVE_GCC_DIAGNOSTIC_PRAGMA | ||
| 232 | #pragma GCC diagnostic push | ||
| 233 | #pragma GCC diagnostic ignored "-Wpedantic" | ||
| 234 | #endif | ||
| 235 | hid_pp_cap caps[0]; | ||
| 236 | hid_pp_link_collection_node LinkCollectionArray[0]; | ||
| 237 | #ifdef HAVE_GCC_DIAGNOSTIC_PRAGMA | ||
| 238 | #pragma GCC diagnostic pop | ||
| 239 | #endif | ||
| 240 | }; | ||
| 241 | #else | ||
| 242 | union { | ||
| 243 | hid_pp_cap caps[]; | ||
| 244 | hid_pp_link_collection_node LinkCollectionArray[]; | ||
| 245 | }; | ||
| 246 | #endif | ||
| 247 | |||
| 248 | } hidp_preparsed_data; | ||
| 249 | |||
| 250 | #ifdef _MSC_VER | ||
| 251 | #pragma warning(pop) | ||
| 252 | #endif | ||
| 253 | |||
| 254 | #endif | ||
