int gpio_set_edge(int gpio, edge_t edge);
int gpio_edge_none(int gpio);
int gpio_edge_rising(int gpio);
int gpio_edge_falling(int gpio);
int gpio_edge_both(int gpio);
int gpio_set_direction(int gpio, gpio_dir_t dir);
int gpio_direction_input(int gpio);
int gpio_direction_output(int gpio);
void gpio_set_value(int gpio, int value);
int gpio_get_value(int gpio);
#endif /* __GPIO_H__ */
**gpio.c:**
#include “gpio.h”
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
/*
gpio 编号计算
index = GPIOn_IOx = (n-1)*32 + x
例如蜂鸣器使用的引脚编号为:index = GPIO1_19 = (1-1)*32 +19 = 19。
又例如GPIO4_IO20的编号为:index = GPIO4_IO20 = (4-1)*32+20=116。
*/
int gpio_export(int gpio)
{
int fd;
char gpio_path[100] = {0};
/* GPIO目录路径 */
sprintf(gpio_path, “/sys/class/gpio/gpio%d”, gpio);
/* 判断GPIO目录是否存在 */
if (access(gpio_path, F_OK) == 0) return 0;
if (0 > (fd = open("/sys/class/gpio/export", O_WRONLY)))
{
perror("open error");
return -1;
}
/\* 导出 gpio \*/
char gpio_str[10] = {0};
sprintf(gpio_str, "%d", gpio);
int len = strlen(gpio_str);
if (len != write(fd, gpio_str, len))