From 1018f10be7a2361c27e9b44271873d591a72de29 Mon Sep 17 00:00:00 2001 From: littleguy77 Date: Tue, 12 Sep 2023 17:51:30 -0400 Subject: [PATCH] [refactor] Read both joystick axes in each loop iteration. Need to consider both axes at once in deadzone calculation. --- .../patches/S922X/000-s922x-devices.patch | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/projects/Amlogic/packages/linux/patches/S922X/000-s922x-devices.patch b/projects/Amlogic/packages/linux/patches/S922X/000-s922x-devices.patch index 8dfd55083..5e6964f59 100644 --- a/projects/Amlogic/packages/linux/patches/S922X/000-s922x-devices.patch +++ b/projects/Amlogic/packages/linux/patches/S922X/000-s922x-devices.patch @@ -2652,7 +2652,7 @@ diff -rupN linux.orig/drivers/input/joystick/amlogic-saradc.h linux/drivers/inpu diff -rupN linux.orig/drivers/input/joystick/odroid-gou-joypad.c linux/drivers/input/joystick/odroid-gou-joypad.c --- linux.orig/drivers/input/joystick/odroid-gou-joypad.c 1970-01-01 00:00:00.000000000 +0000 +++ linux/drivers/input/joystick/odroid-gou-joypad.c 2023-09-12 12:03:27.490291628 +0000 -@@ -0,0 +1,926 @@ +@@ -0,0 +1,950 @@ +/*----------------------------------------------------------------------------*/ +#include +#include @@ -3043,9 +3043,13 @@ diff -rupN linux.orig/drivers/input/joystick/odroid-gou-joypad.c linux/drivers/i + struct joypad *joypad = poll_dev->private; + int nbtn; + -+ for (nbtn = 0; nbtn < joypad->chan_count; nbtn++) { ++ /* Assumes an even number of axes and that joystick axis pairs are sequential */ ++ /* e.g. left stick Y immediately follows left stick X */ ++ for (nbtn = 0; nbtn < joypad->chan_count; nbtn += 2) { + struct bt_adc *adcx = &joypad->adcs[nbtn]; ++ struct bt_adc *adcy = &joypad->adcs[nbtn + 1]; + ++ /* Read first joystick axis */ + adcx->value = joypad_adc_read(joypad, adcx); + if (!adcx->value) { + dev_err(joypad->dev, "%s : saradc channels[%d]!\n", @@ -3054,10 +3058,21 @@ diff -rupN linux.orig/drivers/input/joystick/odroid-gou-joypad.c linux/drivers/i + } + adcx->value = adcx->value - adcx->cal; + ++ /* Read second joystick axis */ ++ adcy->value = joypad_adc_read(joypad, adcy); ++ if (!adcy->value) { ++ dev_err(joypad->dev, "%s : saradc channels[%d]!\n", ++ __func__, nbtn + 1); ++ continue; ++ } ++ adcy->value = adcy->value - adcy->cal; ++ + /* Joystick Deadzone check */ + if (joypad->bt_adc_deadzone) { + if (abs(adcx->value) < joypad->bt_adc_deadzone) + adcx->value = 0; ++ if (abs(adcy->value) < joypad->bt_adc_deadzone) ++ adcy->value = 0; + } + + /* adc data tuning */ @@ -3065,13 +3080,22 @@ diff -rupN linux.orig/drivers/input/joystick/odroid-gou-joypad.c linux/drivers/i + adcx->value = ADC_DATA_TUNING(adcx->value, adcx->tuning_n); + if (adcx->tuning_p && adcx->value > 0) + adcx->value = ADC_DATA_TUNING(adcx->value, adcx->tuning_p); ++ if (adcy->tuning_n && adcy->value < 0) ++ adcy->value = ADC_DATA_TUNING(adcy->value, adcy->tuning_n); ++ if (adcy->tuning_p && adcy->value > 0) ++ adcy->value = ADC_DATA_TUNING(adcy->value, adcy->tuning_p); + + adcx->value = adcx->value > adcx->max ? adcx->max : adcx->value; + adcx->value = adcx->value < adcx->min ? adcx->min : adcx->value; ++ adcy->value = adcy->value > adcy->max ? adcy->max : adcy->value; ++ adcy->value = adcy->value < adcy->min ? adcy->min : adcy->value; + + input_report_abs(poll_dev->input, + adcx->report_type, + adcx->invert ? adcx->value * (-1) : adcx->value); ++ input_report_abs(poll_dev->input, ++ adcy->report_type, ++ adcy->invert ? adcy->value * (-1) : adcy->value); + } + input_sync(poll_dev->input); +}