Skip to content

Commit 1dae523

Browse files
pkg/lvgl: allow monochrome displays
1 parent d4e18fb commit 1dae523

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ extern "C" {
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.

0 commit comments

Comments
 (0)