Remove shitty arduino logging system

This commit is contained in:
2021-05-05 12:53:37 +02:00
parent d237cc9df6
commit 67dfea558a
8 changed files with 18 additions and 161 deletions

View File

@ -112,9 +112,6 @@ void HardwareSerial::updateBaudRate(unsigned long baud)
void HardwareSerial::end() void HardwareSerial::end()
{ {
if(uartGetDebug() == _uart_nr) {
uartSetDebug(0);
}
log_v("pins %d %d",_tx_pin, _rx_pin); log_v("pins %d %d",_tx_pin, _rx_pin);
uartEnd(_uart, _tx_pin, _rx_pin); uartEnd(_uart, _tx_pin, _rx_pin);
_uart = 0; _uart = 0;
@ -124,20 +121,6 @@ size_t HardwareSerial::setRxBufferSize(size_t new_size) {
return uartResizeRxBuffer(_uart, 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) int HardwareSerial::available(void)
{ {
return uartAvailable(_uart); return uartAvailable(_uart);

View File

@ -75,8 +75,6 @@ public:
operator bool() const; operator bool() const;
size_t setRxBufferSize(size_t); size_t setRxBufferSize(size_t);
void setDebugOutput(bool);
void setRxInvert(bool); void setRxInvert(bool);
protected: protected:

View File

@ -102,7 +102,7 @@ bool addApbChangeCallback(void * arg, apb_change_cb_t cb){
// look for duplicate callbacks // look for duplicate callbacks
while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next; while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next;
if (r) { 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); free(c);
xSemaphoreGive(apb_change_lock); xSemaphoreGive(apb_change_lock);
return false; return false;
@ -124,7 +124,7 @@ bool removeApbChangeCallback(void * arg, apb_change_cb_t cb){
// look for matching callback // look for matching callback
while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next; while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next;
if ( r == NULL ) { 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); xSemaphoreGive(apb_change_lock);
return false; return false;
} }

View File

@ -332,7 +332,7 @@ static void i2cDumpDqData(i2c_t * i2c)
static void i2cDumpI2c(i2c_t * i2c) static void i2cDumpI2c(i2c_t * i2c)
{ {
log_e("i2c=%p",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 #if !CONFIG_DISABLE_HAL_LOCKS
log_i("lock=%p",i2c->lock); log_i("lock=%p",i2c->lock);
#endif #endif

View File

@ -21,6 +21,7 @@ extern "C"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_timer.h" #include "esp_timer.h"
#include "esp_log.h"
#define ARDUHAL_LOG_LEVEL_NONE (0) #define ARDUHAL_LOG_LEVEL_NONE (0)
#define ARDUHAL_LOG_LEVEL_ERROR (1) #define ARDUHAL_LOG_LEVEL_ERROR (1)
@ -72,86 +73,57 @@ extern "C"
#define ARDUHAL_LOG_RESET_COLOR #define ARDUHAL_LOG_RESET_COLOR
#endif #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_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 #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
#define log_v(format, ...) log_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, ...) ets_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) #define isr_log_v(format, ...) ESP_LOGV("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
#else #else
#define log_v(format, ...) #define log_v(format, ...)
#define isr_log_v(format, ...) #define isr_log_v(format, ...)
#endif #endif
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
#define log_d(format, ...) log_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, ...) ets_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) #define isr_log_d(format, ...) ESP_LOGD("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
#else #else
#define log_d(format, ...) #define log_d(format, ...)
#define isr_log_d(format, ...) #define isr_log_d(format, ...)
#endif #endif
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
#define log_i(format, ...) log_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, ...) ets_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) #define isr_log_i(format, ...) ESP_LOGI("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
#else #else
#define log_i(format, ...) #define log_i(format, ...)
#define isr_log_i(format, ...) #define isr_log_i(format, ...)
#endif #endif
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
#define log_w(format, ...) log_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, ...) ets_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) #define isr_log_w(format, ...) ESP_LOGW("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
#else #else
#define log_w(format, ...) #define log_w(format, ...)
#define isr_log_w(format, ...) #define isr_log_w(format, ...)
#endif #endif
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
#define log_e(format, ...) log_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, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) #define isr_log_e(format, ...) ESP_LOGE("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
#else #else
#define log_e(format, ...) #define log_e(format, ...)
#define isr_log_e(format, ...) #define isr_log_e(format, ...)
#endif #endif
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE
#define log_n(format, ...) log_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, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) #define isr_log_n(format, ...) ESP_LOGE("ARDUHAL_LOG", ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
#else #else
#define log_n(format, ...) #define log_n(format, ...)
#define isr_log_n(format, ...) #define isr_log_n(format, ...)
#endif #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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -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;
}

View File

@ -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))) #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 #endif
static int s_uart_debug_nr = 0;
struct uart_struct_t { struct uart_struct_t {
uart_dev_t * dev; uart_dev_t * dev;
#if !CONFIG_DISABLE_HAL_LOCKS #if !CONFIG_DISABLE_HAL_LOCKS
@ -566,81 +564,6 @@ static void ARDUINO_ISR_ATTR uart2_write_char(char c)
} }
#endif #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. * 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. * This equals one bit period. If flag is true the function return inmediately, otherwise it waits for enough pulses.

View File

@ -72,9 +72,6 @@ size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
void uartSetRxInvert(uart_t* uart, bool invert); void uartSetRxInvert(uart_t* uart, bool invert);
void uartSetDebug(uart_t* uart);
int uartGetDebug();
void uartStartDetectBaudrate(uart_t *uart); void uartStartDetectBaudrate(uart_t *uart);
unsigned long uartDetectBaudrate(uart_t *uart); unsigned long uartDetectBaudrate(uart_t *uart);