From 588b14f02925ea432a0425dfce0064a9db628c28 Mon Sep 17 00:00:00 2001 From: martinberlin Date: Sun, 13 Jun 2021 15:18:48 +0200 Subject: [PATCH] Leave buf_copy_to_framebuffer as the default method and Gabor method as secondary --- lvgl_tft/epdiy_epaper.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lvgl_tft/epdiy_epaper.cpp b/lvgl_tft/epdiy_epaper.cpp index 569781c..898889b 100644 --- a/lvgl_tft/epdiy_epaper.cpp +++ b/lvgl_tft/epdiy_epaper.cpp @@ -12,8 +12,8 @@ uint8_t temperature = 25; bool init = true; // MODE_DU: Fast monochrome | MODE_GC16 slow with 16 grayscales enum EpdDrawMode updateMode = MODE_DU; - -#define BUF_MAX 111600 +// Ideally this BUF should be width/2*height = 259200. Now set to 111600 +#define BUF_MAX 110400 /* Display initialization routine */ void epdiy_init(void) @@ -26,6 +26,18 @@ void epdiy_init(void) epd_fullclear(&hl, temperature); } +/* Suggested by @kisvegabor https://forum.lvgl.io/t/lvgl-port-to-be-used-with-epaper-displays/5630/26 */ +void buf_area_to_framebuffer(const lv_area_t *area, const uint8_t *image_data) { + assert(framebuffer != NULL); + uint8_t *fb_ptr = &framebuffer[area->y1 * EPD_WIDTH / 2 + area->x1 / 2]; + lv_coord_t img_w = lv_area_get_width(area); + for(uint32_t y = area->y1; y < area->y2; y++) { + memcpy(fb_ptr, image_data, img_w / 2); + fb_ptr += EPD_WIDTH / 2; + image_data += img_w / 2; + } +} + /* A copy from epd_copy_to_framebuffer with temporary lenght prediction */ void buf_copy_to_framebuffer(EpdRect image_area, const uint8_t *image_data) { assert(framebuffer != NULL); @@ -34,10 +46,10 @@ void buf_copy_to_framebuffer(EpdRect image_area, const uint8_t *image_data) { // Get out if we get the end of the buffer. Question: How to detect the end without a lenght? // Zero terminator check gets out before: (image_data[value_index / 2]== '\0') // 111684 seems to be the last element in image_data - if (i / 2 > BUF_MAX) { + /* if (i / 2 > BUF_MAX) { printf("FOUND END incr:%d Aw:%d Ah:%d\n", i, image_area.width, image_area.height); break; - } + } */ uint8_t val = (i % 2) ? (image_data[i / 2] & 0xF0) >> 4 : image_data[i / 2] & 0x0F; int xx = image_area.x + i % image_area.width; @@ -81,6 +93,9 @@ void epdiy_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_ma // Does not work for full screen update yet (Should check large of buf) buf_copy_to_framebuffer(update_area, buf); + //Faster mode suggested in LVGL forum (Leaves ghosting) + //buf_area_to_framebuffer(area, buf); + epd_hl_update_area(&hl, updateMode, temperature, update_area); //update_area printf("epdiy_flush %d x:%d y:%d w:%d h:%d\n", flushcalls,(uint16_t)area->x1,(uint16_t)area->y1,w,h); @@ -89,8 +104,7 @@ void epdiy_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_ma } /* - * Called for each pixel. Designed with the idea to fill the buffer directly, not to set each pixel, see: - * https://forum.lvgl.io/t/lvgl-port-to-be-used-with-epaper-displays/5630/3 + * Called for each pixel. Designed with the idea to fill the buffer directly, not to set each pixel, see LVGL Forum (buf_area_to_framebuffer) */ void epdiy_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t* buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,