如何修复 ESP32 错误:'GPIO' was not declared in this scope

问题

你在 ESP32 上使用快速 IO 如下:

gpio_struct_include.cpp
GPIO.out_w1ts = ((uint32_t)1 << pin);

但当你尝试编译时,你看到如下错误消息

gpio_not_declared_error.txt
.pio/libdeps/esp32dev/Dali/src/DaliBus.h:84:9: error: 'GPIO' was not declared in this scope
   84 |         GPIO.out_w1ts = ((uint32_t)1 << pin);
      |         ^~~~

解决方案

此问题出现在较新版本的 Arduino-ESP32 或 ESP-IDF 中。修复很简单:只需包含

gpio_struct_include_fix.cpp
#include <soc/gpio_struct.h>

Check out similar posts by category: ESP32