mcufriend 2.8 tft 0139

Oops. The inverted colours were due to me setting reg(0x07) without REV bit.

The good news is that the screen will scroll. Here is an amended sketch that should give correct colours.
And tries to scroll different areas of the screen.

#include <Adafruit_GFX.h> // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup(void);
void loop(void);

uint16_t ID;

void setup(void)
{
    ID = tft.readID();
    tft.begin(ID);
    tft.setRotation(0);
    tft.setTextColor(BLACK);
    tft.setTextSize(2);
    switch (ID) {
        case 0x0139:
            break;
        case 0x0154:
            break;
        // 9320 style controllers
        case 0x1505:
        case 0xB505:
        case 0xC505:
        case 0x1580:
        case 0x6809:
        case 0x5408:
        case 0x7783:
        case 0x8230:
        case 0x9320:
        case 0x9325:
        case 0x9328:
            break;
        default:
            tft.fillScreen(MAGENTA);
            tft.println("Not Supported");
            while (1) ;
            break;
    }
}

void base_screen(char *msg)
{
    partial(1, 0, 0, 319);
    partial(2, 0, 0, 319);
    show_partial(0);    //BASEE
    tft.fillScreen(GREEN);
    tft.fillRect(0, 48, 240, 16, RED);
    tft.fillRect(0, 240, 240, 64, BLUE);
    tft.setCursor(0, 0);
    for (int line = 1; line <= 15; line++) {
        if (line < 10) tft.print("0");
        tft.print(line);
        tft.println((line == 4) ? ": IMAGE 1" : ":");
    }
    tft.println("PARTIAL 2 fixed here");
    tft.print("ID = 0x");
    tft.println(ID, HEX);
    tft.println(msg);
}

void partial(int n, int pos, int SA, int EA)
{
    if (ID == 0x7783) pos -= SA;
    switch (n) {
        case 1:
            switch (ID) {
                case 0x0139:
                    tft.WriteCmdData(0x43, SA);           //2
                    tft.WriteCmdData(0x42, EA);        //317
                    break;
                case 0x0154:
                    tft.WriteCmdData(0x35, SA);           //2
                    tft.WriteCmdData(0x34, EA);        //317
                    break;
                default:                       //9320 style
                    tft.WriteCmdData(0x80, pos);
                    tft.WriteCmdData(0x81, SA);           //2
                    tft.WriteCmdData(0x82, EA);        //317
                    break;
            }
        case 2:
            switch (ID) {
                case 0x0139:
                    tft.WriteCmdData(0x45, SA);           //2
                    tft.WriteCmdData(0x44, EA);        //317
                    break;
                case 0x0154:
                    // nuffink.  only one Partial
                    break;
                default:                       //9320 style
                    tft.WriteCmdData(0x83, pos);
                    tft.WriteCmdData(0x84, SA);           //2
                    tft.WriteCmdData(0x85, EA);        //317
                    break;
            }
    }
}

void show_partial(int mode)
{
    switch (ID) {
        case 0x0139:
            mode = (mode & 2) ? 0x0100 : 0;   //SPT
            tft.WriteCmdData(0x07, mode | 0x0037); //REV
            break;
        case 0x0154:
            break;
        default:                       //9320 style
            if (mode == 0) mode = 0x0100; //BASEE
            else mode = mode << 12;   //PTDEn
            tft.WriteCmdData(0x07, mode | 0x0033); //PTDE0=1, PTDE1=1
            break;
    }
    delay(1000);   //handy pause
}

void scroll_0139_band(int top, int bot)
{
    int siz = bot - top + 1;
    partial(1, 0, top, bot);
    for (int VL = 1; VL < siz; VL++) {
        tft.WriteCmdData(0x41, VL);
        delay(20);
    }
    delay(1000);
}

void scroll_0139(void)
{
    tft.WriteCmdData(0x07, 0x0237); //VLE1=1, REV
    //base_screen() resets partial registers to 0, 319
    base_screen("Vertical Scroll\nWhole Screen");
    scroll_0139_band(0, 319);
    base_screen("Vertical Scroll\nUpper Screen");
    scroll_0139_band(0, 239);
    base_screen("Vertical Scroll\nMiddle Screen");
    scroll_0139_band(80, 239);
    base_screen("Vertical Scroll\nBottom Screen");
    scroll_0139_band(240, 319);
    tft.WriteCmdData(0x41, 0);      //VL = 0
    tft.WriteCmdData(0x07, 0x0037); //VLE1=0, REV
}

void loop(void)
{
    base_screen("Move IMAGE from GRAM");
    partial(1, 0x80, 0x30, 0x3F);
    partial(2, 240, 240, 303);
    show_partial(1);    //Partial 1
    show_partial(3);    //Bofe
    for (int pos = 0x80; pos < 224; pos++) {
        partial(1, pos, 0x30, 0x3F);
        partial(2, 240, 240, 303);
        delay(50);
    }
    //    show_partial(3);    //Bofe
    delay(1000);
    base_screen("Move GRAM to Screen");
    show_partial(3);    //Bofe
    for (int SA = 0x80; SA < 224; SA++) {
        partial(1, 0x30, SA, SA + 15);
        partial(2, 240, 240, 303);
        delay(50);
    }
    delay(1000);
    if (ID == 0x0139) scroll_0139();
    else {
        base_screen("Vertical Scroll");
        for (int VL = 1; VL <= 320; VL++) {
            tft.vertScroll(0, 320, VL);
            delay(20);
        }
    }
    delay(1000);
}

Yesterday was the the hottest April day in England since 1949. And it might be even hotter today.

David.

Lucky you. Hope to see some hot time in here. This spring it's about 10 deg bellow normal but it looks promessing for next week.

The new sketch corrected the colors but seems to have disabled the scrools...

The colours are as expected.

All of the Verical Scroll tests fail.
I will need to think about this.

I have been at a funeral this afternoon. I need to sober up.

David.

My sympathy to you.

P.S. :

Fixed the scrolls problem by moving back the "tft.WriteCmdData(0x07, 0x0237); //VLE1=1, REV" line inside the scroll_0139_band function.

Please show the working scroll_0139_band() function.

Did you get different Band scrolling?
Or just the whole screen?

David.

Here : mcufriend 0x0139 v9 - YouTube

Thanks for the video. The scroll is not a proper Band scroll. It simply scrolls the whole screen with a Partial window.

Partial Screens are fairly useless feature of most TFT controllers.
The ILI9320 style supports two Partial windows that you can move around the screen.
ST7781 has two Partial Windows in theory but does not work properly.
ST7781 hardware actually has Vertical Scroll but it is broken. Hence no mention in the datasheet.
S6D0139 has two Partial Windows but no ability to move around the screen.

Most MIPI controllers e.g. ILI9341 have a single Partial screen but no ability to move around the screen

I have amended test_0139 on GitHub. Please try the regular graphictest_kbv example.
You should see whole screen scroll. The "Band scroll" should move the whole screen too. i.e. like a ILI9320

David.

Whole screen scroll works, band scroll works on software scroll if I saw it correctly.

No, I messed up the scan lines. Did you not notice the white band in the vertical scroll?

I have restored my initial NL code. Merged the S6D0139 changes into the master Branch (beta). Removed the test_0139 Branch.

The changes will be in the forthcoming Release. You will need to enable the SUPPORT_0139 macro in the Release.

David.

Yes I saw the white line but I didn't know if it was expected of not.

Thanks a lot for all the hard work you've put into this. It's really appreciated :slight_smile:

Francois