Debian Codegraph @

examples/get_chip_info.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // SPDX-FileCopyrightText: 2023 Kent Gibson <[email protected]>
3
4 /* Minimal example of reading the info for a chip. */
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 /* Example configuration - customize to suit your situation. */
15 static const char *const chip_path = "/dev/gpiochip0";
16
17 struct gpiod_chip_info *info;
18 struct gpiod_chip *chip;
19
20 chip = gpiod_chip_open(chip_path);
21 if (!chip) {
22 fprintf(stderr, "failed to open chip: %s\n", strerror(errno));
23 return EXIT_FAILURE;
24 }
25
26 info = gpiod_chip_get_info(chip);
27 if (!info) {
28 fprintf(stderr, "failed to read info: %s\n", strerror(errno));
29 return EXIT_FAILURE;
30 }
31
32 printf("%s [%s] (%zu lines)\n", gpiod_chip_info_get_name(info),
33 gpiod_chip_info_get_label(info),
34 gpiod_chip_info_get_num_lines(info));
35
36 gpiod_chip_info_free(info);
37 gpiod_chip_close(chip);
38
39 return EXIT_SUCCESS;
40 }