The low-level line lookup should be more fine-grained. As the first
step: introduce a routine performing a line lookup for specific chip.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
struct gpiod_line *
gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset) GPIOD_API;
+/**
+ * @brief Find a GPIO line by name among lines associated with given GPIO chip.
+ * @param chip The GPIO chip object.
+ * @param name The name of the GPIO line.
+ * @return Pointer to the GPIO line handle or NULL if the line could not be
+ * found or an error occurred.
+ *
+ * In case a line with given name is not associated with given chip, the
+ * functions sets errno to ENOENT.
+ */
+struct gpiod_line *
+gpiod_chip_find_line(struct gpiod_chip *chip, const char *name) GPIOD_API;
+
/**
* @}
*
return line;
}
+struct gpiod_line *
+gpiod_chip_find_line(struct gpiod_chip *chip, const char *name)
+{
+ struct gpiod_line_iter iter;
+ struct gpiod_line *line;
+
+ gpiod_line_iter_init(&iter, chip);
+ gpiod_foreach_line(&iter, line) {
+ if (gpiod_line_iter_err(&iter))
+ return NULL;
+
+ if (strcmp(gpiod_line_name(line), name) == 0)
+ return line;
+ }
+
+ errno = ENOENT;
+
+ return NULL;
+}
+
static int line_get_state(struct gpiod_line *line)
{
return line->state;