From: Bartosz Golaszewski Date: Fri, 6 Jan 2017 13:34:55 +0000 (+0100) Subject: gpiofind: new tool X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=cee0b5616e03f751b812078ab63446f1bfc8303c;p=qemu-gpiodev%2Flibgpiod.git gpiofind: new tool Add a simple program for finding the gpiochip and offset of a GPIO line by name. Signed-off-by: Bartosz Golaszewski --- diff --git a/.gitignore b/.gitignore index 2879c59..67e5cad 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ gpioinfo gpioget gpioset gpiomon +gpiofind *.o *.lo doc diff --git a/Makefile.am b/Makefile.am index d996f87..6dc31d8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,7 @@ include_HEADERS = gpiod.h libgpiod_la_SOURCES = core.c -bin_PROGRAMS = gpiodetect gpioinfo gpioget gpioset gpiomon +bin_PROGRAMS = gpiodetect gpioinfo gpioget gpioset gpiomon gpiofind gpiodetect_SOURCES = gpiodetect.c gpiodetect_LDFLAGS = -lgpiod @@ -41,6 +41,10 @@ gpiomon_SOURCES = gpiomon.c gpiomon_LDFLAGS = -lgpiod gpiomon_DEPENDENCIES = libgpiod.la +gpiofind_SOURCES = gpiofind.c +gpiofind_LDFLAGS = -lgpiod +gpiofind_DEPENDENCIES = libgpiod.la + doc: doxygen .PHONY: doc diff --git a/gpiofind.c b/gpiofind.c new file mode 100644 index 0000000..7c7c6f1 --- /dev/null +++ b/gpiofind.c @@ -0,0 +1,37 @@ +/* + * Read value from GPIO line. + * + * Copyright (C) 2017 Bartosz Golaszewski + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + */ + +#include + +#include +#include + +int main(int argc, char **argv) +{ + struct gpiod_line *line; + struct gpiod_chip *chip; + + if (argc < 2) { + fprintf(stderr, "%s: gpiochip must be specified\n", argv[0]); + return EXIT_FAILURE; + } + + line = gpiod_line_find_by_name(argv[1]); + if (!line) + return EXIT_FAILURE; + + chip = gpiod_line_get_chip(line); + + printf("%s %u\n", gpiod_chip_name(chip), gpiod_line_offset(line)); + + gpiod_chip_close(chip); + + return EXIT_SUCCESS; +}