/**1* @file lv_log.c2*3*/45/*********************6* INCLUDES7*********************/8#include "lv_log.h"9#if USE_LV_LOG1011#if LV_LOG_PRINTF12#include <string.h>13#include <mem/heap.h>14#include <soc/uart.h>15#include <utils/sprintf.h>16#endif17/*********************18* DEFINES19*********************/2021/**********************22* TYPEDEFS23**********************/2425/**********************26* STATIC PROTOTYPES27**********************/2829/**********************30* STATIC VARIABLES31**********************/32static void (*print_cb)(lv_log_level_t, const char *, uint32_t, const char *);3334/**********************35* MACROS36**********************/3738/**********************39* GLOBAL FUNCTIONS40**********************/4142/**43* Register custom print (or anything else) function to call when log is added44* @param f a function pointer:45* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`46*/47void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *))48{49print_cb = f;50}5152/**53* Add a log54* @param level the level of log. (From `lv_log_level_t` enum)55* @param file name of the file when the log added56* @param line line number in the source code where the log added57* @param dsc description of the log58*/59void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)60{61if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/6263if(level >= LV_LOG_LEVEL) {6465#if LV_LOG_PRINTF && defined(DEBUG_UART_PORT)66static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};67char *log = (char *)malloc(0x1000);68s_printf(log, "%s: %s \t(%s #%d)\r\n", lvl_prefix[level], dsc, file, line);69uart_send(DEBUG_UART_PORT, (u8 *)log, strlen(log) + 1);70//gfx_printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);71#else72if(print_cb) print_cb(level, file, line, dsc);73#endif74}75}7677/**********************78* STATIC FUNCTIONS79**********************/8081#endif /*USE_LV_LOG*/828384