Hi,
I used gpio uaer APIs, writen this below code its getting error what is the problem which header file i have to include in my code to access gpio APIs.
/* Include the standard linux header files */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/gpio.h>
//#include <asm/gpio.h>
//#include <asm-generic/gpio.h>
int main (int argc, char **argv)
{
int err, value;
unsigned long num;
/* Allocate memory to GPIO line, can be achieved by doing gpio_request() */
err = gpio_request(110, "sample");
if (err < 0)
{
printf("Failed to open gpio pin\n");
return 1;
}
/* you want to initialize a structure with an invalid GPIO number,A number that's not valid will be rejected by calls which may request or free GPIOs*/
if (gpio_is_valid(110))
{
printf("Failed to read gpio %ld \n", num);
return -1;
}
/* Depending on the requirement set GPIO as input or output pin then set gpio value as high or low. Setting the GPIO pin 110 as input set as input or output, returning 0 or negative errno */
err= gpio_direction_input(110);
if (err < 0)
{
printf("Failed to open put number in input direction\n");
return 1;
}
/* GPIO INPUT: return zero or nonzero */
//value=gpio_get_value(30);
/*Make pin 110 as output and set the value as high*/
gpio_direction_output(110, 1);
/*Exporting that particular pin (110) to sysfs entry then use this API */
gpio_export(110, 1);
printf("powerON for GPIO 110 line \n");
sleep(100);
/*Get value from GPIO pin */
value=gpio_get_value(110);
printf("Value for GPIO 110 line after passing 1=%d \n", value);
gpio_direction_output(110, 0);
printf("power OFF GPIO 110 \n");
value=gpio_get_value(110);
printf("Value for GPIO 110 line after passing 0=%d \n", value);
return 0;
}
After compiling i am getting below error, please tell me which header file i have to include in my applications.
main.c:8:24: error: linux/gpio.h: No such file or directory
main.c: In function 'main':
main.c:35: warning: implicit declaration of function 'gpio_request'
main.c:42: warning: implicit declaration of function 'gpio_is_valid'
main.c:48: warning: implicit declaration of function 'gpio_direction_input'
main.c:58: warning: implicit declaration of function 'gpio_direction_output'
main.c:61: warning: implicit declaration of function 'gpio_export'
main.c:63: warning: implicit declaration of function 'sleep'
main.c:66: warning: implicit declaration of function 'gpio_get_value'
make: *** [gpp] Error 1