[Feature][ZXW-147][GPIO]add GPIO API

Only Configure:No
Affected branch:master
Affected module:gpio
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update:Yes

Change-Id: Ic5a78af9c99c49009942d4d7039cee23c9722bae
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-gpio/LICENSE b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/LICENSE
new file mode 100644
index 0000000..cb88533
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("Mobiletek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to Mobiletek Inc. and/or its licensors. Without
+the prior written permission of Mobiletek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of Mobiletek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+Mobiletek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("Mobiletek SOFTWARE")
+RECEIVED FROM Mobiletek AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. Mobiletek EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES Mobiletek PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE Mobiletek SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN Mobiletek
+SOFTWARE. Mobiletek SHALL ALSO NOT BE RESPONSIBLE FOR ANY Mobiletek SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND Mobiletek'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE Mobiletek SOFTWARE
+RELEASED HEREUNDER WILL BE, AT Mobiletek'S OPTION, TO REVISE OR REPLACE THE
+Mobiletek SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO Mobiletek FOR SUCH Mobiletek SOFTWARE AT ISSUE.
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-gpio/include/lynq-gpio.h b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/include/lynq-gpio.h
new file mode 100644
index 0000000..156d9a8
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/include/lynq-gpio.h
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sc_bsp.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MAX_GPIO_NUM        (200)
+static void *test_gpio_handle[MAX_GPIO_NUM]={NULL};
+
+int lynq_gpio_init(int gpio, int direction, int value, int pullsel);
+
+int lynq_gpio_deinit(int gpio);
+
+int lynq_gpio_direction_set(int gpio, int direction);
+
+int lynq_gpio_value_set(int gpio, int value);
+
+int lynq_gpio_value_get(int gpio);
+
+int lynq_gpio_pullsel_set(int gpio, int pullsel);
+
+int lynq_gpio_pullsel_get(int gpio);
+
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-gpio/lynq-gpio.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/lynq-gpio.cpp
new file mode 100755
index 0000000..cf6958f
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/lynq-gpio.cpp
@@ -0,0 +1,230 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sc_bsp.h>
+#include <errno.h>
+#include "lynq-gpio.h"
+#include "liblog/lynq_deflog.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define USER_LOG_TAG "LYNQ_GPIO"
+
+/*****************************************
+* @brief:lynq_gpio_init
+* @param count [IN]:4
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+int lynq_gpio_init(int gpio, int direction, int value, int pullsel)
+{
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+
+    test_gpio_handle[gpio] = sc_gpio_init(gpio, direction, value, pullsel);
+    if (!test_gpio_handle[gpio])
+    {
+        LYINFLOG("do_gpio_init failed, err:%d", errno);
+        return -1;
+    }
+    return 0;
+}
+
+/*****************************************
+* @brief:lynq_gpio_deinit
+* @param count [IN]:1
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+
+int lynq_gpio_deinit(int gpio)
+{
+    int ret;
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+
+    ret = sc_gpio_uninit(test_gpio_handle[gpio]);
+    if (ret)
+    {
+        LYINFLOG("do_gpio_uninit failed, err:%d", ret);
+        return -1;
+    }
+    return 0;
+}
+
+/*****************************************
+* @brief:lynq_gpio_direction_set
+* @param count [IN]:2
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+int lynq_gpio_direction_set(int gpio, int direction)
+{
+    int ret;
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+    if(direction != 0 && direction != 1)
+    {
+        LYINFLOG("input direction is error\n");
+        return -1;
+    }
+    ret = sc_gpio_direction_set(test_gpio_handle[gpio], direction, 0);
+    if (ret)
+    {
+        LYINFLOG("do_gpio_input set direction failed, err:%d\n", ret);
+        return -1;;
+    }
+    return 0;
+}
+
+/*****************************************
+* @brief:lynq_gpio_value_set
+* @param count [IN]:2
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+int lynq_gpio_value_set(int gpio, int value)
+{
+    int ret;
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+    if(value != 0 && value != 1)
+    {
+        LYINFLOG("input value is error\n");
+        return -1;
+    }
+    ret = sc_gpio_direction_set(test_gpio_handle[gpio], 1, 0);
+    if (ret)
+    {
+        LYINFLOG("do_gpio_input set direction failed, err:%d\n", ret);
+        return -1;;
+    }
+    ret = sc_gpio_value_set(test_gpio_handle[gpio], value);
+    if (ret)
+    {
+        LYINFLOG("do_gpio_output set value failed, err:%d\n", ret);
+        return -1;
+    }
+    else
+    {
+        LYINFLOG("gpio%d set value:%d\n", gpio, value);
+    }
+    return 0;
+}
+
+/*****************************************
+* @brief:lynq_gpio_value_set
+* @param count [IN]:1
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+
+int lynq_gpio_value_get(int gpio)
+{
+    int ret;
+    int value;
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+    ret = sc_gpio_value_get(test_gpio_handle[gpio], &value);
+    if (ret)
+    {
+        LYINFLOG("do_gpio_input get value failed, err:%d\n", ret);
+        return -1;
+    }
+    else
+    {
+        LYINFLOG("gpio%d value:%d\n", gpio, value);
+    }
+    return value;
+}
+
+/*****************************************
+* @brief:lynq_gpio_pullsel_set
+* @param count [IN]:2
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+
+int lynq_gpio_pullsel_set(int gpio, int pullsel)
+{
+    int ret;
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+    ret = sc_gpio_pullsel_set(test_gpio_handle[gpio], pullsel);
+    if (ret)
+    {
+        LYINFLOG("do_gpio_input get pull failed, err:%d\n", ret);
+        return -1;
+    }
+    else
+    {
+        LYINFLOG("gpio%d pull:%d\n", gpio, pullsel);
+    }
+    return 0;
+}
+
+/*****************************************
+* @brief:lynq_gpio_pullsel_get
+* @param count [IN]:1
+* @param sum [OUT]:NA
+* @return :success >=0, failed -1
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+
+int lynq_gpio_pullsel_get(int gpio)
+{
+    int ret;
+    int pullsel;
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+    ret = sc_gpio_pullsel_get(test_gpio_handle[gpio], &pullsel);
+    if (ret)
+    {
+        LYINFLOG("do_gpio_input get pull failed, err:%d\n", ret);
+        return -1;
+    }
+    else
+    {
+        LYINFLOG("gpio%d pull:%d\n", gpio, pullsel);
+    }
+    return pullsel;
+}
+
+
+DEFINE_LYNQ_LIB_LOG(LYNQ_GPIO)
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-gpio/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/makefile
new file mode 100644
index 0000000..3211402
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-gpio/makefile
@@ -0,0 +1,67 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+                -std=gnu++14 \
+                -g -Os \
+                -flto \
+                -fPIC \
+                -fpermissive \
+
+
+
+$(warning ################# lynq qser autosuspend API ROOT: $(ROOT),includedir:$(includedir))
+LOCAL_PATH   = .
+
+LOCAL_C_INCLUDES = \
+  -I. \
+  -I$(LOCAL_PATH)/include/ \
+  -I$(LOCAL_PATH)/ \
+  -I$(ROOT)$(includedir)/logger \
+  -I$(ROOT)$(includedir)/liblog \
+
+
+  
+
+LOCAL_LIBS := \
+    -L. \
+    -lstdc++ \
+    -lcutils \
+    -lutils \
+    -lpthread \
+    -llynq-log \
+    -lbsp \
+
+
+SOURCES = $(wildcard *.cpp)
+
+EXECUTABLE = liblynq-gpio.so
+
+OBJECTS=$(SOURCES:.cpp=.o)
+
+
+.PHONY: build clean install pack_rootfs 
+all: build
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.cpp
+	$(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+build:  $(EXECUTABLE)
+	$(warning ########## build $(EXECUTABLE)  ##########)
+install:
+	mkdir -p $(ROOT)$(base_libdir)/
+	install $(EXECUTABLE) $(ROOT)$(base_libdir)/
+	mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk
+pack_rootfs:
+	mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/
+	cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/
+	$(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)
+	mkdir -p $(PACK_TO)$(base_libdir)/
+	cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/
+	$(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)
+	-find . -name "*.o" -delete