Hardware Reference
In-Depth Information
113 /
/
114 gpio_setpath(pin, gp_edge,buf,sizeof buf);
115 f = fopen(buf,"w");
116 assert(f);
117 fprintf(f,"%s\n",edge);
118 fclose(f);
119
120 /
Edge : /sys/class/gpio%d/edge
/
121 gpio_setpath(pin,gp_value,buf,sizeof buf);
122 fd = open(buf,O_RDWR);
123 return fd;
124 }
125
126 /
Value : /sys/class/gpio%d/value
127
Open/sys/class/gpio%d/value for output :
128
/
129 static int
130 gpio_open_output(int pin) {
131 char buf[128];
132 FILE
f;
133 int fd;
134
135 /
/
136 gpio_setpath(pin,gp_export,buf,sizeof buf);
137 f = fopen(buf,"w");
138 assert(f);
139 fprintf(f,"%d\n",pin);
140 fclose(f);
141
142 /
Export pin : /sys/class/gpio/export
/
143 gpio_setpath(pin,gp_direction,buf,sizeof buf);
144 f = fopen(buf,"w");
145 assert(f);
146 fprintf(f,"out\n");
147 fclose(f);
148
149 /
Direction : /sys/class/gpio%d/direction
/
150 gpio_setpath(pin,gp_value,buf,sizeof buf);
151 fd = open(buf,O_WRONLY);
152 return fd;
153 }
154
155 /
Value : /sys/class/gpio%d/value
156
Close (unexport) GPIO pin :
157
/
Search WWH ::




Custom Search