Re: [PATCH v9 12/20] gpiolib: cdev: support setting debounce
From: Andy Shevchenko
Date: Fri Sep 25 2020 - 05:43:43 EST
On Thu, Sep 24, 2020 at 10:49 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
> On Wed, Sep 23, 2020 at 07:27:37PM +0300, Andy Shevchenko wrote:
> > On Tue, Sep 22, 2020 at 5:36 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
...
> > Shouldn't we rather return 0/1 guaranteed?
> >
> > Perhaps
> >
> > if (active_low)
> > return !value;
> >
> > return !!value;
> >
> > ?
> >
>
> Or just make the return value a bool?
If it's good enough.
...
> > > + /* switch from physical level to logical - if they differ */
> > > + if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags))
> > > + level = !level;
> >
> > Seems to me a good candidate to have
> >
> > static inline bool convert_with_active_low_respected(desc, value)
> > {
> > if (active_low)
> > return !value;
> > return !!value;
> > }
> Not sure it is worth the effort - it would only be used twice - here
> and in debounced_value() - which is only a couple of lines itself.
I'm thinking about possible candidates to use this...
gpiod_direction_output()
gpiod_get_array_value_complex()
gpiod_get_value()
gpiod_set_value_nocheck()
gpiod_get_value_cansleep()
...I stopped here...
I agree that not all of them are good to be converted (b/c few flags
being tested and it will bring inconsistency), but many deserve the
perhaps separate patch to introduce the above mentioned helper.
--
With Best Regards,
Andy Shevchenko