|
|
|
|
@ -1,19 +1,22 @@
|
|
|
|
|
// Gerardo Marx 24/09/2026
|
|
|
|
|
// gpio command tool
|
|
|
|
|
//
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
// prototype functions
|
|
|
|
|
int gpio_export(const char *gpio);
|
|
|
|
|
int gpio_direction(int gpio, const char *direction);
|
|
|
|
|
int gpio_write(int gpio, int value);
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
|
|
int fd;
|
|
|
|
|
// export
|
|
|
|
|
fd = open("/sys/class/gpio/chip0/export", O_WRONLY);
|
|
|
|
|
if(fd<0)
|
|
|
|
|
{
|
|
|
|
|
perror("Error opening the GPIO path");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write(fd,"17",2);
|
|
|
|
|
close(fd);
|
|
|
|
|
int fd;
|
|
|
|
|
char pin[] = "17";
|
|
|
|
|
gpio_export(pin);
|
|
|
|
|
|
|
|
|
|
// pin direction
|
|
|
|
|
fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY);
|
|
|
|
|
if(fd<0)
|
|
|
|
|
@ -64,3 +67,17 @@ int main(int argc, char *argv[]){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// comple functions
|
|
|
|
|
//
|
|
|
|
|
// gpio_export
|
|
|
|
|
int gpio_export(const char *gpio){
|
|
|
|
|
int fd;
|
|
|
|
|
fd = open("/sys/class/gpio/chip0/export", O_WRONLY);
|
|
|
|
|
if(fd<0){
|
|
|
|
|
perror("Error opening the GPIO path");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
write(fd,"17",2);
|
|
|
|
|
close(fd);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|