Hardware Reference
In-Depth Information
24 gp_edge, /
/sys/class/gpio%d/edge
/
25 gp_value /
/sys/class/gpio%d/value
/
26 } gpio_path_t;
27
28 /
29
Internal : Create a pathname for type in buf.
30
/
31 static const char
32 gpio_setpath(int pin, gpio_path_t type, char
buf,
unsigned bufsiz) {
33 static const char
paths[] = {
34 "export", "unexport", "gpio%d/direction",
35 "gpio%d/edge", "gpio%d/value"};
36 int slen;
37
38 strncpy (buf, "/sys/class/gpio/", bufsiz);
39 bufsiz -= (slen = strlen(buf));
40 snprintf(buf+slen, bufsiz, paths[type], pin);
41 return buf;
42 }
43
44 /
45
Open /sys/class/gpio%d/value for edge detection :
46
/
47 static int
48 gpio_open_edge(int pin, const char
edge) {
49 char buf [128];
50 FILE
f;
51 int fd;
52
53 /
/
54 gpio_setpath(pin, gp_export, buf, size of buf);
55 f = fopen(buf, "w");
56 assert(f);
57 fprintf(f,"%d\n", pin);
58 fclose(f);
59
60 /
Export pin : /sys/class/gpio/export
/
61 gpio_setpath(pin, gp_direction, buf, size of buf);
62 f = fopen(buf, "w");
63 assert(f);
64 fprintf(f,"in\n");
65 fclose(f);
66
67 /
Direction : /sys/class/gpio%d/direction
/
68 gpio_setpath(pin, gp_edge, buf, size of buf);
69 f = fopen (buf, "w");
Edge : /sys/class/gpio%d/edge
Search WWH ::




Custom Search