M2M Hacks

The Adafruit 2.8" TFT display for 7783 LCD Driver Setting

M2M Hacks 2022. 7. 30. 17:55

# Adafruit_TFTLCD.cpp 

 

1.Insert  7783 Driver Register Setting Variable [Adafruit_TFTLCD.cpp]

//new for SWIFT Display
static const uint16_t ST7781_regValues[] PROGMEM = {
    0x0001,0x0100,    
    0x0002,0x0700,    
    0x0003,0x1030,    
    0x0008,0x0302,    
    0x0009,0x0000,   
    0x000A,0x0008,    
    //*******POWER CONTROL REGISTER INITIAL*******//    
    0x0010,0x0790,    
    0x0011,0x0005,    
    0x0012,0x0000,   
    0x0013,0x0000,    
     //delayms(50, 
    //********POWER SUPPPLY STARTUP 1 SETTING*******//    
    0x0010,0x12B0,    
    // delayms(50,  
    0x0011,0x0007,    
     //delayms(50,  
    //********POWER SUPPLY STARTUP 2 SETTING******//    
    0x0012,0x008C,    
    0x0013,0x1700,    
    0x0029,0x0022,    
    // delayms(50,   
    //******GAMMA CLUSTER SETTING******//    
    0x0030,0x0000,    
    0x0031,0x0505,    
    0x0032,0x0205,    
    0x0035,0x0206,    
    0x0036,0x0408,    
    0x0037,0x0000,    
    0x0038,0x0504,
    0x0039,0x0206,    
    0x003C,0x0206,    
    0x003D,0x0408,    
    // -----------DISPLAY WINDOWS 240*320-------------//    
    0x0050,0x0000,
    0x0051,0x00EF,   
    0x0052,0x0000,   
    0x0053,0x013F,   
    //-----FRAME RATE SETTING-------//    
    0x0060,0xA700,   
    0x0061,0x0001,   
    0x0090,0x0033, //RTNI setting
    //-------DISPLAY ON------//    
    0x0007,0x0133,    0x0001,0x0100,    
     0x0002,0x0700,    
    0x0003,0x1030,    
    0x0008,0x0302,    
    0x0009,0x0000,   
    0x000A,0x0008,    
    //*******POWER CONTROL REGISTER INITIAL*******//    
    0x0010,0x0790,    
    0x0011,0x0005,    
    0x0012,0x0000,   
    0x0013,0x0000,    
     //delayms(50, 
    //********POWER SUPPPLY STARTUP 1 SETTING*******//    
    0x0010,0x12B0,    
    // delayms(50,  
    0x0011,0x0007,    
    // delayms(50,  
    //********POWER SUPPLY STARTUP 2 SETTING******//    
    0x0012,0x008C,    
    0x0013,0x1700,    
    0x0029,0x0022,    
    // delayms(50,   
    //******GAMMA CLUSTER SETTING******//    
    0x0030,0x0000,    
    0x0031,0x0505,    
    0x0032,0x0205,    
    0x0035,0x0206,    
    0x0036,0x0408,    
    0x0037,0x0000,    
    0x0038,0x0504,
    0x0039,0x0206,    
    0x003C,0x0206,    
    0x003D,0x0408,    
    // -----------DISPLAY WINDOWS 240*320-------------//    
    0x0050,0x0000,
    0x0051,0x00EF,   
    0x0052,0x0000,   
    0x0053,0x013F,   
    //-----FRAME RATE SETTING-------//    
    0x0060,0xA700,   
    0x0061,0x0001,   
    0x0090,0x0033, //RTNI setting
    //-------DISPLAY ON------//    
    0x0007,0x0133,   
};

 

2.Modify Adafruit_TFTLCD::begin(uint16_t id) Function [Adafruit_TFTLCD.cpp]

