Skip to content

Commit db7a67b

Browse files
authored
Merge pull request #21726 from leandrolanzieri/pr/lvgl_monochrome
pkg/lvgl: support monochrome displays via u8g2
2 parents 485b386 + 1dae523 commit db7a67b

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

pkg/lvgl/contrib/lvgl.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
#endif
4040

4141
#ifndef LVGL_COLOR_BUF_SIZE
42-
#define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10)
42+
# if IS_USED(MODULE_U8G2_DISP_DEV)
43+
# define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10 * 8)
44+
# else
45+
# define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10)
46+
# endif
4347
#endif
4448

4549
#ifndef CONFIG_LVGL_INACTIVITY_PERIOD_MS
@@ -134,6 +138,23 @@ static void _touch_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
134138
}
135139
#endif
136140

141+
/* Pixel placement for monochrome displays where color depth is 1 bit, and each bit represents
142+
a pixel */
143+
static void _monochrome_1bit_set_px_cb(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w,
144+
lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa)
145+
{
146+
(void)disp_drv;
147+
(void)opa;
148+
149+
uint16_t byte = (y * buf_w / 8) + (x / 8);
150+
if (lv_color_brightness(color) > 128) {
151+
(buf[byte]) |= (1 << (x % 8));
152+
}
153+
else {
154+
(buf[byte]) &= ~(1 << (x % 8));
155+
}
156+
}
157+
137158
void lvgl_init(screen_dev_t *screen_dev)
138159
{
139160
lv_init();
@@ -164,6 +185,11 @@ void lvgl_init(screen_dev_t *screen_dev)
164185
disp_drv.ver_res = disp_dev_height(screen_dev->display);
165186
#endif
166187

188+
if (disp_dev_color_depth(screen_dev->display) == 1) {
189+
disp_drv.full_refresh = 1;
190+
disp_drv.set_px_cb = _monochrome_1bit_set_px_cb;
191+
}
192+
167193
lv_disp_drv_register(&disp_drv);
168194

169195
#if IS_USED(MODULE_TOUCH_DEV)
@@ -208,5 +234,6 @@ void lvgl_run(void)
208234
void lvgl_wakeup(void)
209235
{
210236
thread_t *tcb = thread_get(_task_thread_pid);
237+
211238
thread_flags_set(tcb, LVGL_THREAD_FLAG);
212239
}

pkg/lvgl/include/lv_conf.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ extern "C" {
3030
*====================*/
3131

3232
/* Color depth:
33-
* - 1: 1 byte per pixel
33+
* - 1: 1 bit per pixel
3434
* - 8: RGB233
3535
* - 16: RGB565
3636
* - 32: ARGB8888
3737
*/
3838
#ifndef LV_COLOR_DEPTH
39-
#define LV_COLOR_DEPTH 16
39+
# if IS_USED(MODULE_U8G2_DISP_DEV)
40+
# define LV_COLOR_DEPTH 1
41+
# else
42+
# define LV_COLOR_DEPTH 16
43+
# endif
4044
#endif
4145

4246
/* Swap the 2 bytes of RGB565 color.

sys/auto_init/screen/auto_init_lvgl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ void auto_init_lvgl(void)
5050
/* Only a single screen is supported by lvgl */
5151
#if !IS_USED(MODULE_LV_DRIVERS_SDL)
5252
disp_dev_reg_t *disp_dev = disp_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT);
53+
if (disp_dev == NULL) {
54+
puts("[auto_init_screen] error: no display device found\n");
55+
return;
56+
}
5357
s_screen.display = disp_dev->dev;
5458
#endif
5559

0 commit comments

Comments
 (0)