Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_misc/lv_log.c
1476 views
1
/**
2
* @file lv_log.c
3
*
4
*/
5
6
/*********************
7
* INCLUDES
8
*********************/
9
#include "lv_log.h"
10
#if USE_LV_LOG
11
12
#if LV_LOG_PRINTF
13
#include <string.h>
14
#include <mem/heap.h>
15
#include <soc/uart.h>
16
#include <utils/sprintf.h>
17
#endif
18
/*********************
19
* DEFINES
20
*********************/
21
22
/**********************
23
* TYPEDEFS
24
**********************/
25
26
/**********************
27
* STATIC PROTOTYPES
28
**********************/
29
30
/**********************
31
* STATIC VARIABLES
32
**********************/
33
static void (*print_cb)(lv_log_level_t, const char *, uint32_t, const char *);
34
35
/**********************
36
* MACROS
37
**********************/
38
39
/**********************
40
* GLOBAL FUNCTIONS
41
**********************/
42
43
/**
44
* Register custom print (or anything else) function to call when log is added
45
* @param f a function pointer:
46
* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`
47
*/
48
void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *))
49
{
50
print_cb = f;
51
}
52
53
/**
54
* Add a log
55
* @param level the level of log. (From `lv_log_level_t` enum)
56
* @param file name of the file when the log added
57
* @param line line number in the source code where the log added
58
* @param dsc description of the log
59
*/
60
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)
61
{
62
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
63
64
if(level >= LV_LOG_LEVEL) {
65
66
#if LV_LOG_PRINTF && defined(DEBUG_UART_PORT)
67
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
68
char *log = (char *)malloc(0x1000);
69
s_printf(log, "%s: %s \t(%s #%d)\r\n", lvl_prefix[level], dsc, file, line);
70
uart_send(DEBUG_UART_PORT, (u8 *)log, strlen(log) + 1);
71
//gfx_printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
72
#else
73
if(print_cb) print_cb(level, file, line, dsc);
74
#endif
75
}
76
}
77
78
/**********************
79
* STATIC FUNCTIONS
80
**********************/
81
82
#endif /*USE_LV_LOG*/
83
84