diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index 1453113..e32c4f9 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -4,8 +4,14 @@ // Graphics library by ladyada/adafruit with init code from Rossum // MIT license +#if defined(__SAM3X8E__) + #include + #define PROGMEM + #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) + #define pgm_read_word(addr) (*(const unsigned short *)(addr)) +#endif #ifdef __AVR__ -#include + #include #endif #include "pins_arduino.h" #include "wiring_private.h" @@ -301,6 +307,7 @@ void Adafruit_TFTLCD::begin(uint16_t id) { void Adafruit_TFTLCD::reset(void) { CS_IDLE; +// CD_DATA; WR_IDLE; RD_IDLE; diff --git a/Adafruit_TFTLCD.h b/Adafruit_TFTLCD.h index a001c03..cffe383 100644 --- a/Adafruit_TFTLCD.h +++ b/Adafruit_TFTLCD.h @@ -11,6 +11,7 @@ #else #include "WProgram.h" #endif + #include // **** IF USING THE LCD BREAKOUT BOARD, COMMENT OUT THIS NEXT LINE. **** @@ -24,19 +25,19 @@ class Adafruit_TFTLCD : public Adafruit_GFX { Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst); Adafruit_TFTLCD(void); - void begin(uint16_t id = 0x9325), - drawPixel(int16_t x, int16_t y, uint16_t color), - drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color), - drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color), - fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c), - fillScreen(uint16_t color), - reset(void), - setRegisters8(uint8_t *ptr, uint8_t n), - setRegisters16(uint16_t *ptr, uint8_t n), - setRotation(uint8_t x), - // These methods are public in order for BMP examples to work: - setAddrWindow(int x1, int y1, int x2, int y2), - pushColors(uint16_t *data, uint8_t len, boolean first); + void begin(uint16_t id = 0x9325); + void drawPixel(int16_t x, int16_t y, uint16_t color); + void drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color); + void drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color); + void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c); + void fillScreen(uint16_t color); + void reset(void); + void setRegisters8(uint8_t *ptr, uint8_t n); + void setRegisters16(uint16_t *ptr, uint8_t n); + void setRotation(uint8_t x); + // These methods are public in order for BMP examples to work: + void setAddrWindow(int x1, int y1, int x2, int y2); + void pushColors(uint16_t *data, uint8_t len, boolean first); uint16_t color565(uint8_t r, uint8_t g, uint8_t b), readPixel(int16_t x, int16_t y), @@ -68,10 +69,12 @@ class Adafruit_TFTLCD : public Adafruit_GFX { setLR(void), flood(uint16_t color, uint32_t len); uint8_t driver; + #ifndef read8 uint8_t read8fn(void); #define read8isFunctionalized #endif + #ifndef USE_ADAFRUIT_SHIELD_PINOUT volatile uint8_t *csPort , *cdPort , *wrPort , *rdPort; uint8_t csPinSet , cdPinSet , wrPinSet , rdPinSet , diff --git a/examples/graphicstest/graphicstest.pde b/examples/graphicstest/graphicstest.pde deleted file mode 100644 index 0122b2f..0000000 --- a/examples/graphicstest/graphicstest.pde +++ /dev/null @@ -1,380 +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 { - 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 6d3d0b9..0000000 --- a/examples/rotationtest/rotationtest.pde +++ /dev/null @@ -1,219 +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 { - 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 100644 index 4d20eda..0000000 --- a/examples/tftbmp/tftbmp.pde +++ /dev/null @@ -1,243 +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 the SD library is configured for -// 'soft' SPI in the file Sd2Card.h. - -#include // Core graphics library -#include // Hardware-specific library -#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 { - 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/tftbmp_shield/tftbmp_shield.pde b/examples/tftbmp_shield/tftbmp_shield.pde deleted file mode 100644 index 150b4ff..0000000 --- a/examples/tftbmp_shield/tftbmp_shield.pde +++ /dev/null @@ -1,225 +0,0 @@ -// BMP-loading example specifically for the TFTLCD Arduino shield. -// If using the breakout board, use the tftbmp.pde sketch instead! -// If using an Arduino Mega, make sure the SD library is configured for -// 'soft' SPI in the file Sd2Card.h. - -#include // Core graphics library -#include // Hardware-specific library -#include - -// In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) -// There are examples in the sketch folder - -#define SD_CS 5 // Card select for shield use - -Adafruit_TFTLCD tft; -uint8_t spi_save; - -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 { - 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!")); - spi_save = SPCR; - - 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("Loading image '"); - Serial.print(filename); - Serial.println('\''); - // Open requested file on SD card - SPCR = spi_save; - if ((bmpFile = SD.open(filename)) == NULL) { - Serial.print("File not found"); - return; - } - - // Parse BMP header - if(read16(bmpFile) == 0x4D42) { // BMP signature - Serial.print(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 - SPCR = 0; - 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) { - SPCR = 0; - tft.pushColors(lcdbuffer, lcdidx, first); - lcdidx = 0; - first = false; - } - SPCR = spi_save; - 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) { - SPCR = 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("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.pde b/examples/tftpaint/tftpaint.ino similarity index 100% rename from examples/tftpaint/tftpaint.pde rename to examples/tftpaint/tftpaint.ino diff --git a/examples/tftpaint_shield/glcdfont.c b/examples/tftpaint_shield/glcdfont.c new file mode 100644 index 0000000..c1dcede --- /dev/null +++ b/examples/tftpaint_shield/glcdfont.c @@ -0,0 +1,264 @@ + +#ifndef FONT5X7_H +#define FONT5X7_H + +// standard ascii 5x7 font + +static unsigned char font[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, + 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, + 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, + 0x18, 0x3C, 0x7E, 0x3C, 0x18, + 0x1C, 0x57, 0x7D, 0x57, 0x1C, + 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, + 0x00, 0x18, 0x3C, 0x18, 0x00, + 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, + 0x00, 0x18, 0x24, 0x18, 0x00, + 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, + 0x30, 0x48, 0x3A, 0x06, 0x0E, + 0x26, 0x29, 0x79, 0x29, 0x26, + 0x40, 0x7F, 0x05, 0x05, 0x07, + 0x40, 0x7F, 0x05, 0x25, 0x3F, + 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, + 0x7F, 0x3E, 0x1C, 0x1C, 0x08, + 0x08, 0x1C, 0x1C, 0x3E, 0x7F, + 0x14, 0x22, 0x7F, 0x22, 0x14, + 0x5F, 0x5F, 0x00, 0x5F, 0x5F, + 0x06, 0x09, 0x7F, 0x01, 0x7F, + 0x00, 0x66, 0x89, 0x95, 0x6A, + 0x60, 0x60, 0x60, 0x60, 0x60, + 0x94, 0xA2, 0xFF, 0xA2, 0x94, + 0x08, 0x04, 0x7E, 0x04, 0x08, + 0x10, 0x20, 0x7E, 0x20, 0x10, + 0x08, 0x08, 0x2A, 0x1C, 0x08, + 0x08, 0x1C, 0x2A, 0x08, 0x08, + 0x1E, 0x10, 0x10, 0x10, 0x10, + 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, + 0x30, 0x38, 0x3E, 0x38, 0x30, + 0x06, 0x0E, 0x3E, 0x0E, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x5F, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x07, 0x00, + 0x14, 0x7F, 0x14, 0x7F, 0x14, + 0x24, 0x2A, 0x7F, 0x2A, 0x12, + 0x23, 0x13, 0x08, 0x64, 0x62, + 0x36, 0x49, 0x56, 0x20, 0x50, + 0x00, 0x08, 0x07, 0x03, 0x00, + 0x00, 0x1C, 0x22, 0x41, 0x00, + 0x00, 0x41, 0x22, 0x1C, 0x00, + 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, + 0x08, 0x08, 0x3E, 0x08, 0x08, + 0x00, 0x80, 0x70, 0x30, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x60, 0x60, 0x00, + 0x20, 0x10, 0x08, 0x04, 0x02, + 0x3E, 0x51, 0x49, 0x45, 0x3E, + 0x00, 0x42, 0x7F, 0x40, 0x00, + 0x72, 0x49, 0x49, 0x49, 0x46, + 0x21, 0x41, 0x49, 0x4D, 0x33, + 0x18, 0x14, 0x12, 0x7F, 0x10, + 0x27, 0x45, 0x45, 0x45, 0x39, + 0x3C, 0x4A, 0x49, 0x49, 0x31, + 0x41, 0x21, 0x11, 0x09, 0x07, + 0x36, 0x49, 0x49, 0x49, 0x36, + 0x46, 0x49, 0x49, 0x29, 0x1E, + 0x00, 0x00, 0x14, 0x00, 0x00, + 0x00, 0x40, 0x34, 0x00, 0x00, + 0x00, 0x08, 0x14, 0x22, 0x41, + 0x14, 0x14, 0x14, 0x14, 0x14, + 0x00, 0x41, 0x22, 0x14, 0x08, + 0x02, 0x01, 0x59, 0x09, 0x06, + 0x3E, 0x41, 0x5D, 0x59, 0x4E, + 0x7C, 0x12, 0x11, 0x12, 0x7C, + 0x7F, 0x49, 0x49, 0x49, 0x36, + 0x3E, 0x41, 0x41, 0x41, 0x22, + 0x7F, 0x41, 0x41, 0x41, 0x3E, + 0x7F, 0x49, 0x49, 0x49, 0x41, + 0x7F, 0x09, 0x09, 0x09, 0x01, + 0x3E, 0x41, 0x41, 0x51, 0x73, + 0x7F, 0x08, 0x08, 0x08, 0x7F, + 0x00, 0x41, 0x7F, 0x41, 0x00, + 0x20, 0x40, 0x41, 0x3F, 0x01, + 0x7F, 0x08, 0x14, 0x22, 0x41, + 0x7F, 0x40, 0x40, 0x40, 0x40, + 0x7F, 0x02, 0x1C, 0x02, 0x7F, + 0x7F, 0x04, 0x08, 0x10, 0x7F, + 0x3E, 0x41, 0x41, 0x41, 0x3E, + 0x7F, 0x09, 0x09, 0x09, 0x06, + 0x3E, 0x41, 0x51, 0x21, 0x5E, + 0x7F, 0x09, 0x19, 0x29, 0x46, + 0x26, 0x49, 0x49, 0x49, 0x32, + 0x03, 0x01, 0x7F, 0x01, 0x03, + 0x3F, 0x40, 0x40, 0x40, 0x3F, + 0x1F, 0x20, 0x40, 0x20, 0x1F, + 0x3F, 0x40, 0x38, 0x40, 0x3F, + 0x63, 0x14, 0x08, 0x14, 0x63, + 0x03, 0x04, 0x78, 0x04, 0x03, + 0x61, 0x59, 0x49, 0x4D, 0x43, + 0x00, 0x7F, 0x41, 0x41, 0x41, + 0x02, 0x04, 0x08, 0x10, 0x20, + 0x00, 0x41, 0x41, 0x41, 0x7F, + 0x04, 0x02, 0x01, 0x02, 0x04, + 0x40, 0x40, 0x40, 0x40, 0x40, + 0x00, 0x03, 0x07, 0x08, 0x00, + 0x20, 0x54, 0x54, 0x78, 0x40, + 0x7F, 0x28, 0x44, 0x44, 0x38, + 0x38, 0x44, 0x44, 0x44, 0x28, + 0x38, 0x44, 0x44, 0x28, 0x7F, + 0x38, 0x54, 0x54, 0x54, 0x18, + 0x00, 0x08, 0x7E, 0x09, 0x02, + 0x18, 0xA4, 0xA4, 0x9C, 0x78, + 0x7F, 0x08, 0x04, 0x04, 0x78, + 0x00, 0x44, 0x7D, 0x40, 0x00, + 0x20, 0x40, 0x40, 0x3D, 0x00, + 0x7F, 0x10, 0x28, 0x44, 0x00, + 0x00, 0x41, 0x7F, 0x40, 0x00, + 0x7C, 0x04, 0x78, 0x04, 0x78, + 0x7C, 0x08, 0x04, 0x04, 0x78, + 0x38, 0x44, 0x44, 0x44, 0x38, + 0xFC, 0x18, 0x24, 0x24, 0x18, + 0x18, 0x24, 0x24, 0x18, 0xFC, + 0x7C, 0x08, 0x04, 0x04, 0x08, + 0x48, 0x54, 0x54, 0x54, 0x24, + 0x04, 0x04, 0x3F, 0x44, 0x24, + 0x3C, 0x40, 0x40, 0x20, 0x7C, + 0x1C, 0x20, 0x40, 0x20, 0x1C, + 0x3C, 0x40, 0x30, 0x40, 0x3C, + 0x44, 0x28, 0x10, 0x28, 0x44, + 0x4C, 0x90, 0x90, 0x90, 0x7C, + 0x44, 0x64, 0x54, 0x4C, 0x44, + 0x00, 0x08, 0x36, 0x41, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, + 0x00, 0x41, 0x36, 0x08, 0x00, + 0x02, 0x01, 0x02, 0x04, 0x02, + 0x3C, 0x26, 0x23, 0x26, 0x3C, + 0x1E, 0xA1, 0xA1, 0x61, 0x12, + 0x3A, 0x40, 0x40, 0x20, 0x7A, + 0x38, 0x54, 0x54, 0x55, 0x59, + 0x21, 0x55, 0x55, 0x79, 0x41, + 0x21, 0x54, 0x54, 0x78, 0x41, + 0x21, 0x55, 0x54, 0x78, 0x40, + 0x20, 0x54, 0x55, 0x79, 0x40, + 0x0C, 0x1E, 0x52, 0x72, 0x12, + 0x39, 0x55, 0x55, 0x55, 0x59, + 0x39, 0x54, 0x54, 0x54, 0x59, + 0x39, 0x55, 0x54, 0x54, 0x58, + 0x00, 0x00, 0x45, 0x7C, 0x41, + 0x00, 0x02, 0x45, 0x7D, 0x42, + 0x00, 0x01, 0x45, 0x7C, 0x40, + 0xF0, 0x29, 0x24, 0x29, 0xF0, + 0xF0, 0x28, 0x25, 0x28, 0xF0, + 0x7C, 0x54, 0x55, 0x45, 0x00, + 0x20, 0x54, 0x54, 0x7C, 0x54, + 0x7C, 0x0A, 0x09, 0x7F, 0x49, + 0x32, 0x49, 0x49, 0x49, 0x32, + 0x32, 0x48, 0x48, 0x48, 0x32, + 0x32, 0x4A, 0x48, 0x48, 0x30, + 0x3A, 0x41, 0x41, 0x21, 0x7A, + 0x3A, 0x42, 0x40, 0x20, 0x78, + 0x00, 0x9D, 0xA0, 0xA0, 0x7D, + 0x39, 0x44, 0x44, 0x44, 0x39, + 0x3D, 0x40, 0x40, 0x40, 0x3D, + 0x3C, 0x24, 0xFF, 0x24, 0x24, + 0x48, 0x7E, 0x49, 0x43, 0x66, + 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, + 0xFF, 0x09, 0x29, 0xF6, 0x20, + 0xC0, 0x88, 0x7E, 0x09, 0x03, + 0x20, 0x54, 0x54, 0x79, 0x41, + 0x00, 0x00, 0x44, 0x7D, 0x41, + 0x30, 0x48, 0x48, 0x4A, 0x32, + 0x38, 0x40, 0x40, 0x22, 0x7A, + 0x00, 0x7A, 0x0A, 0x0A, 0x72, + 0x7D, 0x0D, 0x19, 0x31, 0x7D, + 0x26, 0x29, 0x29, 0x2F, 0x28, + 0x26, 0x29, 0x29, 0x29, 0x26, + 0x30, 0x48, 0x4D, 0x40, 0x20, + 0x38, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x38, + 0x2F, 0x10, 0xC8, 0xAC, 0xBA, + 0x2F, 0x10, 0x28, 0x34, 0xFA, + 0x00, 0x00, 0x7B, 0x00, 0x00, + 0x08, 0x14, 0x2A, 0x14, 0x22, + 0x22, 0x14, 0x2A, 0x14, 0x08, + 0xAA, 0x00, 0x55, 0x00, 0xAA, + 0xAA, 0x55, 0xAA, 0x55, 0xAA, + 0x00, 0x00, 0x00, 0xFF, 0x00, + 0x10, 0x10, 0x10, 0xFF, 0x00, + 0x14, 0x14, 0x14, 0xFF, 0x00, + 0x10, 0x10, 0xFF, 0x00, 0xFF, + 0x10, 0x10, 0xF0, 0x10, 0xF0, + 0x14, 0x14, 0x14, 0xFC, 0x00, + 0x14, 0x14, 0xF7, 0x00, 0xFF, + 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x14, 0x14, 0xF4, 0x04, 0xFC, + 0x14, 0x14, 0x17, 0x10, 0x1F, + 0x10, 0x10, 0x1F, 0x10, 0x1F, + 0x14, 0x14, 0x14, 0x1F, 0x00, + 0x10, 0x10, 0x10, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0x1F, 0x10, + 0x10, 0x10, 0x10, 0x1F, 0x10, + 0x10, 0x10, 0x10, 0xF0, 0x10, + 0x00, 0x00, 0x00, 0xFF, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0xFF, 0x10, + 0x00, 0x00, 0x00, 0xFF, 0x14, + 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x00, 0x1F, 0x10, 0x17, + 0x00, 0x00, 0xFC, 0x04, 0xF4, + 0x14, 0x14, 0x17, 0x10, 0x17, + 0x14, 0x14, 0xF4, 0x04, 0xF4, + 0x00, 0x00, 0xFF, 0x00, 0xF7, + 0x14, 0x14, 0x14, 0x14, 0x14, + 0x14, 0x14, 0xF7, 0x00, 0xF7, + 0x14, 0x14, 0x14, 0x17, 0x14, + 0x10, 0x10, 0x1F, 0x10, 0x1F, + 0x14, 0x14, 0x14, 0xF4, 0x14, + 0x10, 0x10, 0xF0, 0x10, 0xF0, + 0x00, 0x00, 0x1F, 0x10, 0x1F, + 0x00, 0x00, 0x00, 0x1F, 0x14, + 0x00, 0x00, 0x00, 0xFC, 0x14, + 0x00, 0x00, 0xF0, 0x10, 0xF0, + 0x10, 0x10, 0xFF, 0x10, 0xFF, + 0x14, 0x14, 0x14, 0xFF, 0x14, + 0x10, 0x10, 0x10, 0x1F, 0x00, + 0x00, 0x00, 0x00, 0xF0, 0x10, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, + 0x38, 0x44, 0x44, 0x38, 0x44, + 0x7C, 0x2A, 0x2A, 0x3E, 0x14, + 0x7E, 0x02, 0x02, 0x06, 0x06, + 0x02, 0x7E, 0x02, 0x7E, 0x02, + 0x63, 0x55, 0x49, 0x41, 0x63, + 0x38, 0x44, 0x44, 0x3C, 0x04, + 0x40, 0x7E, 0x20, 0x1E, 0x20, + 0x06, 0x02, 0x7E, 0x02, 0x02, + 0x99, 0xA5, 0xE7, 0xA5, 0x99, + 0x1C, 0x2A, 0x49, 0x2A, 0x1C, + 0x4C, 0x72, 0x01, 0x72, 0x4C, + 0x30, 0x4A, 0x4D, 0x4D, 0x30, + 0x30, 0x48, 0x78, 0x48, 0x30, + 0xBC, 0x62, 0x5A, 0x46, 0x3D, + 0x3E, 0x49, 0x49, 0x49, 0x00, + 0x7E, 0x01, 0x01, 0x01, 0x7E, + 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, + 0x44, 0x44, 0x5F, 0x44, 0x44, + 0x40, 0x51, 0x4A, 0x44, 0x40, + 0x40, 0x44, 0x4A, 0x51, 0x40, + 0x00, 0x00, 0xFF, 0x01, 0x03, + 0xE0, 0x80, 0xFF, 0x00, 0x00, + 0x08, 0x08, 0x6B, 0x6B, 0x08, + 0x36, 0x12, 0x36, 0x24, 0x36, + 0x06, 0x0F, 0x09, 0x0F, 0x06, + 0x00, 0x00, 0x18, 0x18, 0x00, + 0x00, 0x00, 0x10, 0x10, 0x00, + 0x30, 0x40, 0xFF, 0x01, 0x01, + 0x00, 0x1F, 0x01, 0x01, 0x1E, + 0x00, 0x19, 0x1D, 0x17, 0x12, + 0x00, 0x3C, 0x3C, 0x3C, 0x3C, + 0x00, 0x00, 0x00, 0x00, 0x00, +}; +#endif diff --git a/examples/tftpaint_shield/tftpaint_shield.pde b/examples/tftpaint_shield/tftpaint_shield.ino similarity index 93% rename from examples/tftpaint_shield/tftpaint_shield.pde rename to examples/tftpaint_shield/tftpaint_shield.ino index 5f7b89d..e4e8e60 100644 --- a/examples/tftpaint_shield/tftpaint_shield.pde +++ b/examples/tftpaint_shield/tftpaint_shield.ino @@ -5,6 +5,11 @@ #include // Hardware-specific library #include +#if defined(__SAM3X8E__) + #undef __FlashStringHelper::F(string_literal) + #define F(string_literal) string_literal +#endif + #ifndef USE_ADAFRUIT_SHIELD_PINOUT #error "This sketch is intended for use with the TFT LCD Shield. Make sure that USE_ADAFRUIT_SHIELD_PINOUT is #defined in the Adafruit_TFTLCD.h library file." #endif @@ -15,10 +20,17 @@ #define YM 7 // can be a digital pin #define XP 6 // can be a digital pin -#define TS_MINX 150 -#define TS_MINY 120 -#define TS_MAXX 920 -#define TS_MAXY 940 +#ifdef __SAM3X8E__ + #define TS_MINX 125 + #define TS_MINY 170 + #define TS_MAXX 880 + #define TS_MAXY 940 +#else + #define TS_MINX 150 + #define TS_MINY 120 + #define TS_MAXX 920 + #define TS_MAXY 940 +#endif // For better pressure precision, we need to know the resistance // between X+ and X- Use any multimeter to read it diff --git a/pin_magic.h b/pin_magic.h index b6c3cf1..9fc9c80 100644 --- a/pin_magic.h +++ b/pin_magic.h @@ -32,11 +32,12 @@ // given for each supported board. // Shield pin usage: -// LCD Data Bit : 7 6 5 4 3 2 1 0 -// Digital pin #: 7 6 13 4 11 10 9 8 -// Uno port/pin : PD7 PD6 PB5 PD4 PB3 PB2 PB1 PB0 -// Mega port/pin: PH4 PH3 PB7 PG5 PB5 PB4 PH6 PH5 -// Leo port/pin : PE6 PD7 PC7 PD4 PB7 PB6 PB5 PB4 +// LCD Data Bit : 7 6 5 4 3 2 1 0 +// Digital pin #: 7 6 13 4 11 10 9 8 +// Uno port/pin : PD7 PD6 PB5 PD4 PB3 PB2 PB1 PB0 +// Mega port/pin: PH4 PH3 PB7 PG5 PB5 PB4 PH6 PH5 +// Leo port/pin : PE6 PD7 PC7 PD4 PB7 PB6 PB5 PB4 +// Due port/pin : PC23 PC24 PB27 PC26 PD7 PC29 PC21 PC22 // Breakout pin usage: // LCD Data Bit : 7 6 5 4 3 2 1 0 // Uno dig. pin : 7 6 5 4 3 2 9 8 @@ -45,6 +46,8 @@ // Mega port/pin: PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 (one contiguous PORT) // Leo dig. pin : 7 6 5 4 3 2 9 8 // Leo port/pin : PE6 PD7 PC6 PD4 PD0 PD1 PB5 PB4 +// Due dig. pin : 40 39 38 37 36 35 34 33 +// Due port/pin : PC8 PC7 PC6 PC5 PC4 PC3 PC2 PC1 (one contiguous PORT. -ish…) // Pixel read operations require a minimum 400 nS delay from RD_ACTIVE // to polling the input pins. At 16 MHz, one machine cycle is 62.5 nS. @@ -67,10 +70,10 @@ // LCD control lines: // RD (read), WR (write), CD (command/data), CS (chip select) - #define RD_PORT PORTC - #define WR_PORT PORTC - #define CD_PORT PORTC - #define CS_PORT PORTC + #define RD_PORT PORTC /*pin A0 */ + #define WR_PORT PORTC /*pin A1 */ + #define CD_PORT PORTC /*pin A2 */ + #define CS_PORT PORTC /*pin A3 */ #define RD_MASK B00000001 #define WR_MASK B00000010 #define CD_MASK B00000100 @@ -252,13 +255,108 @@ // program to compile. #define write8 write8inline +#elif defined(__SAM3X8E__) + +// Arduino Due + + #ifdef USE_ADAFRUIT_SHIELD_PINOUT + + #define RD_PORT PIOA /*pin A0 */ + #define WR_PORT PIOA /*pin A1 */ + #define CD_PORT PIOA /*pin A2 */ + #define CS_PORT PIOA /*pin A3 */ + #define RD_MASK 0x00010000 + #define WR_MASK 0x01000000 + #define CD_MASK 0x00800000 + #define CS_MASK 0x00400000 + +#define RD_STROBE RD_ACTIVE, delayMicroseconds(1), RD_IDLE + + #define write8inline(d) { \ + PIO_Set(PIOD, (((d) & 0x08)<<(7-3))); \ + PIO_Clear(PIOD, (((~d) & 0x08)<<(7-3))); \ + PIO_Set(PIOC, (((d) & 0x01)<<(22-0)) | (((d) & 0x02)<<(21-1))| (((d) & 0x04)<<(29-2))| (((d) & 0x10)<<(26-4))| (((d) & 0x40)<<(24-6))| (((d) & 0x80)<<(23-7))); \ + PIO_Clear(PIOC, (((~d) & 0x01)<<(22-0)) | (((~d) & 0x02)<<(21-1))| (((~d) & 0x04)<<(29-2))| (((~d) & 0x10)<<(26-4))| (((~d) & 0x40)<<(24-6))| (((~d) & 0x80)<<(23-7))); \ + PIO_Set(PIOB, (((d) & 0x20)<<(27-5))); \ + PIO_Clear(PIOB, (((~d) & 0x20)<<(27-5))); \ + WR_STROBE; } + + #define read8inline(result) { RD_STROBE; \ + result = (((PIOC->PIO_PDSR & (1<<23)) >> (23-7)) | ((PIOC->PIO_PDSR & (1<<24)) >> (24-6)) | \ + ((PIOB->PIO_PDSR & (1<<27)) >> (27-5)) | ((PIOC->PIO_PDSR & (1<<26)) >> (26-4)) | \ + ((PIOD->PIO_PDSR & (1<< 7)) >> ( 7-3)) | ((PIOC->PIO_PDSR & (1<<29)) >> (29-2)) | \ + ((PIOC->PIO_PDSR & (1<<21)) >> (21-1)) | ((PIOC->PIO_PDSR & (1<<22)) >> (22-0))); } + + #define setWriteDirInline() { \ + PIOD->PIO_MDDR = 0x00000080; /*PIOD->PIO_SODR = 0x00000080;*/ PIOD->PIO_OER = 0x00000080; PIOD->PIO_PER = 0x00000080; \ + PIOC->PIO_MDDR = 0x25E00000; /*PIOC->PIO_SODR = 0x25E00000;*/ PIOC->PIO_OER = 0x25E00000; PIOC->PIO_PER = 0x25E00000; \ + PIOB->PIO_MDDR = 0x08000000; /*PIOB->PIO_SODR = 0x08000000;*/ PIOB->PIO_OER = 0x08000000; PIOB->PIO_PER = 0x08000000; } + + #define setReadDirInline() { \ + pmc_enable_periph_clk( ID_PIOD ) ; pmc_enable_periph_clk( ID_PIOC ) ; pmc_enable_periph_clk( ID_PIOB ) ; \ + PIOD->PIO_PUDR = 0x00000080; PIOD->PIO_IFDR = 0x00000080; PIOD->PIO_ODR = 0x00000080; PIOD->PIO_PER = 0x00000080; \ + PIOC->PIO_PUDR = 0x25E00000; PIOC->PIO_IFDR = 0x25E00000; PIOC->PIO_ODR = 0x25E00000; PIOC->PIO_PER = 0x25E00000; \ + PIOB->PIO_PUDR = 0x08000000; PIOB->PIO_IFDR = 0x08000000; PIOB->PIO_ODR = 0x08000000; PIOB->PIO_PER = 0x08000000; } + + // Control signals are ACTIVE LOW (idle is HIGH) + // Command/Data: LOW = command, HIGH = data + // These are single-instruction operations and always inline + #define RD_ACTIVE RD_PORT->PIO_CODR = RD_MASK + #define RD_IDLE RD_PORT->PIO_SODR = RD_MASK + #define WR_ACTIVE WR_PORT->PIO_CODR = WR_MASK + #define WR_IDLE WR_PORT->PIO_SODR = WR_MASK + #define CD_COMMAND CD_PORT->PIO_CODR = CD_MASK + #define CD_DATA CD_PORT->PIO_SODR = CD_MASK + #define CS_ACTIVE CS_PORT->PIO_CODR = CS_MASK + #define CS_IDLE CS_PORT->PIO_SODR = CS_MASK + + + #else // Due w/Breakout board + + #error "Library does not currently support Breakout Board on Due" + +// #define write8inline(d) { \ +// uint8_t dr1 = (d) >> 1, dl1 = (d) << 1; \ +// PORTE = (PORTE & B10111111) | (dr1 & B01000000); \ +// PORTD = (PORTD & B01101100) | (dl1 & B10000000) | (((d) & B00001000)>>3) | \ +// (dr1 & B00000010) | ((d) & B00010000); \ +// PIOC = (PIOC & B10111111) | (dl1 & B01000000); \ +// PIOB = (PIOB & B11001111) |(((d) & B00000011)<<4); \ +// WR_STROBE; } +// +// #define read8inline() (RD_STROBE, \ +// (((PINE & B01000000) | (PIND & B00000010)) << 1) | \ +// (((PINC & B01000000) | (PIND & B10000000)) >> 1) | \ +// ((PIND & B00000001)<<3) | ((PINB & B00110000)>>4) | (PIND & B00010000)) +// #define setWriteDirInline() { \ +// DDRE |= B01000000; DDRD |= B10010011; \ +// DDRC |= B01000000; DDRB |= B00110000; } +// #define setReadDirInline() { \ +// DDRE &= ~B01000000; DDRD &= ~B10010011; \ +// DDRC &= ~B01000000; DDRB &= ~B00110000; } + + +// // When using the TFT breakout board, control pins are configurable. +// #define RD_ACTIVE *rdPort &= rdPinUnset +// #define RD_IDLE *rdPort |= rdPinSet +// #define WR_ACTIVE *wrPort &= wrPinUnset +// #define WR_IDLE *wrPort |= wrPinSet +// #define CD_COMMAND *cdPort &= cdPinUnset +// #define CD_DATA *cdPort |= cdPinSet +// #define CS_ACTIVE *csPort &= csPinUnset +// #define CS_IDLE *csPort |= csPinSet + + #endif + + #else #error "Board type unsupported / not recognized" #endif -// Stuff common to all Arduino board types: +#if !defined(__SAM3X8E__) +// Stuff common to all Arduino AVR board types: #ifdef USE_ADAFRUIT_SHIELD_PINOUT @@ -287,6 +385,7 @@ #define CS_IDLE *csPort |= csPinSet #endif +#endif // Data write strobe, ~2 instructions and always inline #define WR_STROBE { WR_ACTIVE; WR_IDLE; }