diff mbox series

[1/2] drivers: hid: adjust gyro calibration data

Message ID 20221006183105.5416-1-hcvcastro@gmail.com
State Superseded
Headers show
Series [1/2] drivers: hid: adjust gyro calibration data | expand

Commit Message

Henry Castro Oct. 6, 2022, 6:31 p.m. UTC
For some reason my DualShock 4 get the calibration
data values equal:

	gyro_pitch_plus == gyro_pitch_minus

Probably due to some defect in the DS4 hardware, and cause
a CPU division exception to crash the linux kernel.

At least with the patch, I can continue play Retroarch
without using the Gyroscope :)

Signed-off-by: Henry Castro <hcvcastro@gmail.com>
---

> Are it only these which are equal or are there are other funky ones?
> Are all constants in general the same? I'm just trying to figure out
> if some of this device would even need calibration.

More data logs:

gyro_pitch_plus=8704 giro_pitch_minus=8704
gyro_yaw_plus=8704 giro_yaw_minus=-8704
gyro_roll_plus=-8704 giro_roll_minus=-8704

Yes, They are constants values :( I


 drivers/hid/hid-sony.c | 9 +++++++++
 1 file changed, 9 insertions(+)

--
2.20.1
diff mbox series

Patch

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 87b538656f64..656caa07b25f 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -1823,6 +1823,15 @@  static int dualshock4_get_calibration_data(struct sony_sc *sc)
 	acc_z_plus       = get_unaligned_le16(&buf[31]);
 	acc_z_minus      = get_unaligned_le16(&buf[33]);

+	if (gyro_pitch_plus == gyro_pitch_minus)
+		gyro_pitch_minus *= -1;
+
+	if (gyro_yaw_plus == gyro_yaw_minus)
+		gyro_yaw_minus *= -1;
+
+	if (gyro_roll_plus == gyro_roll_minus)
+		gyro_roll_minus *= -1;
+
 	/* Set gyroscope calibration and normalization parameters.
 	 * Data values will be normalized to 1/DS4_GYRO_RES_PER_DEG_S degree/s.
 	 */