Rémi Bernon : winebus.sys: Move hats before buttons and use one byte each.

Alexandre Julliard julliard at winehq.org
Tue Sep 21 15:59:02 CDT 2021


Module: wine
Branch: master
Commit: 593c4d51493c95b6ffa87c0572f893b42233d803
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=593c4d51493c95b6ffa87c0572f893b42233d803

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue Sep 21 08:36:41 2021 +0200

winebus.sys: Move hats before buttons and use one byte each.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winebus.sys/bus_sdl.c  | 57 ++++++++++++++-------------------------------
 dlls/winebus.sys/bus_udev.c | 34 +++++++++++++--------------
 dlls/winebus.sys/hid.c      |  2 +-
 3 files changed, 35 insertions(+), 58 deletions(-)

diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c
index a589814ee26..c83276aa873 100644
--- a/dlls/winebus.sys/bus_sdl.c
+++ b/dlls/winebus.sys/bus_sdl.c
@@ -126,7 +126,7 @@ struct platform_private
     int button_start;
     int axis_start;
     int ball_start;
-    int hat_bit_offs; /* hatswitches are reported in the same bytes as buttons */
+    int hat_start;
 
     struct hid_descriptor desc;
 
@@ -193,26 +193,8 @@ static void set_ball_value(struct platform_private *ext, int index, int value1,
 
 static void set_hat_value(struct platform_private *ext, int index, int value)
 {
-    int byte = ext->button_start + (ext->hat_bit_offs + 4 * index) / 8;
-    int bit_offs = (ext->hat_bit_offs + 4 * index) % 8;
-    int num_low_bits, num_high_bits;
-    unsigned char val, low_mask, high_mask;
-
-    /* 4-bit hatswitch value is packed into button bytes */
-    if (bit_offs <= 4)
-    {
-        num_low_bits = 4;
-        num_high_bits = 0;
-        low_mask = 0xf;
-        high_mask = 0;
-    }
-    else
-    {
-        num_low_bits = 8 - bit_offs;
-        num_high_bits = 4 - num_low_bits;
-        low_mask = (1 << num_low_bits) - 1;
-        high_mask = (1 << num_high_bits) - 1;
-    }
+    int byte = ext->hat_start + index;
+    unsigned char val;
 
     switch (value)
     {
@@ -231,13 +213,7 @@ static void set_hat_value(struct platform_private *ext, int index, int value)
         default: return;
     }
 
-    ext->report_buffer[byte] &= ~(low_mask << bit_offs);
-    ext->report_buffer[byte] |= (val & low_mask) << bit_offs;
-    if (high_mask)
-    {
-        ext->report_buffer[byte + 1] &= ~high_mask;
-        ext->report_buffer[byte + 1] |= val & high_mask;
-    }
+    ext->report_buffer[byte] = val;
 }
 
 static BOOL descriptor_add_haptic(struct platform_private *ext)
@@ -319,14 +295,14 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext)
         report_size += (sizeof(DWORD) * 2 * ball_count);
     }
 
+    hat_count = pSDL_JoystickNumHats(ext->sdl_joystick);
+    ext->hat_start = report_size;
+    report_size += hat_count;
+
     /* For now lump all buttons just into incremental usages, Ignore Keys */
     button_count = pSDL_JoystickNumButtons(ext->sdl_joystick);
     ext->button_start = report_size;
-
-    hat_count = pSDL_JoystickNumHats(ext->sdl_joystick);
-    ext->hat_bit_offs = button_count;
-
-    report_size += (button_count + hat_count * 4 + 7) / 8;
+    report_size += (button_count + 7) / 8;
 
     TRACE("Report will be %i bytes\n", report_size);
 
@@ -350,10 +326,10 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext)
                                                &joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX))
         return STATUS_NO_MEMORY;
 
-    if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count))
+    if (hat_count && !hid_descriptor_add_hatswitch(&ext->desc, hat_count))
         return STATUS_NO_MEMORY;
 
-    if (hat_count && !hid_descriptor_add_hatswitch(&ext->desc, hat_count))
+    if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count))
         return STATUS_NO_MEMORY;
 
     if (!descriptor_add_haptic(ext))
