ESP-IDF:如何配置 GPIO 为输出并启用下拉

以下示例使用 ESP-IDF API 将 GPIO12 配置为输出并启用集成下拉电阻。

esp32_gpio_pulldown.cpp
#include <driver/gpio.h>

gpio_config_t io_conf;
// Disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
// Set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
// Bit mask of the pins that you want to set
io_conf.pin_bit_mask = (1ULL << GPIO_NUM_12);
// Set to pull-down in case of floating => fix boot
io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
// Disable pull-up mode
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
// Configure GPIO with the given settings
gpio_config(&io_conf);

Check out similar posts by category: ESP32, ESP-IDF, C/C++