* [PATCH libgpiod-v2] gpioinfo: Show edge detection and debounce period if enabled
@ 2021-07-28 23:46 Ben Hutchings
2021-09-20 13:52 ` Bartosz Golaszewski
0 siblings, 1 reply; 4+ messages in thread
From: Ben Hutchings @ 2021-07-28 23:46 UTC (permalink / raw)
To: linux-gpio
gpioinfo shows most settings for each GPIO line, but currently misses
edge detection and debouncing.
* If edge detection is enabled, report it as an additional flag
* If debouncing is enabled, report the duration
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
---
tools/gpioinfo.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/tools/gpioinfo.c b/tools/gpioinfo.c
index cd2b9e4..ed0018c 100644
--- a/tools/gpioinfo.c
+++ b/tools/gpioinfo.c
@@ -44,6 +44,21 @@ static bool line_drive_is_open_source(struct gpiod_line_info *info)
return gpiod_line_info_get_drive(info) == GPIOD_LINE_DRIVE_OPEN_SOURCE;
}
+static bool edge_detection_is_rising(struct gpiod_line_info *info)
+{
+ return gpiod_line_info_get_edge_detection(info) == GPIOD_LINE_EDGE_RISING;
+}
+
+static bool edge_detection_is_falling(struct gpiod_line_info *info)
+{
+ return gpiod_line_info_get_edge_detection(info) == GPIOD_LINE_EDGE_FALLING;
+}
+
+static bool edge_detection_is_both(struct gpiod_line_info *info)
+{
+ return gpiod_line_info_get_edge_detection(info) == GPIOD_LINE_EDGE_BOTH;
+}
+
static const struct flag flags[] = {
{
.name = "used",
@@ -69,6 +84,18 @@ static const struct flag flags[] = {
.name = "bias-disabled",
.is_set = line_bias_is_disabled,
},
+ {
+ .name = "edge-rising",
+ .is_set = edge_detection_is_rising,
+ },
+ {
+ .name = "edge-failling",
+ .is_set = edge_detection_is_falling,
+ },
+ {
+ .name = "edge-both",
+ .is_set = edge_detection_is_both,
+ },
};
static const struct option longopts[] = {
@@ -129,6 +156,7 @@ static void list_lines(struct gpiod_chip *chip)
const char *name, *consumer;
unsigned int i, offset;
int direction;
+ unsigned long debounce_period;
printf("%s - %u lines:\n",
gpiod_chip_get_name(chip), gpiod_chip_get_num_lines(chip));
@@ -142,6 +170,8 @@ static void list_lines(struct gpiod_chip *chip)
consumer = gpiod_line_info_get_consumer(info);
direction = gpiod_line_info_get_direction(info);
active_low = gpiod_line_info_is_active_low(info);
+ debounce_period = gpiod_line_info_is_debounced(info) ?
+ gpiod_line_info_get_debounce_period(info) : 0;
of = false;
@@ -166,6 +196,9 @@ static void list_lines(struct gpiod_chip *chip)
prinfo(&of, 13, "%s ",
active_low ? "active-low" : "active-high");
+ if (debounce_period)
+ printf("debounce=%lu ", debounce_period);
+
flag_printed = false;
for (i = 0; i < ARRAY_SIZE(flags); i++) {
if (flags[i].is_set(info)) {
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH libgpiod-v2] gpioinfo: Show edge detection and debounce period if enabled
2021-07-28 23:46 [PATCH libgpiod-v2] gpioinfo: Show edge detection and debounce period if enabled Ben Hutchings
@ 2021-09-20 13:52 ` Bartosz Golaszewski
2021-09-22 11:49 ` Ben Hutchings
0 siblings, 1 reply; 4+ messages in thread
From: Bartosz Golaszewski @ 2021-09-20 13:52 UTC (permalink / raw)
To: Ben Hutchings; +Cc: open list:GPIO SUBSYSTEM
On Thu, Jul 29, 2021 at 1:46 AM Ben Hutchings <ben.hutchings@mind.be> wrote:
>
> gpioinfo shows most settings for each GPIO line, but currently misses
> edge detection and debouncing.
>
> * If edge detection is enabled, report it as an additional flag
> * If debouncing is enabled, report the duration
>
> Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
> ---
> tools/gpioinfo.c | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/tools/gpioinfo.c b/tools/gpioinfo.c
> index cd2b9e4..ed0018c 100644
> --- a/tools/gpioinfo.c
> +++ b/tools/gpioinfo.c
> @@ -44,6 +44,21 @@ static bool line_drive_is_open_source(struct gpiod_line_info *info)
> return gpiod_line_info_get_drive(info) == GPIOD_LINE_DRIVE_OPEN_SOURCE;
> }
>
> +static bool edge_detection_is_rising(struct gpiod_line_info *info)
> +{
> + return gpiod_line_info_get_edge_detection(info) == GPIOD_LINE_EDGE_RISING;
> +}
> +
> +static bool edge_detection_is_falling(struct gpiod_line_info *info)
> +{
> + return gpiod_line_info_get_edge_detection(info) == GPIOD_LINE_EDGE_FALLING;
> +}
> +
> +static bool edge_detection_is_both(struct gpiod_line_info *info)
> +{
> + return gpiod_line_info_get_edge_detection(info) == GPIOD_LINE_EDGE_BOTH;
> +}
> +
> static const struct flag flags[] = {
> {
> .name = "used",
> @@ -69,6 +84,18 @@ static const struct flag flags[] = {
> .name = "bias-disabled",
> .is_set = line_bias_is_disabled,
> },
> + {
> + .name = "edge-rising",
> + .is_set = edge_detection_is_rising,
> + },
> + {
> + .name = "edge-failling",
> + .is_set = edge_detection_is_falling,
> + },
> + {
> + .name = "edge-both",
> + .is_set = edge_detection_is_both,
> + },
> };
>
> static const struct option longopts[] = {
> @@ -129,6 +156,7 @@ static void list_lines(struct gpiod_chip *chip)
> const char *name, *consumer;
> unsigned int i, offset;
> int direction;
> + unsigned long debounce_period;
>
> printf("%s - %u lines:\n",
> gpiod_chip_get_name(chip), gpiod_chip_get_num_lines(chip));
> @@ -142,6 +170,8 @@ static void list_lines(struct gpiod_chip *chip)
> consumer = gpiod_line_info_get_consumer(info);
> direction = gpiod_line_info_get_direction(info);
> active_low = gpiod_line_info_is_active_low(info);
> + debounce_period = gpiod_line_info_is_debounced(info) ?
> + gpiod_line_info_get_debounce_period(info) : 0;
>
> of = false;
>
> @@ -166,6 +196,9 @@ static void list_lines(struct gpiod_chip *chip)
> prinfo(&of, 13, "%s ",
> active_low ? "active-low" : "active-high");
>
> + if (debounce_period)
> + printf("debounce=%lu ", debounce_period);
You should use prinfo here for formatting. But it would be even better
if this became a flag - like the bias, drive etc settings and be shown
inside the [] brackets at the end of the line - something like:
"[pull-up, used, debounce-period=1000us]".
Bart
> +
> flag_printed = false;
> for (i = 0; i < ARRAY_SIZE(flags); i++) {
> if (flags[i].is_set(info)) {
> --
> 2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH libgpiod-v2] gpioinfo: Show edge detection and debounce period if enabled
2021-09-20 13:52 ` Bartosz Golaszewski
@ 2021-09-22 11:49 ` Ben Hutchings
2021-09-22 12:59 ` Bartosz Golaszewski
0 siblings, 1 reply; 4+ messages in thread
From: Ben Hutchings @ 2021-09-22 11:49 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: open list:GPIO SUBSYSTEM
On Mon, Sep 20, 2021 at 03:52:17PM +0200, Bartosz Golaszewski wrote:
> On Thu, Jul 29, 2021 at 1:46 AM Ben Hutchings <ben.hutchings@mind.be> wrote:
[...]
> > @@ -166,6 +196,9 @@ static void list_lines(struct gpiod_chip *chip)
> > prinfo(&of, 13, "%s ",
> > active_low ? "active-low" : "active-high");
> >
> > + if (debounce_period)
> > + printf("debounce=%lu ", debounce_period);
>
> You should use prinfo here for formatting. But it would be even better
> if this became a flag - like the bias, drive etc settings and be shown
> inside the [] brackets at the end of the line - something like:
> "[pull-up, used, debounce-period=1000us]".
[...]
Well it's not a flag; it's an attribute with a value. But if you
think it should be grouped with the flags anyway, I can do that.
Ben.
--
Ben Hutchings · Senior Embedded Software Engineer, Essensium-Mind · mind.be
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH libgpiod-v2] gpioinfo: Show edge detection and debounce period if enabled
2021-09-22 11:49 ` Ben Hutchings
@ 2021-09-22 12:59 ` Bartosz Golaszewski
0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2021-09-22 12:59 UTC (permalink / raw)
To: Ben Hutchings; +Cc: open list:GPIO SUBSYSTEM
On Wed, Sep 22, 2021 at 1:49 PM Ben Hutchings
<ben.hutchings@essensium.com> wrote:
>
> On Mon, Sep 20, 2021 at 03:52:17PM +0200, Bartosz Golaszewski wrote:
> > On Thu, Jul 29, 2021 at 1:46 AM Ben Hutchings <ben.hutchings@mind.be> wrote:
> [...]
> > > @@ -166,6 +196,9 @@ static void list_lines(struct gpiod_chip *chip)
> > > prinfo(&of, 13, "%s ",
> > > active_low ? "active-low" : "active-high");
> > >
> > > + if (debounce_period)
> > > + printf("debounce=%lu ", debounce_period);
> >
> > You should use prinfo here for formatting. But it would be even better
> > if this became a flag - like the bias, drive etc settings and be shown
> > inside the [] brackets at the end of the line - something like:
> > "[pull-up, used, debounce-period=1000us]".
> [...]
>
> Well it's not a flag; it's an attribute with a value. But if you
> think it should be grouped with the flags anyway, I can do that.
>
Yeah "flags" may be an unfortunate word. I should probably have called
the last column: optional attributes. Now that we have a growing
number of line attributes, I should probably rethink gpioinfo output
formatting for v2.
Bart
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-22 12:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 23:46 [PATCH libgpiod-v2] gpioinfo: Show edge detection and debounce period if enabled Ben Hutchings
2021-09-20 13:52 ` Bartosz Golaszewski
2021-09-22 11:49 ` Ben Hutchings
2021-09-22 12:59 ` Bartosz Golaszewski
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.