You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2021-2021. All rights reserved.
* Description:
*/
#include <stdio.h>
#include <stdlib.h>
#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;
}