add function reserve

This commit is contained in:
Siegfried Kienzle
2017-03-24 15:06:31 +01:00
parent 398a259050
commit 966611815f

View File

@@ -7,9 +7,32 @@
* *
* */ * */
//Source: http://elinux.org/RPi_GPIO_Code_Samples: #include <stdio.h>
#define BCM2837_PERIPHERIAL_BASE 0x3F000000 #include <unistd.h>
#define GPIO_BASE (BCM2837_PERIPHERIAL_BASE + 0x3F000000)
int reserve(char gpioPort)
{
int fd;
char buffer[2];
strcpy(buffer, gpioPort + "\n");
if((fd=open("/sys/class/gpio/export", O_RDWR | O_CREAT | O_TRUNC) == -1) {
perror(NULL);
return EXIT_FAILURE;
}
if(write(fd, &buffer, sizeof(buffer)) == -1) {
perror("Cannot write into file");
return EXIT_FAILURE;
}
printf("Success");
return EXIT_SUCCESS;
}
int main()
{
return 0;
}