From 67dfea558a151d5a5256ae5587c5db77517c4fad Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 5 May 2021 12:53:37 +0200 Subject: [PATCH] Remove shitty arduino logging system --- cores/esp32/HardwareSerial.cpp | 17 -------- cores/esp32/HardwareSerial.h | 4 +- cores/esp32/esp32-hal-cpu.c | 4 +- cores/esp32/esp32-hal-i2c.c | 2 +- cores/esp32/esp32-hal-log.h | 56 +++++++------------------ cores/esp32/esp32-hal-misc.c | 16 ------- cores/esp32/esp32-hal-uart.c | 77 ---------------------------------- cores/esp32/esp32-hal-uart.h | 3 -- 8 files changed, 18 insertions(+), 161 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 288ef081..34fda914 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -112,9 +112,6 @@ void HardwareSerial::updateBaudRate(unsigned long baud) void HardwareSerial::end() { - if(uartGetDebug() == _uart_nr) { - uartSetDebug(0); - } log_v("pins %d %d",_tx_pin, _rx_pin); uartEnd(_uart, _tx_pin, _rx_pin); _uart = 0; @@ -124,20 +121,6 @@ size_t HardwareSerial::setRxBufferSize(size_t new_size) { return uartResizeRxBuffer(_uart, new_size); } -void HardwareSerial::setDebugOutput(bool en) -{ - if(_uart == 0) { - return; - } - if(en) { - uartSetDebug(_uart); - } else { - if(uartGetDebug() == _uart_nr) { - uartSetDebug(NULL); - } - } -} - int HardwareSerial::available(void) { return uartAvailable(_uart); diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index a50b0377..1135ffec 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -74,9 +74,7 @@ public: uint32_t baudRate(); operator bool() const; - size_t setRxBufferSize(size_t); - void setDebugOutput(bool); - + size_t setRxBufferSize(size_t); void setRxInvert(bool); protected: diff --git a/cores/esp32/esp32-hal-cpu.c b/cores/esp32/esp32-hal-cpu.c index a5d33434..ea5407e1 100644 --- a/cores/esp32/esp32-hal-cpu.c +++ b/cores/esp32/esp32-hal-cpu.c @@ -102,7 +102,7 @@ bool addApbChangeCallback(void * arg, apb_change_cb_t cb){ // look for duplicate callbacks while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next; if (r) { - log_e("duplicate func=%08X arg=%08X",c->cb,c->arg); + log_e("duplicate func=%08X arg=%08X",(unsigned int)c->cb,(unsigned int)c->arg); free(c); xSemaphoreGive(apb_change_lock); return false; @@ -124,7 +124,7 @@ bool removeApbChangeCallback(void * arg, apb_change_cb_t cb){ // look for matching callback while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next; if ( r == NULL ) { - log_e("not found func=%08X arg=%08X",cb,arg); + log_e("not found func=%08X arg=%08X",(unsigned int)cb,(unsigned int)arg); xSemaphoreGive(apb_change_lock); return false; } diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index 8c17b4ff..87b1adcd 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -332,7 +332,7 @@ static void i2cDumpDqData(i2c_t * i2c) static void i2cDumpI2c(i2c_t * i2c) { log_e("i2c=%p",i2c); - log_i("dev=%p date=%p",i2c->dev,i2c->dev->date); + log_i("dev=%p date=%u",i2c->dev,i2c->dev->date); #if !CONFIG_DISABLE_HAL_LOCKS log_i("lock=%p",i2c->lock); #endif diff --git a/cores/esp32/esp32-hal-log.h b/cores/esp32/esp32-hal-log.h index 57d779cf..e89760be 100644 --- a/cores/esp32/esp32-hal-log.h +++ b/cores/esp32/esp32-hal-log.h @@ -21,6 +21,7 @@ extern "C" #include "sdkconfig.h" #include "esp_timer.h" +#include "esp_log.h" #define ARDUHAL_LOG_LEVEL_NONE (0) #define ARDUHAL_LOG_LEVEL_ERROR (1) @@ -72,86 +73,57 @@ extern "C" #define ARDUHAL_LOG_RESET_COLOR #endif -const char * pathToFileName(const char * path); -int log_printf(const char *fmt, ...); - #define ARDUHAL_SHORT_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter format ARDUHAL_LOG_RESET_COLOR "\r\n" -#define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter "[%6u][" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", (unsigned long) (esp_timer_get_time() / 1000ULL), pathToFileName(__FILE__), __LINE__, __FUNCTION__ +#define ARDUHAL_LOG_FORMAT(letter, format) "[%s:%u] %s(): " format, __FILE__, __LINE__, __FUNCTION__ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE -#define log_v(format, ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) -#define isr_log_v(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) +#define log_v(format, ...) ESP_LOGV("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) +#define isr_log_v(format, ...) ESP_LOGV("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) #else #define log_v(format, ...) #define isr_log_v(format, ...) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG -#define log_d(format, ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) -#define isr_log_d(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) +#define log_d(format, ...) ESP_LOGD("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) +#define isr_log_d(format, ...) ESP_LOGD("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) #else #define log_d(format, ...) #define isr_log_d(format, ...) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO -#define log_i(format, ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) -#define isr_log_i(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) +#define log_i(format, ...) ESP_LOGI("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) +#define isr_log_i(format, ...) ESP_LOGI("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) #else #define log_i(format, ...) #define isr_log_i(format, ...) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN -#define log_w(format, ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) -#define isr_log_w(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) +#define log_w(format, ...) ESP_LOGW("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) +#define isr_log_w(format, ...) ESP_LOGW("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) #else #define log_w(format, ...) #define isr_log_w(format, ...) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR -#define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) -#define isr_log_e(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) +#define log_e(format, ...) ESP_LOGE("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) +#define isr_log_e(format, ...) ESP_LOGE("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) #else #define log_e(format, ...) #define isr_log_e(format, ...) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE -#define log_n(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) -#define isr_log_n(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) +#define log_n(format, ...) ESP_LOGE("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) +#define isr_log_n(format, ...) ESP_LOGE("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) #else #define log_n(format, ...) #define isr_log_n(format, ...) #endif -#include "esp_log.h" - -#ifdef CONFIG_ARDUHAL_ESP_LOG -#undef ESP_LOGE -#undef ESP_LOGW -#undef ESP_LOGI -#undef ESP_LOGD -#undef ESP_LOGV -#undef ESP_EARLY_LOGE -#undef ESP_EARLY_LOGW -#undef ESP_EARLY_LOGI -#undef ESP_EARLY_LOGD -#undef ESP_EARLY_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__) -#define ESP_EARLY_LOGE(tag, ...) isr_log_e(__VA_ARGS__) -#define ESP_EARLY_LOGW(tag, ...) isr_log_w(__VA_ARGS__) -#define ESP_EARLY_LOGI(tag, ...) isr_log_i(__VA_ARGS__) -#define ESP_EARLY_LOGD(tag, ...) isr_log_d(__VA_ARGS__) -#define ESP_EARLY_LOGV(tag, ...) isr_log_v(__VA_ARGS__) -#endif - #ifdef __cplusplus } #endif diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 751b739f..5e31285a 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -86,19 +86,3 @@ void ARDUINO_ISR_ATTR delayMicroseconds(uint32_t us) } } -//used by hal log -const char * ARDUINO_ISR_ATTR pathToFileName(const char * path) -{ - size_t i = 0; - size_t pos = 0; - char * p = (char *)path; - while(*p){ - i++; - if(*p == '/' || *p == '\\'){ - pos = i; - } - p++; - } - return path+pos; -} - diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 1cf8d2a9..34ede336 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -59,8 +59,6 @@ #define UART_INTR_SOURCE(u) ((u==0)?ETS_UART0_INTR_SOURCE:( (u==1)?ETS_UART1_INTR_SOURCE:((u==2)?ETS_UART2_INTR_SOURCE:0))) #endif -static int s_uart_debug_nr = 0; - struct uart_struct_t { uart_dev_t * dev; #if !CONFIG_DISABLE_HAL_LOCKS @@ -566,81 +564,6 @@ static void ARDUINO_ISR_ATTR uart2_write_char(char c) } #endif -void uart_install_putc() -{ - switch(s_uart_debug_nr) { - case 0: - ets_install_putc1((void (*)(char)) &uart0_write_char); - break; - case 1: - ets_install_putc1((void (*)(char)) &uart1_write_char); - break; -#if CONFIG_IDF_TARGET_ESP32 - case 2: - ets_install_putc1((void (*)(char)) &uart2_write_char); - break; -#endif - default: - ets_install_putc1(NULL); - break; - } -} - -void uartSetDebug(uart_t* uart) -{ - if(uart == NULL || uart->num >= UART_PORTS_NUM) { - s_uart_debug_nr = -1; - //ets_install_putc1(NULL); - //return; - } else - if(s_uart_debug_nr == uart->num) { - return; - } else - s_uart_debug_nr = uart->num; - uart_install_putc(); -} - -int uartGetDebug() -{ - return s_uart_debug_nr; -} - -int log_printf(const char *format, ...) -{ - static char loc_buf[64]; - char * temp = loc_buf; - int len; - va_list arg; - va_list copy; - va_start(arg, format); - va_copy(copy, arg); - len = vsnprintf(NULL, 0, format, arg); - va_end(copy); - if(len >= sizeof(loc_buf)){ - temp = (char*)malloc(len+1); - if(temp == NULL) { - return 0; - } - } - vsnprintf(temp, len+1, format, arg); -#if !CONFIG_DISABLE_HAL_LOCKS - if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){ - xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY); - ets_printf("%s", temp); - xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock); - } else { - ets_printf("%s", temp); - } -#else - ets_printf("%s", temp); -#endif - va_end(arg); - if(len >= sizeof(loc_buf)){ - free(temp); - } - return len; -} - /* * if enough pulses are detected return the minimum high pulse duration + minimum low pulse duration divided by two. * This equals one bit period. If flag is true the function return inmediately, otherwise it waits for enough pulses. diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index e35f05d4..6dd80a90 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -72,9 +72,6 @@ size_t uartResizeRxBuffer(uart_t* uart, size_t new_size); void uartSetRxInvert(uart_t* uart, bool invert); -void uartSetDebug(uart_t* uart); -int uartGetDebug(); - void uartStartDetectBaudrate(uart_t *uart); unsigned long uartDetectBaudrate(uart_t *uart);