What LVGL version are you using?
9.1.0
What do you want to achieve?
I’m totally new in ESP32 and CYD, as well I have basic knowledge of C++. I start with example project that I just doing LVGL demo widgets and start to adopt it for my needs. However, I realised that colors are inverted. It is pretty common problem. However, my code looks little bit different comparing to answers in other topics. So I confused.
What have you tried so far?
I tryied to apply different flags in lv_conf.h
#define CONFIG_LV_INVERT_COLORS 1
#define TFT_INVERSION_ON
#define LV_COLOR_16_SWAP 0
None of them helps.
Next I found the remmendation to run tft.invertDisplay(1);
after tft.init();
but my code looks like operate with highlevel wrapper, so I was not able to implement that.
Next, I have found the recommendation to run lv_draw_sw_rgb565_swap()
it in the flush_cb
. And implement it - no luck, however not sure if that was implemented correctly.
Code to reproduce
Here is some parts of my code. Setup of TFT.
#include <lvgl.h>
#include <lv_conf.h>
#include <TFT_eSPI.h>
#include <misc/lv_color.h>
#include <XPT2046_Touchscreen.h>
// Standard Libraries
// ----------------------------
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <StreamUtils.h>
#include <string>
#include <sstream>
#include <iomanip>
...
lv_indev_t * indev; //Touchscreen input device
uint8_t* draw_buf; //draw_buf is allocated on heap otherwise the static area is too big on ESP32 at compile
void setup()
{
//Some basic info on the Serial console
String LVGL_Arduino = "LVGL demo ";
LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
Serial.begin(115200);
Serial.println(LVGL_Arduino);
//Initialise the touchscreen
touchscreenSpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); /* Start second SPI bus for touchscreen */
touchscreen.begin(touchscreenSpi); /* Touchscreen init */
touchscreen.setRotation(3); /* Inverted landscape orientation to match screen */
//Initialise LVGL
lv_init();
draw_buf = new uint8_t[DRAW_BUF_SIZE];
lv_display_t * disp;
disp = lv_tft_espi_create(TFT_HOR_RES, TFT_VER_RES, draw_buf, DRAW_BUF_SIZE);
//Initialize the XPT2046 input device driver
indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, my_touchpad_read);
//Done
Serial.println( "Setup done" );
}
void loop()
{
lv_tick_inc(millis() - lastTick); //Update the tick timer. Tick is new for LVGL 9
lastTick = millis();
lv_timer_handler(); //Update the UI
delay(5);
}
/* LVGL calls it when a rendered image needs to copied to the display*/
void my_disp_flush( lv_display_t *disp, const lv_area_t *area, uint8_t * px_map)
{
/*Call it to tell LVGL you are ready*/
Serial.println("Flush");
lv_draw_sw_rgb565_swap(draw_buf, DRAW_BUF_SIZE);
lv_disp_flush_ready(disp);
}
As far as I understand I should place lv_draw_sw_rgb565_swap
in my_disp_flush function, which should automaticly called by LVGL as flush function (however, I do not see any binding of that function to LVGL code). But It does not helped. I put simple debug output in that function and there is no ouput as well. So looks like that function is not been called at all. So how could I invert colors in such code?