Hardware Reference
In-Depth Information
Input GPIO pin 17 was changed from this separate session, using output GPIO 27
(recall that it is wired to GPIO 17 for this test):
1 # cd /sys/class/gpio
2 # echo 27 >export
3 # ls
4 export gpio27 gpiochip0 unexport
5 # cd gpio27
6 # ls
7 active_low direction edge power subsystem uevent value
8 # echo out >direction
9 # echo 0 >value
10 # # s t a r t e d . / evinput 17 he r e . . .
11 # echo 1 >value
12 # echo 0 >value
13 # echo 1 >value
From the sessions shown, GPIO 17 was set low in the preceding line 9. After that,
the ./evinput program was started and the first line is reported (line 4 in the evinput
session). As the input pin changed state in lines 11+ (in the preceding code), the input
events were being reported in lines 5+ ( evinput session).
Checking the system with the top command, you'll see that ./evinput does not
consume CPU. Yet the program is indeed responsive to the input change events. This
leaves the CPU for all of your other processes that you may need to run.
1 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
2
evinput.c : Event driven GPIO input
3
4
./evinput gpio#
5
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <signal.h>
14 #include <assert.h>
15 #include <sys/poll.h>
16
17 static int gpio_inpin = -1; /
GPIO input pin
/
18 static int is_signaled = 0; /
Exit program if signaled
/
19
20 typedef enum {
21 gp_export=0, /
/sys/class/gpio/export
/
22 gp_unexport, /
/sys/class/gpio/unexport
/
23 gp_direction, /
/sys/class/gpio%d/direction
/
 
Search WWH ::




Custom Search