#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <dlfcn.h>

#include "gsw_hwpin_interface.h"

#ifndef LOG_ERR_LEVEL
#define LOG_ERR_LEVEL  3      /* error conditions */
#endif
#ifndef LOG_WARN_LEVEL
#define LOG_WARN_LEVEL 4   /* warning conditions */
#endif
#ifndef LOG_INFO_LEVEL
#define LOG_INFO_LEVEL 6      /* informational */
#endif
#ifndef LOG_DEBUG_LEVEL
#define LOG_DEBUG_LEVEL 7     /* debug-level messages */
#endif
#ifndef LOG_VERBOSE_LEVEL
#define LOG_VERBOSE_LEVEL 8
#endif

#define GSW_GPIO "[HAL][GSW_GPIO]"

#define LOGV(fmt, args ...) \
    do{ \
        char *file_ptr_1001 = __FILE__; \
        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
        char line_1001[10] = {0}; \
        sprintf(line_1001, "%d", __LINE__); \
        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
            if(*ptr_1001 == '/') \
                 break; \
            ptr_1001--; \
        } \
        fun_ptr_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_GPIO"" fmt, ptr_1001 + 1, line_1001, ##args); \
    } while(0)

#define LOGI(fmt, args...) \
    do{ \
        char *file_ptr_1001 = __FILE__; \
        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
        char line_1001[10] = {0}; \
        sprintf(line_1001, "%d", __LINE__); \
        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
            if(*ptr_1001 == '/') \
                 break; \
            ptr_1001--; \
        } \
        fun_ptr_log(LOG_INFO_LEVEL, "%s#%s: "GSW_GPIO"" fmt, ptr_1001 + 1, line_1001, ##args); \
    } while(0)

#define LOGD(fmt, args...) \
    do{ \
        char *file_ptr_1001 = __FILE__; \
        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
        char line_1001[10] = {0}; \
        sprintf(line_1001, "%d", __LINE__); \
        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
            if(*ptr_1001 == '/') \
                 break; \
            ptr_1001--; \
        } \
        fun_ptr_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_GPIO"" fmt, ptr_1001 + 1, line_1001, ##args); \
    } while(0)

#define LOGW(fmt, args...) \
    do{ \
        char *file_ptr_1001 = __FILE__; \
        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
        char line_1001[10] = {0}; \
        sprintf(line_1001, "%d", __LINE__); \
        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
            if(*ptr_1001 == '/') \
                 break; \
            ptr_1001--; \
        } \
        fun_ptr_log(LOG_WARN_LEVEL, "%s#%s: "GSW_GPIO"" fmt, ptr_1001 + 1, line_1001, ##args); \
    } while(0)

#define LOGE(fmt, args...) \
    do{ \
        char *file_ptr_1001 = __FILE__; \
        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
        char line_1001[10] = {0}; \
        sprintf(line_1001, "%d", __LINE__); \
        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
            if(*ptr_1001 == '/') \
                 break; \
            ptr_1001--; \
        } \
        fun_ptr_log(LOG_ERR_LEVEL, "%s#%s: "GSW_GPIO"" fmt, ptr_1001 + 1, line_1001, ##args); \
    } while(0)
    

#define GSW_HAL_MEM_INVAILD -2 //表示入参地址为NULL
#define wakeout 117

typedef enum{
  GSW_HAL_PINDIR_IN,
  GSW_HAL_PINDIR_OUT,
}gsw_hal_pinDirection;

typedef enum{
  GSW_HAL_LEVEL_LOW,
  GSW_HAL_LEVEL_HIGH,
}gsw_hal_pinLevel;

typedef enum{
  GSW_HAL_PULL_NULL,
  GSW_HAL_PULL_DOWN,
  GSW_HAL_PULL_UP,
}gsw_hal_pinPullSel;

typedef enum{
  GSW_HAL_USB_DISCONNECTED,
  GSW_HAL_USB_CONNECTED,
}gsw_hal_usbStatus;
typedef void (*mbtk_log)(int level, const char *format,...);
static mbtk_log fun_ptr_log = NULL;
void *dlHandle_gpio = NULL;
char *lynqLib_gpio = "/lib/libmbtk_lib.so";

