|
39 | 39 | #endif |
40 | 40 |
|
41 | 41 | #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 |
43 | 47 | #endif |
44 | 48 |
|
45 | 49 | #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) |
134 | 138 | } |
135 | 139 | #endif |
136 | 140 |
|
| 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 | + |
137 | 158 | void lvgl_init(screen_dev_t *screen_dev) |
138 | 159 | { |
139 | 160 | lv_init(); |
@@ -164,6 +185,11 @@ void lvgl_init(screen_dev_t *screen_dev) |
164 | 185 | disp_drv.ver_res = disp_dev_height(screen_dev->display); |
165 | 186 | #endif |
166 | 187 |
|
| 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 | + |
167 | 193 | lv_disp_drv_register(&disp_drv); |
168 | 194 |
|
169 | 195 | #if IS_USED(MODULE_TOUCH_DEV) |
@@ -208,5 +234,6 @@ void lvgl_run(void) |
208 | 234 | void lvgl_wakeup(void) |
209 | 235 | { |
210 | 236 | thread_t *tcb = thread_get(_task_thread_pid); |
| 237 | + |
211 | 238 | thread_flags_set(tcb, LVGL_THREAD_FLAG); |
212 | 239 | } |
0 commit comments