From: Bartosz Golaszewski Date: Wed, 11 Oct 2017 15:53:32 +0000 (+0200) Subject: simple-api: modify the order of arguments in get value routines X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b3eb355472689c490118d337216d73317f7a74ab;p=qemu-gpiodev%2Flibgpiod.git simple-api: modify the order of arguments in get value routines Move the consumer string to the end of the argument list as the least significant option. Signed-off-by: Bartosz Golaszewski --- diff --git a/include/gpiod.h b/include/gpiod.h index 04f89d9..8171369 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -68,29 +68,29 @@ struct gpiod_chip_iter; /** * @brief Read current value from a single GPIO line. - * @param consumer Name of the consumer. * @param device Name, path or number of the gpiochip. * @param offset GPIO line offset on the chip. * @param active_low The active state of this line - true if low. + * @param consumer Name of the consumer. * @return 0 or 1 (GPIO value) if the operation succeeds, -1 on error. */ -int gpiod_simple_get_value(const char *consumer, const char *device, - unsigned int offset, bool active_low) GPIOD_API; +int gpiod_simple_get_value(const char *device, unsigned int offset, + bool active_low, const char *consumer) GPIOD_API; /** * @brief Read current values from a set of GPIO lines. - * @param consumer Name of the consumer. * @param device Name, path or number of the gpiochip. * @param offsets An array of offsets of lines whose values should be read. * @param values A buffer in which the values will be stored. * @param num_lines Number of lines, must be > 0. * @param active_low The active state of the lines - true if low. + * @param consumer Name of the consumer. * @return 0 if the operation succeeds, -1 on error. */ -int gpiod_simple_get_value_multiple(const char *consumer, const char *device, +int gpiod_simple_get_value_multiple(const char *device, const unsigned int *offsets, int *values, - unsigned int num_lines, - bool active_low) GPIOD_API; + unsigned int num_lines, bool active_low, + const char *consumer) GPIOD_API; /** * @brief Simple set value callback signature. diff --git a/src/lib/simple.c b/src/lib/simple.c index a71ea00..8b3561b 100644 --- a/src/lib/simple.c +++ b/src/lib/simple.c @@ -17,22 +17,23 @@ #include #include -int gpiod_simple_get_value(const char *consumer, const char *device, - unsigned int offset, bool active_low) +int gpiod_simple_get_value(const char *device, unsigned int offset, + bool active_low, const char *consumer) { int value, status; - status = gpiod_simple_get_value_multiple(consumer, device, &offset, - &value, 1, active_low); + status = gpiod_simple_get_value_multiple(device, &offset, &value, + 1, active_low, consumer); if (status < 0) return status; return value; } -int gpiod_simple_get_value_multiple(const char *consumer, const char *device, +int gpiod_simple_get_value_multiple(const char *device, const unsigned int *offsets, int *values, - unsigned int num_lines, bool active_low) + unsigned int num_lines, bool active_low, + const char *consumer) { struct gpiod_line_bulk bulk; struct gpiod_chip *chip; diff --git a/src/tools/gpioget.c b/src/tools/gpioget.c index fba161c..37fd7cc 100644 --- a/src/tools/gpioget.c +++ b/src/tools/gpioget.c @@ -88,9 +88,9 @@ int main(int argc, char **argv) die("invalid GPIO offset: %s", argv[i + 1]); } - status = gpiod_simple_get_value_multiple("gpioset", device, - offsets, values, - num_lines, active_low); + status = gpiod_simple_get_value_multiple(device, offsets, values, + num_lines, active_low, + "gpioget"); if (status < 0) die_perror("error reading GPIO values"); diff --git a/tests/tests-gpioset.c b/tests/tests-gpioset.c index d265bf5..3d10023 100644 --- a/tests/tests-gpioset.c +++ b/tests/tests-gpioset.c @@ -39,8 +39,8 @@ static void gpioset_set_lines_and_exit(void) offsets[6] = 6; offsets[7] = 7; - rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2), - offsets, values, 8, false); + rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets, + values, 8, false, TEST_CONSUMER); TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 0); @@ -80,8 +80,8 @@ static void gpioset_set_lines_and_exit_active_low(void) offsets[6] = 6; offsets[7] = 7; - rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2), - offsets, values, 8, false); + rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets, + values, 8, false, TEST_CONSUMER); TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 1); @@ -121,8 +121,8 @@ static void gpioset_set_lines_and_exit_explicit_mode(void) offsets[6] = 6; offsets[7] = 7; - rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2), - offsets, values, 8, false); + rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets, + values, 8, false, TEST_CONSUMER); TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 0); @@ -159,8 +159,8 @@ static void gpioset_set_some_lines_and_wait_for_enter(void) offsets[3] = 6; offsets[4] = 7; - rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2), - offsets, values, 5, false); + rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets, + values, 5, false, TEST_CONSUMER); TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 0); @@ -198,10 +198,9 @@ static void gpioset_set_some_lines_and_wait_for_signal(void) offsets[3] = 6; offsets[4] = 7; - rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, - test_chip_name(2), + rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets, values, - 5, false); + 5, false, TEST_CONSUMER); TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 0); @@ -235,8 +234,8 @@ static void gpioset_set_some_lines_and_wait_time(void) offsets[1] = 2; offsets[2] = 5; - rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0), - offsets, values, 3, false); + rv = gpiod_simple_get_value_multiple(test_chip_name(0), offsets, + values, 3, false, TEST_CONSUMER); TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 1); diff --git a/tests/tests-simple-api.c b/tests/tests-simple-api.c index bfbe626..11d1a74 100644 --- a/tests/tests-simple-api.c +++ b/tests/tests-simple-api.c @@ -18,16 +18,16 @@ static void simple_set_get_value(void) { int ret; - ret = gpiod_simple_get_value(TEST_CONSUMER, - test_chip_name(0), 3, false); + ret = gpiod_simple_get_value(test_chip_name(0), 3, + false, TEST_CONSUMER); TEST_ASSERT_EQ(ret, 0); ret = gpiod_simple_set_value(TEST_CONSUMER, test_chip_name(0), 3, 1, false, NULL, NULL); TEST_ASSERT_RET_OK(ret); - ret = gpiod_simple_get_value(TEST_CONSUMER, - test_chip_name(0), 3, false); + ret = gpiod_simple_get_value(test_chip_name(0), 3, + false, TEST_CONSUMER); TEST_ASSERT_EQ(ret, 1); } TEST_DEFINE(simple_set_get_value, @@ -37,11 +37,11 @@ TEST_DEFINE(simple_set_get_value, static void simple_set_get_value_multiple(void) { unsigned int offsets[] = { 0, 1, 2, 3, 4, 5, 6, 12, 13, 15 }; - int values[10], ret; + int values[10], rv; - ret = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0), - offsets, values, 10, false); - TEST_ASSERT_RET_OK(ret); + rv = gpiod_simple_get_value_multiple(test_chip_name(0), offsets, + values, 10, false, TEST_CONSUMER); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 0); TEST_ASSERT_EQ(values[1], 0); @@ -65,14 +65,14 @@ static void simple_set_get_value_multiple(void) values[8] = 0; values[9] = 0; - ret = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(0), + rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(0), offsets, values, 10, false, NULL, NULL); - TEST_ASSERT_RET_OK(ret); + TEST_ASSERT_RET_OK(rv); - ret = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0), - offsets, values, 10, false); - TEST_ASSERT_RET_OK(ret); + rv = gpiod_simple_get_value_multiple(test_chip_name(0), offsets, + values, 10, false, TEST_CONSUMER); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(values[0], 1); TEST_ASSERT_EQ(values[1], 1); @@ -94,10 +94,10 @@ static void simple_get_value_multiple_max_lines(void) unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES + 1]; int values[GPIOD_LINE_BULK_MAX_LINES + 1], ret; - ret = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0), - offsets, values, + ret = gpiod_simple_get_value_multiple(test_chip_name(0), offsets, + values, GPIOD_LINE_BULK_MAX_LINES + 1, - false); + false, TEST_CONSUMER); TEST_ASSERT_NOTEQ(ret, 0); TEST_ASSERT_ERRNO_IS(EINVAL); }