GPIO API Reference

GPIO API Reference

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

对GPI涉及到的关键代码进行注解


一、gpio-func

结构

gpio-func <pinnum> <inputmode> <pullup> <pulldown>

功能

配置管脚

参数

pinnum -端口号地址
inputmode- io模式
pullup- 上拉
pulldown-下拉

示例

static void cmd_gpio_func(char *buf, int len, int argc, char **argv) 
{
    /*
    ionum:端口编号
    inputmode:输入模式
    pullup:上拉
    pulldown:下拉
    */
    int ionum = -1, inputmode = -1, pullup = -1, pulldown = -1;

    if (5 != argc) {
        printf("Usage: %s 24 1 1 0\r\n  set GPIO24 to input with pullup\r\n",
                argv[0]
        );
        return;
    }
    ionum = atoi(argv[1]);
    inputmode = atoi(argv[2]);
    pullup = atoi(argv[3]);
    pulldown = atoi(argv[4]);
    if (ionum < 0 || inputmode < 0 || pullup < 0 || pulldown < 0) {
        puts("Illegal arg\r\n");
        return;
    }
    printf("GPIO%d is set %s with %s pullup %s pulldown\r\n",
            ionum,
            inputmode ? "input" : "output",
            pullup ? "Active" : "null",
            pulldown ? "Active" : "null"
    );
    if (inputmode) {
        bl_gpio_enable_input(ionum, pullup ? 1 : 0, pulldown ? 1 : 0);
    } else {
        bl_gpio_enable_output(ionum, pullup ? 1 : 0, pulldown ? 1 : 0);
    }
}

二、gpio_set

结构

gpio_set(uint8 ionum, uint8 val)

功能

获取命令行传入的信息,并作为参数,设置对应gpio口的电平。

参数

ionum -端口号地址
val -电平值

示例

static void cmd_gpio_set(char *buf, int len, int argc, char **argv) 
{
    int ionum = -1, val = -1;

    if  (3 != argc) {
        printf("Usage: %s 24 1\r\n  set GPIO24 output to high\r\n",
                argv[0]
        );
        return;
    }
    ionum = atoi(argv[1]);
    val = atoi(argv[2]);
    if (ionum < 0 || val < 0) {
        puts("Illegal arg\r\n");
        return;
    }
    printf("GPIO%d is set to %s\r\n",
        ionum,
        val ? "high" : "lo"
    );
    bl_gpio_output_set(ionum, val ? 1 : 0);
}

三、gpio_get

结构

gpio_get(uint8 ionum, uint8 val)

功能

获取命令行传入的信息,并作为参数,获取对应gpio口的电平。

参数

ionum -端口号地址
val -电平值

示例

static void uart_echo_task(void *arg)
{
    int length = 0, total = 0;
    uint8_t buf_recv[128];
    uint8_t *pbuf = buf_recv;
    const char *name = arg;
    const char *send_recv_log = "1234567890abcdefg";

    int fd = aos_open(name, 0);

    log_info("%s-> fd = %d\r\n", name, fd);
    if (fd < 0) {
        return;
    }
    memset(buf_recv, 0, sizeof(buf_recv));
    log_step(ci_table_step_init);

    aos_write(fd, send_recv_log, strlen(send_recv_log));
    log_step(ci_table_step_send);

    vTaskDelay(1000);
    length = 0;

    while (1) {
        length = aos_read(fd, pbuf + total, strlen(send_recv_log));
        total += length;    
        
        if (total != strlen(send_recv_log)) {
            continue;
        }
        if (memcmp(buf_recv, send_recv_log, strlen(send_recv_log)) == 0) {
            printf("recvbuff:%s\r\n", send_recv_log);
            log_step(ci_table_step_recv);
            break;
        }
        vTaskDelay(10);
    }
    aos_close(fd);
    log_step(ci_table_step_end);
}

总结

以上api实际上使用很灵活,可以结合cmd,结合具体的功能接口

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唯有云缱绻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值