From 54957b05724ffe786c0c18d038d9d2fedb14c5fe Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 9 Mar 2022 10:14:33 +0100 Subject: [PATCH] gpiosim: add an enum representing line active state In order to avoid confusion and stress the fact that "value" represents the logical state of a GPIO line, add a two-value enum with the names "ACTIVE" and "INACTIVE" to the libgpiosim API. Signed-off-by: Bartosz Golaszewski --- tests/gpiosim/gpiosim-selftest.c | 2 +- tests/gpiosim/gpiosim.c | 4 ++-- tests/gpiosim/gpiosim.h | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/gpiosim/gpiosim-selftest.c b/tests/gpiosim/gpiosim-selftest.c index 205580d..f2d0b35 100644 --- a/tests/gpiosim/gpiosim-selftest.c +++ b/tests/gpiosim/gpiosim-selftest.c @@ -135,7 +135,7 @@ int main(int argc UNUSED, char **argv UNUSED) return EXIT_FAILURE; } - if (ret != 1) { + if (ret != GPIOSIM_VALUE_ACTIVE) { fprintf(stderr, "Invalid value read\n"); return EXIT_FAILURE; } diff --git a/tests/gpiosim/gpiosim.c b/tests/gpiosim/gpiosim.c index ea5357a..3e13ff9 100644 --- a/tests/gpiosim/gpiosim.c +++ b/tests/gpiosim/gpiosim.c @@ -982,9 +982,9 @@ GPIOSIM_API int gpiosim_bank_get_value(struct gpiosim_bank *bank, return ret; if (what[0] == '0') - return 0; + return GPIOSIM_VALUE_INACTIVE; if (what[0] == '1') - return 1; + return GPIOSIM_VALUE_ACTIVE; errno = EIO; return -1; diff --git a/tests/gpiosim/gpiosim.h b/tests/gpiosim/gpiosim.h index 25b245a..32f81bc 100644 --- a/tests/gpiosim/gpiosim.h +++ b/tests/gpiosim/gpiosim.h @@ -15,6 +15,11 @@ struct gpiosim_ctx; struct gpiosim_dev; struct gpiosim_bank; +enum { + GPIOSIM_VALUE_INACTIVE = 0, + GPIOSIM_VALUE_ACTIVE = 1, +}; + enum { GPIOSIM_PULL_DOWN = 1, GPIOSIM_PULL_UP, -- 2.30.2