From 7d0f7fe3db66eb4af36780eab63df22f6b4c863e Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Sun, 25 Apr 2021 08:24:07 +0200 Subject: [PATCH] lvgl monochrome support --- lib/lib_display/UDisplay/uDisplay.cpp | 34 +++++++++++++++++++ lib/lib_display/UDisplay/uDisplay.h | 4 +++ .../Adafruit_LvGL_Glue.cpp | 21 +++++++++--- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/lib/lib_display/UDisplay/uDisplay.cpp b/lib/lib_display/UDisplay/uDisplay.cpp index 9a9a3c5fb..73f993e48 100755 --- a/lib/lib_display/UDisplay/uDisplay.cpp +++ b/lib/lib_display/UDisplay/uDisplay.cpp @@ -924,6 +924,19 @@ void uDisplay::Splash(void) { void uDisplay::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { + if (bpp != 16) { + // just save params or update frame + if (!x0 && !y0 && !x1 && !y1) { + Updateframe(); + } else { + seta_xp1 = x0; + seta_xp2 = x1; + seta_yp1 = y0; + seta_yp2 = y1; + } + return; + } + if (!x0 && !y0 && !x1 && !y1) { SPI_CS_HIGH SPI_END_TRANSACTION @@ -984,9 +997,30 @@ void uDisplay::setAddrWindow_int(uint16_t x, uint16_t y, uint16_t w, uint16_t h) } +static inline uint8_t ulv_color_to1(uint16_t color) { + if (((color>>11) & 0x10) || ((color>>5) & 0x20) || (color & 0x10)) { + return 1; + } + else { + return 0; + } +} void uDisplay::pushColors(uint16_t *data, uint16_t len, boolean first) { uint16_t color; + if (bpp != 16) { + // stupid monchrome version + for (uint32_t y = seta_yp1; y < seta_yp2; y++) { + for (uint32_t x = seta_xp1; x < seta_xp2; x++) { + uint16_t color = *data++; + drawPixel(x, y, ulv_color_to1(color)); + len--; + if (!len) return; + } + } + return; + } + while (len--) { color = *data++; WriteColor(color); diff --git a/lib/lib_display/UDisplay/uDisplay.h b/lib/lib_display/UDisplay/uDisplay.h index bb54d948c..33ccec74e 100755 --- a/lib/lib_display/UDisplay/uDisplay.h +++ b/lib/lib_display/UDisplay/uDisplay.h @@ -205,6 +205,10 @@ class uDisplay : public Renderer { uint8_t lut_array[LUTMAXSIZE][5]; uint8_t lut_cnt[5]; uint8_t lut_cmd[5]; + uint16_t seta_xp1; + uint16_t seta_xp2; + uint16_t seta_yp1; + uint16_t seta_yp2; }; diff --git a/lib/libesp32_lvgl/Adafruit_LvGL_Glue-shadinger/Adafruit_LvGL_Glue.cpp b/lib/libesp32_lvgl/Adafruit_LvGL_Glue-shadinger/Adafruit_LvGL_Glue.cpp index cbe6b5e1c..758f80db3 100644 --- a/lib/libesp32_lvgl/Adafruit_LvGL_Glue-shadinger/Adafruit_LvGL_Glue.cpp +++ b/lib/libesp32_lvgl/Adafruit_LvGL_Glue-shadinger/Adafruit_LvGL_Glue.cpp @@ -23,6 +23,7 @@ static void lv_tick_handler(void) { lv_tick_inc(lv_tick_interval_ms); } #define ADC_YMAX 840 + uint32_t Touch_Status(uint32_t sel); static bool touchscreen_read(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data) { @@ -76,10 +77,10 @@ static void lv_flush_callback(lv_disp_drv_t *disp, const lv_area_t *area, lv_col Renderer *display = glue->display; if (!glue->first_frame) { - //display->dmaWait(); // Wait for prior DMA transfer to complete - //display->endWrite(); // End transaction from any prior call + //display->dmaWait(); // Wait for prior DMA transfer to complete + //display->endWrite(); // End transaction from any prior call } else { - glue->first_frame = false; + glue->first_frame = false; } display->setAddrWindow(area->x1, area->y1, area->x1+width, area->y1+height); @@ -87,6 +88,7 @@ static void lv_flush_callback(lv_disp_drv_t *disp, const lv_area_t *area, lv_col display->setAddrWindow(0,0,0,0); lv_disp_flush_ready(disp); + } #if (LV_USE_LOG) @@ -104,6 +106,7 @@ static void lv_debug(lv_log_level_t level, const char *file, uint32_t line, cons } #endif + // GLUE LIB FUNCTIONS ------------------------------------------------------ // Constructor @@ -198,6 +201,8 @@ LvGLStatus Adafruit_LvGL_Glue::begin(Renderer *tft, bool debug) { LvGLStatus Adafruit_LvGL_Glue::begin(Renderer *tft, void *touch, bool debug) { + + lv_init(); // #if (LV_USE_LOG) // if (debug) { @@ -208,7 +213,13 @@ LvGLStatus Adafruit_LvGL_Glue::begin(Renderer *tft, void *touch, bool debug) { // Allocate LvGL display buffer (x2 because DMA double buffering) LvGLStatus status = LVGL_ERR_ALLOC; // if ((lv_pixel_buf = new lv_color_t[LV_HOR_RES_MAX * LV_BUFFER_ROWS * 2])) { - if ((lv_pixel_buf = new lv_color_t[LV_HOR_RES_MAX * LV_BUFFER_ROWS])) { + + uint32_t lvgl_buffer_size; + //lvgl_buffer_size = LV_HOR_RES_MAX * LV_BUFFER_ROWS; + lvgl_buffer_size = tft->width() * LV_BUFFER_ROWS; + + + if ((lv_pixel_buf = new lv_color_t[lvgl_buffer_size])) { display = tft; touchscreen = (void *)touch; @@ -223,7 +234,7 @@ LvGLStatus Adafruit_LvGL_Glue::begin(Renderer *tft, void *touch, bool debug) { lv_disp_buf_init( &lv_disp_buf, lv_pixel_buf, // 1st half buf nullptr, // 2nd half buf - LV_HOR_RES_MAX * LV_BUFFER_ROWS); + lvgl_buffer_size); // Initialize LvGL display driver lv_disp_drv_init(&lv_disp_drv);