struct gpiod_line *
gpiod_chip_find_line(struct gpiod_chip *chip, const char *name) GPIOD_API;
+/**
+ * @brief Find a set of GPIO lines by names among lines exposed by this chip.
+ * @param chip The GPIO chip object.
+ * @param names Array of pointers to C-strings containing the names of the
+ * lines to lookup. Must end with a NULL-pointer.
+ * @param bulk Line bulk object in which the located lines will be stored.
+ * @return 0 if all lines were located, -1 on error.
+ * @note If at least one line from the list could not be found among the lines
+ * exposed by this chip, the function sets errno to ENOENT.
+ */
+int gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names,
+ struct gpiod_line_bulk *bulk) GPIOD_API;
+
/**
* @}
*
return NULL;
}
+int gpiod_chip_find_lines(struct gpiod_chip *chip,
+ const char **names, struct gpiod_line_bulk *bulk)
+{
+ struct gpiod_line *line;
+ int i;
+
+ gpiod_line_bulk_init(bulk);
+
+ for (i = 0; names[i]; i++) {
+ line = gpiod_chip_find_line(chip, names[i]);
+ if (!line)
+ return -1;
+
+ gpiod_line_bulk_add(bulk, line);
+ }
+
+ return 0;
+}
+
int gpiod_line_request_input(struct gpiod_line *line, const char *consumer)
{
struct gpiod_line_request_config config = {
TEST_DEFINE(chip_find_line_not_found,
"gpiod_chip_find_line() - not found",
TEST_FLAG_NAMED_LINES, { 8, 8, 8 });
+
+static void chip_find_lines_good(void)
+{
+ static const char *names[] = { "gpio-mockup-B-3",
+ "gpio-mockup-B-6",
+ "gpio-mockup-B-7",
+ NULL };
+
+ TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL;
+ struct gpiod_line_bulk bulk;
+ struct gpiod_line *line;
+ int rv;
+
+ chip = gpiod_chip_open(test_chip_path(1));
+ TEST_ASSERT_NOT_NULL(chip);
+
+ rv = gpiod_chip_find_lines(chip, names, &bulk);
+ TEST_ASSERT_RET_OK(rv);
+ TEST_ASSERT_EQ(gpiod_line_bulk_num_lines(&bulk), 3);
+ line = gpiod_line_bulk_get_line(&bulk, 0);
+ TEST_ASSERT_EQ(gpiod_line_offset(line), 3);
+ line = gpiod_line_bulk_get_line(&bulk, 1);
+ TEST_ASSERT_EQ(gpiod_line_offset(line), 6);
+ line = gpiod_line_bulk_get_line(&bulk, 2);
+ TEST_ASSERT_EQ(gpiod_line_offset(line), 7);
+}
+TEST_DEFINE(chip_find_lines_good,
+ "gpiod_chip_find_lines() - good",
+ TEST_FLAG_NAMED_LINES, { 8, 8, 8 });
+
+static void chip_find_lines_not_found(void)
+{
+ static const char *names[] = { "gpio-mockup-B-3",
+ "nonexistent",
+ "gpio-mockup-B-7",
+ NULL };
+
+ TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL;
+ struct gpiod_line_bulk bulk;
+ int rv;
+
+ chip = gpiod_chip_open(test_chip_path(1));
+ TEST_ASSERT_NOT_NULL(chip);
+
+ rv = gpiod_chip_find_lines(chip, names, &bulk);
+ TEST_ASSERT_EQ(rv, -1);
+ TEST_ASSERT_ERRNO_IS(ENOENT);
+}
+TEST_DEFINE(chip_find_lines_not_found,
+ "gpiod_chip_find_lines() - not found",
+ TEST_FLAG_NAMED_LINES, { 8, 8, 8 });