core: remove the active_low boolean argument from single-line requests
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 12 Jul 2017 18:37:43 +0000 (20:37 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 12 Jul 2017 18:41:09 +0000 (20:41 +0200)
Remove the separate argument for setting the active-state to low in
helper functions doing the single GPIO line requests.

Introduce new variants of these helpers that allow to pass
a combination of all available flags to the request.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/core.c
src/lib/simple.c
tests/tests-event.c
tests/tests-gpioinfo.c
tests/tests-line.c

index a8196c9a98fa306659883ac83bb22778fb930ab9..c7a0335dfceea2854d0ee90d48fb319a01cf2c24 100644 (file)
@@ -486,56 +486,102 @@ int gpiod_line_request(struct gpiod_line *line,
  * @brief Reserve a single line, set the direction to input.
  * @param line GPIO line object.
  * @param consumer Name of the consumer.
- * @param active_low Active state of the line (true if low).
  * @return 0 if the line was properly reserved, -1 on failure.
  */
 int gpiod_line_request_input(struct gpiod_line *line,
-                            const char *consumer,
-                            bool active_low) GPIOD_API;
+                            const char *consumer) GPIOD_API;
 
 /**
  * @brief Reserve a single line, set the direction to output.
  * @param line GPIO line object.
  * @param consumer Name of the consumer.
- * @param active_low Active state of the line (true if low).
  * @param default_val Default line value.
  * @return 0 if the line was properly reserved, -1 on failure.
  */
-int gpiod_line_request_output(struct gpiod_line *line, const char *consumer,
-                             bool active_low, int default_val) GPIOD_API;
+int gpiod_line_request_output(struct gpiod_line *line,
+                             const char *consumer, int default_val) GPIOD_API;
 
 /**
  * @brief Request rising edge event notifications on a single line.
  * @param line GPIO line object.
  * @param consumer Name of the consumer.
- * @param active_low Active state of the line - true if low.
  * @return 0 if the operation succeeds, -1 on failure.
  */
 int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
-                                         const char *consumer,
-                                         bool active_low) GPIOD_API;
+                                         const char *consumer) GPIOD_API;
 
 /**
  * @brief Request falling edge event notifications on a single line.
  * @param line GPIO line object.
  * @param consumer Name of the consumer.
- * @param active_low Active state of the line - true if low.
  * @return 0 if the operation succeeds, -1 on failure.
  */
 int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
