Provide a new getter for the line-info object that becomes the counterpart for the setter used to configure the event clock type with line_config. It allows to check which even clock the line uses for edge detection. Signed-off-by: Bartosz Golaszewski <brgl@xxxxxxxx> --- include/gpiod.h | 18 ++++++++++++++++++ lib/line-info.c | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/gpiod.h b/include/gpiod.h index d3c327b..4506571 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -245,6 +245,16 @@ enum { /**< Line detects both rising and falling edge events. */ }; +/** + * @brief Possible event clock settings. + */ +enum { + GPIOD_LINE_EVENT_CLOCK_MONOTONIC = 1, + /**< Line uses the monotonic clock for edge event timestamps. */ + GPIOD_LINE_EVENT_CLOCK_REALTIME, + /**< Line uses the realtime clock for edge event timestamps. */ +}; + /** * @brief Free a line info object and release all associated resources. * @param info GPIO line info object to free. @@ -333,6 +343,14 @@ int gpiod_line_info_get_drive(struct gpiod_line_info *info); */ int gpiod_line_info_get_edge_detection(struct gpiod_line_info *info); +/** + * @brief Read the current event clock setting used for edge event timestamps. + * @param info GPIO line info object. + * @return Returns GPIOD_LINE_EVENT_CLOCK_MONOTONIC or + * GPIOD_LINE_EVENT_CLOCK_REALTIME. + */ +int gpiod_line_info_get_event_clock(struct gpiod_line_info *info); + /** * @brief Check if this line is debounced (either by hardware or by the kernel * software debouncer). diff --git a/lib/line-info.c b/lib/line-info.c index aed8bee..0280981 100644 --- a/lib/line-info.c +++ b/lib/line-info.c @@ -17,6 +17,7 @@ struct gpiod_line_info { int bias; int drive; int edge; + int event_clock; bool debounced; unsigned long debounce_period; }; @@ -86,6 +87,11 @@ GPIOD_API int gpiod_line_info_get_edge_detection(struct gpiod_line_info *info) return info->edge; } +GPIOD_API int gpiod_line_info_get_event_clock(struct gpiod_line_info *info) +{ + return info->event_clock; +} + GPIOD_API bool gpiod_line_info_is_debounced(struct gpiod_line_info *info) { return info->debounced; @@ -150,6 +156,11 @@ gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf) else info->edge = GPIOD_LINE_EDGE_NONE; + if (infobuf->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME) + info->event_clock = GPIOD_LINE_EVENT_CLOCK_REALTIME; + else + info->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC; + /* * We assume that the kernel returns correct configuration and that no * attributes repeat. -- 2.30.1