int gpio_check(int gpio)
{
    char buffer[128];
    memset(buffer,0,128);
    sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
    return access(buffer , F_OK);
}

static int handle()
{
    if(dlHandle_gpio == NULL || fun_ptr_log == NULL)
    {
        dlHandle_gpio = dlopen(lynqLib_gpio, RTLD_NOW);
        fun_ptr_log = (mbtk_log)dlsym(dlHandle_gpio, "mbtk_log");
        if(fun_ptr_log == NULL || dlHandle_gpio == NULL)
        {
            return GSW_HAL_NORMAL_FAIL;
        }
    }
    return GSW_HAL_SUCCESS;
}

static int gpio_export(int gpio)
{
    int file=-1;
    int result =-1;
    char pin_index_buffer[5]= {0};

    if (gpio_check(gpio) == 0)
    {
        LOGE("export has been add\n");
        return 0;
    }

    file = open("/sys/class/gpio/export",O_WRONLY);
    if(file == -1)
    {
        LOGE("Open gpio export file fail.");
        return -1;
    }

    memset(pin_index_buffer,0,5);
    sprintf(pin_index_buffer,"%d", gpio);
    result = write(file,pin_index_buffer,strlen(pin_index_buffer));
    if(result < 0)
    {
        LOGE("Gpio[%d] export fail.", gpio);
        close(file);
        return -1;
    }
    close(file);

    return 0;
}

static int gpio_unexport(int gpio)
{
    int file=-1;
    int result =-1;
    char pin_index_buffer[5]= {0};
    if (gpio_check(gpio) == -1)
    {
        LOGE("export has been not add\n");
        return -1;
    }

    file = open("/sys/class/gpio/unexport",O_WRONLY);
    if(file == -1)
    {
        LOGE("Open gpio unexport file fail.");
        return -1;
    }

    memset(pin_index_buffer,0,5);
    sprintf(pin_index_buffer,"%d", gpio);
    result=write(file,pin_index_buffer,strlen(pin_index_buffer));
    if(result < 0)
    {
        close(file);
        LOGE("Gpio[%d] unexport fail.", gpio);
        return -1;
    }
    close(file);

    return 0;
}

int32_t gsw_gpio_SetDirection(uint32_t gpioNum, gsw_hal_pinDirection dir)
{
    char buffer[128]= {0};
    int file =-1;
    int result =-1;
    char direction[10] = {0};
    memset(buffer,0,128);
    if (handle())
        return GSW_HAL_NORMAL_FAIL;
    
    if (gpio_check(gpioNum) == -1)
    {
        LOGD("in dir export has been not add\n");
        gpio_export(gpioNum);
    }


    sprintf(buffer,"/sys/class/gpio/gpio%u/direction", gpioNum);
    file = open(buffer, O_WRONLY);
    if(file == -1)
    {
        LOGE("Open gpio[%d] direct fail.", gpioNum);
        return -1;
    }
    if (dir == GSW_HAL_PINDIR_IN)
        sprintf(direction,"in");
    else if (dir == GSW_HAL_PINDIR_OUT)
        sprintf(direction,"out");
    
    result = write(file,direction,strlen(direction));
    if(result != strlen(direction))
    {
        LOGE("Set gpio[%d] direct fail.", gpioNum);
        close(file);
        gpio_unexport(gpioNum);
        return GSW_HAL_NORMAL_FAIL;
    }
    close(file);
    gpio_unexport(gpioNum);
    return GSW_HAL_SUCCESS;
}

