int gpiod_line_event_read(struct gpiod_line *line,
struct gpiod_line_event *event)
{
- struct gpioevent_data evdata;
- ssize_t rd;
+ int fd;
if (!gpiod_line_event_configured(line)) {
set_last_error(GPIOD_EEVREQUEST);
return -1;
}
+ fd = line_get_event_fd(line);
+
+ return gpiod_line_event_read_fd(fd, event);
+}
+
+int gpiod_line_event_get_fd(struct gpiod_line *line)
+{
+ return line_get_state(line) == LINE_EVENT
+ ? line_get_event_fd(line) : -1;
+}
+
+int gpiod_line_event_read_fd(int fd, struct gpiod_line_event *event)
+{
+ struct gpioevent_data evdata;
+ ssize_t rd;
+
memset(&evdata, 0, sizeof(evdata));
- rd = read(line_get_event_fd(line), &evdata, sizeof(evdata));
+ rd = read(fd, &evdata, sizeof(evdata));
if (rd < 0) {
last_error_from_errno();
return -1;
return 0;
}
-int gpiod_line_event_get_fd(struct gpiod_line *line)
-{
- return line_get_state(line) == LINE_EVENT
- ? line_get_event_fd(line) : -1;
-}
-
struct gpiod_chip * gpiod_chip_open(const char *path)
{
struct gpiod_chip *chip;
*/
int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API;
+/**
+ * @brief Read the last GPIO event directly from a file descriptor.
+ * @param fd File descriptor.
+ * @param event Buffer to which the event data will be copied.
+ * @return 0 if the event was read correctly, -1 on error.
+ *
+ * Users who directly poll the file descriptor for incoming events can also
+ * directly read the event data from it using this routine. This function
+ * translates the kernel representation of the event to the libgpiod format.
+ */
+int gpiod_line_event_read_fd(int fd, struct gpiod_line_event *event) GPIOD_API;
+
/**
* @}
*