Go Down

Topic: 2 and more duplicated screen on 2.4 LCD TFT Arduino Uno Shield (Read 1 time) previous topic - next topic

david_prentice

Ok,  my guess was wrong.  Please try d[1] = 0x88  and then try 0x00

Please be patient.   I do not even know which make it is.

David.

DesironnA


DesironnA


david_prentice

Here is a diagnostic sketch:

It will show a big WHITE letter F with the default power-up registers.

It will then cycle through the argument bytes, flipping one bit at a time.
These will show a RED letter F with the specific argument byte.

Watch the display.   Take notes with pencil and paper.
e.g. does the RED display look exactly like the WHITE display for every argument ?
e.g. does the RED F turn BLUE ?
e.g. do you get a single F or two F ?
e.g. does the F get mirrored vertically?
e.g. does the F get mirrored horizontally?

Write down the argument value that gets a single F


Code: [Select]

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

uint16_t ID;

uint8_t d7[] = { 0x20, 0x80, 0x31, 0x80 };  //mystery
uint8_t b6[] = { 0x0A, 0x82, 0x27, 0x80 };  //ILI9341
uint8_t c0[] = { 0x0A };     //R61520

#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()
{
    ID = tft.readID();
    ID = 0x9327;     //force ID for mystery controller
    tft.begin(ID);
}

void printhex(uint8_t c)
{
    if (c < 0x10) tft.print("0");
    tft.print(c, HEX);
}

void showreg(uint8_t reg, uint8_t d[], uint8_t n, uint8_t idx, uint16_t color)
{
    tft.fillScreen(BLACK);
    tft.setTextColor(color, BLACK);
    tft.setTextSize(10);
    tft.setCursor(0, 0);
    tft.print("F");
    tft.setTextSize(2);
    tft.print(" ID = 0x");
    printhex(ID >> 8);
    printhex(ID & 0xFF);
    tft.pushCommand(reg, d, n);
    tft.setCursor(0, 100);
    tft.println("reg: args ...");
    printhex(reg);
    tft.print(":");
    for (uint8_t i = 0; i < n; i++) {
        tft.setTextColor(color, BLACK);
        tft.print(" ");
        if (i == idx) tft.setTextColor(BLACK, WHITE);
        printhex(d[i]);
    }
    delay(5000);
}

void flipreg(uint8_t reg, uint8_t args[], uint8_t n, uint8_t idx)
{
    uint8_t d[6];
    memcpy(d, args, n);
    showreg(reg, d, n, idx, WHITE);
    for (uint8_t mask = 0x80; mask; mask >>= 1) {
        d[idx] = args[idx];    //default
        d[idx] ^= mask;
        showreg(reg, d, n, idx, RED);
    }
    d[idx] = args[idx];    //default
    showreg(reg, d, n, idx, WHITE);
}

void loop()
{
    switch (ID) {
        case 0x9341:
            flipreg(0xB6, b6, sizeof(b6), 0);
            flipreg(0xB6, b6, sizeof(b6), 1);
            flipreg(0xB6, b6, sizeof(b6), 3);
            break;
        case 0x1520:
        case 0x1526:
            flipreg(0xC0, c0, sizeof(c0), 0);
            break;
        case 0x9327:                    //forced for mystery controller
            flipreg(0xD7, d7, sizeof(d7), 0);
            flipreg(0xD7, d7, sizeof(d7), 1);
            flipreg(0xD7, d7, sizeof(d7), 3);
            break;
        default:
            tft.println("not supported");
            delay(1000);
            break;
    }
}


David.

DesironnA

Quote
e.g. does the RED display look exactly like the WHITE display for every argument ?
YES
Quote
e.g. does the RED F turn BLUE ?
NO
Quote
e.g. do you get a single F or two F ?
Two F
Quote
e.g. does the F get mirrored vertically?
NO
Quote
e.g. does the F get mirrored horizontally?
NO
Quote
Write down the argument value that gets a single F
all F are two (if i undrestand what you mean)

