@@ -251,14 +251,15 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
251
251
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!" );
252
252
253
253
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 );
254
255
if (disp_cfg -> flags .swap_bytes ) {
255
256
/* Swap bytes can be used only in RGB565 color format */
256
257
ESP_RETURN_ON_FALSE (display_color_format == LV_COLOR_FORMAT_RGB565 , NULL , TAG , "Swap bytes can be used only in display color format RGB565!" );
257
258
}
258
259
259
260
if (disp_cfg -> flags .buff_dma ) {
260
261
/* 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)!" );
262
263
}
263
264
264
265
/* Display context */
@@ -307,10 +308,10 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
307
308
} else {
308
309
/* alloc draw buffers used by LVGL */
309
310
/* 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 );
311
312
ESP_GOTO_ON_FALSE (buf1 , ESP_ERR_NO_MEM , err , TAG , "Not enough memory for LVGL buffer (buf1) allocation!" );
312
313
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 );
314
315
ESP_GOTO_ON_FALSE (buf2 , ESP_ERR_NO_MEM , err , TAG , "Not enough memory for LVGL buffer (buf2) allocation!" );
315
316
}
316
317
@@ -336,7 +337,7 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
336
337
ESP_GOTO_ON_FALSE ((disp_cfg -> hres * disp_cfg -> vres == buffer_size ), ESP_ERR_INVALID_ARG , err , TAG , "Monochromatic display must using full buffer!" );
337
338
338
339
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 );
340
341
341
342
if (display_color_format == LV_COLOR_FORMAT_I1 ) {
342
343
/* OLED monochrome buffer */
@@ -350,15 +351,15 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
350
351
ESP_GOTO_ON_FALSE ((disp_cfg -> hres * disp_cfg -> vres == buffer_size ), ESP_ERR_INVALID_ARG , err , TAG , "Direct mode must using full buffer!" );
351
352
352
353
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 );
354
355
} else if (disp_cfg -> flags .full_refresh ) {
355
356
/* When using full_refresh, there must be used full bufer! */
356
357
ESP_GOTO_ON_FALSE ((disp_cfg -> hres * disp_cfg -> vres == buffer_size ), ESP_ERR_INVALID_ARG , err , TAG , "Full refresh must using full buffer!" );
357
358
358
359
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 );
360
361
} 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 );
362
363
}
363
364
364
365
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
371
372
372
373
/* Use SW rotation */
373
374
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 );
375
376
ESP_GOTO_ON_FALSE (disp_ctx -> draw_buffs [2 ], ESP_ERR_NO_MEM , err , TAG , "Not enough memory for LVGL buffer (rotation buffer) allocation!" );
376
377
}
377
378
0 commit comments