由于sdk不支持标准gpio api函数int gpio_pull_updown(unsigned gpio,unsigned value),需要用到soc/gpio.h中的int jzgpio_set_func(int port, enum gpio_function func, unsigned long pins)函数。
函数原型如下:
#include<soc/gpio.h> //包含此结构体
enum gpio_function { //gpio功能枚举,提供给gpio功能设置函数使用
GPIO_FUNC_0 = 0x10,
GPIO_FUNC_1 = 0x11,
GPIO_FUNC_2 = 0x12,
GPIO_FUNC_3 = 0x13,
GPIO_OUTPUT0 = 0x14,
GPIO_OUTPUT1 = 0x15,
GPIO_INPUT = 0x16,
GPIO_INT_LO = 0x18,
GPIO_INT_HI = 0x19,
GPIO_INT_FE = 0x1a,
GPIO_INT_RE = 0x1b,
GPIO_INT_MASK_LO = 0x1c,
GPIO_INT_MASK_HI = 0x1d,
GPIO_INT_MASK_FE = 0x1e,
GPIO_INT_MASK_RE = 0x1f,
GPIO_PULL_HIZ = 0x80,
GPIO_PULL_UP = 0xa0,
GPIO_PULL_DOWN = 0xc0,
};
int jzgpio_set_func(int port, enum gpio_function func, unsigned long pins)
功能:设置gpio功能
参数:
port //gpio引脚组别
func //描述gpio引脚功能
pins //gpio引脚
返回值:
成功: 0
失败:负数
举例
设置PC00为上拉:
int gpio_num = 64;
jzgpio_set_func(gpio_num /32, GPIO_PULL_UP, 1<< (gpio_num % 32));