-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled_glow.c
53 lines (44 loc) · 1.03 KB
/
led_glow.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
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#define GPIO 488 //gpio 2_0 in Hikey 96 board
#define MAX_BUF 100
main()
{
int fd = 0 ;
char buf[MAX_BUF] = { 0 } ;
sprintf(buf, "/sys/class/gpio/export");
fd = open(buf, O_WRONLY);
if(fd < 0) {
printf("file:: %s open failed\n",buf);
return;
}
printf("file:: %s open success fd %d\n",buf, fd);
sprintf(buf, "%d", GPIO);
printf("file :: %s\n", buf);
write(fd, buf, strlen(buf));
close(fd);
sprintf(buf, "/sys/class/gpio/gpio%d/direction", GPIO);
fd = open(buf, O_WRONLY);
if(fd < 0) {
printf("file:: %s open failed\n",buf);
return;
}
printf("file:: %s open success fd %d\n",buf, fd);
//Set out direction
write(fd, "out", 3);
close(fd);
sprintf(buf, "/sys/class/gpio/gpio%d/value", GPIO);
fd = open(buf, O_WRONLY);
if(fd < 0) {
printf("file:: %s open failed\n",buf);
return;
}
printf("file:: %s open success fd %d\n",buf, fd);
while(1) {
write(fd, "1", 1);
sleep(1);
write(fd, "0", 1);
sleep(1);
}
}