|
|
|
@ -16,16 +16,9 @@ int main (int argc, char *argv[]){
|
|
|
|
|
|
|
|
|
|
|
|
int fd;
|
|
|
|
int fd;
|
|
|
|
char pin[] = "17";
|
|
|
|
char pin[] = "17";
|
|
|
|
|
|
|
|
|
|
|
|
gpio_export(pin);
|
|
|
|
gpio_export(pin);
|
|
|
|
|
|
|
|
char direction[] = "out";
|
|
|
|
//pin direction
|
|
|
|
//pin direction
|
|
|
|
fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY);
|
|
|
|
|
|
|
|
if (fd < 0){
|
|
|
|
|
|
|
|
perror("Error opening the GPIO path");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
write(fd,"out", 3);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//pin value
|
|
|
|
//pin value
|
|
|
|
@ -79,7 +72,25 @@ int gpio_export(const char *gpio){
|
|
|
|
perror("Error opening the GPIO path");
|
|
|
|
perror("Error opening the GPIO path");
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write(fd,gpio, strlen(gpio));
|
|
|
|
write(fd, gpio, strlen(gpio));
|
|
|
|
close(fd);
|
|
|
|
close(fd);
|
|
|
|
return(0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//pin_directions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int gpio_direction(int gpio, const char *direction){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY);
|
|
|
|
|
|
|
|
if (fd < 0){
|
|
|
|
|
|
|
|
perror("Error opening the GPIO path");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
write(fd, direction, 3);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//pin_value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|