diff mbox series

[libgpiod,v2,2/3] line-info: provide gpiod_line_info_get_event_clock()

Message ID 20210730144356.23079-3-brgl@bgdev.pl
State New
Headers show
Series libgpiod v2: new API improvements | expand

Commit Message

Bartosz Golaszewski July 30, 2021, 2:43 p.m. UTC
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@bgdev.pl>
---
 include/gpiod.h | 18 ++++++++++++++++++
 lib/line-info.c | 11 +++++++++++
 2 files changed, 29 insertions(+)

Comments

Kent Gibson July 31, 2021, 2:27 a.m. UTC | #1
On Fri, Jul 30, 2021 at 04:43:55PM +0200, Bartosz Golaszewski wrote:
> 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.
> 

"to check which even" -> "checking which event"

That is my only comment for the whole patch set - eveything else looks
good.

Cheers,
Kent.
Bartosz Golaszewski Aug. 2, 2021, 8:12 a.m. UTC | #2
On Sat, Jul 31, 2021 at 4:27 AM Kent Gibson <warthog618@gmail.com> wrote:
>

> On Fri, Jul 30, 2021 at 04:43:55PM +0200, Bartosz Golaszewski wrote:

> > 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.

> >

>

> "to check which even" -> "checking which event"

>

> That is my only comment for the whole patch set - eveything else looks

> good.

>

> Cheers,

> Kent.


This will be squashed with the big v2 commit, thanks!

Bart
diff mbox series

Patch

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.