Hardware Reference
In-Depth Information
158 static void
159 gpio_close(int pin) {
160 char buf [128];
161 FILE
f ;
∗
162
163 /
/
164 gpio_setpath(pin,gp_unexport,buf,sizeof buf);
165 f = fopen(buf,"w");
166 assert(f);
167 fprintf(f,"%d\n",pin);
168 fclose(f);
169 }
170
171 /
Unexport : /sys/class/gpio/unexport
∗
∗
∗
172
This routine will block until the open GPIO pin has changed
∗
173
value.
∗
174
/
175 static int
176 gpio_poll(int fd) {
177 struct poll fd_polls;
178 char buf[32];
179 int rc, n;
180
181 polls.fd = fd; /
∗
/sys/class/gpio17/value
/
∗
∗
182 polls.events = POLLPRI; /
Exceptions
/
∗
∗
183
184 do {
185 rc = poll (&polls,1, −1); /
Block
/
∗
∗
186 } while ( rc < 0 && errno == EINTR );
187
188 assert(rc > 0);
189
190 lseek(fd,0,SEEK_SET);
191 n = read(fd,buf,sizeof buf); /
Read value
/
∗
∗
192 assert(n>0);
193 buf[n] = 0;
194
195 rc = sscanf(buf,"%d",&n);
196 assert(rc==1);
197 return; /
Return value
/
∗
∗
198 }
199
200 /
∗
201
Write to the GPIO pin
∗
202
/
∗