1
0
Fork 0
mirror of https://github.com/s1204IT/Lockpick_RCM.git synced 2024-11-27 03:52:18 +00:00
Lockpick_RCM/bdk/libs/lvgl/lv_misc/lv_log.c

83 lines
2 KiB
C
Raw Normal View History

2020-06-26 21:17:06 +01:00
/**
* @file lv_log.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_log.h"
#if USE_LV_LOG
#if LV_LOG_PRINTF
#include <string.h>
#include <mem/heap.h>
#include <soc/uart.h>
#include <utils/sprintf.h>
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static void (*print_cb)(lv_log_level_t, const char *, uint32_t, const char *);
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Register custom print (or anything else) function to call when log is added
* @param f a function pointer:
* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`
*/
void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *))
{
print_cb = f;
}
/**
* Add a log
* @param level the level of log. (From `lv_log_level_t` enum)
* @param file name of the file when the log added
* @param line line number in the source code where the log added
* @param dsc description of the log
*/
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)
{
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
if(level >= LV_LOG_LEVEL) {
2021-05-12 22:38:34 +01:00
#if LV_LOG_PRINTF && defined(DEBUG_UART_PORT)
2020-06-26 21:17:06 +01:00
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
char *log = (char *)malloc(0x1000);
s_printf(log, "%s: %s \t(%s #%d)\r\n", lvl_prefix[level], dsc, file, line);
uart_send(DEBUG_UART_PORT, (u8 *)log, strlen(log) + 1);
2020-06-26 21:17:06 +01:00
//gfx_printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
#else
if(print_cb) print_cb(level, file, line, dsc);
#endif
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*USE_LV_LOG*/