ps: the only colors are red and white
white    20  80  31  80
red        A0  80  31  80
red        60  80  31  80
red        00  80  31  80
red        30  80  31  80
red        28  80  31  80
red        24  80  31  80
red        22  80  31  80
red        21  80  31  80
white   20  80  31  80
white   20  80  31  80
red        20  00  31  80
red        20  C0  31  80
red        20  A0  31  80
red        20  90  31  80
red        20  88  31  80
red        20  84  31  80
red        20  82  31  80
red        20  81  31  80
white    20  80  31  80
white    20  80  31  80
red         20  80  31  00
red         20  80  31  C0
red         20  80  31  A0
red         20  80  31  90
red         20  80  31  88
red         20  80  31  84
red         20  80  31  82
red         20  80  31  81
white    20  80  31  80
   

david_prentice

Quote
Quote
e.g. does the RED display look exactly like the WHITE display for every argument ?
YES
Unfortunately this means that the registers are "command protected".
You have to unlock them before you can make any alterations.

There are various protection schemes and unlock procedures:
1.  write 0x00 to reg(0xB0) ------------ which is the most common method
2.  write 0x3F to reg(0cB0) ------------ only used by Renesas R61526 as far as I know
3.  write a magic value to a special register.  e.g. write 0x8357 to reg(0xB9) for a HX8357-D

tft.begin(0x1520) and tft.begin(0x9327) already use the first method.
We can try method (2) but method (3) is almost impossible without knowing the make.

Please edit setup() in the sketch that I posted:
Code: [Select]

void setup()
{
    ID = tft.readID();
    ID = 0x1520;     //force ID for mystery controller
    tft.begin(ID);
    uint8_t unlock = 0x00;
    tft.pushCommand(0xD0, &unlock, 1);  //guess that 0xD0 is the protection register
//    unlock = 0x3F; tft.pushCommand(0xB0, &unlock, 1);  //perhaps it is R61626 style
}


If there is no change between White F and Red F with this "unlock",  please uncomment the next line.    If no change,  just say so.    There is no need to report all the values.

As a last resort,  you can try this sketch.    Copy-Paste the Serial Terminal to your message.
Code: [Select]

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
//#include <ILI9341_kbv.h>
//ILI9341_kbv tft;
uint8_t running;

uint16_t ID;
uint8_t read_xx = 0;     //first read is a dummy
uint8_t verbose = 0;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define GREY    0x7BEF

void setup(void)
{
    Serial.begin(9600);
    tft.reset();
    ID = tft.readID();
    Serial.print("TFT ID = 0x");
    //    Serial.println(tft.readReg(0xA1, 1), HEX);
    Serial.println(ID, HEX);
    ID = 0x1520;      //force 0x1520
    tft.begin(ID);
    tft.fillScreen(RED);
}

void printhex(uint8_t val)
{
    if (val < 0x10) Serial.print("0");
    Serial.print(val, HEX);
}

void printhex16(uint16_t val)
{
    printhex(val >> 8);
    printhex(val);
}

void hexdump(uint16_t loc, uint8_t *block, int16_t n)
{
    int16_t cnt;
    char buf[20], ascbuf[25], *p, wid = 24;
    bool xx = read_xx;
    while (n > 0) {
        printhex(loc >> 8);
        printhex(loc);
        Serial.print(":");
        p = ascbuf;
        cnt = n;
        if (cnt > wid) cnt = wid;
        loc += cnt;
        n -= cnt;
        while (cnt--) {
            uint8_t c = *block++;
            *p++ = (c >= ' ' && c < 128) ? c : '.';
            Serial.print(" ");
            if (xx) {
                Serial.print("xx");
                xx = false;
            }
            else printhex(c);
        }
        *p = 0;
        /*
                Serial.print(" *");
                Serial.print(ascbuf);
                Serial.println("*");
        */
    }
}

void readRegs(uint8_t cmd, uint8_t *buf, uint8_t sz)
{
    int8_t i = 0;
    uint16_t arg16;
    do {
        arg16 = tft.readReg(cmd, i >> 1);  //we read in pairs
        *buf++ = arg16 >> 8;
        *buf++ = arg16;
        i += 2;
    } while (i < sz);
}

