2021-12-20 12:15:35 +00:00
|
|
|
#include <esp_log.h>
|
|
|
|
#include <soft-uart.h>
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-02-25 01:55:40 +00:00
|
|
|
extern void esp_log_impl_lock(void);
|
|
|
|
extern void esp_log_impl_unlock(void);
|
2021-12-20 12:15:35 +00:00
|
|
|
|
2022-02-25 01:55:40 +00:00
|
|
|
#define LOG_BUFFER_SIZE (128)
|
2021-12-20 12:15:35 +00:00
|
|
|
static SoftUart* log_uart = NULL;
|
|
|
|
static char log_buffer[LOG_BUFFER_SIZE];
|
|
|
|
|
|
|
|
static int soft_uart_log_vprintf(const char* str, va_list l) {
|
2022-02-25 01:55:40 +00:00
|
|
|
esp_log_impl_lock();
|
2021-12-20 12:15:35 +00:00
|
|
|
|
|
|
|
int len = vsnprintf(log_buffer, LOG_BUFFER_SIZE, str, l);
|
|
|
|
soft_uart_transmit(log_uart, (uint8_t*)log_buffer, strlen(log_buffer));
|
|
|
|
|
2022-02-25 01:55:40 +00:00
|
|
|
esp_log_impl_unlock();
|
2021-12-20 12:15:35 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void soft_uart_log_init(uint8_t pin, uint32_t baudrate) {
|
|
|
|
log_uart = soft_uart_init(baudrate, pin);
|
|
|
|
|
|
|
|
esp_log_set_vprintf(soft_uart_log_vprintf);
|
|
|
|
}
|