From: Bartosz Golaszewski Date: Wed, 12 Jul 2017 18:37:43 +0000 (+0200) Subject: core: remove the active_low boolean argument from single-line requests X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=47d97c70accb769b7a7a96c549004da77d31b53c;p=qemu-gpiodev%2Flibgpiod.git core: remove the active_low boolean argument from single-line requests 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 --- diff --git a/include/gpiod.h b/include/gpiod.h index a8196c9..c7a0335 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -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. diff --git a/src/lib/core.c b/src/lib/core.c index 1e07b82..f770252 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -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) { diff --git a/src/lib/simple.c b/src/lib/simple.c index 5eb121f..0f81d1c 100644 --- a/src/lib/simple.c +++ b/src/lib/simple.c @@ -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; diff --git a/tests/tests-event.c b/tests/tests-event.c index fe59daf..1406c19 100644 --- a/tests/tests-event.c +++ b/tests/tests-event.c @@ -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); diff --git a/tests/tests-gpioinfo.c b/tests/tests-gpioinfo.c index 8a4a4ad..adfeb40 100644 --- a/tests/tests-gpioinfo.c +++ b/tests/tests-gpioinfo.c @@ -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); diff --git a/tests/tests-line.c b/tests/tests-line.c index 8f5862e..368275e 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -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);