mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 07:27:19 +08:00
Use Uint32 instead of unsigned int for descriptor values
This commit is contained in:
@@ -148,7 +148,7 @@ typedef struct
|
|||||||
Uint64 rumble_time;
|
Uint64 rumble_time;
|
||||||
bool rumble_pending;
|
bool rumble_pending;
|
||||||
SDL_ReportDescriptor *descriptor;
|
SDL_ReportDescriptor *descriptor;
|
||||||
unsigned int last_buttons;
|
Uint32 last_buttons;
|
||||||
Uint8 last_state[USB_PACKET_LENGTH];
|
Uint8 last_state[USB_PACKET_LENGTH];
|
||||||
Uint8 *chunk_buffer;
|
Uint8 *chunk_buffer;
|
||||||
Uint32 chunk_length;
|
Uint32 chunk_length;
|
||||||
@@ -396,7 +396,7 @@ static bool HIDAPI_DriverXboxOne_InitDevice(SDL_HIDAPI_Device *device)
|
|||||||
for (int i = 0; i < field_count; ++i) {
|
for (int i = 0; i < field_count; ++i) {
|
||||||
DescriptorInputField *field = &fields[i];
|
DescriptorInputField *field = &fields[i];
|
||||||
if (field->usage == MAKE_USAGE(USB_USAGEPAGE_BUTTON, 1)) {
|
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;
|
int expected_offset = field->bit_offset;
|
||||||
for (int j = i; j < field_count; ++j) {
|
for (int j = i; j < field_count; ++j) {
|
||||||
DescriptorInputField *other = &fields[j];
|
DescriptorInputField *other = &fields[j];
|
||||||
@@ -640,7 +640,7 @@ static bool HIDAPI_DriverXboxOne_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *de
|
|||||||
return SDL_Unsupported();
|
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);
|
bool on_usb = (((flags & 0x0C) >> 2) == 0);
|
||||||
SDL_PowerState state;
|
SDL_PowerState state;
|
||||||
@@ -670,13 +670,13 @@ static void HIDAPI_DriverXboxOne_HandleBatteryState(SDL_Joystick *joystick, unsi
|
|||||||
SDL_SendJoystickPowerInfo(joystick, state, percent);
|
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);
|
Sint16 axis_value = (Sint16)((int)value - 0x8000);
|
||||||
SDL_SendJoystickAxis(timestamp, joystick, axis, axis_value);
|
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);
|
Sint16 axis_value = (Sint16)(((int)value * 64) - 32768);
|
||||||
if (axis_value == 32704) {
|
if (axis_value == 32704) {
|
||||||
@@ -701,7 +701,7 @@ static bool HIDAPI_DriverXboxOne_HandleDescriptorReport(SDL_Joystick *joystick,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int value;
|
Uint32 value;
|
||||||
if (!SDL_ReadReportData(data, size, field->bit_offset, field->bit_size, &value)) {
|
if (!SDL_ReadReportData(data, size, field->bit_offset, field->bit_size, &value)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,16 +87,16 @@ typedef enum
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned int usage_page;
|
Uint32 usage_page;
|
||||||
unsigned int report_size;
|
Uint32 report_size;
|
||||||
unsigned int report_count;
|
Uint32 report_count;
|
||||||
unsigned int report_id;
|
Uint32 report_id;
|
||||||
} DescriptorGlobalState;
|
} DescriptorGlobalState;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned int usage_minimum;
|
Uint32 usage_minimum;
|
||||||
unsigned int usage_maximum;
|
Uint32 usage_maximum;
|
||||||
int usage_maxcount;
|
int usage_maxcount;
|
||||||
int usage_count;
|
int usage_count;
|
||||||
Uint32 *usages;
|
Uint32 *usages;
|
||||||
@@ -137,7 +137,7 @@ static void DebugDescriptor(DescriptorContext *ctx, const char *fmt, ...)
|
|||||||
#endif // DEBUG_DESCRIPTOR
|
#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
|
#ifdef DEBUG_DESCRIPTOR
|
||||||
char message[1024] = { 0 };
|
char message[1024] = { 0 };
|
||||||
@@ -196,13 +196,13 @@ static void DebugMainTag(DescriptorContext *ctx, const char *tag, unsigned int f
|
|||||||
#endif // DEBUG_DESCRIPTOR
|
#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;
|
int shift = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
value |= ((unsigned int)*data++) << shift;
|
value |= ((Uint32)(*data++)) << shift;
|
||||||
shift += 8;
|
shift += 8;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@@ -215,7 +215,7 @@ static void ResetLocalState(DescriptorContext *ctx)
|
|||||||
ctx->local.usage_count = 0;
|
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) {
|
if (ctx->local.usage_count == ctx->local.usage_maxcount) {
|
||||||
int usage_maxcount = ctx->local.usage_maxcount + 4;
|
int usage_maxcount = ctx->local.usage_maxcount + 4;
|
||||||
@@ -234,7 +234,7 @@ static bool AddUsage(DescriptorContext *ctx, unsigned int usage)
|
|||||||
return true;
|
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) {
|
if (ctx->field_count == ctx->field_maxcount) {
|
||||||
int field_maxcount = ctx->field_maxcount + 4;
|
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)
|
static bool AddInputFields(DescriptorContext *ctx)
|
||||||
{
|
{
|
||||||
unsigned int usage = 0;
|
Uint32 usage = 0;
|
||||||
|
|
||||||
if (ctx->global.report_count == 0 || ctx->global.report_size == 0) {
|
if (ctx->global.report_count == 0 || ctx->global.report_size == 0) {
|
||||||
return true;
|
return true;
|
||||||
@@ -275,7 +275,7 @@ static bool AddInputFields(DescriptorContext *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int usage_index = 0;
|
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) {
|
if (usage_index < ctx->local.usage_count) {
|
||||||
usage = ctx->local.usages[usage_index];
|
usage = ctx->local.usages[usage_index];
|
||||||
if (usage_index < (ctx->local.usage_count - 1)) {
|
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)
|
static bool ParseMainItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
|
||||||
{
|
{
|
||||||
unsigned int flags;
|
Uint32 flags;
|
||||||
|
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case MainTagInput:
|
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)
|
static bool ParseGlobalItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
|
||||||
{
|
{
|
||||||
unsigned int value;
|
Uint32 value;
|
||||||
|
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case GlobalTagUsagePage:
|
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)
|
static bool ParseLocalItem(DescriptorContext *ctx, int tag, int size, const Uint8 *data)
|
||||||
{
|
{
|
||||||
unsigned int value;
|
Uint32 value;
|
||||||
|
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case LocalTagUsage:
|
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);
|
int offset = (bit_offset / 8);
|
||||||
if (offset >= size) {
|
if (offset >= size) {
|
||||||
|
|||||||
@@ -37,4 +37,4 @@ typedef struct
|
|||||||
extern SDL_ReportDescriptor *SDL_ParseReportDescriptor(const Uint8 *descriptor, int descriptor_size);
|
extern SDL_ReportDescriptor *SDL_ParseReportDescriptor(const Uint8 *descriptor, int descriptor_size);
|
||||||
extern bool SDL_DescriptorHasUsage(SDL_ReportDescriptor *descriptor, Uint16 usage_page, Uint16 usage);
|
extern bool SDL_DescriptorHasUsage(SDL_ReportDescriptor *descriptor, Uint16 usage_page, Uint16 usage);
|
||||||
extern void SDL_DestroyDescriptor(SDL_ReportDescriptor *descriptor);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user