Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactored to use GFX, & 4 times faster for the fixed shield pinout!

  • Loading branch information...
commit 115fc817ef017b2d0a49da30290a0de1b2718796 1 parent 8566cff
@ladyada ladyada authored
View
466 TFTLCD.cpp → Adafruit_TFTLCD.cpp
@@ -1,8 +1,11 @@
-#include "TFTLCD.h"
+#include "Adafruit_TFTLCD.h"
// Graphics library by ladyada/adafruit with init code from Rossum
// MIT license
+static volatile uint8_t *wrportreg;
+
+
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
// special defines for the dataport
#define DATAPORT1 PORTD
@@ -16,6 +19,15 @@
#define DATA1_MASK 0xD0
#define DATA2_MASK 0x2F
+ #define WRPORT PORTC
+ #define RDPORT PORTC
+ #define CSPORT PORTC
+ #define CDPORT PORTC
+ #define WRPIN 1
+ #define CDPIN 2
+ #define CSPIN 3
+ #define RDPIN 4
+
// for mega & shield usage, we just hardcoded it (its messy)
#else
@@ -44,148 +56,14 @@
#include "wiring_private.h"
-void TFTLCD::goHome(void) {
- goTo(0,0);
-}
-
-uint16_t TFTLCD::width(void) {
- return _width;
-}
-uint16_t TFTLCD::height(void) {
- return _height;
-}
-
-void TFTLCD::goTo(int x, int y) {
+void Adafruit_TFTLCD::goTo(int x, int y) {
writeRegister(0x0020, x); // GRAM Address Set (Horizontal Address) (R20h)
writeRegister(0x0021, y); // GRAM Address Set (Vertical Address) (R21h)
writeCommand(0x0022); // Write Data to GRAM (R22h)
}
-void TFTLCD::setCursor(uint16_t x, uint16_t y) {
- cursor_x = x;
- cursor_y = y;
-}
-
-void TFTLCD::setTextSize(uint8_t s) {
- textsize = s;
-}
-
-void TFTLCD::setTextColor(uint16_t c) {
- textcolor = c;
-}
-
-#if ARDUINO >= 100
-size_t TFTLCD::write(uint8_t c) {
-#else
-void TFTLCD::write(uint8_t c) {
-#endif
- if (c == '\n') {
- cursor_y += textsize*8;
- cursor_x = 0;
- } else if (c == '\r') {
- // skip em
- } else {
- drawChar(cursor_x, cursor_y, c, textcolor, textsize);
- cursor_x += textsize*6;
- }
-#if ARDUINO >= 100
- return 1;
-#endif
-}
-
-void TFTLCD::drawString(uint16_t x, uint16_t y, char *c,
- uint16_t color, uint8_t size) {
- while (c[0] != 0) {
- drawChar(x, y, c[0], color, size);
- x += size*6;
- c++;
- }
-}
-// draw a character
-void TFTLCD::drawChar(uint16_t x, uint16_t y, char c,
- uint16_t color, uint8_t size) {
- for (uint8_t i =0; i<5; i++ ) {
- uint8_t line = pgm_read_byte(font+(c*5)+i);
- for (uint8_t j = 0; j<8; j++) {
- if (line & 0x1) {
- if (size == 1) // default size
- drawPixel(x+i, y+j, color);
- else { // big size
- fillRect(x+i*size, y+j*size, size, size, color);
- }
- }
- line >>= 1;
- }
- }
-}
-
-// draw a triangle!
-void TFTLCD::drawTriangle(uint16_t x0, uint16_t y0,
- uint16_t x1, uint16_t y1,
- uint16_t x2, uint16_t y2, uint16_t color)
-{
- drawLine(x0, y0, x1, y1, color);
- drawLine(x1, y1, x2, y2, color);
- drawLine(x2, y2, x0, y0, color);
-}
-
-void TFTLCD::fillTriangle ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint16_t color)
-{
- if (y0 > y1) {
- swap(y0, y1); swap(x0, x1);
- }
- if (y1 > y2) {
- swap(y2, y1); swap(x2, x1);
- }
- if (y0 > y1) {
- swap(y0, y1); swap(x0, x1);
- }
-
- int32_t dx1, dx2, dx3; // Interpolation deltas
- int32_t sx1, sx2, sy; // Scanline co-ordinates
-
- sx2=(int32_t)x0 * (int32_t)1000; // Use fixed point math for x axis values
- sx1 = sx2;
- sy=y0;
-
- // Calculate interpolation deltas
- if (y1-y0 > 0) dx1=((x1-x0)*1000)/(y1-y0);
- else dx1=0;
- if (y2-y0 > 0) dx2=((x2-x0)*1000)/(y2-y0);
- else dx2=0;
- if (y2-y1 > 0) dx3=((x2-x1)*1000)/(y2-y1);
- else dx3=0;
-
- // Render scanlines (horizontal lines are the fastest rendering method)
- if (dx1 > dx2)
- {
- for(; sy<=y1; sy++, sx1+=dx2, sx2+=dx1)
- {
- drawHorizontalLine(sx1/1000, sy, (sx2-sx1)/1000, color);
- }
- sx2 = x1*1000;
- sy = y1;
- for(; sy<=y2; sy++, sx1+=dx2, sx2+=dx3)
- {
- drawHorizontalLine(sx1/1000, sy, (sx2-sx1)/1000, color);
- }
- }
- else
- {
- for(; sy<=y1; sy++, sx1+=dx1, sx2+=dx2)
- {
- drawHorizontalLine(sx1/1000, sy, (sx2-sx1)/1000, color);
- }
- sx1 = x1*1000;
- sy = y1;
- for(; sy<=y2; sy++, sx1+=dx3, sx2+=dx2)
- {
- drawHorizontalLine(sx1/1000, sy, (sx2-sx1)/1000, color);
- }
- }
-}
-uint16_t TFTLCD::Color565(uint8_t r, uint8_t g, uint8_t b) {
+uint16_t Adafruit_TFTLCD::Color565(uint8_t r, uint8_t g, uint8_t b) {
uint16_t c;
c = r >> 3;
c <<= 6;
@@ -196,155 +74,29 @@ uint16_t TFTLCD::Color565(uint8_t r, uint8_t g, uint8_t b) {
return c;
}
-// draw a rectangle
-void TFTLCD::drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
- uint16_t color) {
- // smarter version
- drawHorizontalLine(x, y, w, color);
- drawHorizontalLine(x, y+h-1, w, color);
- drawVerticalLine(x, y, h, color);
- drawVerticalLine(x+w-1, y, h, color);
-}
-
-// draw a rounded rectangle
-void TFTLCD::drawRoundRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r,
- uint16_t color) {
- // smarter version
- drawHorizontalLine(x+r, y, w-2*r, color);
- drawHorizontalLine(x+r, y+h-1, w-2*r, color);
- drawVerticalLine(x, y+r, h-2*r, color);
- drawVerticalLine(x+w-1, y+r, h-2*r, color);
- // draw four corners
- drawCircleHelper(x+r, y+r, r, 1, color);
- drawCircleHelper(x+w-r-1, y+r, r, 2, color);
- drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
- drawCircleHelper(x+r, y+h-r-1, r, 8, color);
-}
-
-
-// fill a rounded rectangle
-void TFTLCD::fillRoundRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r,
- uint16_t color) {
- // smarter version
- fillRect(x+r, y, w-2*r, h, color);
-
- // draw four corners
- fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
- fillCircleHelper(x+r, y+r, r, 2, h-2*r-1, color);
-}
-
-// fill a circle
-void TFTLCD::fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) {
- writeRegister(TFTLCD_ENTRY_MOD, 0x1030);
- drawVerticalLine(x0, y0-r, 2*r+1, color);
- fillCircleHelper(x0, y0, r, 3, 0, color);
-}
-
-
-// used to do circles and roundrects!
-void TFTLCD::fillCircleHelper(uint16_t x0, uint16_t y0, uint16_t r, uint8_t cornername, uint16_t delta,
- uint16_t color) {
-
- int16_t f = 1 - r;
- int16_t ddF_x = 1;
- int16_t ddF_y = -2 * r;
- int16_t x = 0;
- int16_t y = r;
-
- while (x<y) {
- if (f >= 0) {
- y--;
- ddF_y += 2;
- f += ddF_y;
- }
- x++;
- ddF_x += 2;
- f += ddF_x;
-
- if (cornername & 0x1) {
- drawVerticalLine(x0+x, y0-y, 2*y+1+delta, color);
- drawVerticalLine(x0+y, y0-x, 2*x+1+delta, color);
- }
- if (cornername & 0x2) {
- drawVerticalLine(x0-x, y0-y, 2*y+1+delta, color);
- drawVerticalLine(x0-y, y0-x, 2*x+1+delta, color);
- }
- }
-}
-
-
-// draw a circle outline
-
-void TFTLCD::drawCircle(uint16_t x0, uint16_t y0, uint16_t r,
- uint16_t color) {
- drawPixel(x0, y0+r, color);
- drawPixel(x0, y0-r, color);
- drawPixel(x0+r, y0, color);
- drawPixel(x0-r, y0, color);
-
- drawCircleHelper(x0, y0, r, 0xF, color);
-}
-
-void TFTLCD::drawCircleHelper(uint16_t x0, uint16_t y0, uint16_t r, uint8_t cornername,
- uint16_t color) {
- int16_t f = 1 - r;
- int16_t ddF_x = 1;
- int16_t ddF_y = -2 * r;
- int16_t x = 0;
- int16_t y = r;
-
-
- while (x<y) {
- if (f >= 0) {
- y--;
- ddF_y += 2;
- f += ddF_y;
- }
- x++;
- ddF_x += 2;
- f += ddF_x;
- if (cornername & 0x4) {
- drawPixel(x0 + x, y0 + y, color);
- drawPixel(x0 + y, y0 + x, color);
- }
- if (cornername & 0x2) {
- drawPixel(x0 + x, y0 - y, color);
- drawPixel(x0 + y, y0 - x, color);
- }
- if (cornername & 0x8) {
- drawPixel(x0 - y, y0 + x, color);
- drawPixel(x0 - x, y0 + y, color);
- }
- if (cornername & 0x1) {
- drawPixel(x0 - y, y0 - x, color);
- drawPixel(x0 - x, y0 - y, color);
- }
- }
-}
-
// fill a rectangle
-void TFTLCD::fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
+void Adafruit_TFTLCD::fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
uint16_t fillcolor) {
// smarter version
while (h--)
- drawHorizontalLine(x, y++, w, fillcolor);
+ drawFastHLine(x, y++, w, fillcolor);
}
-void TFTLCD::drawVerticalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
+void Adafruit_TFTLCD::drawFastVLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
{
if (x >= _width) return;
drawFastLine(x,y,length,color,1);
}
-void TFTLCD::drawHorizontalLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
+void Adafruit_TFTLCD::drawFastHLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
{
if (y >= _height) return;
drawFastLine(x,y,length,color,0);
}
-void TFTLCD::drawFastLine(uint16_t x, uint16_t y, uint16_t length,
+void Adafruit_TFTLCD::drawFastLine(uint16_t x, uint16_t y, uint16_t length,
uint16_t color, uint8_t rotflag)
{
uint16_t newentrymod;
@@ -412,52 +164,9 @@ void TFTLCD::drawFastLine(uint16_t x, uint16_t y, uint16_t length,
-// bresenham's algorithm - thx wikpedia
-void TFTLCD::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
- uint16_t color) {
- // if you're in rotation 1 or 3, we need to swap the X and Y's
-
- int16_t steep = abs(y1 - y0) > abs(x1 - x0);
- if (steep) {
- swap(x0, y0);
- swap(x1, y1);
- }
-
- if (x0 > x1) {
- swap(x0, x1);
- swap(y0, y1);
- }
-
- int16_t dx, dy;
- dx = x1 - x0;
- //dy = abs(y1 - y0);
- dy = abs(y1 - y0);
-
- int16_t err = dx / 2;
- int16_t ystep;
-
- if (y0 < y1) {
- ystep = 1;
- } else {
- ystep = -1;}
- for (; x0<=x1; x0++) {
- if (steep) {
- drawPixel(y0, x0, color);
- } else {
- drawPixel(x0, y0, color);
- }
- err -= dy;
- if (err < 0) {
- y0 += ystep;
- err += dx;
- }
- }
-}
-
-
-void TFTLCD::fillScreen(uint16_t color) {
- goHome();
+void Adafruit_TFTLCD::fillScreen(uint16_t color) {
+ goTo(0,0);
uint32_t i;
i = 320;
@@ -481,7 +190,7 @@ void TFTLCD::fillScreen(uint16_t color) {
//digitalWrite(_cs, HIGH);
}
-void TFTLCD::drawPixel(uint16_t x, uint16_t y, uint16_t color)
+void Adafruit_TFTLCD::drawPixel(uint16_t x, uint16_t y, uint16_t color)
{
// check rotation, move pixel around if necessary
switch (rotation) {
@@ -577,7 +286,9 @@ static const uint16_t _regValues[] PROGMEM = {
TFTLCD_DISP_CTRL1, 0x0133, // Display Control (R07h)
};
-void TFTLCD::initDisplay(void) {
+void Adafruit_TFTLCD::begin(void) {
+ constructor(240,320);
+
uint16_t a, d;
reset();
@@ -596,38 +307,9 @@ void TFTLCD::initDisplay(void) {
}
}
-uint8_t TFTLCD::getRotation(void) {
- return rotation;
-}
-
-void TFTLCD::setRotation(uint8_t x) {
- writeRegister(TFTLCD_ENTRY_MOD, 0x1030);
-
- x %= 4; // cant be higher than 3
- rotation = x;
- switch (x) {
- case 0:
- _width = TFTWIDTH;
- _height = TFTHEIGHT;
- break;
- case 1:
- _width = TFTHEIGHT;
- _height = TFTWIDTH;
- break;
- case 2:
- _width = TFTWIDTH;
- _height = TFTHEIGHT;
- break;
- case 3:
- _width = TFTHEIGHT;
- _height = TFTWIDTH;
- break;
- }
-}
-
/********************************* low level pin initialization */
-TFTLCD::TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset) {
+Adafruit_TFTLCD::Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset) {
_cs = cs;
_cd = cd;
_wr = wr;
@@ -664,6 +346,8 @@ TFTLCD::TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset) {
wrpin = digitalPinToBitMask(_wr);
rdpin = digitalPinToBitMask(_rd);
+ wrportreg = portOutputRegister(wrport);
+
cursor_y = cursor_x = 0;
textsize = 1;
textcolor = 0xFFFF;
@@ -672,7 +356,7 @@ TFTLCD::TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset) {
/********************************** low level pin interface */
-void TFTLCD::reset(void) {
+void Adafruit_TFTLCD::reset(void) {
if (_reset)
digitalWrite(_reset, LOW);
delay(2);
@@ -686,7 +370,7 @@ void TFTLCD::reset(void) {
writeData(0);
}
-inline void TFTLCD::setWriteDir(void) {
+inline void Adafruit_TFTLCD::setWriteDir(void) {
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328__) || defined(__AVR_ATmega8__)
DATADDR2 |= DATA2_MASK;
DATADDR1 |= DATA1_MASK;
@@ -704,7 +388,7 @@ inline void TFTLCD::setWriteDir(void) {
#endif
}
-inline void TFTLCD::setReadDir(void) {
+inline void Adafruit_TFTLCD::setReadDir(void) {
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328) || (__AVR_ATmega8__)
DATADDR2 &= ~DATA2_MASK;
DATADDR1 &= ~DATA1_MASK;
@@ -722,7 +406,7 @@ inline void TFTLCD::setReadDir(void) {
#endif
}
-inline void TFTLCD::write8(uint8_t d) {
+inline void Adafruit_TFTLCD::write8(uint8_t d) {
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328) || (__AVR_ATmega8__)
DATAPORT2 = (DATAPORT2 & DATA1_MASK) |
@@ -760,7 +444,7 @@ inline void TFTLCD::write8(uint8_t d) {
#endif
}
-inline uint8_t TFTLCD::read8(void) {
+inline uint8_t Adafruit_TFTLCD::read8(void) {
uint8_t d;
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328) || (__AVR_ATmega8__)
@@ -799,91 +483,137 @@ inline uint8_t TFTLCD::read8(void) {
/********************************** low level readwrite interface */
// the C/D pin is high during write
-void TFTLCD::writeData(uint16_t data) {
- volatile uint8_t *wrportreg = portOutputRegister(wrport);
+void Adafruit_TFTLCD::writeData(uint16_t data) {
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT |= _BV(WRPIN);
+ CSPORT &= ~_BV(CSPIN);
+ CDPORT |= _BV(CDPIN);
+ RDPORT |= _BV(RDPIN);
+#else
+ *wrportreg |= wrpin;
+ //digitalWrite(_wr, HIGH);
*portOutputRegister(csport) &= ~cspin;
//digitalWrite(_cs, LOW);
*portOutputRegister(cdport) |= cdpin;
//digitalWrite(_cd, HIGH);
*portOutputRegister(rdport) |= rdpin;
//digitalWrite(_rd, HIGH);
-
- *wrportreg |= wrpin;
- //digitalWrite(_wr, HIGH);
+#endif
setWriteDir();
write8(data >> 8);
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT &= ~_BV(WRPIN);
+ WRPORT |= _BV(WRPIN);
+#else
*wrportreg &= ~wrpin;
//digitalWrite(_wr, LOW);
*wrportreg |= wrpin;
//digitalWrite(_wr, HIGH);
+#endif
write8(data);
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT &= ~_BV(WRPIN);
+ WRPORT |= _BV(WRPIN);
+#else
*wrportreg &= ~wrpin;
//digitalWrite(_wr, LOW);
*wrportreg |= wrpin;
//digitalWrite(_wr, HIGH);
+#endif
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ CSPORT |= _BV(CSPIN);
+#else
*portOutputRegister(csport) |= cspin;
//digitalWrite(_cs, HIGH);
+#endif
}
// this is a 'sped up' version, with no direction setting, or pin initialization
// not for external usage, but it does speed up stuff like a screen fill
-inline void TFTLCD::writeData_unsafe(uint16_t data) {
- volatile uint8_t *wrportreg = portOutputRegister(wrport);
-
+inline void Adafruit_TFTLCD::writeData_unsafe(uint16_t data) {
write8(data >> 8);
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT &= ~_BV(WRPIN);
+ WRPORT |= _BV(WRPIN);
+#else
*wrportreg &= ~wrpin;
//digitalWrite(_wr, LOW);
*wrportreg |= wrpin;
//digitalWrite(_wr, HIGH);
+#endif
write8(data);
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT &= ~_BV(WRPIN);
+ WRPORT |= _BV(WRPIN);
+#else
*wrportreg &= ~wrpin;
//digitalWrite(_wr, LOW);
*wrportreg |= wrpin;
//digitalWrite(_wr, HIGH);
+#endif
}
// the C/D pin is low during write
-void TFTLCD::writeCommand(uint16_t cmd) {
- volatile uint8_t *wrportreg = portOutputRegister(wrport);
-
+void Adafruit_TFTLCD::writeCommand(uint16_t cmd) {
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT |= _BV(WRPIN);
+ CSPORT &= ~_BV(CSPIN);
+ CDPORT &= ~_BV(CDPIN);
+ RDPORT |= _BV(RDPIN);
+#else
+ *wrportreg |= wrpin;
+ //digitalWrite(_wr, HIGH);
*portOutputRegister(csport) &= ~cspin;
//digitalWrite(_cs, LOW);
*portOutputRegister(cdport) &= ~cdpin;
- //digitalWrite(_cd, LOW);
+ //digitalWrite(_cd, HIGH);
*portOutputRegister(rdport) |= rdpin;
//digitalWrite(_rd, HIGH);
-
- *wrportreg |= wrpin;
- //digitalWrite(_wr, HIGH);
+#endif
setWriteDir();
write8(cmd >> 8);
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT &= ~_BV(WRPIN);
+ WRPORT |= _BV(WRPIN);
+#else
*wrportreg &= ~wrpin;
//digitalWrite(_wr, LOW);
*wrportreg |= wrpin;
//digitalWrite(_wr, HIGH);
+#endif
write8(cmd);
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ WRPORT &= ~_BV(WRPIN);
+ WRPORT |= _BV(WRPIN);
+#else
*wrportreg &= ~wrpin;
//digitalWrite(_wr, LOW);
*wrportreg |= wrpin;
//digitalWrite(_wr, HIGH);
+#endif
+#ifdef USE_ADAFRUIT_SHIELD_PINOUT
+ CSPORT |= _BV(CSPIN);
+#else
*portOutputRegister(csport) |= cspin;
+ //digitalWrite(_cs, HIGH);
+#endif
}
-uint16_t TFTLCD::readData() {
+uint16_t Adafruit_TFTLCD::readData() {
uint16_t d = 0;
*portOutputRegister(csport) &= ~cspin;
@@ -924,12 +654,12 @@ uint16_t TFTLCD::readData() {
/************************************* medium level data reading/writing */
-uint16_t TFTLCD::readRegister(uint16_t addr) {
+uint16_t Adafruit_TFTLCD::readRegister(uint16_t addr) {
writeCommand(addr);
return readData();
}
-void TFTLCD::writeRegister(uint16_t addr, uint16_t data) {
+void Adafruit_TFTLCD::writeRegister(uint16_t addr, uint16_t data) {
writeCommand(addr);
writeData(data);
}
View
57 TFTLCD.h → Adafruit_TFTLCD.h
@@ -7,8 +7,10 @@
#include "WProgram.h"
#endif
+#include <Adafruit_GFX.h>
+
// comment or uncomment the next line for special pinout!
-//#define USE_ADAFRUIT_SHIELD_PINOUT
+#define USE_ADAFRUIT_SHIELD_PINOUT
// register names from Peter Barrett's Microtouch code
@@ -68,53 +70,24 @@
#define swap(a, b) { int16_t t = a; a = b; b = t; }
-class TFTLCD : public Print {
+class Adafruit_TFTLCD : public Adafruit_GFX {
public:
- TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset);
+ Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset);
uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
// drawing primitives!
void drawPixel(uint16_t x, uint16_t y, uint16_t color);
void fillScreen(uint16_t color);
- void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
- void drawFastLine(uint16_t x0, uint16_t y0, uint16_t l, uint16_t color, uint8_t flag);
- void drawVerticalLine(uint16_t x0, uint16_t y0, uint16_t length, uint16_t color);
- void drawHorizontalLine(uint16_t x0, uint16_t y0, uint16_t length, uint16_t color);
- void drawTriangle(uint16_t x0, uint16_t y0,
- uint16_t x1, uint16_t y1,
- uint16_t x2, uint16_t y2, uint16_t color);
- void fillTriangle(int32_t x0, int32_t y0,
- int32_t x1, int32_t y1,
- int32_t x2, int32_t y2,
- uint16_t color);
- void drawRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
- void fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
- void drawRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);
- void fillRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);
- void drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
- void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
-
- void setCursor(uint16_t x, uint16_t y);
- void setTextColor(uint16_t c);
- void setTextSize(uint8_t s);
-#if ARDUINO >= 100
- virtual size_t write(uint8_t);
-#else
- virtual void write(uint8_t);
-#endif
+ void drawFastVLine(uint16_t x0, uint16_t y0, uint16_t length, uint16_t color);
+ void drawFastHLine(uint16_t x0, uint16_t y0, uint16_t length, uint16_t color);
- void drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint8_t s = 1);
- void drawString(uint16_t x, uint16_t y, char *c, uint16_t color, uint8_t s = 1);
+ void fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
// commands
- void initDisplay(void);
- void goHome(void);
+ void begin(void);
void goTo(int x, int y);
-
void reset(void);
- void setRotation(uint8_t x);
- uint8_t getRotation();
/* low level */
@@ -124,10 +97,6 @@ class TFTLCD : public Print {
uint16_t readRegister(uint16_t addr);
void writeRegister(uint16_t addr, uint16_t data);
-
- uint16_t width();
- uint16_t height();
-
static const uint16_t TFTWIDTH = 240;
static const uint16_t TFTHEIGHT = 320;
@@ -140,8 +109,7 @@ class TFTLCD : public Print {
void write8(uint8_t d);
private:
- void drawCircleHelper(uint16_t x0, uint16_t y0, uint16_t r, uint8_t corner, uint16_t color);
- void fillCircleHelper(uint16_t x0, uint16_t y0, uint16_t r, uint8_t corner, uint16_t delta, uint16_t color);
+ void drawFastLine(uint16_t x0, uint16_t y0, uint16_t l, uint16_t color, uint8_t flag);
uint8_t read8(void);
@@ -150,9 +118,4 @@ class TFTLCD : public Print {
uint8_t csport, cdport, wrport, rdport;
uint8_t cspin, cdpin, wrpin, rdpin;
- uint16_t _width, _height;
- uint8_t textsize;
- uint16_t cursor_x, cursor_y;
- uint16_t textcolor;
- uint8_t rotation;
};
View
22 examples/graphicstest/graphicstest.pde
@@ -1,6 +1,7 @@
// The control pins can connect to any pins but we'll use the
// analog lines since that means we can 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
@@ -33,9 +34,11 @@ For Mega's use pins 22 thru 29 (on the double header at the end)
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
-#include "TFTLCD.h"
+#include "Adafruit_TFTLCD.h"
+#include <Adafruit_GFX.h>
+
-TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
+Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup(void) {
Serial.begin(9600);
@@ -55,13 +58,19 @@ void setup(void) {
while (1);
}
- tft.initDisplay();
+ tft.begin();
+ uint32_t time = millis();
testtext(RED);
+ Serial.println(millis() - time);
delay(2000);
+ time = millis();
testlines(CYAN);
+ Serial.println(millis() - time);
delay(500);
+ time = millis();
testfastlines(RED, BLUE);
+ Serial.println(millis() - time);
delay(500);
testdrawrects(GREEN);
delay(500);
@@ -78,6 +87,7 @@ void setup(void) {
testRoundRect();
delay(500);
testFillRoundRect();
+
}
void loop(void) {
@@ -176,10 +186,10 @@ void testdrawrects(uint16_t color) {
void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(BLACK);
for (uint16_t y=0; y < tft.height(); y+=5) {
- tft.drawHorizontalLine(0, y, tft.width(), color1);
+ tft.drawFastHLine(0, y, tft.width(), color1);
}
for (uint16_t x=0; x < tft.width(); x+=5) {
- tft.drawVerticalLine(x, 0, tft.height(), color2);
+ tft.drawFastVLine(x, 0, tft.height(), color2);
}
}
@@ -235,4 +245,4 @@ void testBars() {
else tft.writeData(BLACK);
}
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.