@@ -204,3 +204,25 @@ struct gpiod_chip *chip_by_line_name(const char *name)
return NULL;
}
+int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
+ unsigned int *offsets, int num_lines)
+{
+ int i;
+
+ for (i = 0; i < num_lines; i++) {
+ const char *line_name = lines[i];
+ int offset;
+
+ offset = gpiod_chip_find_line(chip, line_name);
+
+ if (offset < 0) {
+ die("chip '%s' does not contain line '%s'",
+ gpiod_chip_get_name(chip),
+ line_name);
+ }
+
+ offsets[i] = offset;
+ }
+
+ return 0;
+}
@@ -32,5 +32,7 @@ int chip_dir_filter(const struct dirent *entry);
struct gpiod_chip *chip_open_by_name(const char *name);
struct gpiod_chip *chip_open_lookup(const char *device);
struct gpiod_chip *chip_by_line_name(const char *name);
+int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
+ unsigned int *offsets, int num_lines);
#endif /* __GPIOD_TOOLS_COMMON_H__ */
line_names_to_offsets to be used by tools that support --by-name. Signed-off-by: Joel Stanley <joel@jms.id.au> --- tools/tools-common.c | 22 ++++++++++++++++++++++ tools/tools-common.h | 2 ++ 2 files changed, 24 insertions(+)