From 409c75da042192ba5dbeb13cbde6c41e0674ed6e Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sat, 14 Oct 2017 00:06:55 +0300 Subject: [PATCH] Implement ESP_LOGx override option Usable for library developers who write code not dependent on Arduino. Adding 3 lines to the includes will permit their debug messages to be visible in Arduino IDE or when enabled under IDF --- Kconfig | 10 ++++++++++ cores/esp32/esp32-hal-log.h | 16 ++++++++++++++++ docs/esp-idf_component.md | 13 +++++++++++++ tools/sdk/include/config/sdkconfig.h | 1 + tools/sdk/sdkconfig | 1 + 5 files changed, 41 insertions(+) diff --git a/Kconfig b/Kconfig index f0077d405..67f31c68a 100644 --- a/Kconfig +++ b/Kconfig @@ -66,6 +66,16 @@ config ARDUHAL_LOG_COLORS Enable ANSI terminal color codes in bootloader output. In order to view these, your terminal program must support ANSI color codes. +config ARDUHAL_ESP_LOG + bool "Forward ESP_LOGx to Arduino log output" + default "n" + help + This option will redefine the ESP_LOGx macros to Arduino's log_x macros. + To enable for your application, add the follwing after your includes: + #ifdef ARDUINO_ARCH_ESP32 + #include "esp32-hal-log.h" + #endif + endmenu config AUTOCONNECT_WIFI diff --git a/cores/esp32/esp32-hal-log.h b/cores/esp32/esp32-hal-log.h index 0456fc0f0..015cd67aa 100644 --- a/cores/esp32/esp32-hal-log.h +++ b/cores/esp32/esp32-hal-log.h @@ -107,6 +107,22 @@ int log_printf(const char *fmt, ...); #define log_e(format, ...) #endif +#ifdef CONFIG_ARDUHAL_ESP_LOG +#include "esp_log.h" + +#undef ESP_LOGE +#undef ESP_LOGW +#undef ESP_LOGI +#undef ESP_LOGD +#undef ESP_LOGV + +#define ESP_LOGE(tag, ...) log_e(__VA_ARGS__) +#define ESP_LOGW(tag, ...) log_w(__VA_ARGS__) +#define ESP_LOGI(tag, ...) log_i(__VA_ARGS__) +#define ESP_LOGD(tag, ...) log_d(__VA_ARGS__) +#define ESP_LOGV(tag, ...) log_v(__VA_ARGS__) +#endif + #ifdef __cplusplus } #endif diff --git a/docs/esp-idf_component.md b/docs/esp-idf_component.md index b6ca9197e..08d4f030a 100644 --- a/docs/esp-idf_component.md +++ b/docs/esp-idf_component.md @@ -1,6 +1,8 @@ To use as a component of ESP-IDF ================================================= +## Installation + - Download and install [esp-idf](https://github.com/espressif/esp-idf) - Create blank idf project (from one of the examples) - in the project folder, create a folder called components and clone this repository inside @@ -55,3 +57,14 @@ To use as a component of ESP-IDF - If enabled, WiFi will start with the last known configuration - Else it will wait for WiFi.begin - ```make flash monitor``` will build, upload and open serial monitor to your board + +## Logging To Serial + +If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines after your includes: + + ```cpp + #ifdef ARDUINO_ARCH_ESP32 + #include "esp32-hal-log.h" + #endif + ``` + diff --git a/tools/sdk/include/config/sdkconfig.h b/tools/sdk/include/config/sdkconfig.h index a28d5cca1..b44dd6d0f 100644 --- a/tools/sdk/include/config/sdkconfig.h +++ b/tools/sdk/include/config/sdkconfig.h @@ -134,6 +134,7 @@ #define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1 #define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32 #define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1 +#define CONFIG_ARDUHAL_ESP_LOG 1 #define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1 #define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240 #define CONFIG_MBEDTLS_HARDWARE_AES 1 diff --git a/tools/sdk/sdkconfig b/tools/sdk/sdkconfig index ec068fab1..ee1448053 100644 --- a/tools/sdk/sdkconfig +++ b/tools/sdk/sdkconfig @@ -126,6 +126,7 @@ CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_DEBUG= CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE= CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=1 CONFIG_ARDUHAL_LOG_COLORS= +CONFIG_ARDUHAL_ESP_LOG=y CONFIG_AUTOCONNECT_WIFI= CONFIG_AWS_IOT_SDK= CONFIG_BT_ENABLED=y -- GitLab