Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions L2_Core/utils/inc/ek_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
# define EK_LOG_BUFFER_SIZE (256) // 字符串缓冲区
# endif /* EK_LOG_BUFFER_SIZE */

# define EK_LOG_FILE_TAG(tag) static const char *__EK_LOG_TAG__ = tag;
# define EK_LOG_FILE_TAG(tag) static const char *_EK_LOG_TAG_ = tag;

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro name has been changed from __EK_LOG_TAG__ to _EK_LOG_TAG_ (double underscores to single underscores). This is a breaking change for any code that defines file tags using the old naming convention. While the new naming is better (avoiding reserved identifiers), this change needs to be documented and existing code must be updated.

Suggested change
# define EK_LOG_FILE_TAG(tag) static const char *_EK_LOG_TAG_ = tag;
# define EK_LOG_FILE_TAG(tag) \
static const char *_EK_LOG_TAG_ = tag; \
static const char *__EK_LOG_TAG__ = tag;

Copilot uses AI. Check for mistakes.

# define EK_LOG_GET_TICK() uint32_t __ek_log_get_tick(void)
# define EK_LOG_GET_TICK() uint32_t _ek_log_get_tick(void)

typedef enum
{
Expand All @@ -40,27 +40,20 @@ extern "C"
{
# endif

/**
* @brief 日志打印
*
* @param tag 文件标签
* @param line 行号
* @param type 日志类型
* @param fmt 格式化
* @param ...
*/
void _ek_log_printf(const char *tag, uint32_t line, ek_log_type_t type, const char *fmt, ...);
void _ek_log_printf(const char *tag, uint32_t line, ek_log_type_t type, uint32_t tick, const char *fmt, ...);
uint32_t _ek_log_get_tick(void);

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function signature of _ek_log_printf has been changed to add a tick parameter. This is a breaking API change that could affect existing code calling this function directly. The tick parameter is now passed explicitly instead of being called internally, which changes the function's interface. Consider whether this breaking change is intentional and if so, ensure all call sites are updated accordingly.

Copilot uses AI. Check for mistakes.

# if (EK_LOG_DEBUG_ENABLE == 1)
# define EK_LOG_DEBUG(...) _ek_log_printf(__EK_LOG_TAG__, __LINE__, EK_LOG_TYPE_DEBUG, __VA_ARGS__)
# define EK_LOG_DEBUG(...) \
_ek_log_printf(_EK_LOG_TAG_, __LINE__, EK_LOG_TYPE_DEBUG, _ek_log_get_tick(), __VA_ARGS__)
# else
# define EK_LOG_DEBUG(...)
# endif

# define EK_LOG(...) _ek_log_printf(__EK_LOG_TAG__, __LINE__, EK_LOG_TYPE_NONE, __VA_ARGS__)
# define EK_LOG_INFO(...) _ek_log_printf(__EK_LOG_TAG__, __LINE__, EK_LOG_TYPE_INFO, __VA_ARGS__)
# define EK_LOG_WARN(...) _ek_log_printf(__EK_LOG_TAG__, __LINE__, EK_LOG_TYPE_WARN, __VA_ARGS__)
# define EK_LOG_ERROR(...) _ek_log_printf(__EK_LOG_TAG__, __LINE__, EK_LOG_TYPE_ERROR, __VA_ARGS__)
# define EK_LOG(...) _ek_log_printf(_EK_LOG_TAG_, __LINE__, EK_LOG_TYPE_NONE, _ek_log_get_tick(), __VA_ARGS__)
# define EK_LOG_INFO(...) _ek_log_printf(_EK_LOG_TAG_, __LINE__, EK_LOG_TYPE_INFO, _ek_log_get_tick(), __VA_ARGS__)
# define EK_LOG_WARN(...) _ek_log_printf(_EK_LOG_TAG_, __LINE__, EK_LOG_TYPE_WARN, _ek_log_get_tick(), __VA_ARGS__)
# define EK_LOG_ERROR(...) _ek_log_printf(_EK_LOG_TAG_, __LINE__, EK_LOG_TYPE_ERROR, _ek_log_get_tick(), __VA_ARGS__)

# ifdef __cplusplus
}
Expand Down
11 changes: 5 additions & 6 deletions L2_Core/utils/src/ek_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ static const char *ek_log_type_table[EK_LOG_TYPE_MAX] = {

static char ek_log_buffer[EK_LOG_BUFFER_SIZE];

__WEAK uint32_t __ek_log_get_tick(void)
__WEAK uint32_t _ek_log_get_tick(void)

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name has been changed from __ek_log_get_tick to _ek_log_get_tick (removing one underscore). While this follows better naming conventions (avoiding double underscores which are reserved by the C standard), this is a breaking change. Any code that overrides this weak function will need to be updated to match the new name.

Copilot uses AI. Check for mistakes.
{
return 0;
}

void _ek_log_printf(const char *tag, uint32_t line, ek_log_type_t type, const char *fmt, ...)
void _ek_log_printf(const char *tag, uint32_t line, ek_log_type_t type, uint32_t tick, const char *fmt, ...)
{
if (EK_LOG_CHECK_LOCK() == 1) return;

Expand All @@ -54,16 +54,15 @@ void _ek_log_printf(const char *tag, uint32_t line, ek_log_type_t type, const ch
ek_log_type_table[type],
tag,
line,
__ek_log_get_tick());
_ek_log_get_tick());

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an inconsistency in the logging implementation. On line 57, _ek_log_get_tick() is still being called within _ek_log_printf, but the function signature was changed to accept tick as a parameter (line 44). This means the tick is calculated twice - once by the caller and once inside the function. Either remove the internal call and use the parameter, or revert the signature change.

Suggested change
_ek_log_get_tick());
tick);

