From 9445dab325c0b3559ae6816e8c12c4ab5b9b221a Mon Sep 17 00:00:00 2001 From: martinberlin Date: Sat, 26 Aug 2023 12:23:37 +0200 Subject: [PATCH] epdiy V7 made a bit faster --- lvgl_helpers.h | 2 +- lvgl_tft/epdiy_epaper.c | 9 ++++ lvgl_tft/epdiy_epaper.cpp | 24 ++++------ lvgl_tft/epdiy_epaper_v1.cpp | 92 ------------------------------------ 4 files changed, 19 insertions(+), 108 deletions(-) delete mode 100644 lvgl_tft/epdiy_epaper_v1.cpp diff --git a/lvgl_helpers.h b/lvgl_helpers.h index db76c70..ad66cd7 100644 --- a/lvgl_helpers.h +++ b/lvgl_helpers.h @@ -42,7 +42,7 @@ extern "C" { #define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40) #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S #define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX/3) -// IMPORTANT: This will render the screen in 8 times (Max more and it skips lines) +// IMPORTANT: This will render the screen in 8 times (more and it skips lines, supposedly limited by PSRAM speed) #elif defined (CONFIG_LV_EPAPER_EPDIY_DISPLAY_CONTROLLER) #define DISP_BUF_SIZE LV_HOR_RES_MAX*(LV_VER_RES_MAX/ 8) diff --git a/lvgl_tft/epdiy_epaper.c b/lvgl_tft/epdiy_epaper.c index 784096a..e532a79 100644 --- a/lvgl_tft/epdiy_epaper.c +++ b/lvgl_tft/epdiy_epaper.c @@ -1,3 +1,12 @@ +/************************************************************************************************** + * NOTE: This file is the first version that writes directly on the set_px callback + * each pixel into the epaper display buffer. The second version is epdiy_epaper.cpp + * It writes *buf and then it comes as *color_map on the flush callback. + * Feel free to experiment with this 2. epdiy_epaper.cpp works better to make a small UX + * + * BOTH are oriented to latest version of epdiy driver that uses LCD module for parallel communication + * BRANCH: s3_lcd + **************************************************************************************************/ #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/lvgl_tft/epdiy_epaper.cpp b/lvgl_tft/epdiy_epaper.cpp index 9fb3ef7..30aecd6 100644 --- a/lvgl_tft/epdiy_epaper.cpp +++ b/lvgl_tft/epdiy_epaper.cpp @@ -3,7 +3,6 @@ #include "freertos/task.h" #include "epdiy_epaper.h" #include "epdiy.h" -//#include "epd_highlevel.h" EpdiyHighlevelState hl; uint16_t flushcalls = 0; @@ -21,17 +20,16 @@ void epdiy_init(void) // This will print an error if unsupported. In this case, // set VCOM using the hardware potentiometer and delete this line. epd_set_vcom(1760); - - // Only for older versions epdiy - //epd_init(EPD_OPTIONS_DEFAULT); hl = epd_hl_init(EPD_BUILTIN_WAVEFORM); framebuffer = epd_hl_get_framebuffer(&hl); epd_poweron(); - //Clear all always in init: + //Clear all display in initialization to remove any ghosts epd_fullclear(&hl, temperature); } -/* Suggested by @kisvegabor https://forum.lvgl.io/t/lvgl-port-to-be-used-with-epaper-displays/5630/26 */ +/* Suggested by @kisvegabor https://forum.lvgl.io/t/lvgl-port-to-be-used-with-epaper-displays/5630/26 + * @deprecated +*/ 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]; @@ -48,8 +46,7 @@ void buf_copy_to_framebuffer(EpdRect image_area, const uint8_t *image_data) { assert(framebuffer != NULL); for (uint32_t i = 0; i < image_area.width * image_area.height; i++) { - uint8_t val = (i % 2) ? (image_data[i / 2] & 0xF0) >> 4 - : image_data[i / 2] & 0x0F; + 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; if (xx < 0 || xx >= epd_width()) { continue; @@ -83,17 +80,14 @@ void epdiy_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_ma uint8_t* buf = (uint8_t *) color_map; // Buffer debug - /* - for (int index=0; index<400; index++) { + /* for (int index=0; index<400; index++) { printf("%x ", buf[index]); } */ - - // UNCOMMENT only one of this options - // SAFE Option with EPDiy copy of epd_copy_to_framebuffer - buf_copy_to_framebuffer(update_area, buf); + // This is the slower version that works good without leaving any white line + //buf_copy_to_framebuffer(update_area, buf); //Faster mode suggested in LVGL forum (Leaves ghosting&prints bad sections / experimental) NOTE: Do NOT use in production - //buf_area_to_framebuffer(area, buf); + buf_area_to_framebuffer(area, buf); epd_hl_update_area(&hl, updateMode, temperature, update_area); //update_area diff --git a/lvgl_tft/epdiy_epaper_v1.cpp b/lvgl_tft/epdiy_epaper_v1.cpp deleted file mode 100644 index 38cd948..0000000 --- a/lvgl_tft/epdiy_epaper_v1.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "esp_log.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" - -#include "epdiy_epaper.h" - -#include "epd_driver.h" -#include "epd_highlevel.h" - -/************************************************************************************************** - * NOTE: This file iis the first version that writes directly on the set_px callback - * each pixel into the epaper display buffer. The second version is not epdiy_epaper.cpp - * It writes *buf and then it comes as *color_map on the flush callback. - * Feel free to experiment with this 2. epdiy_epaper.cpp works better to make a small UX - **************************************************************************************************/ -#define TAG "EPDIY" -EpdiyHighlevelState hl; -uint16_t flushcalls = 0; -uint8_t * framebuffer; -uint8_t temperature = 25; - -/* Display initialization routine */ -void epdiy_init(void) -{ - epd_init(EPD_OPTIONS_DEFAULT); - hl = epd_hl_init(EPD_BUILTIN_WAVEFORM); - framebuffer = epd_hl_get_framebuffer(&hl); - epd_poweron(); - //Clear all always in init? - //epd_fullclear(&hl, temperature); -} - -uint16_t xo = 0; -uint16_t yo = 0; - -/* Required by LVGL */ -void epdiy_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) -{ - ++flushcalls; - xo = area->x1; - yo = area->y1; - uint16_t w = lv_area_get_width(area); - uint16_t h = lv_area_get_height(area); - - EpdRect update_area = { - .x = xo, - .y = yo, - .width = w, - .height = h, - }; - - epd_hl_update_area(&hl, MODE_GC16, temperature, update_area); //update_area - - printf("epdiy_flush %d x:%d y:%d w:%d h:%d\n", flushcalls,xo,yo,w,h); - /* Inform the graphics library that you are ready with the flushing */ - lv_disp_flush_ready(drv); -} - -/* - * 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 -*/ -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, - lv_color_t color, lv_opa_t opa) -{ - // Debug where x y is printed, not all otherwise is too much Serial - /* if ((int16_t)y%10==0 && flushcalls>0){ - if ((int16_t)x%2==0){ - printf("x%d y%d\n", (int16_t)x, (int16_t)y); - } - } - */ - - // Test using RGB232 - int16_t epd_color = 255; - if ((int16_t)color.full<250) { - epd_color = (int16_t)color.full/3; - } - - int16_t x1 = (int16_t)x; - int16_t y1 = (int16_t)y; - - //Instead of using epd_draw_pixel: Set pixel directly in buffer - //epd_draw_pixel(x1, y1, epd_color, framebuffer); - uint8_t *buf_ptr = &framebuffer[y1 * buf_w / 2 + x1 / 2]; - if (x % 2) { - *buf_ptr = (*buf_ptr & 0x0F) | (epd_color & 0xF0); - } else { - *buf_ptr = (*buf_ptr & 0xF0) | (epd_color >> 4); - } -}