-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpio.c
60 lines (46 loc) · 1010 Bytes
/
gpio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <gpiod.h>
int main() {
struct gpiod_chip *chip;
struct gpiod_line *line;
int req, value;
chip = gpiod_chip_open("/dev/gpiochip0");
if (!chip)
return -1;
line = gpiod_chip_get_line(chip, 8);
if (!line) {
gpiod_chip_close(chip);
return -1;
}
/*req = gpiod_line_request_input(line, "gpio_state");
if (req) {
gpiod_chip_close(chip);
return -1;
}
value = gpiod_line_get_value(line);
printf("GPIO value is: %d\n", value);*/
req = gpiod_line_request_output(line, "gpio_state", 1);
if (req) {
gpiod_chip_close(chip);
return -1;
}
req = gpiod_line_set_value(line, 0);
if (req) {
gpiod_chip_close(chip);
return -1;
}
req = gpiod_line_set_value(line, 1);
if (req) {
gpiod_chip_close(chip);
return -1;
}
/*req = gpiod_line_request_input(line, "gpio_state");
if (req) {
gpiod_chip_close(chip);
return -1;
}
value = gpiod_line_get_value(line);
printf("GPIO value is: %d\n", value);*/
printf("OK.\n");
gpiod_chip_close(chip);
}