From 328a69052fdd50ece5d7155dd2a5b5e0324dba48 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 10 Feb 2019 16:54:44 +0100 Subject: [PATCH 1/9] Added 0x7783 device support --- Adafruit_TFTLCD.cpp | 103 +++++++ README.txt | 10 + examples/graphicstest/graphicstest.pde | 385 ------------------------- examples/rotationtest/rotationtest.pde | 223 -------------- examples/tftbmp/tftbmp.pde | 248 ---------------- examples/tftpaint/tftpaint.ino | 2 + 6 files changed, 115 insertions(+), 856 deletions(-) delete mode 100755 examples/graphicstest/graphicstest.pde delete mode 100644 examples/rotationtest/rotationtest.pde delete mode 100755 examples/tftbmp/tftbmp.pde diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index ee7693f..5db1af2 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -171,6 +171,97 @@ static const uint8_t HX8347G_regValues[] PROGMEM = { 0x08 , 0x01, 0x09 , 0x3F }; +//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, +}; + static const uint8_t HX8357D_regValues[] PROGMEM = { HX8357_SWRESET, 0, @@ -268,6 +359,18 @@ void Adafruit_TFTLCD::begin(uint16_t id) { } setRotation(rotation); setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1); + } 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 if (id == 0x9341) { diff --git a/README.txt b/README.txt index 85e3032..a705b37 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,13 @@ +# Fork working with 0x7783 LCD devices + +Added the hardware specific values from the SWIFT driver by Smoke And Wires +This works also for some Iduino 2.8'' displays + +Now you can work with the Adafruit examples. + +This library is only for the Arduino Uno + + This is a library for the Adafruit 2.8" TFT display. This library works with the Adafruit 2.8" TFT Breakout w/SD card ----> http://www.adafruit.com/products/335 diff --git a/examples/graphicstest/graphicstest.pde b/examples/graphicstest/graphicstest.pde deleted file mode 100755 index 14701c7..0000000 --- a/examples/graphicstest/graphicstest.pde +++ /dev/null @@ -1,385 +0,0 @@ -// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY -// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. -// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. - -#include // Core graphics library -#include // Hardware-specific library - -// The control pins for the LCD can be assigned to any digital or -// analog pins...but we'll use the analog pins as this allows us to -// double up the pins with the touch screen (see the TFT paint example). -#define LCD_CS A3 // Chip Select goes to Analog 3 -#define LCD_CD A2 // Command/Data goes to Analog 2 -#define LCD_WR A1 // LCD Write goes to Analog 1 -#define LCD_RD A0 // LCD Read goes to Analog 0 - -#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin - -// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: -// For the Arduino Uno, Duemilanove, Diecimila, etc.: -// D0 connects to digital pin 8 (Notice these are -// D1 connects to digital pin 9 NOT in order!) -// D2 connects to digital pin 2 -// D3 connects to digital pin 3 -// D4 connects to digital pin 4 -// D5 connects to digital pin 5 -// D6 connects to digital pin 6 -// D7 connects to digital pin 7 -// For the Arduino Mega, use digital pins 22 through 29 -// (on the 2-row header at the end of the board). - -// 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 - -Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); -// If using the shield, all control and data lines are fixed, and -// a simpler declaration can optionally be used: -// Adafruit_TFTLCD tft; - -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 { - 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!")); -} - -void loop(void) { - for(uint8_t rotation=0; rotation<4; rotation++) { - tft.setRotation(rotation); - testText(); - delay(2000); - } -} - -unsigned long testFillScreen() { - unsigned long start = micros(); - tft.fillScreen(BLACK); - tft.fillScreen(RED); - tft.fillScreen(GREEN); - tft.fillScreen(BLUE); - tft.fillScreen(BLACK); - return micros() - start; -} - -unsigned long testText() { - tft.fillScreen(BLACK); - unsigned long start = micros(); - tft.setCursor(0, 0); - tft.setTextColor(WHITE); tft.setTextSize(1); - tft.println("Hello World!"); - tft.setTextColor(YELLOW); tft.setTextSize(2); - tft.println(1234.56); - tft.setTextColor(RED); tft.setTextSize(3); - tft.println(0xDEADBEEF, HEX); - tft.println(); - tft.setTextColor(GREEN); - tft.setTextSize(5); - tft.println("Groop"); - tft.setTextSize(2); - tft.println("I implore thee,"); - tft.setTextSize(1); - tft.println("my foonting turlingdromes."); - tft.println("And hooptiously drangle me"); - tft.println("with crinkly bindlewurdles,"); - tft.println("Or I will rend thee"); - tft.println("in the gobberwarts"); - tft.println("with my blurglecruncheon,"); - tft.println("see if I don't!"); - return micros() - start; -} - -unsigned long testLines(uint16_t color) { - unsigned long start, t; - int x1, y1, x2, y2, - w = tft.width(), - h = tft.height(); - - tft.fillScreen(BLACK); - - x1 = y1 = 0; - y2 = h - 1; - start = micros(); - for(x2=0; x20; i-=6) { - i2 = i / 2; - start = micros(); - tft.fillRect(cx-i2, cy-i2, i, i, color1); - t += micros() - start; - // Outlines are not included in timing results - tft.drawRect(cx-i2, cy-i2, i, i, color2); - } - - return t; -} - -unsigned long testFilledCircles(uint8_t radius, uint16_t color) { - unsigned long start; - int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; - - tft.fillScreen(BLACK); - start = micros(); - for(x=radius; x10; i-=5) { - start = micros(); - tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, - tft.color565(0, i, i)); - t += micros() - start; - tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, - tft.color565(i, i, 0)); - } - - return t; -} - -unsigned long testRoundRects() { - unsigned long start; - int w, i, i2, - cx = tft.width() / 2 - 1, - cy = tft.height() / 2 - 1; - - tft.fillScreen(BLACK); - w = min(tft.width(), tft.height()); - start = micros(); - for(i=0; i20; i-=6) { - i2 = i / 2; - tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); - } - - return micros() - start; -} diff --git a/examples/rotationtest/rotationtest.pde b/examples/rotationtest/rotationtest.pde deleted file mode 100644 index 7b83622..0000000 --- a/examples/rotationtest/rotationtest.pde +++ /dev/null @@ -1,223 +0,0 @@ -// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY -// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. -// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. - -#include // Core graphics library -#include // Hardware-specific library - -// The control pins for the LCD can be assigned to any digital or -// analog pins...but we'll use the analog pins as this allows us to -// double up the pins with the touch screen (see the TFT paint example). -#define LCD_CS A3 // Chip Select goes to Analog 3 -#define LCD_CD A2 // Command/Data goes to Analog 2 -#define LCD_WR A1 // LCD Write goes to Analog 1 -#define LCD_RD A0 // LCD Read goes to Analog 0 - -#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin - -// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: -// For the Arduino Uno, Duemilanove, Diecimila, etc.: -// D0 connects to digital pin 8 (Notice these are -// D1 connects to digital pin 9 NOT in order!) -// D2 connects to digital pin 2 -// D3 connects to digital pin 3 -// D4 connects to digital pin 4 -// D5 connects to digital pin 5 -// D6 connects to digital pin 6 -// D7 connects to digital pin 7 -// For the Arduino Mega, use digital pins 22 through 29 -// (on the 2-row header at the end of the board). - -// 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 - -Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); -// If using the shield, all control and data lines are fixed, and -// a simpler declaration can optionally be used: -// Adafruit_TFTLCD tft; - -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 - - 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 { - 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); - - tft.fillScreen(BLACK); - - Serial.println(F("This is a test of the rotation capabilities of the TFT library!")); - Serial.println(F("Press (or type a character) to advance")); -} - -void loop(void) { - rotatePixel(); - rotateLine(); - rotateFastline(); - rotateDrawrect(); - rotateFillrect(); - rotateDrawcircle(); - rotateFillcircle(); - rotateText(); -} - -void rotateText() { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.setCursor(0, 30); - tft.setTextColor(RED); - tft.setTextSize(1); - tft.println("Hello World!"); - tft.setTextColor(YELLOW); - tft.setTextSize(2); - tft.println("Hello World!"); - tft.setTextColor(GREEN); - tft.setTextSize(3); - tft.println("Hello World!"); - tft.setTextColor(BLUE); - tft.setTextSize(4); - tft.print(1234.567); - - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - -void rotateFillcircle(void) { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.fillCircle(10, 30, 10, YELLOW); - - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - -void rotateDrawcircle(void) { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.drawCircle(10, 30, 10, YELLOW); - - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - -void rotateFillrect(void) { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.fillRect(10, 20, 10, 20, GREEN); - - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - -void rotateDrawrect(void) { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.drawRect(10, 20, 10, 20, GREEN); - - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - -void rotateFastline(void) { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.drawFastHLine(0, 20, tft.width(), RED); - tft.drawFastVLine(20, 0, tft.height(), BLUE); - - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - -void rotateLine(void) { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, RED); - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - -void rotatePixel(void) { - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(BLACK); - Serial.println(tft.getRotation(), DEC); - - tft.drawPixel(10,20, RED); - while (!Serial.available()); - Serial.read(); Serial.read(); Serial.read(); - - tft.setRotation(tft.getRotation()+1); - } -} - diff --git a/examples/tftbmp/tftbmp.pde b/examples/tftbmp/tftbmp.pde deleted file mode 100755 index 8979ed1..0000000 --- a/examples/tftbmp/tftbmp.pde +++ /dev/null @@ -1,248 +0,0 @@ -// BMP-loading example specifically for the TFTLCD breakout board. -// If using the Arduino shield, use the tftbmp_shield.pde sketch instead! -// If using an Arduino Mega make sure to use its hardware SPI pins, OR make -// sure the SD library is configured for 'soft' SPI in the file Sd2Card.h. - -#include // Core graphics library -#include // Hardware-specific library -#include -#include - -// The control pins for the LCD can be assigned to any digital or -// analog pins...but we'll use the analog pins as this allows us to -// double up the pins with the touch screen (see the TFT paint example). -#define LCD_CS A3 // Chip Select goes to Analog 3 -#define LCD_CD A2 // Command/Data goes to Analog 2 -#define LCD_WR A1 // LCD Write goes to Analog 1 -#define LCD_RD A0 // LCD Read goes to Analog 0 - -// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: -// For the Arduino Uno, Duemilanove, Diecimila, etc.: -// D0 connects to digital pin 8 (Notice these are -// D1 connects to digital pin 9 NOT in order!) -// D2 connects to digital pin 2 -// D3 connects to digital pin 3 -// D4 connects to digital pin 4 -// D5 connects to digital pin 5 -// D6 connects to digital pin 6 -// D7 connects to digital pin 7 -// For the Arduino Mega, use digital pins 22 through 29 -// (on the 2-row header at the end of the board). - -// For Arduino Uno/Duemilanove, etc -// connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard) -// Then pin 10 goes to CS (or whatever you have set up) -#define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library) - -// In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) -// There are examples in the sketch folder - -// our TFT wiring -Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4); - -void setup() -{ - Serial.begin(9600); - - 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 { - 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.print(F("Initializing SD card...")); - if (!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - return; - } - Serial.println(F("OK!")); - - bmpDraw("woof.bmp", 0, 0); - delay(1000); -} - -void loop() -{ - for(int i = 0; i<4; i++) { - tft.setRotation(i); - tft.fillScreen(0); - for(int j=0; j <= 200; j += 50) { - bmpDraw("miniwoof.bmp", j, j); - } - delay(1000); - } -} - -// This function opens a Windows Bitmap (BMP) file and -// displays it at the given coordinates. It's sped up -// by reading many pixels worth of data at a time -// (rather than pixel by pixel). Increasing the buffer -// size takes more of the Arduino's precious RAM but -// makes loading a little faster. 20 pixels seems a -// good balance. - -#define BUFFPIXEL 20 - -void bmpDraw(char *filename, int x, int y) { - - File bmpFile; - int bmpWidth, bmpHeight; // W+H in pixels - uint8_t bmpDepth; // Bit depth (currently must be 24) - uint32_t bmpImageoffset; // Start of image data in file - uint32_t rowSize; // Not always = bmpWidth; may have padding - uint8_t sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel) - uint16_t lcdbuffer[BUFFPIXEL]; // pixel out buffer (16-bit per pixel) - uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer - boolean goodBmp = false; // Set to true on valid header parse - boolean flip = true; // BMP is stored bottom-to-top - int w, h, row, col; - uint8_t r, g, b; - uint32_t pos = 0, startTime = millis(); - uint8_t lcdidx = 0; - boolean first = true; - - if((x >= tft.width()) || (y >= tft.height())) return; - - Serial.println(); - Serial.print(F("Loading image '")); - Serial.print(filename); - Serial.println('\''); - // Open requested file on SD card - if ((bmpFile = SD.open(filename)) == NULL) { - Serial.println(F("File not found")); - return; - } - - // Parse BMP header - if(read16(bmpFile) == 0x4D42) { // BMP signature - Serial.println(F("File size: ")); Serial.println(read32(bmpFile)); - (void)read32(bmpFile); // Read & ignore creator bytes - bmpImageoffset = read32(bmpFile); // Start of image data - Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC); - // Read DIB header - Serial.print(F("Header size: ")); Serial.println(read32(bmpFile)); - bmpWidth = read32(bmpFile); - bmpHeight = read32(bmpFile); - if(read16(bmpFile) == 1) { // # planes -- must be '1' - bmpDepth = read16(bmpFile); // bits per pixel - Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth); - if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed - - goodBmp = true; // Supported BMP format -- proceed! - Serial.print(F("Image size: ")); - Serial.print(bmpWidth); - Serial.print('x'); - Serial.println(bmpHeight); - - // BMP rows are padded (if needed) to 4-byte boundary - rowSize = (bmpWidth * 3 + 3) & ~3; - - // If bmpHeight is negative, image is in top-down order. - // This is not canon but has been observed in the wild. - if(bmpHeight < 0) { - bmpHeight = -bmpHeight; - flip = false; - } - - // Crop area to be loaded - w = bmpWidth; - h = bmpHeight; - if((x+w-1) >= tft.width()) w = tft.width() - x; - if((y+h-1) >= tft.height()) h = tft.height() - y; - - // Set TFT address window to clipped image bounds - tft.setAddrWindow(x, y, x+w-1, y+h-1); - - for (row=0; row= sizeof(sdbuffer)) { // Indeed - // Push LCD buffer to the display first - if(lcdidx > 0) { - tft.pushColors(lcdbuffer, lcdidx, first); - lcdidx = 0; - first = false; - } - bmpFile.read(sdbuffer, sizeof(sdbuffer)); - buffidx = 0; // Set index to beginning - } - - // Convert pixel from BMP to TFT format - b = sdbuffer[buffidx++]; - g = sdbuffer[buffidx++]; - r = sdbuffer[buffidx++]; - lcdbuffer[lcdidx++] = tft.color565(r,g,b); - } // end pixel - } // end scanline - // Write any remaining data to LCD - if(lcdidx > 0) { - tft.pushColors(lcdbuffer, lcdidx, first); - } - Serial.print(F("Loaded in ")); - Serial.print(millis() - startTime); - Serial.println(" ms"); - } // end goodBmp - } - } - - bmpFile.close(); - if(!goodBmp) Serial.println(F("BMP format not recognized.")); -} - -// These read 16- and 32-bit types from the SD card file. -// BMP data is stored little-endian, Arduino is little-endian too. -// May need to reverse subscript order if porting elsewhere. - -uint16_t read16(File f) { - uint16_t result; - ((uint8_t *)&result)[0] = f.read(); // LSB - ((uint8_t *)&result)[1] = f.read(); // MSB - return result; -} - -uint32_t read32(File f) { - uint32_t result; - ((uint8_t *)&result)[0] = f.read(); // LSB - ((uint8_t *)&result)[1] = f.read(); - ((uint8_t *)&result)[2] = f.read(); - ((uint8_t *)&result)[3] = f.read(); // MSB - return result; -} - diff --git a/examples/tftpaint/tftpaint.ino b/examples/tftpaint/tftpaint.ino index 0380b2c..5f5b3d1 100644 --- a/examples/tftpaint/tftpaint.ino +++ b/examples/tftpaint/tftpaint.ino @@ -101,6 +101,8 @@ void setup(void) { 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); From 0a6e6f74465a59321905418299e0c9182bf70e4a Mon Sep 17 00:00:00 2001 From: AlfredoCubitos Date: Sun, 10 Feb 2019 16:58:04 +0100 Subject: [PATCH 2/9] Update README.txt --- README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.txt b/README.txt index a705b37..93d3a57 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -# Fork working with 0x7783 LCD devices +#Fork working with 0x7783 LCD devices Added the hardware specific values from the SWIFT driver by Smoke And Wires This works also for some Iduino 2.8'' displays From 5bf2aaeb6ad282ca3f9c45c8a7d6c89eefbfa2cf Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 10 Feb 2019 17:05:13 +0100 Subject: [PATCH 3/9] Readme changed --- README.txt | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 README.txt diff --git a/README.txt b/README.txt deleted file mode 100644 index a705b37..0000000 --- a/README.txt +++ /dev/null @@ -1,31 +0,0 @@ -# Fork working with 0x7783 LCD devices - -Added the hardware specific values from the SWIFT driver by Smoke And Wires -This works also for some Iduino 2.8'' displays - -Now you can work with the Adafruit examples. - -This library is only for the Arduino Uno - - -This is a library for the Adafruit 2.8" TFT display. -This library works with the Adafruit 2.8" TFT Breakout w/SD card - ----> http://www.adafruit.com/products/335 -as well as Adafruit TFT Touch Shield - ----> http://www.adafruit.com/products/376 - -Check out the links above for our tutorials and wiring diagrams. -These displays use 8-bit parallel to communicate, 12 or 13 pins are required -to interface (RST is optional). -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -MIT license, all text above must be included in any redistribution - -To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_TFTLCD. Check that the Adafruit_TFTLCD folder contains Adafruit_TFTLCD.cpp and Adafruit_TFTLCD. - -Place the Adafruit_TFT library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE - -Also requires the Adafruit_GFX library for Arduino. https://github.com/adafruit/Adafruit-GFX-Library From 44457de7103b0f684e6da5b81f5aa203ec6c8c2e Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 10 Feb 2019 17:07:21 +0100 Subject: [PATCH 4/9] Examples changed --- README.md | 31 ++ examples/graphicstest/graphicstest.ino | 387 +++++++++++++++++++++++++ examples/rotationtest/rotationtest.ino | 225 ++++++++++++++ examples/tftbmp/tftbmp.ino | 250 ++++++++++++++++ 4 files changed, 893 insertions(+) create mode 100644 README.md create mode 100755 examples/graphicstest/graphicstest.ino create mode 100644 examples/rotationtest/rotationtest.ino create mode 100755 examples/tftbmp/tftbmp.ino diff --git a/README.md b/README.md new file mode 100644 index 0000000..a705b37 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Fork working with 0x7783 LCD devices + +Added the hardware specific values from the SWIFT driver by Smoke And Wires +This works also for some Iduino 2.8'' displays + +Now you can work with the Adafruit examples. + +This library is only for the Arduino Uno + + +This is a library for the Adafruit 2.8" TFT display. +This library works with the Adafruit 2.8" TFT Breakout w/SD card + ----> http://www.adafruit.com/products/335 +as well as Adafruit TFT Touch Shield + ----> http://www.adafruit.com/products/376 + +Check out the links above for our tutorials and wiring diagrams. +These displays use 8-bit parallel to communicate, 12 or 13 pins are required +to interface (RST is optional). +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +Written by Limor Fried/Ladyada for Adafruit Industries. +MIT license, all text above must be included in any redistribution + +To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_TFTLCD. Check that the Adafruit_TFTLCD folder contains Adafruit_TFTLCD.cpp and Adafruit_TFTLCD. + +Place the Adafruit_TFT library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE + +Also requires the Adafruit_GFX library for Arduino. https://github.com/adafruit/Adafruit-GFX-Library diff --git a/examples/graphicstest/graphicstest.ino b/examples/graphicstest/graphicstest.ino new file mode 100755 index 0000000..6b15f85 --- /dev/null +++ b/examples/graphicstest/graphicstest.ino @@ -0,0 +1,387 @@ +// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY +// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. +// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. + +#include // Core graphics library +#include // Hardware-specific library + +// The control pins for the LCD can be assigned to any digital or +// analog pins...but we'll use the analog pins as this allows us to +// double up the pins with the touch screen (see the TFT paint example). +#define LCD_CS A3 // Chip Select goes to Analog 3 +#define LCD_CD A2 // Command/Data goes to Analog 2 +#define LCD_WR A1 // LCD Write goes to Analog 1 +#define LCD_RD A0 // LCD Read goes to Analog 0 + +#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin + +// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: +// For the Arduino Uno, Duemilanove, Diecimila, etc.: +// D0 connects to digital pin 8 (Notice these are +// D1 connects to digital pin 9 NOT in order!) +// D2 connects to digital pin 2 +// D3 connects to digital pin 3 +// D4 connects to digital pin 4 +// D5 connects to digital pin 5 +// D6 connects to digital pin 6 +// D7 connects to digital pin 7 +// For the Arduino Mega, use digital pins 22 through 29 +// (on the 2-row header at the end of the board). + +// 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 + +Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); +// If using the shield, all control and data lines are fixed, and +// a simpler declaration can optionally be used: +// Adafruit_TFTLCD tft; + +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!")); +} + +void loop(void) { + for(uint8_t rotation=0; rotation<4; rotation++) { + tft.setRotation(rotation); + testText(); + delay(2000); + } +} + +unsigned long testFillScreen() { + unsigned long start = micros(); + tft.fillScreen(BLACK); + tft.fillScreen(RED); + tft.fillScreen(GREEN); + tft.fillScreen(BLUE); + tft.fillScreen(BLACK); + return micros() - start; +} + +unsigned long testText() { + tft.fillScreen(BLACK); + unsigned long start = micros(); + tft.setCursor(0, 0); + tft.setTextColor(WHITE); tft.setTextSize(1); + tft.println("Hello World!"); + tft.setTextColor(YELLOW); tft.setTextSize(2); + tft.println(1234.56); + tft.setTextColor(RED); tft.setTextSize(3); + tft.println(0xDEADBEEF, HEX); + tft.println(); + tft.setTextColor(GREEN); + tft.setTextSize(5); + tft.println("Groop"); + tft.setTextSize(2); + tft.println("I implore thee,"); + tft.setTextSize(1); + tft.println("my foonting turlingdromes."); + tft.println("And hooptiously drangle me"); + tft.println("with crinkly bindlewurdles,"); + tft.println("Or I will rend thee"); + tft.println("in the gobberwarts"); + tft.println("with my blurglecruncheon,"); + tft.println("see if I don't!"); + return micros() - start; +} + +unsigned long testLines(uint16_t color) { + unsigned long start, t; + int x1, y1, x2, y2, + w = tft.width(), + h = tft.height(); + + tft.fillScreen(BLACK); + + x1 = y1 = 0; + y2 = h - 1; + start = micros(); + for(x2=0; x20; i-=6) { + i2 = i / 2; + start = micros(); + tft.fillRect(cx-i2, cy-i2, i, i, color1); + t += micros() - start; + // Outlines are not included in timing results + tft.drawRect(cx-i2, cy-i2, i, i, color2); + } + + return t; +} + +unsigned long testFilledCircles(uint8_t radius, uint16_t color) { + unsigned long start; + int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; + + tft.fillScreen(BLACK); + start = micros(); + for(x=radius; x10; i-=5) { + start = micros(); + tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, + tft.color565(0, i, i)); + t += micros() - start; + tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, + tft.color565(i, i, 0)); + } + + return t; +} + +unsigned long testRoundRects() { + unsigned long start; + int w, i, i2, + cx = tft.width() / 2 - 1, + cy = tft.height() / 2 - 1; + + tft.fillScreen(BLACK); + w = min(tft.width(), tft.height()); + start = micros(); + for(i=0; i20; i-=6) { + i2 = i / 2; + tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); + } + + return micros() - start; +} diff --git a/examples/rotationtest/rotationtest.ino b/examples/rotationtest/rotationtest.ino new file mode 100644 index 0000000..3d96992 --- /dev/null +++ b/examples/rotationtest/rotationtest.ino @@ -0,0 +1,225 @@ +// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY +// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. +// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. + +#include // Core graphics library +#include // Hardware-specific library + +// The control pins for the LCD can be assigned to any digital or +// analog pins...but we'll use the analog pins as this allows us to +// double up the pins with the touch screen (see the TFT paint example). +#define LCD_CS A3 // Chip Select goes to Analog 3 +#define LCD_CD A2 // Command/Data goes to Analog 2 +#define LCD_WR A1 // LCD Write goes to Analog 1 +#define LCD_RD A0 // LCD Read goes to Analog 0 + +#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin + +// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: +// For the Arduino Uno, Duemilanove, Diecimila, etc.: +// D0 connects to digital pin 8 (Notice these are +// D1 connects to digital pin 9 NOT in order!) +// D2 connects to digital pin 2 +// D3 connects to digital pin 3 +// D4 connects to digital pin 4 +// D5 connects to digital pin 5 +// D6 connects to digital pin 6 +// D7 connects to digital pin 7 +// For the Arduino Mega, use digital pins 22 through 29 +// (on the 2-row header at the end of the board). + +// 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 + +Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); +// If using the shield, all control and data lines are fixed, and +// a simpler declaration can optionally be used: +// Adafruit_TFTLCD tft; + +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 + + 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); + + tft.fillScreen(BLACK); + + Serial.println(F("This is a test of the rotation capabilities of the TFT library!")); + Serial.println(F("Press (or type a character) to advance")); +} + +void loop(void) { + rotatePixel(); + rotateLine(); + rotateFastline(); + rotateDrawrect(); + rotateFillrect(); + rotateDrawcircle(); + rotateFillcircle(); + rotateText(); +} + +void rotateText() { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.setCursor(0, 30); + tft.setTextColor(RED); + tft.setTextSize(1); + tft.println("Hello World!"); + tft.setTextColor(YELLOW); + tft.setTextSize(2); + tft.println("Hello World!"); + tft.setTextColor(GREEN); + tft.setTextSize(3); + tft.println("Hello World!"); + tft.setTextColor(BLUE); + tft.setTextSize(4); + tft.print(1234.567); + + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + +void rotateFillcircle(void) { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.fillCircle(10, 30, 10, YELLOW); + + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + +void rotateDrawcircle(void) { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.drawCircle(10, 30, 10, YELLOW); + + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + +void rotateFillrect(void) { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.fillRect(10, 20, 10, 20, GREEN); + + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + +void rotateDrawrect(void) { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.drawRect(10, 20, 10, 20, GREEN); + + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + +void rotateFastline(void) { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.drawFastHLine(0, 20, tft.width(), RED); + tft.drawFastVLine(20, 0, tft.height(), BLUE); + + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + +void rotateLine(void) { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, RED); + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + +void rotatePixel(void) { + for (uint8_t i=0; i<4; i++) { + tft.fillScreen(BLACK); + Serial.println(tft.getRotation(), DEC); + + tft.drawPixel(10,20, RED); + while (!Serial.available()); + Serial.read(); Serial.read(); Serial.read(); + + tft.setRotation(tft.getRotation()+1); + } +} + diff --git a/examples/tftbmp/tftbmp.ino b/examples/tftbmp/tftbmp.ino new file mode 100755 index 0000000..b5418ce --- /dev/null +++ b/examples/tftbmp/tftbmp.ino @@ -0,0 +1,250 @@ +// BMP-loading example specifically for the TFTLCD breakout board. +// If using the Arduino shield, use the tftbmp_shield.pde sketch instead! +// If using an Arduino Mega make sure to use its hardware SPI pins, OR make +// sure the SD library is configured for 'soft' SPI in the file Sd2Card.h. + +#include // Core graphics library +#include // Hardware-specific library +#include +#include + +// The control pins for the LCD can be assigned to any digital or +// analog pins...but we'll use the analog pins as this allows us to +// double up the pins with the touch screen (see the TFT paint example). +#define LCD_CS A3 // Chip Select goes to Analog 3 +#define LCD_CD A2 // Command/Data goes to Analog 2 +#define LCD_WR A1 // LCD Write goes to Analog 1 +#define LCD_RD A0 // LCD Read goes to Analog 0 + +// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: +// For the Arduino Uno, Duemilanove, Diecimila, etc.: +// D0 connects to digital pin 8 (Notice these are +// D1 connects to digital pin 9 NOT in order!) +// D2 connects to digital pin 2 +// D3 connects to digital pin 3 +// D4 connects to digital pin 4 +// D5 connects to digital pin 5 +// D6 connects to digital pin 6 +// D7 connects to digital pin 7 +// For the Arduino Mega, use digital pins 22 through 29 +// (on the 2-row header at the end of the board). + +// For Arduino Uno/Duemilanove, etc +// connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard) +// Then pin 10 goes to CS (or whatever you have set up) +#define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library) + +// In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) +// There are examples in the sketch folder + +// our TFT wiring +Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4); + +void setup() +{ + Serial.begin(9600); + + 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.print(F("Initializing SD card...")); + if (!SD.begin(SD_CS)) { + Serial.println(F("failed!")); + return; + } + Serial.println(F("OK!")); + + bmpDraw("woof.bmp", 0, 0); + delay(1000); +} + +void loop() +{ + for(int i = 0; i<4; i++) { + tft.setRotation(i); + tft.fillScreen(0); + for(int j=0; j <= 200; j += 50) { + bmpDraw("miniwoof.bmp", j, j); + } + delay(1000); + } +} + +// This function opens a Windows Bitmap (BMP) file and +// displays it at the given coordinates. It's sped up +// by reading many pixels worth of data at a time +// (rather than pixel by pixel). Increasing the buffer +// size takes more of the Arduino's precious RAM but +// makes loading a little faster. 20 pixels seems a +// good balance. + +#define BUFFPIXEL 20 + +void bmpDraw(char *filename, int x, int y) { + + File bmpFile; + int bmpWidth, bmpHeight; // W+H in pixels + uint8_t bmpDepth; // Bit depth (currently must be 24) + uint32_t bmpImageoffset; // Start of image data in file + uint32_t rowSize; // Not always = bmpWidth; may have padding + uint8_t sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel) + uint16_t lcdbuffer[BUFFPIXEL]; // pixel out buffer (16-bit per pixel) + uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer + boolean goodBmp = false; // Set to true on valid header parse + boolean flip = true; // BMP is stored bottom-to-top + int w, h, row, col; + uint8_t r, g, b; + uint32_t pos = 0, startTime = millis(); + uint8_t lcdidx = 0; + boolean first = true; + + if((x >= tft.width()) || (y >= tft.height())) return; + + Serial.println(); + Serial.print(F("Loading image '")); + Serial.print(filename); + Serial.println('\''); + // Open requested file on SD card + if ((bmpFile = SD.open(filename)) == NULL) { + Serial.println(F("File not found")); + return; + } + + // Parse BMP header + if(read16(bmpFile) == 0x4D42) { // BMP signature + Serial.println(F("File size: ")); Serial.println(read32(bmpFile)); + (void)read32(bmpFile); // Read & ignore creator bytes + bmpImageoffset = read32(bmpFile); // Start of image data + Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC); + // Read DIB header + Serial.print(F("Header size: ")); Serial.println(read32(bmpFile)); + bmpWidth = read32(bmpFile); + bmpHeight = read32(bmpFile); + if(read16(bmpFile) == 1) { // # planes -- must be '1' + bmpDepth = read16(bmpFile); // bits per pixel + Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth); + if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed + + goodBmp = true; // Supported BMP format -- proceed! + Serial.print(F("Image size: ")); + Serial.print(bmpWidth); + Serial.print('x'); + Serial.println(bmpHeight); + + // BMP rows are padded (if needed) to 4-byte boundary + rowSize = (bmpWidth * 3 + 3) & ~3; + + // If bmpHeight is negative, image is in top-down order. + // This is not canon but has been observed in the wild. + if(bmpHeight < 0) { + bmpHeight = -bmpHeight; + flip = false; + } + + // Crop area to be loaded + w = bmpWidth; + h = bmpHeight; + if((x+w-1) >= tft.width()) w = tft.width() - x; + if((y+h-1) >= tft.height()) h = tft.height() - y; + + // Set TFT address window to clipped image bounds + tft.setAddrWindow(x, y, x+w-1, y+h-1); + + for (row=0; row= sizeof(sdbuffer)) { // Indeed + // Push LCD buffer to the display first + if(lcdidx > 0) { + tft.pushColors(lcdbuffer, lcdidx, first); + lcdidx = 0; + first = false; + } + bmpFile.read(sdbuffer, sizeof(sdbuffer)); + buffidx = 0; // Set index to beginning + } + + // Convert pixel from BMP to TFT format + b = sdbuffer[buffidx++]; + g = sdbuffer[buffidx++]; + r = sdbuffer[buffidx++]; + lcdbuffer[lcdidx++] = tft.color565(r,g,b); + } // end pixel + } // end scanline + // Write any remaining data to LCD + if(lcdidx > 0) { + tft.pushColors(lcdbuffer, lcdidx, first); + } + Serial.print(F("Loaded in ")); + Serial.print(millis() - startTime); + Serial.println(" ms"); + } // end goodBmp + } + } + + bmpFile.close(); + if(!goodBmp) Serial.println(F("BMP format not recognized.")); +} + +// These read 16- and 32-bit types from the SD card file. +// BMP data is stored little-endian, Arduino is little-endian too. +// May need to reverse subscript order if porting elsewhere. + +uint16_t read16(File f) { + uint16_t result; + ((uint8_t *)&result)[0] = f.read(); // LSB + ((uint8_t *)&result)[1] = f.read(); // MSB + return result; +} + +uint32_t read32(File f) { + uint32_t result; + ((uint8_t *)&result)[0] = f.read(); // LSB + ((uint8_t *)&result)[1] = f.read(); + ((uint8_t *)&result)[2] = f.read(); + ((uint8_t *)&result)[3] = f.read(); // MSB + return result; +} + From 53714497ac26002c455a4ea095780a926b6fe476 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 10 Feb 2019 17:11:11 +0100 Subject: [PATCH 5/9] Readme again --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93d3a57..a705b37 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Fork working with 0x7783 LCD devices +# Fork working with 0x7783 LCD devices Added the hardware specific values from the SWIFT driver by Smoke And Wires This works also for some Iduino 2.8'' displays From 93f7011c9df1f191ab39b89c945a0c862c857021 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 10 Feb 2019 21:38:48 +0100 Subject: [PATCH 6/9] new example added --- examples/tftpaint/tftpaint.ino | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/tftpaint/tftpaint.ino b/examples/tftpaint/tftpaint.ino index 5f5b3d1..7229e85 100644 --- a/examples/tftpaint/tftpaint.ino +++ b/examples/tftpaint/tftpaint.ino @@ -49,6 +49,15 @@ #define YM 9 // can be a digital pin #define XP 8 // can be a digital pin +//Measured ADC values for (0,0) and (210-1,320-1) +//TS_MINX corresponds to ADC value when X = 0 +//TS_MINY corresponds to ADC value when Y = 0 +//TS_MAXX corresponds to ADC value when X = 240 -1 +//TS_MAXY corresponds to ADC value when Y = 320 -1 +/* + * use touch_calibrate to check out + */ + #define TS_MINX 150 #define TS_MINY 120 #define TS_MAXX 920 From 40d618e5567bae9b357e5fa3ba703531c183914e Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 10 Feb 2019 21:40:33 +0100 Subject: [PATCH 7/9] usage calibrate example --- examples/touch_calibrate/touch_calibrate.ino | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 examples/touch_calibrate/touch_calibrate.ino diff --git a/examples/touch_calibrate/touch_calibrate.ino b/examples/touch_calibrate/touch_calibrate.ino new file mode 100644 index 0000000..26e67c4 --- /dev/null +++ b/examples/touch_calibrate/touch_calibrate.ino @@ -0,0 +1,67 @@ +// Touch screen library with X Y and Z (pressure) readings as well +// as oversampling to avoid 'bouncing' +// This demo code returns raw readings, public domain + +/* + * This library is for calibrating your touch screen + */ + +#include +#include +#include +#include "TouchScreen.h" + +#define YP A2 // must be an analog pin, use "An" notation! +#define XM A3 // must be an analog pin, use "An" notation! +#define YM 8 // can be a digital pin +#define XP 9 // can be a digital pin + +#define LCD_CS A3 +#define LCD_CD A2 +#define LCD_WR A1 +#define LCD_RD A0 +// optional +#define LCD_RESET A4 + +#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 BOXSIZE 40 +#define PENRADIUS 3 + + +Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); +// For better pressure precision, we need to know the resistance +// between X+ and X- Use any multimeter to read it +// For the one we're using, its 300 ohms across the X plate +TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); + +void setup(void) { + Serial.begin(9600); + tft.reset(); + uint16_t identifier = tft.readID(); + tft.begin(identifier); + tft.fillScreen(BLACK); + tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); + tft.fillRect(tft.width()-BOXSIZE-1,tft.height()-BOXSIZE-1,BOXSIZE, BOXSIZE,GREEN); +} + +void loop(void) { + // a point object holds x y and z coordinates + TSPoint p = ts.getPoint(); + + // we have some minimum pressure we consider 'valid' + // pressure of 0 means no pressing! + if (p.z > ts.pressureThreshhold) { + Serial.print("X = "); Serial.print(p.x); + Serial.print("\tY = "); Serial.print(p.y); + Serial.print("\tPressure = "); Serial.println(p.z); + } + + delay(100); +} From 58cc1ee7329f13803057e4df58aaf796f70b0be2 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 10 Feb 2019 22:21:14 +0100 Subject: [PATCH 8/9] touchpoints fo 0x7783 devices --- examples/tftpaint/tftpaint.ino | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/tftpaint/tftpaint.ino b/examples/tftpaint/tftpaint.ino index 7229e85..db0e198 100644 --- a/examples/tftpaint/tftpaint.ino +++ b/examples/tftpaint/tftpaint.ino @@ -57,11 +57,19 @@ /* * use touch_calibrate to check out */ - +/* #define TS_MINX 150 #define TS_MINY 120 #define TS_MAXX 920 #define TS_MAXY 940 +*/ +/* + * values for 0x7783 device + */ +#define TS_MINX 900 +#define TS_MINY 160 +#define TS_MAXX 120 +#define TS_MAXY 710 // For better pressure precision, we need to know the resistance // between X+ and X- Use any multimeter to read it From 3849344d23b857bababf721c28dd6bbcfe0610f8 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Fri, 9 Oct 2020 19:40:27 +0200 Subject: [PATCH 9/9] bugfix line 362 --- Adafruit_TFTLCD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index 5db1af2..bd24a71 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -359,7 +359,7 @@ void Adafruit_TFTLCD::begin(uint16_t id) { } setRotation(rotation); setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1); - } else if (id = 0x7783 ){ //new for SWITCH Display + } else if (id == 0x7783 ){ //new for SWITCH Display uint16_t a, d; driver = ID_932X; CS_ACTIVE;