[PATCH 4/4] input: hid-microsoft: Implement trigger rumble for Xbox One S over bluetooth

From: Daniel Bomar
Date: Sun Apr 10 2022 - 18:07:25 EST


Signed-off-by: Daniel Bomar <dbdaniel42@xxxxxxxxx>
---
drivers/hid/hid-microsoft.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index 071fd093a5f4..061275626c42 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -32,6 +32,8 @@ struct ms_data {
unsigned long quirks;
struct hid_device *hdev;
struct work_struct ff_worker;
+ __u8 trigger_left;
+ __u8 trigger_right;
__u8 strong;
__u8 weak;
void *output_report_dmabuf;
@@ -40,9 +42,13 @@ struct ms_data {
#define XB1S_FF_REPORT 3
#define ENABLE_WEAK BIT(0)
#define ENABLE_STRONG BIT(1)
+#define ENABLE_RIGHT BIT(2)
+#define ENABLE_LEFT BIT(3)

enum {
- MAGNITUDE_STRONG = 2,
+ MAGNITUDE_LEFT,
+ MAGNITUDE_RIGHT,
+ MAGNITUDE_STRONG,
MAGNITUDE_WEAK,
MAGNITUDE_NUM
};
@@ -288,7 +294,7 @@ static void ms_ff_worker(struct work_struct *work)
memset(r, 0, sizeof(*r));

r->report_id = XB1S_FF_REPORT;
- r->enable = ENABLE_WEAK | ENABLE_STRONG;
+ r->enable = ENABLE_WEAK | ENABLE_STRONG | ENABLE_RIGHT | ENABLE_LEFT;
/*
* Specifying maximum duration and maximum loop count should
* cover maximum duration of a single effect, which is 65536
@@ -296,6 +302,8 @@ static void ms_ff_worker(struct work_struct *work)
*/
r->duration_10ms = U8_MAX;
r->loop_count = U8_MAX;
+ r->magnitude[MAGNITUDE_LEFT] = ms->trigger_left;
+ r->magnitude[MAGNITUDE_RIGHT] = ms->trigger_right;
r->magnitude[MAGNITUDE_STRONG] = ms->strong; /* left actuator */
r->magnitude[MAGNITUDE_WEAK] = ms->weak; /* right actuator */

@@ -316,6 +324,8 @@ static int ms_play_effect(struct input_dev *dev, void *data,
/*
* Magnitude is 0..100 so scale the 16-bit input here
*/
+ ms->trigger_left = ((u32) effect->u.rumble.trigger_left * 100) / U16_MAX;
+ ms->trigger_right = ((u32) effect->u.rumble.trigger_right * 100) / U16_MAX;
ms->strong = ((u32) effect->u.rumble.strong_magnitude * 100) / U16_MAX;
ms->weak = ((u32) effect->u.rumble.weak_magnitude * 100) / U16_MAX;

--
2.35.1