Browse Source

Use Uint32 instead of unsigned int for descriptor values

Sam Lantinga 18 hours ago
parent
commit
ec19f1e12f

+ 6 - 6
src/joystick/hidapi/SDL_hidapi_xboxone.c

@@ -148,7 +148,7 @@ typedef struct
     Uint64 rumble_time;
     bool rumble_pending;
     SDL_ReportDescriptor *descriptor;
-    unsigned int last_buttons;
+    Uint32 last_buttons;
     Uint8 last_state[USB_PACKET_LENGTH];
     Uint8 *chunk_buffer;
     Uint32 chunk_length;
@@ -396,7 +396,7 @@ static bool HIDAPI_DriverXboxOne_InitDevice(SDL_HIDAPI_Device *device)
             for (int i = 0; i < field_count; ++i) {
                 DescriptorInputField *field = &fields[i];
                 if (field->usage == MAKE_USAGE(USB_USAGEPAGE_BUTTON, 1)) {
-                    unsigned int expected_usage = field->usage;
+                    Uint32 expected_usage = field->usage;
                     int expected_offset = field->bit_offset;
                     for (int j = i; j < field_count; ++j) {
                         DescriptorInputField *other = &fields[j];
@@ -640,7 +640,7 @@ static bool HIDAPI_DriverXboxOne_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *de
     return SDL_Unsupported();
 }
 
-static void HIDAPI_DriverXboxOne_HandleBatteryState(SDL_Joystick *joystick, unsigned int flags)
+static void HIDAPI_DriverXboxOne_HandleBatteryState(SDL_Joystick *joystick, Uint32 flags)
 {
     bool on_usb = (((flags & 0x0C) >> 2) == 0);
     SDL_PowerState state;
@@ -670,13 +670,13 @@ static void HIDAPI_DriverXboxOne_HandleBatteryState(SDL_Joystick *joystick, unsi
     SDL_SendJoystickPowerInfo(joystick, state, percent);
 }
 
-static void HandleDescriptorAxis(Uint64 timestamp, SDL_Joystick *joystick, SDL_GamepadAxis axis, unsigned int value)
+static void HandleDescriptorAxis(Uint64 timestamp, SDL_Joystick *joystick, SDL_GamepadAxis axis, Uint32 value)
 {
     Sint16 axis_value = (Sint16)((int)value - 0x8000);
     SDL_SendJoystickAxis(timestamp, joystick, axis, axis_value);
 }
 
-static void HandleDescriptorTrigger(Uint64 timestamp, SDL_Joystick *joystick, SDL_GamepadAxis axis, unsigned int value)
+static void HandleDescriptorTrigger(Uint64 timestamp, SDL_Joystick *joystick, SDL_GamepadAxis axis, Uint32 value)
 {
     Sint16 axis_value = (Sint16)(((int)value * 64) - 32768);
     if (axis_value == 32704) {
@@ -701,7 +701,7 @@ static bool HIDAPI_DriverXboxOne_HandleDescriptorReport(SDL_Joystick *joystick,
             continue;
         }
 
-        unsigned int value;
+        Uint32 value;
         if (!SDL_ReadReportData(data, size, field->bit_offset, field->bit_size, &value)) {
             continue;
         }

+ 18 - 18
src/joystick/hidapi/SDL_report_descriptor.c

@@ -87,16 +87,16 @@ typedef enum
 
 typedef struct
 {
-    unsigned int usage_page;
-    unsigned int report_size;
-    unsigned int report_count;
-    unsigned int report_id;
+    Uint32 usage_page;
+    Uint32 report_size;
+    Uint32 report_count;
+    Uint32 report_id;
 } DescriptorGlobalState;
 
 typedef struct
 {
-    unsigned int usage_minimum;
-    unsigned int usage_maximum;
+    Uint32 usage_minimum;
+    Uint32 usage_maximum;
     int usage_maxcount;
     int usage_count;
     Uint32 *usages;
@@ -137,7 +137,7 @@ static void DebugDescriptor(DescriptorContext *ctx, const char *fmt, ...)
 #endif // DEBUG_DESCRIPTOR
 }
 
-static void DebugMainTag(DescriptorContext *ctx, const char *tag, unsigned int flags)
+static void DebugMainTag(DescriptorContext *ctx, const char *tag, Uint32 flags)
 {
 #ifdef DEBUG_DESCRIPTOR
     char message[1024] = { 0 };
@@ -196,13 +196,13 @@ static void DebugMainTag(DescriptorContext *ctx, const char *tag, unsigned int f
 #endif // DEBUG_DESCRIPTOR
 }
 
-static unsigned int ReadValue(const Uint8 *data, int size)
+static Uint32 ReadValue(const Uint8 *data, int size)
 {
-    unsigned int value = 0;
+    Uint32 value = 0;
 
     int shift = 0;
     while (size--) {
-        value |= ((unsigned int)*data++) << shift;
+        value |= ((Uint32)(*data++)) << shift;
         shift += 8;
     }
     return value;
@@ -215,7 +215,7 @@ static void ResetLocalState(DescriptorContext *ctx)
     ctx->local.usage_count = 0;
 }
 
-static bool AddUsage(DescriptorContext *ctx, unsigned int usage)
+static bool AddUsage(DescriptorContext *ctx, Uint32 usage)
 {
     if (ctx->local.usage_count == ctx->local.usage_maxcount) {
         int usage_maxcount = ctx->local.usage_maxcount + 4;
@@ -234,7 +234,7 @@ static bool AddUsage(DescriptorContext *ctx, unsigned int usage)
     return true;
 }
 
-static bool AddInputField(DescriptorContext *ctx, unsigned int usage, int bit_size)
+static bool AddInputField(DescriptorContext *ctx, Uint32 usage, int bit_size)
 {
     if (ctx->field_count == ctx->field_maxcount) {
         int field_maxcount = ctx->field_maxcount + 4;
@@ -258,7 +258,7 @@ static bool AddInputField(DescriptorContext *ctx, unsigned int usage, int bit_si
 
 static bool AddInputFields(DescriptorContext *ctx)
 {
-    unsigned int usage = 0;
+    Uint32 usage = 0;
 
     if (ctx->global.report_count == 0 || ctx->global.report_size == 0) {
         return true;
@@ -275,7 +275,7 @@ static bool AddInputFields(DescriptorContext *ctx)
     }
 
     int usage_index = 0;
-    for (unsigned int i = 0; i < ctx->global.report_count; ++i) {
+    for (Uint32 i = 0; i < ctx->global.report_count; ++i) {
         if (usage_index < ctx->local.usage_count) {
             usage = ctx->local.usages[usage_index];
             if (usage_index < (ctx->local.usage_count - 1)) {
@@ -296,7 +296,7 @@ static bool AddInputFields(DescriptorContext *ctx)
 
 static bool ParseMainItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
 {
-    unsigned int flags;
+    Uint32 flags;
 
     switch (tag) {
     case MainTagInput:
@@ -359,7 +359,7 @@ static bool ParseMainItem(DescriptorContext *ctx, int tag, int size, const Uint8
 
 static bool ParseGlobalItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
 {
-    unsigned int value;
+    Uint32 value;
 
     switch (tag) {
     case GlobalTagUsagePage:
@@ -416,7 +416,7 @@ static bool ParseGlobalItem(DescriptorContext *ctx, int tag, int size, const Uin
 
 static bool ParseLocalItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
 {
-    unsigned int value;
+    Uint32 value;
 
     switch (tag) {
     case LocalTagUsage:
@@ -551,7 +551,7 @@ void SDL_DestroyDescriptor(SDL_ReportDescriptor *descriptor)
     }
 }
 
-bool SDL_ReadReportData(const Uint8 *data, int size, int bit_offset, int bit_size, unsigned int *value)
+bool SDL_ReadReportData(const Uint8 *data, int size, int bit_offset, int bit_size, Uint32 *value)
 {
     int offset = (bit_offset / 8);
     if (offset >= size) {

+ 1 - 1
src/joystick/hidapi/SDL_report_descriptor.h

@@ -37,4 +37,4 @@ typedef struct
 extern SDL_ReportDescriptor *SDL_ParseReportDescriptor(const Uint8 *descriptor, int descriptor_size);
 extern bool SDL_DescriptorHasUsage(SDL_ReportDescriptor *descriptor, Uint16 usage_page, Uint16 usage);
 extern void SDL_DestroyDescriptor(SDL_ReportDescriptor *descriptor);
-extern bool SDL_ReadReportData(const Uint8 *data, int size, int bit_offset, int bit_size, unsigned int *value);
+extern bool SDL_ReadReportData(const Uint8 *data, int size, int bit_offset, int bit_size, Uint32 *value);