-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
I use ESP-IDF4.0 + arduino-esp32-4.0 as component (and this pair works very well in VSCode with CMake)
Many perfect third-party libraries for ArduinoIDE use standard Arduino macros in their header files, depending on which the library is configured during compilation.
Example:
Streaming.h use ARDUINO macros
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
M5Stack.h use ESP32, M5STACK_MPU6886, M5STACK_MPU9250 and M5STACK_MPU6050 macroses
#if defined(ESP32)
...
#if defined(M5STACK_MPU6886) || defined(M5STACK_MPU9250) || defined(M5STACK_MPU6050)
#include "utility/MPU6886.h"
#elif defined M5STACK_200Q
#include "utility/SH200Q.h"
#endif
...
#endif
Some libraries use ARDUINO_ARCH_ESP32 macros and so-on.
These macros are usually defined by the Arduino IDE, but they are undefined if you work with ESP-IDF and arduino-esp32 as a component in other IDEs.
So, of course, we don’t want to edit the contents of the library itself to define these macros.
What is the best way to define these macros when using arduino-esp32 as component?
- Configure somewhere in the menuconfig ESP-IDF, if possible?
- Maybe we can place a header file with these macros in the arduino-esp32 framework itself?
- Or maybe in the main.cpp file we can somehow declare these macros before including libraries?
- Make some kind of header file with these definitions, and then insert it at the beginning of each library, similar to C++ (stdafx.h or pch.h - precompiled header files option)?
e.g. header.h
#define ARDUINO 181
#define ESP32
#define ARDUINO_ARCH_ESP32
#define M5STACK_MPU9250
I would be grateful for the most correct vector for solving the problem.