From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Chris Morgan <macroalpha82@gmail.com>
Cc: linux-input@vger.kernel.org, hdegoede@redhat.com,
paul@crapouillou.net, peter.hutterer@who-t.net, svv@google.com,
biswarupp@google.com, contact@artur-rojek.eu,
Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [PATCH 1/2] Input: add input_invert_abs()
Date: Thu, 4 Jan 2024 09:59:24 -0800 [thread overview]
Message-ID: <ZZbx_Lv4kt5jvcpz@google.com> (raw)
In-Reply-To: <20231231205643.129435-2-macroalpha82@gmail.com>
Hi Chris,
On Sun, Dec 31, 2023 at 02:56:42PM -0600, Chris Morgan wrote:
> From: Chris Morgan <macromorgan@hotmail.com>
>
> Add a helper function to make it easier for a driver to invert abs
> values when needed. It is up to the driver itself to track axes that
> need to be inverted and normalize the data before it is passed on.
>
> This function assumes that drivers will set the min and max values
> so that min < max and then will simply call this function each time
> the values need to be inverted.
>
> Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> ---
> drivers/input/input.c | 19 +++++++++++++++++++
> include/linux/input.h | 1 +
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 8c5fdb0f858a..f135aed165a1 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -552,6 +552,25 @@ void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
> }
> EXPORT_SYMBOL(input_copy_abs);
>
> +/**
> + * input_invert_abs - Invert the abs value for an inverted axis.
> + * @dev: Input device with absolute events
> + * @axis: ABS_* value selecting the destination axis for the event to
> + * invert.
> + * @val: Value to be inverted based on min and max values of the axis.
> + *
> + * Return an inverted value for a given ABS axis based on its min and
> + * max values.
> + */
> +int input_invert_abs(struct input_dev *dev, unsigned int axis, int val)
> +{
> + int min = dev->absinfo[axis].minimum;
> + int max = dev->absinfo[axis].maximum;
> +
> + return (max + min) - val;
I do not think this is generic enough (i.e. sometimes you have a
theoretical range in which you want to invert that is bigger than the
normal min/max - see synaptics_invert_y()), so I would prefer this be
lolcal to the ADC joystick driver, at least for now.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2024-01-04 17:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-31 20:56 [PATCH 0/2] Allow inverted axes for adc-joystick Chris Morgan
2023-12-31 20:56 ` [PATCH 1/2] Input: add input_invert_abs() Chris Morgan
2024-01-04 17:59 ` Dmitry Torokhov [this message]
2023-12-31 20:56 ` [PATCH 2/2] Input: adc-joystick: Handle inverted axes Chris Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZZbx_Lv4kt5jvcpz@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=biswarupp@google.com \
--cc=contact@artur-rojek.eu \
--cc=hdegoede@redhat.com \
--cc=linux-input@vger.kernel.org \
--cc=macroalpha82@gmail.com \
--cc=macromorgan@hotmail.com \
--cc=paul@crapouillou.net \
--cc=peter.hutterer@who-t.net \
--cc=svv@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.