Skip to content

Commit 7c7bf42

Browse files
committed
modules: lvgl: Update gluecode to v9.2
This patch updates the module gluecode to be compatible with LVGL version 9.2. This includes changes done to display and input driver initialization and draw buffer handling. Signed-off-by: Fabian Blatz <[email protected]>
1 parent eecd7f5 commit 7c7bf42

21 files changed

+396
-321
lines changed

modules/lvgl/Kconfig

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ choice LV_COLOR_DEPTH
7777

7878
config LV_COLOR_DEPTH_32
7979
bool "32: ARGB8888"
80+
config LV_COLOR_DEPTH_24
81+
bool "24: RGB888"
8082
config LV_COLOR_DEPTH_16
8183
bool "16: RGB565"
8284
config LV_COLOR_DEPTH_8
@@ -86,7 +88,7 @@ choice LV_COLOR_DEPTH
8688
endchoice
8789

8890
config LV_COLOR_16_SWAP
89-
bool
91+
bool "Swap the 2 bytes of RGB565 color."
9092
depends on LV_COLOR_DEPTH_16
9193

9294
config LV_Z_FLUSH_THREAD
@@ -128,10 +130,26 @@ config LV_Z_AREA_Y_ALIGNMENT_WIDTH
128130
the current frame dimensions to meet display and/or LCD host
129131
controller requirements. The value must be power of 2.
130132

131-
config LV_USE_GPU_STM32_DMA2D
133+
config LV_Z_AUTO_INIT
134+
bool "Initialize LVGL before application startup"
135+
default y
136+
help
137+
Configure LVGL callbacks and display initialization before the application starts.
138+
This can be useful to disable if you need to change a display's pixel format
139+
prior to initialization. If using static allocation, ensure that LV_Z_BITS_PER_PIXEL
140+
is set correctly.
141+
142+
config LV_Z_INIT_PRIORITY
143+
int "Default init priority for LVGL"
144+
default 90
145+
depends on LV_Z_AUTO_INIT
146+
help
147+
Priority used for the automatic initialization of LVGL.
148+
149+
config LV_USE_DRAW_DMA2D
132150
bool
133151

134-
config LV_GPU_DMA2D_CMSIS_INCLUDE
152+
config LV_DRAW_DMA2D_HAL_INCLUDE
135153
string
136154
help
137155
Must be defined to include path of CMSIS header of target processor

modules/lvgl/Kconfig.memory

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ menu "Memory manager settings"
77
config LV_Z_BITS_PER_PIXEL
88
int "Bits per pixel"
99
default 32
10+
default 32 if LV_COLOR_DEPTH_32
11+
default 24 if LV_COLOR_DEPTH_24
12+
default 16 if LV_COLOR_DEPTH_16
13+
default 8 if LV_COLOR_DEPTH_8
14+
default 1 if LV_COLOR_DEPTH_1
1015
range 1 32
11-
depends on LV_Z_BUFFER_ALLOC_STATIC
1216
help
1317
Number of bits per pixel.
1418

@@ -88,6 +92,13 @@ config LV_Z_VBD_CUSTOM_SECTION
8892
rendering buffers to a custom location, such as tightly coupled or
8993
external memory.
9094

95+
config LV_Z_MONOCHROME_CONVERSION_BUFFER
96+
bool "Use intermediate conversion buffer for monochrome displays"
97+
default y
98+
help
99+
When using a monochrome display an intermediate buffer with LV_Z_VDB_SIZE
100+
is needed to perform the conversion.
101+
91102
choice LV_Z_RENDERING_BUFFER_ALLOCATION
92103
prompt "Rendering Buffer Allocation"
93104
default LV_Z_BUFFER_ALLOC_STATIC

modules/lvgl/include/lv_conf.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,33 @@
1212

1313
/* Memory manager settings */
1414

15-
#define LV_MEMCPY_MEMSET_STD 1
16-
#define LV_MEM_CUSTOM 1
15+
#define LV_USE_STDLIB_MALLOC LV_STDLIB_CUSTOM
1716

1817
#if defined(CONFIG_LV_Z_MEM_POOL_HEAP_LIB_C)
19-
20-
#define LV_MEM_CUSTOM_INCLUDE "stdlib.h"
21-
#define LV_MEM_CUSTOM_ALLOC malloc
22-
#define LV_MEM_CUSTOM_REALLOC realloc
23-
#define LV_MEM_CUSTOM_FREE free
24-
18+
#define LV_STDLIB_INCLUDE "stdlib.h"
19+
#define lv_malloc_core malloc
20+
#define lv_realloc_core realloc
21+
#define lv_free_core free
2522
#else
26-
27-
#define LV_MEM_CUSTOM_INCLUDE "lvgl_mem.h"
28-
#define LV_MEM_CUSTOM_ALLOC lvgl_malloc
29-
#define LV_MEM_CUSTOM_REALLOC lvgl_realloc
30-
#define LV_MEM_CUSTOM_FREE lvgl_free
31-
23+
#define LV_STDLIB_INCLUDE "lvgl_mem.h"
24+
#define lv_malloc_core lvgl_malloc
25+
#define lv_realloc_core lvgl_realloc
26+
#define lv_free_core lvgl_free
3227
#endif
3328

