Hardware Reference
In-Depth Information
48 /
/
49 gpio_setpath(pin,gp_direction,buf,sizeof buf);
50 f = fopen(buf,"w");
51 assert(f);
52 fprintf(f,"in\n");
53 fclose(f);
54
55 /
Direction: /sys/class/gpio%d/direction
/
56 gpio_setpath(pin,gp_edge,buf,sizeof buf);
57 f = fopen(buf,"w");
58 assert(f);
59 fprintf(f,"falling\n");
60 fclose(f);
61
62 /
Edge: /sys/class/gpio%d/edge
/
63 gpio_setpath(pin,gp_value,buf,sizeof buf);
64 fd = open(buf,O_RDWR);
65 return fd;
66 }
67
68 /
Value: /sys/class/gpio%d/value
69
Close (unexport) GPIO pin :
70
/
71 static void
72 gpio_close(int pin) {
73 char buf[128];
74 FILE
f ;
75
76 /
/
77 gpio_setpath(pin,gp_unexport,buf,size of buf);
78 f = fopen(buf,"w");
79 assert(f);
80 fprintf(f,"%d\n",pin);
81 fclose(f);
82 }
83
84 /
Unexport: /sys/class/gpio/unexport
85
This routine will block until the open GPIO pin has changed
86
value. This pin should be connected to the MCP23017 /INTA
87
pin.
88
/
89 static int
90 gpio_poll(int fd) {
91 unsigned char buf[32];
92 struct pollfd polls;
93 int rc;
94
 
Search WWH ::




Custom Search