QT對linux下/sys/class/gpio中的gpio的控制

#define SYSFS_GPIO_EXPORT           "/sys/class/gpio/export"
#define SYSFS_GPIO_RST_PIN_VAL      "926"
#define SYSFS_GPIO_RST_DIR          "/sys/class/gpio/gpio926/direction"
#define SYSFS_GPIO_RST_DIR_VAL      "IN"spa

1.導出控制的GPIO引腳編號code

fd = open(SYSFS_GPIO_EXPORT, O_WRONLY);
if(fd == -1)
{
            printf("ERR: Radio hard reset pin open error.\n");
            
 }
 write(fd, SYSFS_GPIO_RST_PIN_VAL ,sizeof(SYSFS_GPIO_RST_PIN_VAL));
 ::close(fd);

 

2.定義輸入輸入方向blog

fd = open(SYSFS_GPIO_RST_DIR, O_WRONLY);
 if(fd == -1)
 {
          printf("ERR: Radio hard reset pin direction open error.\n");
         
 }
write(fd, SYSFS_GPIO_RST_DIR_VAL, sizeof(SYSFS_GPIO_RST_DIR_VAL));
 ::close(fd);

 

3.讀取數據it

 IOfd = open("/sys/class/gpio/gpio926/value",O_RDONLY);
char buf[1];
read(IOfd,buf,1);
相關文章
相關標籤/搜索