-                                          const char *consumer,
-                                          bool active_low) GPIOD_API;
+                                          const char *consumer) GPIOD_API;
 
 /**
  * @brief Request all event type notifications on a single line.
  * @param line GPIO line object.
  * @param consumer Name of the consumer.
- * @param active_low Active state of the line - true if low.
  * @return 0 if the operation succeeds, -1 on failure.
  */
 int gpiod_line_request_both_edges_events(struct gpiod_line *line,
-                                        const char *consumer,
-                                        bool active_low) GPIOD_API;
+                                        const char *consumer) GPIOD_API;
+
+/**
+ * @brief Reserve a single line, set the direction to input.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param flags Additional request flags.
+ * @return 0 if the line was properly reserved, -1 on failure.
+ */
+int gpiod_line_request_input_flags(struct gpiod_line *line,
+                                  const char *consumer, int flags) GPIOD_API;
+
+/**
+ * @brief Reserve a single line, set the direction to output.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param flags Additional request flags.
+ * @param default_val Default line value.
+ * @return 0 if the line was properly reserved, -1 on failure.
+ */
+int gpiod_line_request_output_flags(struct gpiod_line *line,
+                                   const char *consumer, int flags,
+                                   int default_val) GPIOD_API;
+
+/**
+ * @brief Request rising edge event notifications on a single line.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param flags Additional request flags.
+ * @return 0 if the operation succeeds, -1 on failure.
+ */
+int gpiod_line_request_rising_edge_events_flags(struct gpiod_line *line,
+                                               const char *consumer,
+                                               int flags) GPIOD_API;
+
+/**
+ * @brief Request falling edge event notifications on a single line.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param flags Additional request flags.
+ * @return 0 if the operation succeeds, -1 on failure.
+ */
+int gpiod_line_request_falling_edge_events_flags(struct gpiod_line *line,
+                                                const char *consumer,
+                                                int flags) GPIOD_API;
+
+/**
+ * @brief Request all event type notifications on a single line.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param flags Additional request flags.
+ * @return 0 if the operation succeeds, -1 on failure.
+ */
+int gpiod_line_request_both_edges_events_flags(struct gpiod_line *line,
+                                              const char *consumer,
+                                              int flags) GPIOD_API;
 
 /**
  * @brief Reserve a set of GPIO lines.
index 1e07b82e9eddc929e80edff27140749c0f422118..f770252283fb9884671020c9bde05465bf302669 100644 (file)
@@ -222,25 +222,47 @@ int gpiod_line_request(struct gpiod_line *line,
        return gpiod_line_request_bulk(&bulk, config, &default_val);
 }
 
-int gpiod_line_request_input(struct gpiod_line *line,
-                            const char *consumer, bool active_low)
+int gpiod_line_request_input(struct gpiod_line *line, const char *consumer)
 {
        struct gpiod_line_request_config config = {
                .consumer = consumer,
                .request_type = GPIOD_REQUEST_DIRECTION_INPUT,
-               .flags = active_low ? GPIOD_REQUEST_ACTIVE_LOW : 0,
        };
 
        return gpiod_line_request(line, &config, 0);
 }
 
-int gpiod_line_request_output(struct gpiod_line *line, const char *consumer,
-                             bool active_low, int default_val)
+int gpiod_line_request_output(struct gpiod_line *line,
+                             const char *consumer, int default_val)
 {
        struct gpiod_line_request_config config = {
                .consumer = consumer,
                .request_type = GPIOD_REQUEST_DIRECTION_OUTPUT,
-               .flags = active_low ? GPIOD_REQUEST_ACTIVE_LOW : 0,
+       };
+
+       return gpiod_line_request(line, &config, default_val);
+}
+
+int gpiod_line_request_input_flags(struct gpiod_line *line,
+                                  const char *consumer, int flags)
+{
+       struct gpiod_line_request_config config = {
+               .consumer = consumer,
+               .request_type = GPIOD_REQUEST_DIRECTION_INPUT,
+               .flags = flags,
+       };
+
+       return gpiod_line_request(line, &config, 0);
+}
+
+int gpiod_line_request_output_flags(struct gpiod_line *line,
+                                   const char *consumer, int flags,
+                                   int default_val)
+{
+       struct gpiod_line_request_config config = {
+               .consumer = consumer,
+               .request_type = GPIOD_REQUEST_DIRECTION_OUTPUT,
+               .flags = flags,
        };
 
        return gpiod_line_request(line, &config, default_val);
@@ -591,41 +613,61 @@ struct gpiod_line * gpiod_line_find_by_name(const char *name)
 }
 
 static int line_event_request_type(struct gpiod_line *line,
-                                  const char *consumer,
-                                  bool active_low, int type)
+                                  const char *consumer, int flags, int type)
 {
        struct gpiod_line_request_config config = {
                .consumer = consumer,
                .request_type = type,
-               .flags = active_low ? GPIOD_REQUEST_ACTIVE_LOW : 0,
+               .flags = flags,
        };
 
        return gpiod_line_request(line, &config, 0);
 }
 
 int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
-                                         const char *consumer,
-                                         bool active_low)
+                                         const char *consumer)
 {
-       return line_event_request_type(line, consumer, active_low,
+       return line_event_request_type(line, consumer, 0,
                                       GPIOD_REQUEST_EVENT_RISING_EDGE);
 }
 
 int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
-                                          const char *consumer,
-                                          bool active_low)
+                                          const char *consumer)
 {
-       return line_event_request_type(line, consumer, active_low,
+       return line_event_request_type(line, consumer, 0,
                                       GPIOD_REQUEST_EVENT_FALLING_EDGE);
 }
 
 int gpiod_line_request_both_edges_events(struct gpiod_line *line,
-                                        const char *consumer, bool active_low)
+                                        const char *consumer)
 {
-       return line_event_request_type(line, consumer, active_low,
+       return line_event_request_type(line, consumer, 0,
                                       GPIOD_REQUEST_EVENT_BOTH_EDGES);
 }
 
+int gpiod_line_request_rising_edge_events_flags(struct gpiod_line *line,
+                                               const char *consumer,
+                                               int flags)
+{
+       return line_event_request_type(line, consumer, flags,
+                                      GPIOD_REQUEST_EVENT_RISING_EDGE);
+}
+
+int gpiod_line_request_falling_edge_events_flags(struct gpiod_line *line,
+                                                const char *consumer,
+                                                int flags)
+{
+       return line_event_request_type(line, consumer, flags,
+                                      GPIOD_REQUEST_EVENT_RISING_EDGE);
+}
+
+int gpiod_line_request_both_edges_events_flags(struct gpiod_line *line,
+                                              const char *consumer, int flags)
+{
+       return line_event_request_type(line, consumer, flags,
+                                      GPIOD_REQUEST_EVENT_RISING_EDGE);
+}
+
 int gpiod_line_event_wait(struct gpiod_line *line,
                          const struct timespec *timeout)
 {
index 5eb121f64e1ec6ca84c501542f136791dd1ca39d..0f81d1c8e913d2fd3394d02e16b4af790b335604 100644 (file)
@@ -152,7 +152,8 @@ int gpiod_simple_event_loop(const char *consumer, const char *device,
                return -1;
        }
 
-       status = gpiod_line_request_both_edges_events(line, consumer, active_low);
+       status = gpiod_line_request_both_edges_events_flags(line, consumer,
+                                                           active_low);
        if (status < 0) {
                gpiod_chip_close(chip);
                return -1;
index fe59dafb8e5d607636214e43e74382373ffebd4b..1406c19f7c9a14ccf2b836e6641a12341f7f2380 100644 (file)
@@ -26,7 +26,7 @@ static void event_rising_edge_good(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false);
+       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_RISING, 100);
@@ -57,8 +57,7 @@ static void event_falling_edge_good(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       rv = gpiod_line_request_falling_edge_events(line,
-                                                   TEST_CONSUMER, false);
+       rv = gpiod_line_request_falling_edge_events(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_FALLING, 100);
@@ -88,7 +87,7 @@ static void event_rising_edge_ignore_falling(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false);
+       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_FALLING, 100);
@@ -114,7 +113,8 @@ static void event_rising_edge_active_low(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, true);
+       rv = gpiod_line_request_rising_edge_events_flags(line, TEST_CONSUMER,
+                                               GPIOD_REQUEST_ACTIVE_LOW);
        TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_RISING, 100);
@@ -145,7 +145,7 @@ static void event_get_value(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false);
+       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        rv = gpiod_line_get_value(line);
index 8a4a4adb25e5dac92351ac88341fdb9e9b64637e..adfeb40fd21e87a0a5ddd5d647fccf7ae1a50eb4 100644 (file)
@@ -51,7 +51,8 @@ static void gpioinfo_dump_all_chips_one_exported(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       rv = gpiod_line_request_input(line, TEST_CONSUMER, true);
+       rv = gpiod_line_request_input_flags(line, TEST_CONSUMER,
+                                           GPIOD_REQUEST_ACTIVE_LOW);
        TEST_ASSERT_RET_OK(rv);
 
        test_tool_run("gpioinfo", (char *)NULL);
index 8f5862ecb1cb0cfe88d5d9fa1e0d1f7a6ffa1af6..368275e56f13789e2286048a854b161615a0cdaa 100644 (file)
@@ -29,9 +29,9 @@ static void line_request_output(void)
        TEST_ASSERT_NOT_NULL(line_0);
        TEST_ASSERT_NOT_NULL(line_1);
 
-       status = gpiod_line_request_output(line_0, TEST_CONSUMER, false, 0);
+       status = gpiod_line_request_output(line_0, TEST_CONSUMER, 0);
        TEST_ASSERT_RET_OK(status);
-       status = gpiod_line_request_output(line_1, TEST_CONSUMER, false, 1);
+       status = gpiod_line_request_output(line_1, TEST_CONSUMER, 1);
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT_EQ(gpiod_line_get_value(line_0), 0);
@@ -56,10 +56,10 @@ static void line_request_already_requested(void)
        line = gpiod_chip_get_line(chip, 0);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_request_input(line, TEST_CONSUMER, false);
+       status = gpiod_line_request_input(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(status);
 
-       status = gpiod_line_request_input(line, TEST_CONSUMER, false);
+       status = gpiod_line_request_input(line, TEST_CONSUMER);
        TEST_ASSERT_NOTEQ(status, 0);
        TEST_ASSERT_EQ(errno, EBUSY);
 }
@@ -81,7 +81,7 @@ static void line_consumer(void)
 
        TEST_ASSERT_NULL(gpiod_line_consumer(line));
 
-       status = gpiod_line_request_input(line, TEST_CONSUMER, false);
+       status = gpiod_line_request_input(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT(!gpiod_line_needs_update(line));
@@ -106,8 +106,7 @@ static void line_consumer_long_string(void)
        TEST_ASSERT_NULL(gpiod_line_consumer(line));
 
        status = gpiod_line_request_input(line,
-                                         "consumer string over 32 characters long",
-                                         false);
+                                         "consumer string over 32 characters long");
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT(!gpiod_line_needs_update(line));
@@ -267,7 +266,7 @@ static void line_set_value(void)
        line = gpiod_chip_get_line(chip, 2);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_request_output(line, TEST_CONSUMER, false, 0);
+       status = gpiod_line_request_output(line, TEST_CONSUMER, 0);
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT_RET_OK(gpiod_line_set_value(line, 1));
@@ -309,14 +308,14 @@ static void line_direction(void)
        line = gpiod_chip_get_line(chip, 5);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_request_output(line, TEST_CONSUMER, false, 0);
+       status = gpiod_line_request_output(line, TEST_CONSUMER, 0);
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT_EQ(gpiod_line_direction(line), GPIOD_DIRECTION_OUTPUT);
 
        gpiod_line_release(line);
 
-       status = gpiod_line_request_input(line, TEST_CONSUMER, false);
+       status = gpiod_line_request_input(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT_EQ(gpiod_line_direction(line), GPIOD_DIRECTION_INPUT);
@@ -337,14 +336,15 @@ static void line_active_state(void)
        line = gpiod_chip_get_line(chip, 5);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_request_input(line, TEST_CONSUMER, false);
+       status = gpiod_line_request_input(line, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT_EQ(gpiod_line_active_state(line), GPIOD_ACTIVE_STATE_HIGH);
 
        gpiod_line_release(line);
 
-       status = gpiod_line_request_input(line, TEST_CONSUMER, true);
+       status = gpiod_line_request_input_flags(line, TEST_CONSUMER,
+                                               GPIOD_REQUEST_ACTIVE_LOW);
        TEST_ASSERT_RET_OK(status);
 
        TEST_ASSERT_EQ(gpiod_line_direction(line), GPIOD_DIRECTION_INPUT);