Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - support for ST7789 1.14" 135x240 TFT #379

Closed
BbIKTOP opened this issue Jun 14, 2019 · 11 comments
Closed

Feature request - support for ST7789 1.14" 135x240 TFT #379

BbIKTOP opened this issue Jun 14, 2019 · 11 comments

Comments

@BbIKTOP
Copy link

BbIKTOP commented Jun 14, 2019

There's a lot of 135x240 TFT screens available on ebay and aliexpress. They do work with ST7789 driver, except they have different colstart and rowstart values. It's colstart = 52 and rowstart = 40 for rotation 0 and so on accordingly. Is it possible to add support for such a displays? Currently I have modified standard headers changing ST7789_Rotation.h but it will be nice probably to move it to the dedicated driver. It's good that width and height can be changed via #define but these offsets cannot, as far as I understand the code.
Thank you.

$ diff ST7789_135_Rotation.h ST7789_Rotation.h
8,9c8,9
<       colstart = 52;
<       rowstart = 40;
---
>       colstart = 0;
>       rowstart = 0;
19,20c19,20
<       colstart = 40;
<       rowstart = 52;
---
>       colstart = 0;
>       rowstart = 0;
30,31c30,31
<        colstart = 52;
<        rowstart = 40;
---
>        colstart = 0;
>        rowstart = 80;
40,41c40,41
<       colstart = 40;
<       rowstart = 52;
---
>       colstart = 80;
>       rowstart = 0;
@Bodmer
Copy link
Owner

Bodmer commented Jun 18, 2019

Adding configurable offsets is on my to do list but it may be quite a while before I can find time to make and test the changes.

@BbIKTOP
Copy link
Author

BbIKTOP commented Jul 7, 2019

Sure, but what about a driver for it? I suppose it would help people like me, who bought this screen

@Bodmer
Copy link
Owner

Bodmer commented Jul 7, 2019

I do not have one of those displays to test the offsets. I suspect that the offsets in the list you gave are not correct, in two places 52 should be 53. This is because 52+135+53 = 240. You can check by drawing rectangles in the periphery pixels (135x240 and 240x135) for each rotation and seeing if a row is missing.

I suspect the correct offsets are:
Rotation 0
colstart = 52;
rowstart = 40;
Rotation 1
colstart = 40;
rowstart = 53;
Rotation 2
colstart = 53;
rowstart = 40;
Rotation 3
colstart = 40;
rowstart = 52;

@BbIKTOP
Copy link
Author

BbIKTOP commented Jul 8, 2019

Yes, you're absolutely right. This one is correct, checked it with drawrectangle:

switch (rotation) {
    case 0: // Portrait
#ifdef CGRAM_OFFSET
      colstart = 52;
      rowstart = 40;
#endif
      writedata(TFT_MAD_COLOR_ORDER);

      _width  = _init_width;
      _height = _init_height;
      break;

    case 1: // Landscape (Portrait + 90)
#ifdef CGRAM_OFFSET
      colstart = 40;
      rowstart = 53;
#endif
      writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);

      _width  = _init_height;
      _height = _init_width;
      break;

      case 2: // Inverter portrait
#ifdef CGRAM_OFFSET
       colstart = 53;
       rowstart = 40;
#endif
      writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);

      _width  = _init_width;
      _height = _init_height;
       break;
    case 3: // Inverted landscape
#ifdef CGRAM_OFFSET
      colstart = 40;
      rowstart = 52;
#endif
      writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);

      _width  = _init_height;
      _height = _init_width;
      break;
  }

test loop:

void loop()
{
  static int rotation = 0;

  tft.setRotation(rotation);
  tft.fillScreen(TFT_BLACK);
  if (rotation % 2)
  {
    tft.drawRect(0, 0, 240, 135, TFT_WHITE);
  }
  else
  {
    tft.drawRect(0, 0, 135, 240, TFT_WHITE);
  }
  tft.setCursor(5, 5);
  tft.println("Rotation " + String(rotation));
  Serial.println("Rotation " + String(rotation));
  if (++rotation > 3)
    rotation = 0;
  delay(5000);
}

Observed result - white border around screen on all its sides

@Bodmer
Copy link
Owner

Bodmer commented Jul 8, 2019

OK, this is helpful info. I can create a driver set for you but this wil be a temporary solution as eventually the library will allow offsets to be defined for each rotation in the setup. Due to work commitments it will be a few days before I have time to create the driver for you to test.

@BbIKTOP
Copy link
Author

BbIKTOP commented Jul 9, 2019

Thank you. Just in case - I made a working driver, not sure is it correct, but it works on all examples you included as well as with some I made myself. Here's an archive that also contains a small video confirming everything works fine https://tut.etogo.net/in/tft_espi.135x240.st7789v.tgz
And a little remark - of course it's for me as well, but not only - the display is quite good and cheap, you can look it up on aliexpress with "135x240 lcd" search query, there are some. So, I suppose this driver will be useful, maybe even more than configurable offsets, because there's no need to test and configure anything, just to include and use the driver

@tablatronix
Copy link
Contributor

Really gotta get setup offsets in the library heh this is going to get hairy

@TotallyInformation
Copy link

Relates to Issue #1 in the Xinyuan-LilyGO/TTGO-T-Display repo.

@tablatronix
Copy link
Contributor

fyi

lewisxhe@d594f67

@tablatronix
Copy link
Contributor

tablatronix commented Jul 30, 2019

Hmm I can confirm this works, but I cannot seem to get the display to rotate..

EDIT:
oh nm, the code above is missing rotation = m % 4;

Bodmer added a commit that referenced this issue Jul 31, 2019
Added support for ST7789 135 x 240 display which needs offsets
Added Setup135_ST7789.h as an example setup file for ESP8266
@Bodmer
Copy link
Owner

Bodmer commented Jul 31, 2019

I have made some changes and added a new user setup file "Setup135_ST7789.h" that shows how to define the required setup.

Let me know if this works OK for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants