一、GPIO的配置及相关函数
1.1 头文件包含
#include "driver/gpio.h"
1.2 基本配置包含
以GPIO_NUM_3 举例,配置包括设置中断类型,模式,是否上下拉。
void gpio_init(void)
{
gpio_config_t io_conf =
{
/*中断使能*/
.intr_type = GPIO_INTR_DISABLE,
/*输出模式调节*/
.mode = GPIO_MODE_OUTPUT,
/*配置引脚的掩码*/
.pin_bit_mask = 1 << GPIO_NUM_3,
/*下拉使能*/
.pull_down_en = 0,
/*上拉使能*/
.pull_up_en = 0,
};
gpio_config(&io_conf);
/*设置中断类型*/
gpio_set_intr_type(GPIO_NUM_3, GPIO_INTR_ANYEDGE);
}
其中中断类型的选择有以下几种
typedef enum {
GPIO_INTR_DISABLE = 0, /*!< Disable GPIO interrupt */
GPIO_INTR_POSEDGE = 1, /*!< GPIO interrupt type : rising edge */
GPIO_INTR_NEGEDGE = 2, /*!< GPIO interrupt type : falling edge */
GPIO_INTR_ANYEDGE = 3, /*!< GPIO interrupt type : both rising and falling edge */
GPIO_INTR_LOW_LEVEL = 4, /*!< GPIO interrupt type : input low level trigger */
GPIO_INTR_HIGH_LEVEL = 5, /*!< GPIO interrupt type : input high level trigger */
GPIO_INTR_MAX,
} gpio_int_type_t;
1.3 中断回调函数的注册
// install gpio isr service
gpio_install_isr_service(0);
// hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_3, gpio_isr_handler, (void *)GPIO_NUM_3);
1.4 相关的一些控制函数
/**
* @brief GPIO common configuration
*
* Configure GPIO's Mode,pull-up,PullDown,IntrType
*
* @param pG