| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <errno.h> |
| 7 |
#include <gpiod.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <string.h> |
| 11 |
|
| 12 |
int main(void) |
| 13 |
{ |
| 14 |
|
| 15 |
static const char *const chip_path = "/dev/gpiochip0"; |
| 16 |
static const unsigned int line_offset = 3; |
| 17 |
|
| 18 |
const char *name, *consumer, *dir; |
| 19 |
struct gpiod_line_info *info; |
| 20 |
struct gpiod_chip *chip; |
| 21 |
|
| 22 |
chip = gpiod_chip_open(chip_path); |
| 23 |
if (!chip) { |
| 24 |
fprintf(stderr, "failed to open chip: %s\n", strerror(errno)); |
| 25 |
return EXIT_FAILURE; |
| 26 |
} |
| 27 |
|
| 28 |
info = gpiod_chip_get_line_info(chip, line_offset); |
| 29 |
if (!info) { |
| 30 |
fprintf(stderr, "failed to read info: %s\n", strerror(errno)); |
| 31 |
return EXIT_FAILURE; |
| 32 |
} |
| 33 |
|
| 34 |
name = gpiod_line_info_get_name(info); |
| 35 |
if (!name) |
| 36 |
name = "unnamed"; |
| 37 |
|
| 38 |
consumer = gpiod_line_info_get_consumer(info); |
| 39 |
if (!consumer) |
| 40 |
consumer = "unused"; |
| 41 |
|
| 42 |
dir = (gpiod_line_info_get_direction(info) == |
| 43 |
GPIOD_LINE_DIRECTION_INPUT) ? |
| 44 |
"input" : |
| 45 |
"output"; |
| 46 |
|
| 47 |
printf("line %3d: %12s %12s %8s %10s\n", |
| 48 |
gpiod_line_info_get_offset(info), name, consumer, dir, |
| 49 |
gpiod_line_info_is_active_low(info) ? "active-low" : |
| 50 |
"active-high"); |
| 51 |
|
| 52 |
gpiod_line_info_free(info); |
| 53 |
gpiod_chip_close(chip); |
| 54 |
|
| 55 |
return EXIT_SUCCESS; |
| 56 |
} |