MT7681本身具备5个GPIO,可以设备输入输出模式,外接led、按键等人机交互
想必使用7681的人都是必须要使用gpio的,做智能家居少不了有几个led给用户显示一些状态信息。
下面给出一些有用的api,没有直接粘贴复制文档中的,如果要看,就直接下载文档
MediaTek_LinkIt_Connect_7681_API_Reference_v1_0.pdf找到gpio那一章节看详解。
iot_gpio_read 读取给定gpio的当前值
iot_gpio_input 设置给定gpio为input模式
iot_gpio_output 设置给定gpio为输出模式
iot_gpios_mode_chg 设置多个gpio为输出模式,它使用一个位图来指示哪个引脚应该设置与否。
iot_gpios_output 设置一批gpio为输出模式
iot_cust_set_gpiint_mode 设置gpio中断模式,支持上升沿、下降沿、上升下降沿、不触发
iot_cust_get_gpiint_mode 获取gpio中断模式
iot_cust_gpiint_hdlr gpio中断时调用的函数
实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
void iot_cust_init(void)//用户自定义的初始化函数 { /* run customer initial function */ uint32 input = 0; iot_gpio_input(1, &input); //设置gpio1为输入模式 iot_cust_set_gpiint_mode(1, 3)}; //设置gpio1,上升下降沿中断 } void iot_cust_gpiint_hdlr(IN uint8 GPI_STS) //中断回调函数,sdk中已经具备 { if ((GPI_STS >> 0) & 0x01) { printf_high("GPIO_0 interrupted\n"); } else if ((GPI_STS >> 1) & 0x01) { //当发现是gpio1中断时执行如下! printf_high("GPIO_1 interrupted\n"); } else if ((GPI_STS >> 2) & 0x01) { printf_high("GPIO_2 interrupted\n"); } else if ((GPI_STS >> 3) & 0x01) { printf_high("GPIO_3 interrupted\n"); } else if ((GPI_STS >> 4) & 0x01) { printf_high("GPIO_4 interrupted\n"); } else { printf_high("Ignored\n"); } } |