ESP32S3 - ST7796 - LovyanGFX, wrong color with the same code, different number of pixels

Hi, I asked this issue to LovyanGFX github too. The issue is that it shows 2 different colors with the same code, just different number of pixel.

Environment

  • MCU or Board name: ESP32-S3-N16R8
  • Panel Driver IC: ST7796 - 320x480
  • Bus type: Parallel8
  • LovyanGFX version: 1.2.7
  • FrameWork version: framework-arduinoespressif32 @ 3.20017.0 (2.0.17)
  • Build Environment: PlatformIO - Core 6.1.18 - Home 3.4.4
  • Operating System: Windows

Problem Description

This is the minimal block of code that describes my issue.
I draw 2 lines with different number of pixels (1st line has 131 pixels and 2nd line has 130 pixels), the same color code, and the lcd shows 2 lines with different colors.

Expected Behavior

It should show 2 lines with the same color

Actual Behavior

It shows different colors with the same code.

Steps to reproduce

  1. I prepare a uint16_t array which is filled with TFT_RED color code.
  2. I use setAddrWindow w = 131, h = 1 (one line), pushPixels with len = 131, the lcd shows a BLUE line
  3. I use setAddrWindow w = 130, h = 1 (one line), pushPixels with len = 130, the lcd shows a RED line
  4. I draw a 50x50 red square to check the color, it shows correct red square

Code to reproduce this issue

#include <Arduino.h>
#include <LovyanGFX.hpp>

// Create a display class
class LGFX : public lgfx::LGFX_Device
{
  lgfx::Panel_ST7796 _panel_instance;  // Change this to your LCD driver
  lgfx::Bus_Parallel8 _bus_instance;   // Parallel 8-bit bus

public:
  LGFX(void)
  {
    {
      auto cfg = _bus_instance.config();
      cfg.freq_write = 4000000;   // 4MHz
      cfg.pin_wr = 12;            // WR pin
      cfg.pin_rd = 11;            // No read pin
      cfg.pin_rs = 7;             // RS (D/C) pin

      // Data bus pins (D0 - D7)
      cfg.pin_d0 = 14;
      cfg.pin_d1 = 13;
      cfg.pin_d2 = 10;
      cfg.pin_d3 = 9;
      cfg.pin_d4 = 3;
      cfg.pin_d5 = 4;
      cfg.pin_d6 = 2;
      cfg.pin_d7 = 1;

      _bus_instance.config(cfg);
      _panel_instance.setBus(&_bus_instance);
    }

    { // Configure display panel
      auto cfg = _panel_instance.config();
      cfg.pin_cs = 5;    // No CS pin required for parallel mode
      cfg.pin_rst = 6;    // Reset pin
      cfg.invert = false;  // Set `true` if colors are inverted
      cfg.rgb_order = false; // RGB or BGR order
      cfg.dlen_16bit = false; // Use 8-bit mode
      cfg.bus_shared = false; // Parallel bus is not shared

      _panel_instance.config(cfg);
    }

    setPanel(&_panel_instance);
  }
};

LGFX _tft;
uint16_t *pBitmap = nullptr;

void setup()
{
  Serial.begin(115200);

  /* Enable LCD */
  pinMode(48, OUTPUT); digitalWrite(48, HIGH);

  /* Init LCD */
  _tft.init();
  _tft.fillScreen(TFT_BLACK);

  /* Prepare data */
  int32_t PIXELS_NUM = 150;
  pBitmap = (uint16_t *)calloc(PIXELS_NUM, sizeof(uint16_t));
  for (int i = 0; i < PIXELS_NUM; i++) {
    pBitmap[i] = TFT_RED;
  }

  /* Draw one line */
  _tft.setAddrWindow(0, 0, 131, 1 /* ONE line */);
  _tft.pushPixels((const uint16_t *)pBitmap, 131);
  // delay(1000); // No difference with or without delay

  /* Draw another line */
  _tft.setAddrWindow(0, 10, 130, 1 /* ONE line */);
  _tft.pushPixels((const uint16_t *)pBitmap, 130);

  /* Draw a red square */
  _tft.fillRect(0, 20, 50, 50, TFT_RED);
}

void loop()
{}

Move the horizontal lines down one pixel. My guess is R will be B and maybe vice-versa... and if the horizontal lines are moved two pixels down, R will be G (recalling old RGB picture tubes and early big-screen "t.v."s.

Try drawing the lines through different color boxes. Does bleeding or color change occur?

Does the same issue occur with a different TFT or different library?

Hi, thank you for your reply. This is just the minamal code that reproduce the issue which is a part of my big project. The issue happens in any position. It's not the R,G,B order issue as I can draw any color by fillRect with x = 0, y = 0 correctly

Any color has the same issue as long as I use different number of pixels (not only TFT_RED as described in the example code). Currently I found number of pixels 130 & 131 can reproduce my issue. However, in my big project, there are some other number of pixels can cause the issue too.

This issue only happens in LovyanGFX. The TFT_eSPI library is working very well with the same drawing code.