/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2021-2021. All rights reserved. * Description: */ #include #include #include "uapi_gpio.h" #include "uapi_system.h" td_s32 main(int argc, char *argv[]) { td_s32 ret; td_u32 group; td_u32 bit; td_bool value; if (argc < 3) { /* argc must equal 3 */ printf("./sample_gpio_read Group | Bit \n"); return TD_FAILURE; } if (argv == TD_NULL) { printf("para argv is NULL.\n"); return TD_FAILURE; } group = (td_u32)strtol(argv[1], NULL, 0); /* index 1 means Group */ bit = (td_u32)strtol(argv[2], NULL, 0); /* index 2 means Bit */ if (bit >= 8) { /* bit must less than 8 */ printf("Bit must be 0 - 7!\n"); return TD_FAILURE; } (td_void)uapi_sys_init(); ret = uapi_gpio_init(); if (ret != TD_SUCCESS) { printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret); goto ERR0; } ret = uapi_gpio_read(group, bit, &value); if (ret != TD_SUCCESS) { printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret); goto ERR1; } else { printf("gpio value =0x%x\n", value); } ERR1: ret = uapi_gpio_deinit(); if (ret != TD_SUCCESS) { printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret); } ERR0: (td_void)uapi_sys_deinit(); return ret; }