添加常规GPIOapi接口
Change-Id: I616e3c70bb9d1795d443e2d9df338bc56939ad7f
diff --git a/mbtk/libmbtk_lib/common/mbtk_gpio.c b/mbtk/libmbtk_lib/common/mbtk_gpio.c
index 0116f60..40106f3 100755
--- a/mbtk/libmbtk_lib/common/mbtk_gpio.c
+++ b/mbtk/libmbtk_lib/common/mbtk_gpio.c
@@ -210,3 +210,118 @@
}
}
+int gpio_direct_get(int gpio, char *value, int value_size)
+{
+ char buffer[50]= {0};
+ int file =-1;
+ int result =-1;
+
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
+ file = open(buffer, O_RDONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] direct fail.", gpio);
+ return -1;
+ }
+
+ memset(value, 0x0, value_size);
+ result = read(file,value,value_size);
+ if(result <= 0)
+ {
+ LOGE("Get gpio[%d] direct fail.", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+int gpio_direct_set(int gpio, char *value)
+{
+ char buffer[50]= {0};
+ int file =-1;
+ int result =-1;
+
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
+ file = open(buffer, O_WRONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] direct fail.", gpio);
+ return -1;
+ }
+
+ result = write(file,value,strlen(value));
+ if(result != strlen(value))
+ {
+ LOGE("Set gpio[%d] direct fail.", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+int gpio_value_get(int gpio)
+{
+ char buffer[50];
+ char path[10];
+ int file =-1;
+ int result =-1;
+ int value;
+
+ memset(path,0,50);
+ memset(buffer,0,10);
+ sprintf(path,"/sys/class/gpio/gpio%d/value", gpio);
+ file = open(path,O_RDONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] fail.", gpio);
+ return -1;
+ }
+ result = read(file,buffer,5);
+ if(result <= 0)
+ {
+ LOGE("Get gpio[%d] value fail", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+ value = atoi(buffer);
+ return value;
+}
+
+int gpio_value_set(int gpio, int value)
+{
+ char buffer[50]= {0};
+ int file =-1;
+ int result =-1;
+
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/value", gpio);
+ file = open(buffer,O_WRONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] value fail.", gpio);
+ return -1;
+ }
+ if(value == 0) {
+ result = write(file,"0",1);
+ } else {
+ result = write(file,"1",1);
+ }
+ if(result != 1)
+ {
+ LOGE("Set gpio[%d] value fail err =%d.", gpio, errno);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+