34-
/* HAL settings */
35-
36-
#define LV_TICK_CUSTOM 1
37-
#define LV_TICK_CUSTOM_INCLUDE <zephyr/kernel.h>
38-
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (k_uptime_get_32())
39-
4029
/* Misc settings */
41-
42-
#define LV_SPRINTF_CUSTOM 1
43-
#define LV_SPRINTF_INCLUDE "stdio.h"
44-
#define lv_snprintf snprintf
45-
#define lv_vsnprintf vsnprintf
30+
#define lv_snprintf snprintf
31+
#define lv_vsnprintf vsnprintf
32+
#define LV_ASSERT_HANDLER __ASSERT_NO_MSG(false);
33+
#define LV_ASSERT_HANDLER_INCLUDE "zephyr/sys/__assert.h"
4634

4735
/* Provide definition to align LVGL buffers */
4836
#define LV_ATTRIBUTE_MEM_ALIGN __aligned(CONFIG_LV_ATTRIBUTE_MEM_ALIGN_SIZE)
4937

38+
#ifdef CONFIG_LV_COLOR_16_SWAP
39+
#define LV_COLOR_16_SWAP 1
40+
#endif /* CONFIG_LV_COLOR_16_SWAP */
41+
5042
/*
5143
* Needed because of a workaround for a GCC bug,
5244
* see https://github.com/lvgl/lvgl/issues/3078

modules/lvgl/include/lvgl_common_input.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct lvgl_common_input_config {
2020
};
2121

2222
struct lvgl_common_input_data {
23-
lv_indev_drv_t indev_drv;
2423
lv_indev_t *indev;
2524
lv_indev_data_t pending_event;
2625
lv_indev_data_t previous_event;

modules/lvgl/include/lvgl_display.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,27 @@ struct lvgl_disp_data {
2222
};
2323

2424
struct lvgl_display_flush {
25-
lv_disp_drv_t *disp_drv;
25+
lv_display_t *display;
2626
uint16_t x;
2727
uint16_t y;
2828
struct display_buffer_descriptor desc;
2929
void *buf;
3030
};
3131

32-
void lvgl_flush_cb_mono(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
33-
void lvgl_flush_cb_16bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
34-
void lvgl_flush_cb_24bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
35-
void lvgl_flush_cb_32bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
32+
void lvgl_flush_cb_mono(lv_display_t *display, const lv_area_t *area, uint8_t *px_map);
33+
void lvgl_flush_cb_16bit(lv_display_t *display, const lv_area_t *area, uint8_t *px_map);
34+
void lvgl_flush_cb_24bit(lv_display_t *display, const lv_area_t *area, uint8_t *px_map);
35+
void lvgl_flush_cb_32bit(lv_display_t *display, const lv_area_t *area, uint8_t *px_map);
3636

37-
void lvgl_set_px_cb_mono(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
38-
lv_coord_t y, lv_color_t color, lv_opa_t opa);
39-
void lvgl_set_px_cb_16bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
40-
lv_coord_t y, lv_color_t color, lv_opa_t opa);
41-
void lvgl_set_px_cb_24bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
42-
lv_coord_t y, lv_color_t color, lv_opa_t opa);
43-
void lvgl_set_px_cb_32bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
44-
lv_coord_t y, lv_color_t color, lv_opa_t opa);
37+
void lvgl_rounder_cb_mono(lv_event_t *e);
38+
void lvgl_set_mono_conversion_buffer(uint8_t *buffer, uint32_t buffer_size);
4539

46-
void lvgl_rounder_cb_mono(lv_disp_drv_t *disp_drv, lv_area_t *area);
47-
48-
int set_lvgl_rendering_cb(lv_disp_drv_t *disp_drv);
40+
int set_lvgl_rendering_cb(lv_display_t *display);
4941

5042
void lvgl_flush_display(struct lvgl_display_flush *request);
5143

5244
#ifdef CONFIG_LV_Z_USE_ROUNDER_CB
53-
void lvgl_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area);
45+
void lvgl_rounder_cb(lv_event_t *e);
5446
#endif
5547

5648
#ifdef __cplusplus

modules/lvgl/include/lvgl_mem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <stdlib.h>
1111
#include <stdbool.h>
12+
#include <zephyr/sys/mem_stats.h>
1213

1314
#ifdef __cplusplus
1415
extern "C" {
@@ -22,6 +23,8 @@ void lvgl_free(void *ptr);
2223

2324
void lvgl_print_heap_info(bool dump_chunks);
2425

26+
void lvgl_heap_stats(struct sys_memory_stats *stats);
27+
2528
void lvgl_heap_init(void);
2629

2730
#ifdef __cplusplus

modules/lvgl/include/lvgl_zephyr.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2024 Fabian Blatz <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_MODULES_LVGL_ZEPHYR_H_
8+
#define ZEPHYR_MODULES_LVGL_ZEPHYR_H_
9+
10+
#include <zephyr/kernel.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
/**
17+
* @brief Initialize the LittlevGL library
18+
*
19+
* This function initializes the LittlevGL library and setups the display and input devices.
20+
* If `LV_Z_AUTO_INIT` is disabled it must be called before any other LittlevGL function.
21+
*
22+
* @return 0 on success, negative errno code on failure
23+
*/
24+
int lvgl_init(void);
25+
26+
#ifdef __cplusplus
27+
}
28+
#endif
29+
30+
#endif /* ZEPHYR_MODULES_LVGL_ZEPHYR_H_ */