Copilot uses AI. Check for mistakes.
# else /* EK_LOG_COLOR_ENABLE == 1 */
lwprintf("[%s/%s L:%" PRIu32 ",T:%" PRIu32 "]:", ek_log_type_table[type], tag, line, __ek_log_get_tick());
lwprintf("[%s/%s L:%" PRIu32 ",T:%" PRIu32 "]:", ek_log_type_table[type], tag, line, tick);
# endif /* EK_LOG_COLOR_ENABLE == 1 */

va_list args;
va_start(args, fmt);
uint32_t length = lwvsnprintf(ek_log_buffer, EK_LOG_BUFFER_SIZE - 1, fmt, args);
lwvsnprintf(ek_log_buffer, EK_LOG_BUFFER_SIZE - 1, fmt, args);
va_end(args);
Comment on lines +64 to 65

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the explicit null termination after lwvsnprintf may cause issues. The lwvsnprintf function typically null-terminates the buffer, but explicitly setting ek_log_buffer[length] = '\0' was a safety measure. Removing this line assumes that lwvsnprintf always properly null-terminates, which may not be guaranteed in all implementations. Consider keeping the explicit null termination for safety.

Copilot uses AI. Check for mistakes.
ek_log_buffer[length] = '\0';

lwprintf("%s", ek_log_buffer);

Expand Down
6 changes: 2 additions & 4 deletions L3_Middlewares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ if(USE_LVGL)

add_library(lvgl_config INTERFACE)
target_include_directories(lvgl_config INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/LVGL)
target_compile_definitions(lvgl_config INTERFACE
LV_CONF_BUILD_DISABLE_DEMOS=1
)
target_compile_definitions(lvgl_config INTERFACE)
target_link_libraries(lvgl PUBLIC l1_mcu)
endif()

Expand All @@ -38,7 +36,7 @@ if(USE_FATFS)
endif()

if(USE_LVGL)
target_link_libraries(l3_middlewares INTERFACE lvgl lvgl::examples lvgl_config)
target_link_libraries(l3_middlewares INTERFACE lvgl lvgl::examples lvgl::demos lvgl_config)
endif()

target_link_libraries(l3_middlewares INTERFACE l2_core global_macros global_options)
97 changes: 97 additions & 0 deletions L3_Middlewares/LVGL/demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Demos for LVGL

## Add the examples to your projects
1. demos can be found in the 'demos' folder once you clone the lvgl.

2. In the ***lv_conf.h*** or equivalent places, you can find demo related macros, change its value to enable or disable specified demos:

