/* * 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 dir; if (argc < 4) { /* argc must equal 4 */ printf("./sample_gpio_write Group | Bit | Dir\n"); printf(" Dir:0--Output; 1--Input\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 */ dir = (td_bool)strtol(argv[3], NULL, 0); /* index 3 means Dir */ if (bit >= 8) { /* bit must less than 8 */ printf("Bit must be 0 - 7!\n"); return TD_FAILURE; } if (dir != 0 && dir != 1) { printf("Value must be 0 or 1!\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_set_direction(group, bit, dir); if (ret != TD_SUCCESS) { printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret); goto ERR1; } 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; }