From 1d2b82be5bd41a7167681d29e5c7b01e4a9fad71 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 17 Jan 2017 15:54:24 +0100 Subject: [PATCH] core: allow to specify the consumer in simple set value routines Signed-off-by: Bartosz Golaszewski --- include/gpiod.h | 17 +++++++++++------ src/lib/core.c | 10 +++++----- src/tools/gpioset.c | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/gpiod.h b/include/gpiod.h index 23f36a9..f0b739c 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -163,6 +163,7 @@ typedef void (*gpiod_set_value_cb)(void *); /** * @brief Set values of a set of 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 set. * @param values An array of integers containing new values. @@ -173,13 +174,15 @@ typedef void (*gpiod_set_value_cb)(void *); * @param data User data that will be passed to the callback function. * @return 0 if the operation succeeds, -1 on error. */ -int gpiod_simple_set_value_multiple(const char *device, unsigned int *offsets, - int *values, unsigned int num_lines, - bool active_low, gpiod_set_value_cb cb, +int gpiod_simple_set_value_multiple(const char *consumer, const char *device, + unsigned int *offsets, int *values, + unsigned int num_lines, bool active_low, + gpiod_set_value_cb cb, void *data) GPIOD_API; /** * @brief Set value of 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 value New value. @@ -190,13 +193,15 @@ int gpiod_simple_set_value_multiple(const char *device, unsigned int *offsets, * @param data User data that will be passed to the callback function. * @return 0 if the operation succeeds, -1 on error. */ -static inline int gpiod_simple_set_value(const char *device, +static inline int gpiod_simple_set_value(const char *consumer, + const char *device, unsigned int offset, int value, bool active_low, gpiod_set_value_cb cb, void *data) { - return gpiod_simple_set_value_multiple(device, &offset, &value, 1, - active_low, cb, data); + return gpiod_simple_set_value_multiple(consumer, device, &offset, + &value, 1, active_low, + cb, data); } /** diff --git a/src/lib/core.c b/src/lib/core.c index 526023e..3488d43 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -205,10 +205,10 @@ int gpiod_simple_get_value_multiple(const char *consumer, const char *device, return status; } -int gpiod_simple_set_value_multiple(const char *device, unsigned int *offsets, - int *values, unsigned int num_lines, - bool active_low, gpiod_set_value_cb cb, - void *data) +int gpiod_simple_set_value_multiple(const char *consumer, const char *device, + unsigned int *offsets, int *values, + unsigned int num_lines, bool active_low, + gpiod_set_value_cb cb, void *data) { struct gpiod_line_bulk bulk; struct gpiod_chip *chip; @@ -237,7 +237,7 @@ int gpiod_simple_set_value_multiple(const char *device, unsigned int *offsets, gpiod_line_bulk_add(&bulk, line); } - status = gpiod_line_request_bulk_output(&bulk, libgpiod_consumer, + status = gpiod_line_request_bulk_output(&bulk, consumer, active_low, values); if (status < 0) { gpiod_chip_close(chip); diff --git a/src/tools/gpioset.c b/src/tools/gpioset.c index b6f9465..cb30a70 100644 --- a/src/tools/gpioset.c +++ b/src/tools/gpioset.c @@ -264,8 +264,8 @@ int main(int argc, char **argv) die("invalid offset: %s", argv[i + 1]); } - status = gpiod_simple_set_value_multiple(device, offsets, values, - num_lines, active_low, + status = gpiod_simple_set_value_multiple("gpioset", device, offsets, + values, num_lines, active_low, mode->callback, &cbdata); if (status < 0) die_perror("error setting the GPIO line values"); -- 2.30.2