| #include <stdlib.h> |
| #include <stdio.h> |
| #include <string.h> |
| #include <errno.h> |
| #include "ql_gpio.h" |
| #include "mbtk_log.h" |
| |
| int gpio_g = -1; |
| |
| int main(int argc, char *argv[]) |
| { |
| char operator[10]; |
| int opt; |
| int ret; |
| int gpio; |
| int direction; |
| int value; |
| // int pullsel; |
| |
| mbtk_log_init("radio", "GPIO_TEST"); |
| |
| printf("=========ql gpio main=========\n" |
| "\t0 exit\n" |
| "\t1 gpio init\n" |
| "\t2 gpio uninit\n" |
| "\t3 gpio set direction\n" |
| "\t4 gpio set level\n" |
| "\t5 gpio get level\n" |
| "operator: >> \n"); |
| |
| while(1) |
| { |
| memset(operator, 0, sizeof(operator)); |
| if(NULL != fgets(operator, sizeof(operator), stdin)) |
| break; |
| fflush(stdin); |
| opt = atoi(operator); |
| switch (opt) |
| { |
| case 0: |
| printf("main exit\n"); |
| return 0; |
| case 1: |
| { |
| printf("INPUT gpio \n"); |
| memset(operator, 0, sizeof(operator)); |
| if(NULL == fgets(operator, sizeof(operator), stdin)) |
| break; |
| fflush(stdin); |
| gpio = atoi(operator); |
| printf("gpio is %d\n", gpio); |
| ret = ql_gpio_init(gpio, 1, 1, 0); |
| if(ret != 0) |
| { |
| printf("ql_gpio_init fail\n"); |
| } |
| else |
| { |
| printf("ql_gpio_init success\n"); |
| gpio_g = gpio; |
| } |
| } |
| break; |
| case 2: |
| { |
| printf(">>>>>gpio uninit\n"); |
| if (gpio_g != -1) |
| { |
| ret = ql_gpio_uninit(gpio_g); |
| if(ret != 0) |
| { |
| printf("ql_gpio_uninit fail\n"); |
| printf("ret=%d\n", ret); |
| } |
| else |
| { |
| printf("ql_gpio_uninit success\n"); |
| gpio_g = -1; |
| } |
| } |
| else |
| { |
| printf(">>>>>pleas gpio init<<<<<\n"); |
| } |
| } |
| break; |
| case 3: |
| { |
| printf(">>>>>Input set direction<<<<<\n"); |
| memset(operator, 0, sizeof(operator)); |
| if(NULL == fgets(operator, sizeof(operator), stdin)) |
| break; |
| fflush(stdin); |
| direction = atoi(operator); |
| if (gpio_g != -1) |
| { |
| ret = ql_gpio_set_direction(gpio_g, direction); |
| if(ret != 0) |
| { |
| printf("ql_gpio_set_direction fail\n"); |
| } |
| else |
| { |
| printf("ql_gpio_set_direction success\n"); |
| } |
| } |
| else |
| { |
| printf(">>>>>pleas gpio init<<<<<\n"); |
| } |
| } |
| break; |
| case 4: |
| { |
| printf(">>>>>Input set level<<<<<\n"); |
| memset(operator, 0, sizeof(operator)); |
| if(NULL == fgets(operator, sizeof(operator), stdin)) |
| break; |
| fflush(stdin); |
| value = atoi(operator); |
| if (gpio_g != -1) |
| { |
| ret = ql_gpio_set_level(gpio_g, value); |
| if(ret < 0) |
| { |
| printf("ql_gpio_set_level fail\n"); |
| } |
| else |
| { |
| printf("ql_gpio_set_level success\n"); |
| } |
| } |
| else |
| { |
| printf(">>>>>pleas gpio init<<<<<\n"); |
| } |
| } |
| break; |
| case 5: |
| { |
| printf(">>>>>Input get level<<<<<\n"); |
| if (gpio_g != -1) |
| { |
| ret = ql_gpio_get_level(gpio_g); |
| if(ret < 0) |
| { |
| printf("ql_gpio_get_level fail\n"); |
| printf("ret=%d\n", ret); |
| } |
| else |
| { |
| printf("ql_gpio_get_level success\n"); |
| printf("ret=%d\n", ret); |
| } |
| } |
| else |
| { |
| printf(">>>>>pleas gpio init<<<<<\n"); |
| } |
| } |
| break; |
| |
| |
| default: |
| break; |
| } |
| |
| } |
| |
| return 0; |
| |
| } |