#include <stdio.h> | |
#include <string.h> | |
#include <strings.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <signal.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <pthread.h> | |
#include <termios.h> | |
#include <time.h> | |
#include <sys/ioctl.h> | |
#include <dlfcn.h> | |
#include <stdint.h> | |
#include <stdbool.h> | |
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; | |
int32_t (*gsw_gpio_Init)(uint32_t, gsw_hal_pinDirection, gsw_hal_pinLevel); | |
int32_t (*gsw_gpio_SetDirection)(uint32_t, gsw_hal_pinDirection); | |
int32_t (*gsw_gpio_SetLevel)(uint32_t, gsw_hal_pinLevel); | |
gsw_hal_pinLevel (*gsw_gpio_GetLevel)(uint32_t); | |
gsw_hal_usbStatus (*gsw_hwpin_is_usb_connected)(); | |
int32_t (*gsw_setWakeupLevel)(gsw_hal_pinLevel); | |
void *dlHandle_gpio; | |
char *lynqLib_gpio = "/lib/libgsw_lib.so"; | |
int main(int argc,char **argv) | |
{ | |
int ret; | |
dlHandle_gpio = dlopen(lynqLib_gpio, RTLD_NOW); | |
if (argc == 4) | |
{ | |
if (strcmp(argv[1], "D") == 0) | |
{ | |
gsw_gpio_SetDirection=(int32_t(*)(uint32_t, gsw_hal_pinDirection))dlsym(dlHandle_gpio, "gsw_gpio_SetDirection"); | |
ret = gsw_gpio_SetDirection(atoi(argv[2]), atoi(argv[3])); | |
if(ret < 0) | |
{ | |
printf("gsw_gpio_SetDirection FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gpio_SetDirection success.\n"); | |
} | |
else if (strcmp(argv[1], "V") == 0) | |
{ | |
gsw_gpio_SetLevel=(int32_t(*)(uint32_t, gsw_hal_pinLevel))dlsym(dlHandle_gpio, "gsw_gpio_SetLevel"); | |
ret = gsw_gpio_SetLevel(atoi(argv[2]), atoi(argv[3])); | |
if(ret < 0) | |
{ | |
printf("gsw_gpio_SetLevel FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gpio_SetLevel success.\n"); | |
} | |
else | |
{ | |
gsw_gpio_Init=(int32_t(*)(uint32_t, gsw_hal_pinDirection, gsw_hal_pinLevel))dlsym(dlHandle_gpio, "gsw_gpio_Init"); | |
ret = gsw_gpio_Init(atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); | |
if(ret < 0) | |
{ | |
printf("gsw_gpio_Init FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gpio_Init success.\n"); | |
} | |
} | |
else if (argc == 3) | |
{ | |
if (strcmp(argv[1], "W") == 0) | |
{ | |
gsw_setWakeupLevel=(int32_t(*)(gsw_hal_pinLevel))dlsym(dlHandle_gpio, "gsw_setWakeupLevel"); | |
ret = gsw_setWakeupLevel(atoi(argv[2])); | |
if(ret < 0) | |
{ | |
printf("gsw_setWakeupLevel FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_setWakeupLevel success.\n"); | |
} | |
else | |
{ | |
printf("error,please check input\n"); | |
return -1; | |
} | |
} | |
else if (argc == 2) | |
{ | |
if (strcmp(argv[1], "U") == 0) | |
{ | |
gsw_hwpin_is_usb_connected=(gsw_hal_usbStatus(*)())dlsym(dlHandle_gpio, "gsw_hwpin_is_usb_connected"); | |
ret = gsw_hwpin_is_usb_connected(); | |
if(ret == 0) | |
{ | |
printf("gsw_hwpin_is_usb_Unconnected ret = %d\n",ret); | |
return 0; | |
} | |
else | |
{ | |
printf("gsw_hwpin_is_usb_connected.ret = %d\n",ret); | |
return 0; | |
} | |
} | |
else | |
{ | |
gsw_gpio_GetLevel=(gsw_hal_pinLevel(*)(uint32_t))dlsym(dlHandle_gpio, "gsw_gpio_GetLevel"); | |
ret = gsw_gpio_GetLevel(atoi(argv[1])); | |
if(ret < 0) | |
{ | |
printf("gsw_gpio_GetLevel FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gpio_GetLevel success.\n"); | |
} | |
} | |
else | |
{ | |
printf("error,please check input\n"); | |
return -1; | |
} | |
return 0; | |
} |