```c
...
/*===================
* DEMO USAGE
====================*/

/*Show some widget. It might be required to increase `LV_MEM_SIZE` */
#define LV_USE_DEMO_WIDGETS 0
#if LV_USE_DEMO_WIDGETS
#define LV_DEMO_WIDGETS_SLIDESHOW 0
#endif

/*Demonstrate the usage of encoder and keyboard*/
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0

/*Benchmark your system*/
#define LV_USE_DEMO_BENCHMARK 0

/*Stress test for LVGL*/
#define LV_USE_DEMO_STRESS 0

/*Music player demo*/
#define LV_USE_DEMO_MUSIC 0
#if LV_USE_DEMO_MUSIC
# define LV_DEMO_MUSIC_SQUARE 0
# define LV_DEMO_MUSIC_LANDSCAPE 0
# define LV_DEMO_MUSIC_ROUND 0
# define LV_DEMO_MUSIC_LARGE 0
# define LV_DEMO_MUSIC_AUTO_PLAY 0
#endif
...
```

3. If your development environment or toolchain does not add source files inside '***lvgl***' folder automatically, ensure the `demos` folder is included for compilation.
4. Include "***demos/lv_demos.h***" in your application source file, for example:

```c
//! main.c
#include "lvgl.h"
#include "demos/lv_demos.h"
...
```



## Demos

### Widgets
Shows how the widgets look like out of the box using the built-in material theme.

