From 3a903b5abbb0ae7ce24a53aad1a67e225a12afda Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 13 Jul 2017 13:53:46 +0200 Subject: [PATCH] core: add bulk event requests Add functions for requesting events for line bulk objects. Both with and without additional flags. Signed-off-by: Bartosz Golaszewski --- include/gpiod.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/core.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/include/gpiod.h b/include/gpiod.h index 828f824..fb00106 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -620,6 +620,33 @@ int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk, const char *consumer, const int *default_vals) GPIOD_API; +/** + * @brief Request rising edge event notifications on a set of lines. + * @param bulk Set of GPIO lines to request. + * @param consumer Name of the consumer. + * @return 0 if the operation succeeds, -1 on failure. + */ +int gpiod_line_request_bulk_rising_edge_events(struct gpiod_line_bulk *bulk, + const char *consumer) GPIOD_API; + +/** + * @brief Request falling edge event notifications on a set of lines. + * @param bulk Set of GPIO lines to request. + * @param consumer Name of the consumer. + * @return 0 if the operation succeeds, -1 on failure. + */ +int gpiod_line_request_bulk_falling_edge_events(struct gpiod_line_bulk *bulk, + const char *consumer) GPIOD_API; + +/** + * @brief Request all event type notifications on a set of lines. + * @param bulk Set of GPIO lines to request. + * @param consumer Name of the consumer. + * @return 0 if the operation succeeds, -1 on failure. + */ +int gpiod_line_request_bulk_both_edges_events(struct gpiod_line_bulk *bulk, + const char *consumer) GPIOD_API; + /** * @brief Reserve a set of GPIO lines, set the direction to input. * @param bulk Set of GPIO lines to reserve. @@ -643,6 +670,42 @@ int gpiod_line_request_bulk_output_flags(struct gpiod_line_bulk *bulk, const char *consumer, int flags, const int *default_vals) GPIOD_API; +/** + * @brief Request rising edge event notifications on a set of lines. + * @param bulk Set of GPIO lines to request. + * @param consumer Name of the consumer. + * @param flags Additional request flags. + * @return 0 if the operation succeeds, -1 on failure. + */ +int gpiod_line_request_bulk_rising_edge_events_flags( + struct gpiod_line_bulk *bulk, + const char *consumer, + int flags) GPIOD_API; + +/** + * @brief Request falling edge event notifications on a set of lines. + * @param bulk Set of GPIO lines to request. + * @param consumer Name of the consumer. + * @param flags Additional request flags. + * @return 0 if the operation succeeds, -1 on failure. + */ +int gpiod_line_request_bulk_falling_edge_events_flags( + struct gpiod_line_bulk *bulk, + const char *consumer, + int flags) GPIOD_API; + +/** + * @brief Request all event type notifications on a set of lines. + * @param bulk Set of GPIO lines to request. + * @param consumer Name of the consumer. + * @param flags Additional request flags. + * @return 0 if the operation succeeds, -1 on failure. + */ +int gpiod_line_request_bulk_both_edges_events_flags( + struct gpiod_line_bulk *bulk, + const char *consumer, + int flags) GPIOD_API; + /** * @brief Release a previously reserved line. * @param line GPIO line object. diff --git a/src/lib/core.c b/src/lib/core.c index 96b0d2c..4a2ef84 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -690,6 +690,40 @@ int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk, return gpiod_line_request_bulk(bulk, &config, default_vals); } +static int line_event_request_type_bulk(struct gpiod_line_bulk *bulk, + const char *consumer, + int flags, int type) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .request_type = type, + .flags = flags, + }; + + return gpiod_line_request_bulk(bulk, &config, 0); +} + +int gpiod_line_request_bulk_rising_edge_events(struct gpiod_line_bulk *bulk, + const char *consumer) +{ + return line_event_request_type_bulk(bulk, consumer, 0, + GPIOD_REQUEST_EVENT_RISING_EDGE); +} + +int gpiod_line_request_bulk_falling_edge_events(struct gpiod_line_bulk *bulk, + const char *consumer) +{ + return line_event_request_type_bulk(bulk, consumer, 0, + GPIOD_REQUEST_EVENT_FALLING_EDGE); +} + +int gpiod_line_request_bulk_both_edges_events(struct gpiod_line_bulk *bulk, + const char *consumer) +{ + return line_event_request_type_bulk(bulk, consumer, 0, + GPIOD_REQUEST_EVENT_BOTH_EDGES); +} + int gpiod_line_request_bulk_input_flags(struct gpiod_line_bulk *bulk, const char *consumer, int flags) { @@ -715,6 +749,30 @@ int gpiod_line_request_bulk_output_flags(struct gpiod_line_bulk *bulk, return gpiod_line_request_bulk(bulk, &config, default_vals); } +int gpiod_line_request_bulk_rising_edge_events_flags( + struct gpiod_line_bulk *bulk, + const char *consumer, int flags) +{ + return line_event_request_type_bulk(bulk, consumer, flags, + GPIOD_REQUEST_EVENT_RISING_EDGE); +} + +int gpiod_line_request_bulk_falling_edge_events_flags( + struct gpiod_line_bulk *bulk, + const char *consumer, int flags) +{ + return line_event_request_type_bulk(bulk, consumer, flags, + GPIOD_REQUEST_EVENT_FALLING_EDGE); +} + +int gpiod_line_request_bulk_both_edges_events_flags( + struct gpiod_line_bulk *bulk, + const char *consumer, int flags) +{ + return line_event_request_type_bulk(bulk, consumer, flags, + GPIOD_REQUEST_EVENT_BOTH_EDGES); +} + void gpiod_line_release(struct gpiod_line *line) { struct gpiod_line_bulk bulk; -- 2.30.2