Closed BbIKTOP closed 5 years ago
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.
Sure, but what about a driver for it? I suppose it would help people like me, who bought this screen
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;
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
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.
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
Really gotta get setup offsets in the library heh this is going to get hairy
Relates to Issue #1 in the Xinyuan-LilyGO/TTGO-T-Display repo.
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;
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.
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.