See in [widgets](https://github.com/lvgl/lvgl/tree/master/demos/widgets) folder.

<img src="https://github.com/lvgl/lvgl/tree/master/demos/widgets/screenshot1.png?raw=true" width=600px alt="Basic demo to show the widgets of LVGL">

For running this demo properly, please make sure **LV_MEM_SIZE** is at least **38KB** (and **48KB** is recommended):

```c
#define LV_MEME_SIZE (38ul * 1024ul)
```



### Music player
The music player demo shows what kind of modern, smartphone-like user interfaces can be created on LVGL. It works the best with display with 480x272 or 272x480 resolution.

See in [music](https://github.com/lvgl/lvgl/tree/master/demos/music) folder.

<img src="https://github.com/lvgl/lvgl/tree/master/demos/music/screenshot1.gif?raw=true" width=600px alt="Music player demo with LVGL">

### Keypad and encoder
LVGL allows you to control the widgets with a keypad and/or encoder without a touchpad. This demo shows how to handle buttons, drop-down lists, rollers, sliders, switches, and text inputs without touchpad.
Learn more about the touchpad-less usage of LVGL [here](https://docs.lvgl.io/master/overview/indev.html#keypad-and-encoder).

See in [keypad_encoder](https://github.com/lvgl/lvgl/tree/master/demos/keypad_encoder) folder.

<img src="https://github.com/lvgl/lvgl/tree/master/demos/keypad_encoder/screenshot1.png?raw=true" width=600px alt="Keypad and encoder navigation in LVGL embedded GUI library">

### Benchmark
A demo to measure the performance of LVGL or to compare different settings.
See in [benchmark](https://github.com/lvgl/lvgl/tree/master/demos/benchmark) folder.
<img src="https://github.com/lvgl/lvgl/tree/master/demos/benchmark/screenshot1.png?raw=true" width=600px alt="Benchmark demo with LVGL embedded GUI library">

### Stress
A stress test for LVGL. It contains a lot of object creation, deletion, animations, style usage, and so on. It can be used if there is any memory corruption during heavy usage or any memory leaks.
See in [stress](https://github.com/lvgl/lvgl/tree/master/demos/stress) folder.
<img src="https://github.com/lvgl/lvgl/tree/master/demos/stress/screenshot1.png?raw=true" width=600px alt="Stress test for LVGL">

## Contributing
For contribution and coding style guidelines, please refer to the file docs/CONTRIBUTING.md in the main LVGL repo:
  https://github.com/lvgl/lvgl
134 changes: 134 additions & 0 deletions L3_Middlewares/LVGL/demos/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Benchmark demo

## Overview

The benchmark demo tests the performance in various cases.
For example rectangle, border, shadow, text, image blending, image transformation, blending modes, etc.
All tests are repeated with 50% opacity.

The size and position of the objects during testing are set with a pseudo random number to make the benchmark repeatable.

On to top of the screen the title of the current test step, and the result of the previous step is displayed.

## Run the benchmark
- In `lv_conf.h` or equivalent places set `LV_USE_DEMO_BENCHMARK 1`
- After `lv_init()` and initializing the drivers call `lv_demo_benchmark()`
- If you only want to run a specific scene for any purpose (e.g. debug, performance optimization etc.), you can call `lv_demo_benchmark_run_scene()` instead of `lv_demo_benchmark()`and pass the scene number.
- If you enabled trace output by setting macro `LV_USE_LOG` to `1` and trace level `LV_LOG_LEVEL` to `LV_LOG_LEVEL_USER` or higher, benchmark results are printed out in `csv` format.
- If you want to know when the testing is finished, you can register a callback function via `lv_demo_benchmark_register_finished_handler()` before calling `lv_demo_benchmark()` or `lv_demo_benchmark_run_scene()`.
- If you want to know the maximum rendering performance of the system, call `lv_demo_benchmark_set_max_speed(true)` before `lv_demo_benchmark()`.

## Interpret the result

The FPS is measured like this:
- load the next step
- in the display driver's `monitor_cb` accumulate the time-to-render and the number of cycles
- measure for 1 second
- calculate `FPS = time_sum / render_cnt`

Note that it can result in very high FPS results for simple cases.
E.g. if some simple rectangles are drawn in 5 ms, the benchmark will tell it's 200 FPS.
So it ignores `LV_DISP_REFR_PERIOD` which tells LVGL how often it should refresh the screen.
In other words, the benchmark shows the FPS from the pure rendering time.

By default, only the changed areas are refreshed. It means if only a few pixels are changed in 1 ms the benchmark will show 1000 FPS. To measure the performance with full screen refresh uncomment `lv_obj_invalidate(lv_scr_act())` in `monitor_cb()` in `lv_demo_benchmark.c`.

![LVGL benchmark running](screenshot1.png)

If you are doing performance analysis for 2D image processing optimization, LCD latency (flushing data to LCD) introduced by `disp_flush()` might dilute the performance results of the LVGL drawing process, hence make it harder to see your optimization results (gain or loss). To avoid such problem, please:

1. Use a flag to control the LCD flushing inside `disp_flush()`. For example:

```c
volatile bool disp_flush_enabled = true;

/* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
*/
void disp_enable_update(void)
{
disp_flush_enabled = true;
}

/* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
*/
void disp_disable_update(void)
{
disp_flush_enabled = false;
}

static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
if(disp_flush_enabled) {
GLCD_DrawBitmap(area->x1, //!< x
area->y1, //!< y
area->x2 - area->x1 + 1, //!< width
area->y2 - area->y1 + 1, //!< height
(const uint8_t *)color_p);
}

/*IMPORTANT!!!
*Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}
```

2. Disable flushing before calling `lv_demo_benchmark()` or `lv_demo_benchmark_run_scene()`, for example:

```c
extern void disp_enable_update(void);
extern void disp_disable_update(void);

static void on_benchmark_finished(void)
{
disp_enable_update();
}

int main(void)
{
lv_init();
lv_port_disp_init();
lv_port_indev_init();

LV_LOG("Running LVGL Benchmark...");
LV_LOG("Please stand by...");
LV_LOG("NOTE: You will NOT see anything until the end.");

disp_disable_update();

lv_demo_benchmark_set_finished_cb(&on_benchmark_finished);
lv_demo_benchmark_set_max_speed(true);
lv_demo_benchmark();

//lv_demo_benchmark_run_scene(43); // run scene no 31

...
while(1){
lv_timer_handler(); //! run lv task at the max speed
}
}
```



3. Alternatively, you can use trace output to get the benchmark results in csv format by:
- Setting macro `LV_USE_LOG` to `1`
- Setting trace level `LV_LOG_LEVEL` to `LV_LOG_LEVEL_USER` or higher.




## Result summary
In the end, a table is created to display measured FPS values.

On top of the summary screen, the "Weighted FPS" value is shown.
In this, the result of the more common cases are taken into account with a higher weight.

"Opa. speed" shows the speed of the measurements with opacity compared to full opacity.
E.g. "Opa. speed = 90%" means that rendering with opacity is 10% slower.

In the first section of the table, "Slow but common cases", those cases are displayed which are considered common but were slower than 20 FPS.

Below this in the "All cases section" all the results are shown. The < 10 FPS results are shown with red, the >= 10 but < 20 FPS values are displayed with orange.


![LVGL benchmark result summary](https://github.com/lvgl/lvgl/tree/master/demos/benchmark/screenshot2.png?raw=true)
Loading