Compare commits

..

2 Commits

@ -1,26 +1,24 @@
// Ignacio Abundez Ortega
// 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);
char direction[] = "out";
//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
@ -61,4 +59,38 @@ int main (int argc, char *argv[]){
return 0;
}
//Complete 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, gpio, strlen(gpio));
close(fd);
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

Loading…
Cancel
Save