void Adafruit_TFTLCD::begin(uint16_t id) {
  uint8_t i = 0;

  reset();

  delay(200);

  if ((id == 0x9325) || (id == 0x9328)) {

    uint16_t a, d;
    driver = ID_932X;
    CS_ACTIVE;
    while (i < sizeof(ILI932x_regValues) / sizeof(uint16_t)) {
      a = pgm_read_word(&ILI932x_regValues[i++]);
      d = pgm_read_word(&ILI932x_regValues[i++]);
      if (a == TFTLCD_DELAY)
        delay(d);
      else
        writeRegister16(a, d);
    }
    setRotation(rotation);
    setAddrWindow(0, 0, TFTWIDTH - 1, TFTHEIGHT - 1);

  } else if (id == 0x9341) {

    driver = ID_9341;
    CS_ACTIVE;
    writeRegister8(ILI9341_SOFTRESET, 0);
    delay(50);
    writeRegister8(ILI9341_DISPLAYOFF, 0);

    writeRegister8(ILI9341_POWERCONTROL1, 0x23);
    writeRegister8(ILI9341_POWERCONTROL2, 0x10);
    writeRegister16(ILI9341_VCOMCONTROL1, 0x2B2B);
    writeRegister8(ILI9341_VCOMCONTROL2, 0xC0);
    writeRegister8(ILI9341_MEMCONTROL, ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR);
    writeRegister8(ILI9341_PIXELFORMAT, 0x55);
    writeRegister16(ILI9341_FRAMECONTROL, 0x001B);

    writeRegister8(ILI9341_ENTRYMODE, 0x07);
    /* writeRegister32(ILI9341_DISPLAYFUNC, 0x0A822700);*/

    writeRegister8(ILI9341_SLEEPOUT, 0);
    delay(150);
    writeRegister8(ILI9341_DISPLAYON, 0);
    delay(500);
    setAddrWindow(0, 0, TFTWIDTH - 1, TFTHEIGHT - 1);
    return;

  } else if (id == 0x8357) {
    // HX8357D
    driver = ID_HX8357D;
    CS_ACTIVE;
    while (i < sizeof(HX8357D_regValues)) {
      uint8_t r = pgm_read_byte(&HX8357D_regValues[i++]);
      uint8_t len = pgm_read_byte(&HX8357D_regValues[i++]);
      if (r == TFTLCD_DELAY) {
        delay(len);
      } else {
        // Serial.print("Register $"); Serial.print(r, HEX);
        // Serial.print(" datalen "); Serial.println(len);

        CS_ACTIVE;
        CD_COMMAND;
        write8(r);
        CD_DATA;
        for (uint8_t d = 0; d < len; d++) {
          uint8_t x = pgm_read_byte(&HX8357D_regValues[i++]);
          write8(x);
        }
        CS_IDLE;
      }
    }
    return;

  } else if (id == 0x7575) {

    uint8_t a, d;
    driver = ID_7575;
    CS_ACTIVE;
    while (i < sizeof(HX8347G_regValues)) {
      a = pgm_read_byte(&HX8347G_regValues[i++]);
      d = pgm_read_byte(&HX8347G_regValues[i++]);
      if (a == TFTLCD_DELAY)
        delay(d);
      else
        writeRegister8(a, d);
    }
    setRotation(rotation);
    setLR(); // Lower-right corner of address window

  } else if (id == 0x7783 ){ //new for SWITCH Display
      uint16_t a, d;
      driver = ID_932X;
    CS_ACTIVE;
    while(i < sizeof(ST7781_regValues) / sizeof(uint16_t)) {
      a = pgm_read_word(&ST7781_regValues[i++]);
      d = pgm_read_word(&ST7781_regValues[i++]);
      if(a == TFTLCD_DELAY) delay(d);
      else                  writeRegister16(a, d);
    }
    setRotation(rotation);
    setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1);

  } else {
    driver = ID_UNKNOWN;
    return;
  }
}

 3. Modify Identifier Code [graphictest.ino]

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());

  tft.reset();

  uint16_t identifier = tft.readID();

  if (identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if (identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if (identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if (identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if (identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if (identifier == 0x7783) {
    Serial.println(F("Found 7783 LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    return;
  }

  tft.begin(identifier);

  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

  Serial.print(F("Lines                    "));
  Serial.println(testLines(CYAN));
  delay(500);

  Serial.print(F("Horiz/Vert Lines         "));
  Serial.println(testFastLines(RED, BLUE));
  delay(500);

  Serial.print(F("Rectangles (outline)     "));
  Serial.println(testRects(GREEN));
  delay(500);

  Serial.print(F("Rectangles (filled)      "));
  Serial.println(testFilledRects(YELLOW, MAGENTA));
  delay(500);

  Serial.print(F("Circles (filled)         "));
  Serial.println(testFilledCircles(10, MAGENTA));

  Serial.print(F("Circles (outline)        "));
  Serial.println(testCircles(10, WHITE));
  delay(500);

  Serial.print(F("Triangles (outline)      "));
  Serial.println(testTriangles());
  delay(500);

  Serial.print(F("Triangles (filled)       "));
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print(F("Rounded rects (outline)  "));
  Serial.println(testRoundRects());
  delay(500);

  Serial.print(F("Rounded rects (filled)   "));
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println(F("Done!"));
}