From 3e0ab165eb2249acee146d89be672531c2e4d5d1 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 16 Jan 2017 11:42:03 +0100 Subject: [PATCH] event: new event request helpers Signed-off-by: Bartosz Golaszewski --- include/gpiod.h | 55 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/include/gpiod.h b/include/gpiod.h index f6cfefd..132f979 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -635,6 +635,51 @@ struct gpiod_line_event { int gpiod_line_event_request(struct gpiod_line *line, struct gpiod_line_evreq_config *config) GPIOD_API; +static inline int _gpiod_line_event_request_type(struct gpiod_line *line, + const char *consumer, + bool active_low, + int type) +{ + struct gpiod_line_evreq_config config = { + .consumer = consumer, + .event_type = type, + .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW + : GPIOD_ACTIVE_STATE_HIGH, + }; + + return gpiod_line_event_request(line, &config); +} + +/** + * @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. + */ +static inline int gpiod_line_event_request_rising(struct gpiod_line *line, + const char *consumer, + bool active_low) +{ + return _gpiod_line_event_request_type(line, consumer, active_low, + GPIOD_EVENT_RISING_EDGE); +} + +/** + * @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. + */ +static inline int gpiod_line_event_request_falling(struct gpiod_line *line, + const char *consumer, + bool active_low) +{ + return _gpiod_line_event_request_type(line, consumer, active_low, + GPIOD_EVENT_FALLING_EDGE); +} + /** * @brief Request all event type notifications on a single line. * @param line GPIO line object. @@ -646,14 +691,8 @@ static inline int gpiod_line_event_request_all(struct gpiod_line *line, const char *consumer, bool active_low) { - struct gpiod_line_evreq_config config = { - .consumer = consumer, - .event_type = GPIOD_EVENT_BOTH_EDGES, - .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW - : GPIOD_ACTIVE_STATE_HIGH, - }; - - return gpiod_line_event_request(line, &config); + return _gpiod_line_event_request_type(line, consumer, active_low, + GPIOD_EVENT_BOTH_EDGES); } /** -- 2.30.2