Skip to content

Commit e2c22a4

Browse files
Merge pull request #496 from 100312dog/fix/esp_lvgl_port
Fix/esp lvgl port ()
2 parents dddc990 + 62c7ed1 commit e2c22a4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,15 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
251251
ESP_RETURN_ON_FALSE(disp_cfg->color_format == 0 || disp_cfg->color_format == LV_COLOR_FORMAT_RGB565 || disp_cfg->color_format == LV_COLOR_FORMAT_RGB888 || disp_cfg->color_format == LV_COLOR_FORMAT_XRGB8888 || disp_cfg->color_format == LV_COLOR_FORMAT_ARGB8888 || disp_cfg->color_format == LV_COLOR_FORMAT_I1, NULL, TAG, "Not supported display color format!");
252252

253253
lv_color_format_t display_color_format = (disp_cfg->color_format != 0 ? disp_cfg->color_format : LV_COLOR_FORMAT_RGB565);
254+
uint8_t color_bytes = lv_color_format_get_size(display_color_format);
254255
if (disp_cfg->flags.swap_bytes) {
255256
/* Swap bytes can be used only in RGB565 color format */
256257
ESP_RETURN_ON_FALSE(display_color_format == LV_COLOR_FORMAT_RGB565, NULL, TAG, "Swap bytes can be used only in display color format RGB565!");
257258
}
258259

259260
if (disp_cfg->flags.buff_dma) {
260261
/* DMA buffer can be used only in RGB565 color format */
261-
ESP_RETURN_ON_FALSE(display_color_format == LV_COLOR_FORMAT_RGB565, NULL, TAG, "DMA buffer can be used only in display color format RGB565 (not alligned copy)!");
262+
ESP_RETURN_ON_FALSE(display_color_format == LV_COLOR_FORMAT_RGB565, NULL, TAG, "DMA buffer can be used only in display color format RGB565 (not aligned copy)!");
262263
}
263264

264265
/* Display context */
@@ -307,10 +308,10 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
307308
} else {
308309
/* alloc draw buffers used by LVGL */
309310
/* it's recommended to choose the size of the draw buffer(s) to be at least 1/10 screen sized */
310-
buf1 = heap_caps_malloc(buffer_size * sizeof(lv_color_t), buff_caps);
311+
buf1 = heap_caps_malloc(buffer_size * color_bytes, buff_caps);
311312
ESP_GOTO_ON_FALSE(buf1, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for LVGL buffer (buf1) allocation!");
312313
if (disp_cfg->double_buffer) {
313-
buf2 = heap_caps_malloc(buffer_size * sizeof(lv_color_t), buff_caps);
314+
buf2 = heap_caps_malloc(buffer_size * color_bytes, buff_caps);
314315
ESP_GOTO_ON_FALSE(buf2, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for LVGL buffer (buf2) allocation!");
315316
}
316317

@@ -336,7 +337,7 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
336337
ESP_GOTO_ON_FALSE((disp_cfg->hres * disp_cfg->vres == buffer_size), ESP_ERR_INVALID_ARG, err, TAG, "Monochromatic display must using full buffer!");
337338

338339
disp_ctx->flags.monochrome = 1;
339-
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_FULL);
340+
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_FULL);
340341

341342
if (display_color_format == LV_COLOR_FORMAT_I1) {
342343
/* OLED monochrome buffer */
@@ -350,15 +351,15 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
350351
ESP_GOTO_ON_FALSE((disp_cfg->hres * disp_cfg->vres == buffer_size), ESP_ERR_INVALID_ARG, err, TAG, "Direct mode must using full buffer!");
351352

352353
disp_ctx->flags.direct_mode = 1;
353-
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_DIRECT);
354+
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_DIRECT);
354355
} else if (disp_cfg->flags.full_refresh) {
355356
/* When using full_refresh, there must be used full bufer! */
356357
ESP_GOTO_ON_FALSE((disp_cfg->hres * disp_cfg->vres == buffer_size), ESP_ERR_INVALID_ARG, err, TAG, "Full refresh must using full buffer!");
357358

358359
disp_ctx->flags.full_refresh = 1;
359-
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_FULL);
360+
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_FULL);
360361
} else {
361-
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_PARTIAL);
362+
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_PARTIAL);
362363
}
363364

364365
lv_display_set_flush_cb(disp, lvgl_port_flush_callback);
@@ -371,7 +372,7 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
371372

372373
/* Use SW rotation */
373374
if (disp_cfg->flags.sw_rotate) {
374-
disp_ctx->draw_buffs[2] = heap_caps_malloc(buffer_size * sizeof(lv_color_t), buff_caps);
375+
disp_ctx->draw_buffs[2] = heap_caps_malloc(buffer_size * color_bytes, buff_caps);
375376
ESP_GOTO_ON_FALSE(disp_ctx->draw_buffs[2], ESP_ERR_NO_MEM, err, TAG, "Not enough memory for LVGL buffer (rotation buffer) allocation!");
376377
}
377378

0 commit comments

Comments
 (0)