Skip to content

Commit

Permalink
modules: lvgl: Fix usage of LVGL log levels
Browse files Browse the repository at this point in the history
Introduces a Kconfig symbol `LV_Z_LOG_LEVEL` because contrary to Zephyr the
numerical value of log levels in LVGL increases with severity. Also support
for the `LV_LOG_LEVEL_USER` is added.

Resolves issue zephyrproject-rtos#64351.

Signed-off-by: Fabian Blatz <[email protected]>
  • Loading branch information
faxe1008 authored and carlescufi committed Nov 15, 2023
1 parent 92560ac commit 84c7f2f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
30 changes: 30 additions & 0 deletions modules/lvgl/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ config LV_CONF_SKIP
bool
default n

config LV_USE_LOG
bool

config LV_LOG_LEVEL_NONE
bool

config LV_LOG_LEVEL_ERROR
bool

config LV_LOG_LEVEL_WARN
bool

config LV_LOG_LEVEL_INFO
bool

config LV_LOG_LEVEL_USER
bool

config LV_LOG_LEVEL_TRACE
bool

config LV_Z_LOG_LEVEL
int
default 0 if LV_LOG_LEVEL_NONE || !LV_USE_LOG
default 1 if LV_LOG_LEVEL_ERROR
default 2 if LV_LOG_LEVEL_WARN
default 3 if LV_LOG_LEVEL_INFO
default 3 if LV_LOG_LEVEL_USER
default 4 if LV_LOG_LEVEL_TRACE

config APP_LINK_WITH_LVGL
bool "Link 'app' with LVGL"
default y
Expand Down
2 changes: 1 addition & 1 deletion modules/lvgl/input/lvgl_button_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(lvgl);
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);

struct lvgl_button_input_config {
struct lvgl_common_input_config common_config; /* Needs to be first member */
Expand Down
2 changes: 1 addition & 1 deletion modules/lvgl/input/lvgl_common_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "lvgl_button_input.h"
#include "lvgl_encoder_input.h"

LOG_MODULE_DECLARE(lvgl);
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);

lv_indev_t *lvgl_input_get_indev(const struct device *dev)
{
Expand Down
2 changes: 1 addition & 1 deletion modules/lvgl/input/lvgl_encoder_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(lvgl);
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);

struct lvgl_encoder_input_config {
struct lvgl_common_input_config common_config; /* Needs to be first member */
Expand Down
2 changes: 1 addition & 1 deletion modules/lvgl/input/lvgl_pointer_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <lvgl_display.h>
#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(lvgl);
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);

struct lvgl_pointer_input_config {
struct lvgl_common_input_config common_config; /* Needs to be first member */
Expand Down
2 changes: 1 addition & 1 deletion modules/lvgl/input/lvgl_pointer_kscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "lvgl_display.h"

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(lvgl);
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);

static lv_indev_drv_t indev_drv;
#define KSCAN_NODE DT_CHOSEN(zephyr_keyboard_scan)
Expand Down
12 changes: 7 additions & 5 deletions modules/lvgl/lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
#endif
#include LV_MEM_CUSTOM_INCLUDE

#define LOG_LEVEL CONFIG_LV_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(lvgl);
LOG_MODULE_REGISTER(lvgl, CONFIG_LV_Z_LOG_LEVEL);

static lv_disp_drv_t disp_drv;
struct lvgl_disp_data disp_data = {
Expand Down Expand Up @@ -61,7 +60,7 @@ static uint8_t buf1[BUFFER_SIZE]

#endif /* CONFIG_LV_Z_BUFFER_ALLOC_STATIC */

#if CONFIG_LV_LOG_LEVEL != 0
#if CONFIG_LV_Z_LOG_LEVEL != 0
/*
* In LVGLv8 the signature of the logging callback has changes and it no longer
* takes the log level as an integer argument. Instead, the log level is now
Expand All @@ -83,14 +82,17 @@ static void lvgl_log(const char *buf)
LOG_ERR("%s", buf + strlen("[Error] "));
break;
case 'W':
LOG_WRN("%s", buf + strlen("Warn] "));
LOG_WRN("%s", buf + strlen("[Warn] "));
break;
case 'I':
LOG_INF("%s", buf + strlen("[Info] "));
break;
case 'T':
LOG_DBG("%s", buf + strlen("[Trace] "));
break;
case 'U':
LOG_INF("%s", buf + strlen("[User] "));
break;
}
}
#endif
Expand Down Expand Up @@ -207,7 +209,7 @@ static int lvgl_init(void)
lvgl_heap_init();
#endif

#if CONFIG_LV_LOG_LEVEL != 0
#if CONFIG_LV_Z_LOG_LEVEL != 0
lv_log_register_print_cb(lvgl_log);
#endif

Expand Down

0 comments on commit 84c7f2f

Please sign in to comment.