From f2349eb8a31cce9fda84f1ef6dbcca17323bfc50 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 3 Jan 2017 11:17:19 +0100 Subject: [PATCH] core: implement gpiod_line_polarity() Instead of returning a boolean value from gpiod_line_is_active_low(), introduce two separate values as is done for direction and implement gpiod_line_polarity(). This makes the code less confusing. Signed-off-by: Bartosz Golaszewski --- core.c | 6 ++++-- gpiod.h | 7 ++++++- gpioinfo.c | 10 +++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core.c b/core.c index 4ba7bae..fe3b54e 100644 --- a/core.c +++ b/core.c @@ -168,9 +168,11 @@ int gpiod_line_direction(struct gpiod_line *line) : GPIOD_DIRECTION_IN; } -bool gpiod_line_is_active_low(struct gpiod_line *line) +int gpiod_line_polarity(struct gpiod_line *line) { - return line->info.flags & GPIOLINE_FLAG_ACTIVE_LOW; + return line->info.flags & GPIOLINE_FLAG_ACTIVE_LOW + ? GPIOD_POLARITY_ACTIVE_LOW + : GPIOD_POLARITY_ACTIVE_HIGH; } bool gpiod_line_is_used_by_kernel(struct gpiod_line *line) diff --git a/gpiod.h b/gpiod.h index 5e34b29..dea05d4 100644 --- a/gpiod.h +++ b/gpiod.h @@ -51,6 +51,11 @@ enum { GPIOD_DIRECTION_OUT, }; +enum { + GPIOD_POLARITY_ACTIVE_HIGH, + GPIOD_POLARITY_ACTIVE_LOW, +}; + enum { GPIOD_REQUEST_ACTIVE_LOW = GPIOD_BIT(0), GPIOD_REQUEST_OPEN_DRAIN = GPIOD_BIT(1), @@ -69,7 +74,7 @@ const char * gpiod_line_consumer(struct gpiod_line *line) GPIOD_API; int gpiod_line_direction(struct gpiod_line *line) GPIOD_API; -bool gpiod_line_is_active_low(struct gpiod_line *line) GPIOD_API; +int gpiod_line_polarity(struct gpiod_line *line) GPIOD_API; bool gpiod_line_is_used_by_kernel(struct gpiod_line *line) GPIOD_API; diff --git a/gpioinfo.c b/gpioinfo.c index 9ca0ecc..90c1d60 100644 --- a/gpioinfo.c +++ b/gpioinfo.c @@ -39,12 +39,11 @@ static const struct flag flags[] = { int main(int argc, char **argv) { - int i, direction, flag_printed; + int i, direction, flag_printed, polarity; struct gpiod_line_iter iter; const char *name, *consumer; struct gpiod_line *line; struct gpiod_chip *chip; - bool active_low; unsigned int j; for (i = 1; i < argc; i++) { @@ -65,7 +64,7 @@ int main(int argc, char **argv) name = gpiod_line_name(line); consumer = gpiod_line_consumer(line); direction = gpiod_line_direction(line); - active_low = gpiod_line_is_active_low(line); + polarity = gpiod_line_polarity(line); printf("\tline %2u: ", gpiod_line_offset(line)); @@ -83,8 +82,9 @@ int main(int argc, char **argv) printf("%s ", direction == GPIOD_DIRECTION_IN ? "input" : "output"); - printf("%s ", active_low ? "active-low" - : "active-high"); + printf("%s ", polarity == GPIOD_POLARITY_ACTIVE_LOW + ? "active-low" + : "active-high"); flag_printed = false; for (j = 0; j < ARRAY_SIZE(flags); j++) { -- 2.30.2