modules/lvgl/input/lvgl_button_input.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct lvgl_button_input_config {
1717
struct lvgl_common_input_config common_config; /* Needs to be first member */
1818
const uint16_t *input_codes;
1919
uint8_t num_codes;
20-
const lv_coord_t *coordinates;
20+
const int32_t *coordinates;
2121
};
2222

2323
static void lvgl_button_process_event(struct input_event *evt, void *user_data)
@@ -39,7 +39,7 @@ static void lvgl_button_process_event(struct input_event *evt, void *user_data)
3939
}
4040

4141
data->pending_event.btn_id = i;
42-
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
42+
data->pending_event.state = evt->value ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
4343

4444
if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
4545
LOG_WRN("Could not put input data into queue");
@@ -72,8 +72,7 @@ int lvgl_button_input_init(const struct device *dev)
7272
LVGL_INPUT_DEFINE(inst, button, CONFIG_LV_Z_BUTTON_INPUT_MSGQ_COUNT, \
7373
lvgl_button_process_event); \
7474
static const uint16_t lvgl_button_input_codes_##inst[] = DT_INST_PROP(inst, input_codes); \
75-
static const lv_coord_t lvgl_button_coordinates_##inst[] = \
76-
DT_INST_PROP(inst, coordinates); \
75+
static const int32_t lvgl_button_coordinates_##inst[] = DT_INST_PROP(inst, coordinates); \
7776
static const struct lvgl_button_input_config lvgl_button_input_config_##inst = { \
7877
.common_config.event_msgq = &LVGL_INPUT_EVENT_MSGQ(inst, button), \
7978
.input_codes = lvgl_button_input_codes_##inst, \

modules/lvgl/input/lvgl_common_input.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ lv_indev_t *lvgl_input_get_indev(const struct device *dev)
2323
return common_data->indev;
2424
}
2525

26-
static void lvgl_input_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data)
26+
static void lvgl_input_read_cb(lv_indev_t *indev, lv_indev_data_t *data)
2727
{
28-
const struct device *dev = drv->user_data;
28+
const struct device *dev = lv_indev_get_user_data(indev);
2929
const struct lvgl_common_input_config *cfg = dev->config;
3030
struct lvgl_common_input_data *common_data = dev->data;
3131

3232
if (k_msgq_get(cfg->event_msgq, data, K_NO_WAIT) != 0) {
3333
memcpy(data, &common_data->previous_event, sizeof(lv_indev_data_t));
34-
if (drv->type == LV_INDEV_TYPE_ENCODER) {
34+
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
3535
data->enc_diff = 0; /* For encoders, clear last movement */
3636
}
3737
data->continue_reading = false;
@@ -54,16 +54,16 @@ int lvgl_input_register_driver(lv_indev_type_t indev_type, const struct device *
5454
return -EINVAL;
5555
}
5656

57-
lv_indev_drv_init(&common_data->indev_drv);
58-
common_data->indev_drv.type = indev_type;
59-
common_data->indev_drv.read_cb = lvgl_input_read_cb;
60-
common_data->indev_drv.user_data = (void *)dev;
61-
common_data->indev = lv_indev_drv_register(&common_data->indev_drv);
57+
common_data->indev = lv_indev_create();
6258

6359
if (common_data->indev == NULL) {
6460
return -EINVAL;
6561
}
6662

63+
lv_indev_set_type(common_data->indev, indev_type);
64+
lv_indev_set_read_cb(common_data->indev, lvgl_input_read_cb);
65+
lv_indev_set_user_data(common_data->indev, (void *)dev);
66+
6767
return 0;
6868
}
6969

modules/lvgl/input/lvgl_encoder_input.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ static void lvgl_encoder_process_event(struct input_event *evt, void *user_data)
2828
if (evt->code == cfg->rotation_input_code) {
2929
data->pending_event.enc_diff = evt->value;
3030
} else if (evt->code == cfg->button_input_code) {
31-
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
31+
data->pending_event.state =
32+
evt->value ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
3233
data->pending_event.enc_diff = 0;
3334
data->pending_event.key = LV_KEY_ENTER;
3435
} else {

0 commit comments

Comments
 (0)