@@ -413,13 +389,14 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext)
     static const USAGE trigger_axis_usages[] = {HID_USAGE_GENERIC_Z, HID_USAGE_GENERIC_RZ};
     INT i;
 
-    static const int BUTTON_BIT_COUNT = CONTROLLER_NUM_BUTTONS + CONTROLLER_NUM_HATSWITCHES * 4;
+    static const int BUTTON_BIT_COUNT = CONTROLLER_NUM_BUTTONS;
 
     ext->axis_start = 0;
-    ext->button_start = CONTROLLER_NUM_AXES * sizeof(DWORD);
-    ext->hat_bit_offs = CONTROLLER_NUM_BUTTONS;
+    ext->hat_start = CONTROLLER_NUM_AXES * sizeof(DWORD);
+    ext->button_start = ext->hat_start + CONTROLLER_NUM_HATSWITCHES;
 
     ext->buffer_length = (BUTTON_BIT_COUNT + 7) / 8
+        + CONTROLLER_NUM_HATSWITCHES
         + CONTROLLER_NUM_AXES * sizeof(DWORD);
 
     TRACE("Report will be %i bytes\n", ext->buffer_length);
@@ -439,10 +416,10 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext)
                                  FALSE, 0, 0x7fff))
         return STATUS_NO_MEMORY;
 
-    if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS))
+    if (!hid_descriptor_add_hatswitch(&ext->desc, CONTROLLER_NUM_HATSWITCHES))
         return STATUS_NO_MEMORY;
 
-    if (!hid_descriptor_add_hatswitch(&ext->desc, 1))
+    if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS))
         return STATUS_NO_MEMORY;
 
     if (BUTTON_BIT_COUNT % 8 != 0)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c
index e62c8c2eda1..00c64829172 100644
--- a/dlls/winebus.sys/bus_udev.c
+++ b/dlls/winebus.sys/bus_udev.c
@@ -496,6 +496,23 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u
         rel_count++;
     }
 
+    hat_count = 0;
+    for (i = ABS_HAT0X; i <=ABS_HAT3X; i+=2)
+    {
+        if (!test_bit(absbits, i)) continue;
+        ext->hat_map[i - ABS_HAT0X] = report_size;
+        ext->hat_values[i - ABS_HAT0X] = 0;
+        ext->hat_values[i - ABS_HAT0X + 1] = 0;
+        report_size++;
+        hat_count++;
+    }
+
+    if (hat_count)
+    {
+        if (!hid_descriptor_add_hatswitch(&ext->desc, hat_count))
+            return STATUS_NO_MEMORY;
+    }
+
     /* For now lump all buttons just into incremental usages, Ignore Keys */
     ext->button_start = report_size;
     button_count = count_buttons(ext->base.device_fd, ext->button_map);
@@ -514,23 +531,6 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u
         report_size += (button_count + 7) / 8;
     }
 
-    hat_count = 0;
-    for (i = ABS_HAT0X; i <=ABS_HAT3X; i+=2)
-    {
-        if (!test_bit(absbits, i)) continue;
-        ext->hat_map[i - ABS_HAT0X] = report_size;
-        ext->hat_values[i - ABS_HAT0X] = 0;
-        ext->hat_values[i - ABS_HAT0X + 1] = 0;
-        report_size++;
-        hat_count++;
-    }
-
-    if (hat_count)
-    {
-        if (!hid_descriptor_add_hatswitch(&ext->desc, hat_count))
-            return STATUS_NO_MEMORY;
-    }
-
     if (!hid_descriptor_end(&ext->desc))
         return STATUS_NO_MEMORY;
 
diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c
index feff8aec013..ba9fa4ba12d 100644
--- a/dlls/winebus.sys/hid.c
+++ b/dlls/winebus.sys/hid.c
@@ -138,7 +138,7 @@ BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count)
         LOGICAL_MAXIMUM(1, 8),
         PHYSICAL_MINIMUM(1, 0),
         PHYSICAL_MAXIMUM(2, 8),
-        REPORT_SIZE(1, 4),
+        REPORT_SIZE(1, 8),
         REPORT_COUNT(4, count),
         UNIT(1, 0x0e /* none */),
         INPUT(1, Data|Var|Abs|Null),




More information about the wine-cvs mailing list