#define SZ 24
uint8_t zero[SZ];
void diagnose_fk(void)
{
    uint8_t args[2], sz, len, unlock = 0;
    uint16_t val16, arg16;
    uint8_t actual[SZ], flipped[SZ], result[SZ], active[SZ];
    bool equal;
    // write to a register: 12 34 56
    // reads back as      : xx 12 34 56 i.e. DUMMY byte
    // write to a register: 12 34 56
    // reads back as      : 12 34 56 i.e. IMMEDIATE
    // if we read a register as: AA
    // flipping the bits gives : 55
    // read-only bits unchanged: AA
    // we can identify RMW bits: 55
    // and see which bitmask   : FF
    read_xx = 1;     //most controllers read as: xx 12 34
    if (ID == 0x1526) unlock = 0x3F;
    for (uint8_t cmd = 0x00; cmd < 0xFF; cmd++) {
        if (ID == 0) read_xx = (cmd > 0x20 && cmd < 0x40);
        sz = SZ;
        tft.reset();
        if (ID == 0x1520 || ID == 0x1526) tft.pushCommand(0xB0, &unlock, 1);
        readRegs(cmd, actual, sz);
        for (int i = 0; i < sz; i++)
            flipped[i] = actual[i] ^ 0xFF;
        tft.pushCommand(cmd, flipped + read_xx, sz - read_xx);
        readRegs(cmd, result, sz);
        equal = memcmp(result, actual + read_xx, sz - read_xx) == 0;
        tft.pushCommand(cmd, actual + read_xx, sz - read_xx);
        if (equal && memcmp(result, zero, sz) == 0) {
            continue;
        }
        len = 0;
        for (int i = 0; i < sz; i++) {
            active[i] = actual[i] ^ result[i];
        }
        uint8_t last = actual[sz - 1];
        uint8_t mask = active[sz - 1];
        for (len = sz - 1; len > 1 + read_xx; --len) {
            if (actual[len - 2] != last || active[len - 2] != mask)
                break;
        }
        if (last == 0 && mask == 0) len--;
        Serial.print("\norg ");
        sz = len;
        hexdump(cmd, actual, sz);
        if (verbose) {
            Serial.print("\n~   ");
            hexdump(cmd, flipped, sz);
            Serial.print("\n=   ");
            hexdump(cmd, result, sz);
            Serial.print("\n^   ");
            hexdump(cmd, active, sz);
        }
        Serial.print(" [" + String(len - read_xx) + "]");
        if (equal || memcmp(active + read_xx, zero, sz - read_xx) == 0) {
            Serial.print(" read only");
        }
    }
    Serial.println("");
}


void loop()
{
    diagnose_fk();     //just diagnose
//    renesas_test();    //
    while (1);         //stop forever
}


David.

DesironnA

Quote
There are various protection schemes and unlock procedures:
1.  write 0x00 to reg(0xB0) ------------ which is the most common method
2.  write 0x3F to reg(0cB0) ------------ only used by Renesas R61526 as far as I know
3.  write a magic value to a special register.  e.g. write 0x8357 to reg(0xB9) for a HX8357-D

tft.begin(0x1520) and tft.begin(0x9327) already use the first method.
We can try method (2) but method (3) is almost impossible without knowing the make.
Sorry i don't undrestand. where i should write these ?

david_prentice

Edit the sketch that I posted in #18.
Replace the setup() function with the setup() that I posted in #20.

DesironnA

I did it. no change.
Quote
If there is no change between White F and Red F with this "unlock",  please uncomment the next line.
screen is dark
Quote
As a last resort,  you can try this sketch.    Copy-Paste the Serial Terminal to your message.
Serial Monitor :
Code: [Select]
.

TFT ID = 0x0

