core: allow to specify the consumer in simple set value routines
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 14:54:24 +0000 (15:54 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 14:54:24 +0000 (15:54 +0100)
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/core.c
src/tools/gpioset.c

index 23f36a93149fcb62b71a827aa9851e6d9c0e81bd..f0b739c42d7712885e998d325f7a3579edac1bbb 100644 (file)
@@ -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);
 }
 
 /**
index 526023eba74dece47c6dc4a7c5e001dc2b5fa67c..3488d4379a95f21c620635a8832c172d25331486 100644 (file)
@@ -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);
index b6f94654808e8ae7039683f649c3910349fcb098..cb30a70fc4fbd3fce63f7f5d0df1a900954c37b9 100644 (file)
@@ -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");