From: Bartosz Golaszewski Date: Mon, 10 Jul 2017 08:15:05 +0000 (+0200) Subject: event: rename event requests routines X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=54dba79b4219a9eb7cc3c9332d0c310ec256d785;p=qemu-gpiodev%2Flibgpiod.git event: rename event requests routines The event request functionality is now merged with the regular requests. Change the naming pattern for event requests and move the prototypes under the input and output requests. Signed-off-by: Bartosz Golaszewski --- diff --git a/include/gpiod.h b/include/gpiod.h index 0ac9583..8fd521c 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -425,6 +425,39 @@ int gpiod_line_request_input(struct gpiod_line *line, int gpiod_line_request_output(struct gpiod_line *line, const char *consumer, bool active_low, 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; + +/** + * @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; + +/** + * @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; + /** * @brief Reserve a set of GPIO lines. * @param bulk Set of GPIO lines to reserve. @@ -584,39 +617,6 @@ struct gpiod_line_event { /**< Type of the event that occurred. */ }; -/** - * @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_event_request_rising(struct gpiod_line *line, - const char *consumer, - bool active_low) 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_event_request_falling(struct gpiod_line *line, - const char *consumer, - bool active_low) 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_event_request_both(struct gpiod_line *line, - const char *consumer, - bool active_low) GPIOD_API; - /** * @brief Wait for an event on a single line. * @param line GPIO line object. diff --git a/src/lib/line.c b/src/lib/line.c index 4dde754..b155028 100644 --- a/src/lib/line.c +++ b/src/lib/line.c @@ -642,22 +642,24 @@ static int line_event_request_type(struct gpiod_line *line, return gpiod_line_request(line, &config, 0); } -int gpiod_line_event_request_rising(struct gpiod_line *line, - const char *consumer, bool active_low) +int gpiod_line_request_rising_edge_events(struct gpiod_line *line, + const char *consumer, + bool active_low) { return line_event_request_type(line, consumer, active_low, GPIOD_REQUEST_EVENT_RISING_EDGE); } -int gpiod_line_event_request_falling(struct gpiod_line *line, - const char *consumer, bool active_low) +int gpiod_line_request_falling_edge_events(struct gpiod_line *line, + const char *consumer, + bool active_low) { return line_event_request_type(line, consumer, active_low, GPIOD_REQUEST_EVENT_FALLING_EDGE); } -int gpiod_line_event_request_both(struct gpiod_line *line, - const char *consumer, bool active_low) +int gpiod_line_request_both_edges_events(struct gpiod_line *line, + const char *consumer, bool active_low) { return line_event_request_type(line, consumer, active_low, GPIOD_REQUEST_EVENT_BOTH_EDGES); diff --git a/src/lib/simple.c b/src/lib/simple.c index f3ac1b9..d6db02e 100644 --- a/src/lib/simple.c +++ b/src/lib/simple.c @@ -150,7 +150,7 @@ int gpiod_simple_event_loop(const char *consumer, const char *device, return -1; } - status = gpiod_line_event_request_both(line, consumer, active_low); + status = gpiod_line_request_both_edges_events(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 532b00e..a00752f 100644 --- a/tests/tests-event.c +++ b/tests/tests-event.c @@ -16,7 +16,7 @@ static void event_rising_edge_good(void) struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -24,16 +24,16 @@ static void event_rising_edge_good(void) line = gpiod_chip_get_line(chip, 7); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_event_request_rising(line, TEST_CONSUMER, false); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false); + TEST_ASSERT_RET_OK(rv); test_set_event(0, 7, TEST_EVENT_RISING, 100); - status = gpiod_line_event_wait(line, &ts); - TEST_ASSERT_EQ(status, 1); + rv = gpiod_line_event_wait(line, &ts); + TEST_ASSERT_EQ(rv, 1); - status = gpiod_line_event_read(line, &ev); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_event_read(line, &ev); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_RISING_EDGE); } @@ -47,7 +47,7 @@ static void event_falling_edge_good(void) struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -55,16 +55,17 @@ static void event_falling_edge_good(void) line = gpiod_chip_get_line(chip, 7); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_event_request_falling(line, TEST_CONSUMER, false); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_falling_edge_events(line, + TEST_CONSUMER, false); + TEST_ASSERT_RET_OK(rv); test_set_event(0, 7, TEST_EVENT_FALLING, 100); - status = gpiod_line_event_wait(line, &ts); - TEST_ASSERT_EQ(status, 1); + rv = gpiod_line_event_wait(line, &ts); + TEST_ASSERT_EQ(rv, 1); - status = gpiod_line_event_read(line, &ev); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_event_read(line, &ev); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_FALLING_EDGE); } @@ -77,7 +78,7 @@ static void event_rising_edge_ignore_falling(void) TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; struct timespec ts = { 0, 300 }; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -85,13 +86,13 @@ static void event_rising_edge_ignore_falling(void) line = gpiod_chip_get_line(chip, 7); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_event_request_rising(line, TEST_CONSUMER, false); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false); + TEST_ASSERT_RET_OK(rv); test_set_event(0, 7, TEST_EVENT_FALLING, 100); - status = gpiod_line_event_wait(line, &ts); - TEST_ASSERT_EQ(status, 0); + rv = gpiod_line_event_wait(line, &ts); + TEST_ASSERT_EQ(rv, 0); } TEST_DEFINE(event_rising_edge_ignore_falling, "events - request rising edge & ignore falling edge events", @@ -103,7 +104,7 @@ static void event_rising_edge_active_low(void) struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -111,16 +112,16 @@ static void event_rising_edge_active_low(void) line = gpiod_chip_get_line(chip, 7); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_event_request_rising(line, TEST_CONSUMER, true); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, true); + TEST_ASSERT_RET_OK(rv); test_set_event(0, 7, TEST_EVENT_RISING, 100); - status = gpiod_line_event_wait(line, &ts); - TEST_ASSERT_EQ(status, 1); + rv = gpiod_line_event_wait(line, &ts); + TEST_ASSERT_EQ(rv, 1); - status = gpiod_line_event_read(line, &ev); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_event_read(line, &ev); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_RISING_EDGE); } @@ -134,7 +135,7 @@ static void event_get_value(void) struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -142,24 +143,24 @@ static void event_get_value(void) line = gpiod_chip_get_line(chip, 7); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_event_request_rising(line, TEST_CONSUMER, false); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false); + TEST_ASSERT_RET_OK(rv); - status = gpiod_line_get_value(line); - TEST_ASSERT_EQ(status, 0); + rv = gpiod_line_get_value(line); + TEST_ASSERT_EQ(rv, 0); test_set_event(0, 7, TEST_EVENT_RISING, 100); - status = gpiod_line_event_wait(line, &ts); - TEST_ASSERT_EQ(status, 1); + rv = gpiod_line_event_wait(line, &ts); + TEST_ASSERT_EQ(rv, 1); - status = gpiod_line_event_read(line, &ev); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_event_read(line, &ev); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_RISING_EDGE); - status = gpiod_line_get_value(line); - TEST_ASSERT_EQ(status, 1); + rv = gpiod_line_get_value(line); + TEST_ASSERT_EQ(rv, 1); } TEST_DEFINE(event_get_value, "events - mixing events and gpiod_line_get_value()",