bool active_low, struct timespec *timeout,
gpiod_event_cb callback, void *cbdata)
{
- struct gpiod_line_evreq_config config;
struct gpiod_line_event event;
struct gpiod_chip *chip;
struct gpiod_line *line;
int status, evtype;
- memset(&config, 0, sizeof(config));
- config.consumer = libgpiod_consumer;
- config.event_type = GPIOD_EVENT_BOTH_EDGES;
- config.active_state = active_low ? GPIOD_ACTIVE_STATE_LOW
- : GPIOD_ACTIVE_STATE_HIGH;
-
chip = gpiod_chip_open_lookup(device);
if (!chip)
return -1;
return -1;
}
- status = gpiod_line_event_request(line, &config);
+ status = gpiod_line_event_request_all(line,
+ libgpiod_consumer, active_low);
if (status < 0) {
gpiod_chip_close(chip);
return -1;
int gpiod_line_event_request(struct gpiod_line *line,
struct gpiod_line_evreq_config *config) GPIOD_API;
+/**
+ * @brief Request all event type 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_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);
+}
+
/**
* @brief Stop listening for events and release the line.
* @param line GPIO line object.