Hardware Reference
In-Depth Information
70 assert(f);
71 fprintf(f,"% s\n", edge);
72 fclose(f);
73
74 /
/
75 gpio_setpath(pin, gp_value, buf, size of buf);
76 fd = open(buf,O_RDWR);
77 return fd;
78 }
79
80 /
Value : /sys/class/gpio%d/value
81
Close (unexport) GPIO pin :
82
/
83 static void
84 gpio_close(int pin) {
85 char buf[128];
86 FILE
f;
87
88 /
/
89 gpio_setpath(pin, gp_unexport, buf, size of buf);
90 f = fopen(buf, "w");
91 assert(f);
92 fprintf(f,"%d\n", pin);
93 fclose(f);
94 }
95
96 /
Unexport : /sys/class/gpio/unexport
97
This routine will block until the open GPIO pin has changed
98
value. This pin should be connected to the MCP23017 /INTA
99
pin.
100
/
101 static int
102 gpio_poll(int fd) {
103 struct pollfd polls;
104 char buf [32];
105 int rc, n;
106
107 polls.fd = fd; /
/sys/class/gpio17/value
/
108 polls.events = POLLPRI; /
Exceptions
/
109
110 do {
111 rc = poll(&polls, 1, -1); /
Block
/
112 if ( is_signaled )
113 return -1; /
Exit if ^C received
/
114 } while ( rc < 0 && errno == EINTR );
115
116 assert (rc > 0);
117
Search WWH ::




Custom Search