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.
61 lines
1.4 KiB
61 lines
1.4 KiB
4 months ago
|
/*
|
||
|
* 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 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;
|
||
|
}
|