org 0009: xx 00 71 [2] read only
org 000A: xx 08 [1] read only
org 000C: xx 77 [1] read only
org 002E: xx [0] read only
org 00B0: xx 00 00 00 00 00 00 00 [7]
org 00C6: xx 03 [1]
org 00D6: xx 00 80 B2 [3] read only
org 00D7: xx 20 80 31 80 [4] read only
org 00D8: xx 00 2A 0C 80 [4] read only
org 00D9: xx 07 00 00 [3]
org 00E0: xx 00 [1]
org 00E1: xx 00 00 [2]
org 00F0: xx 04 [1]
org 00F1: xx 04 [1]
org 00F2: xx 16 16 03 08 08 08 08 10 00 16 16 [11]
org 00F3: xx 80 2A 2A 01 22 00 00 2C [8]
org 00F4: xx 00 00 00 00 44 [5]
org 00F5: xx 10 00 03 F0 00 1F [6]
org 00F6: xx 00 80 10 10 [4]
org 00F7: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00F8: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00F9: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FA: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FB: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FC: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FD: xx 11 00 35 [3]


david_prentice

#24
Sep 29, 2017, 04:16 pm Last Edit: Sep 30, 2017, 12:26 pm by david_prentice
Ok,  more guesswork:

Code: [Select]

void setup()
{
    ID = tft.readID();
    ID = 0x1520;     //force ID for mystery controller
    tft.begin(ID);
    ID = 0x9327;     //THIS IS A NEW STATEMENT
    uint8_t unlock = 0x00;
    tft.pushCommand(0xC6, &unlock, 1);  //guess that 0xC6 is the protection register
//    tft.pushCommand(0xD0, &unlock, 1);  //guess that 0xD0 is the protection register - NO
//    tft.pushCommand(0xF0, &unlock, 1);  //guess that 0xF0 is the protection register
//    unlock = 0x3F; tft.pushCommand(0xB0, &unlock, 1);  //perhaps it is R61626 style
//    unlock = 0x3F; tft.pushCommand(0xE0, &unlock, 1);  //perhaps it is R61626 style
}


Please try all these pushCommand() statements.  One at a time.
You just have to add two slashes // to disable a statement i.e. makes it a comment
And remove the two slashes to enable a statement

This is all quite technical.   You must be a very clever 11-year old.

David.

DesironnA

I did it. and then i uploaded previous diagnostic codes. but same result in serial monitor.

You must be a very clever 11-year old.

If I was clever, I had solved my problem.

david_prentice

Oops.    The setup() that I posted in #24 would have done the wrong tests.    I have edited #24 to correct it,

Please can you try this again.   I am sure that one of those push commands will unlock the device.

David.

DesironnA

Same result :(
Code: [Select]
TFT ID = 0x0

org 0009: xx 00 71 [2] read only
org 000A: xx 08 [1] read only
org 000C: xx 77 [1] read only
org 002E: xx [0] read only
org 00B0: xx 00 00 00 00 00 00 00 [7]
org 00C6: xx 03 [1]
org 00D6: xx 00 80 B2 [3] read only
org 00D7: xx 20 80 31 80 [4] read only
org 00D8: xx 00 2A 0C 80 [4] read only
org 00D9: xx 07 00 00 [3]
org 00E0: xx 00 [1]
org 00E1: xx 00 00 [2]
org 00F0: xx 04 [1]
org 00F1: xx 04 [1]
org 00F2: xx 16 16 03 08 08 08 08 10 00 16 16 [11]
org 00F3: xx 80 2A 2A 01 22 00 00 2C [8]
org 00F4: xx 00 00 00 00 44 [5]
org 00F5: xx 10 00 03 F0 00 1F [6]
org 00F6: xx 00 80 10 10 [4]
org 00F7: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00F8: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00F9: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FA: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FB: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FC: xx 06 03 04 0A 10 1A 22 2C 13 12 1D 11 02 22 22 [15]
org 00FD: xx 11 00 35 [3]


Maybe it's unlockable.

david_prentice

The setup() in #24 should replace the setup() in the sketch that I posted in #18.

If you have no luck with editing,   I will post a complete sketch that does everything automatically.
I will also log to the Serial. 

David.

DesironnA

I did it. and everytime i tried one of those lines, i got two F all in white and red color.

Go Up