gsw_hal_pinLevel gsw_gpio_GetLevel(uint32_t gpioNum)
{
    char buffer[50];
    char path[128];
    int file =-1;
    int result =-1;
    memset(path,0,128);
    memset(buffer,0,50);
    if (handle())
        return GSW_HAL_NORMAL_FAIL;

    if (gpio_check(gpioNum) == -1)
    {
        LOGD("in get value export has been not add\n");
        gpio_export(gpioNum);
    }
    sprintf(path,"/sys/class/gpio/gpio%u/value", gpioNum);
    file = open(path,O_RDONLY);
    if(file == -1)
    {
        LOGE("Open gpio[%d] fail.", gpioNum);
        return -1;
    }
    result = read(file,buffer,50);
    if(result <= 0)
    {
        LOGE("Get gpio[%d] value fail", gpioNum);
        close(file);
        gpio_unexport(gpioNum);
        return GSW_HAL_NORMAL_FAIL;
    }
    close(file);
    gpio_unexport(gpioNum);
    return atoi(buffer);
}

int32_t gsw_gpio_SetLevel(uint32_t gpioNum, gsw_hal_pinLevel level)
{
    char buffer[128]= {0};
    int file =-1;
    int result =-1;
    memset(buffer,0,50);
    if (handle())
        return GSW_HAL_NORMAL_FAIL;

    if (gpio_check(gpioNum) == -1)
    {
        LOGD("in set value export has been not add\n");
        gpio_export(gpioNum);
    }

    sprintf(buffer,"/sys/class/gpio/gpio%u/value", gpioNum);
    file = open(buffer,O_WRONLY);
    if(file == -1)
    {
        LOGE("Open gpio[%d] value fail.", gpioNum);
        return -1;
    }
    if(level == GSW_HAL_LEVEL_LOW) {
        result = write(file,"0",1);
    } else {
        result = write(file,"1",1);
    }
    if(result != 1)
    {
        LOGE("Set gpio[%d] value fail err =%d.", gpioNum, errno);
        close(file);
        gpio_unexport(gpioNum);
        return GSW_HAL_NORMAL_FAIL;
    }
    close(file);
    gpio_unexport(gpioNum);
    return GSW_HAL_SUCCESS;
}


int32_t gsw_gpio_Init(uint32_t gpioNum, gsw_hal_pinDirection dir, gsw_hal_pinLevel level, gsw_hal_pinPullSel pullsel)
{
    if (handle())
        return GSW_HAL_NORMAL_FAIL;

    if (dir != 1 && dir != 0)
    {
        LOGE("[lynq_gpio_init] direction fail.");
        return -1;
    }

    if (level != 1 && level != 0)
    {
        LOGE("[lynq_gpio_init] value fail.");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(gpio_export(gpioNum))
    {
        LOGE("[lynq_gpio_init]gpio_export fail.");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(gsw_gpio_SetDirection(gpioNum, dir))
    {
        LOGE("[lynq_gpio_init]gpio_direct_set fail.");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(dir == 1 && (gsw_gpio_SetLevel(gpioNum, level) != 0))
    {
        LOGE("[lynq_gpio_init]gpio_value_set fail.");
        return GSW_HAL_NORMAL_FAIL;
    }
    return GSW_HAL_SUCCESS;
}
int gsw_hwpin_is_usb_connected(void)
{
    FILE *fp;
    char cmd[128] = {0};
    char tmp_rsp[20] = {0};
    //char *CONNECTED = "configured";
    char *DISCONNECTED = "not attached";
    if (handle())
        return GSW_HAL_NORMAL_FAIL;

    sprintf(cmd,"cat /sys/devices/platform/soc/d4200000.axi/c0000000.usb/udc/c0000000.usb/state");
    fp=popen(cmd, "r");
    if (fgets(tmp_rsp,sizeof(tmp_rsp),fp) == NULL)
        LOGE("gsw_hwpin_is_usb_connected fail.");
    pclose(fp);
    if (strncmp(tmp_rsp,DISCONNECTED,strlen(DISCONNECTED)) == 0)
        return GSW_HAL_USB_DISCONNECTED;
    else
        return GSW_HAL_USB_CONNECTED;
}

int32_t gsw_setWakeupLevel(gsw_hal_pinLevel level)
{
    if (gsw_gpio_SetLevel(wakeout, level) == GSW_HAL_NORMAL_FAIL)
    {
        return GSW_HAL_NORMAL_FAIL;
    }
    return GSW_HAL_SUCCESS;
}
