Skip to content

Commit 409c75d

Browse files
committed
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
1 parent c8ffcac commit 409c75d

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

Diff for: Kconfig

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ config ARDUHAL_LOG_COLORS
6666
Enable ANSI terminal color codes in bootloader output.
6767
In order to view these, your terminal program must support ANSI color codes.
6868

69+
config ARDUHAL_ESP_LOG
70+
bool "Forward ESP_LOGx to Arduino log output"
71+
default "n"
72+
help
73+
This option will redefine the ESP_LOGx macros to Arduino's log_x macros.
74+
To enable for your application, add the follwing after your includes:
75+
#ifdef ARDUINO_ARCH_ESP32
76+
#include "esp32-hal-log.h"
77+
#endif
78+
6979
endmenu
7080

7181
config AUTOCONNECT_WIFI

Diff for: cores/esp32/esp32-hal-log.h

+16
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ int log_printf(const char *fmt, ...);
107107
#define log_e(format, ...)
108108
#endif
109109

110+
#ifdef CONFIG_ARDUHAL_ESP_LOG
111+
#include "esp_log.h"
112+
113+
#undef ESP_LOGE
114+
#undef ESP_LOGW
115+
#undef ESP_LOGI
116+
#undef ESP_LOGD
117+
#undef ESP_LOGV
118+
119+
#define ESP_LOGE(tag, ...) log_e(__VA_ARGS__)
120+
#define ESP_LOGW(tag, ...) log_w(__VA_ARGS__)
121+
#define ESP_LOGI(tag, ...) log_i(__VA_ARGS__)
122+
#define ESP_LOGD(tag, ...) log_d(__VA_ARGS__)
123+
#define ESP_LOGV(tag, ...) log_v(__VA_ARGS__)
124+
#endif
125+
110126
#ifdef __cplusplus
111127
}
112128
#endif

Diff for: docs/esp-idf_component.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
To use as a component of ESP-IDF
22
=================================================
33

4+
## Installation
5+
46
- Download and install [esp-idf](https://github.com/espressif/esp-idf)
57
- Create blank idf project (from one of the examples)
68
- 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
5557
- If enabled, WiFi will start with the last known configuration
5658
- Else it will wait for WiFi.begin
5759
- ```make flash monitor``` will build, upload and open serial monitor to your board
60+
61+
## Logging To Serial
62+
63+
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:
64+
65+
```cpp
66+
#ifdef ARDUINO_ARCH_ESP32
67+
#include "esp32-hal-log.h"
68+
#endif
69+
```
70+

Diff for: tools/sdk/include/config/sdkconfig.h

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1
135135
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32
136136
#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1
137+
#define CONFIG_ARDUHAL_ESP_LOG 1
137138
#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1
138139
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240
139140
#define CONFIG_MBEDTLS_HARDWARE_AES 1

Diff for: tools/sdk/sdkconfig

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_DEBUG=
126126
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE=
127127
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=1
128128
CONFIG_ARDUHAL_LOG_COLORS=
129+
CONFIG_ARDUHAL_ESP_LOG=y
129130
CONFIG_AUTOCONNECT_WIFI=
130131
CONFIG_AWS_IOT_SDK=
131132
CONFIG_BT_ENABLED=y

0 commit comments

Comments
 (0)