Permalink
Browse files

Tweaks for Adafruit_GFX

  • Loading branch information...
PaintYourDragon committed Apr 10, 2012
1 parent ce39dff commit ca4b16ac34711d203c54499ca49d6e0582545622
View
@@ -70,7 +70,7 @@ void Adafruit_TFTLCD::goTo(int x, int y) {
writeRegister8(HX8347G_COLADDREND2, 0);
writeRegister8(HX8347G_COLADDREND1, TFTWIDTH-1);
writeRegister8(HX8347G_ROWADDREND2, (TFTHEIGHT-1)>>8);
- writeRegister8(HX8347G_ROWADDREND1, (TFTHEIGHT-1));
+ writeRegister8(HX8347G_ROWADDREND1, (TFTHEIGHT-1)&0xFF);
writeCommand(0x0022); // Write Data to GRAM (R22h)
}
}
@@ -88,28 +88,28 @@ uint16_t Adafruit_TFTLCD::Color565(uint8_t r, uint8_t g, uint8_t b) {
}
// fill a rectangle
-void Adafruit_TFTLCD::fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
+void Adafruit_TFTLCD::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t fillcolor) {
// smarter version
while (h--)
drawFastHLine(x, y++, w, fillcolor);
}
-void Adafruit_TFTLCD::drawFastVLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
+void Adafruit_TFTLCD::drawFastVLine(int16_t x, int16_t y, int16_t length, uint16_t color)
{
if (x >= _width) return;
drawFastLine(x,y,length,color,1);
}
-void Adafruit_TFTLCD::drawFastHLine(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
+void Adafruit_TFTLCD::drawFastHLine(int16_t x, int16_t y, int16_t length, uint16_t color)
{
if (y >= _height) return;
drawFastLine(x,y,length,color,0);
}
-void Adafruit_TFTLCD::drawFastLine(uint16_t x, uint16_t y, uint16_t length,
+void Adafruit_TFTLCD::drawFastLine(int16_t x, int16_t y, int16_t length,
uint16_t color, uint8_t rotflag)
{
uint16_t newentrymod;
@@ -220,8 +220,10 @@ void Adafruit_TFTLCD::fillScreen(uint16_t color) {
*portOutputRegister(csport) |= cspin; //digitalWrite(_cs, HIGH);
}
-void Adafruit_TFTLCD::drawPixel(uint16_t x, uint16_t y, uint16_t color)
+void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color)
{
+ if ((x >= _width) || (y >= _height)) return;
+
// check rotation, move pixel around if necessary
switch (rotation) {
case 1:
@@ -238,8 +240,6 @@ void Adafruit_TFTLCD::drawPixel(uint16_t x, uint16_t y, uint16_t color)
break;
}
- if ((x >= TFTWIDTH) || (y >= TFTHEIGHT)) return;
-
if (driver == 0x9328 || driver == 0x9325) {
writeRegister16(ILI932X_GRAM_HOR_AD, x); // GRAM Address Set (Horizontal Address)
writeRegister16(ILI932X_GRAM_VER_AD, y); // GRAM Address Set (Vertical Address)
View
@@ -87,12 +87,12 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
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 drawPixel(int16_t x, int16_t y, uint16_t color);
void fillScreen(uint16_t color);
- 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 drawFastVLine(int16_t x0, int16_t y0, int16_t length, uint16_t color);
+ void drawFastHLine(int16_t x0, int16_t y0, int16_t length, uint16_t color);
- void fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
+ void fillRect(int16_t x0, int16_t y0, int16_t w, int16_t h, uint16_t color);
// commands
void begin(uint16_t id = 0x9325);
@@ -121,7 +121,7 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
private:
uint16_t driver;
- void drawFastLine(uint16_t x0, uint16_t y0, uint16_t l, uint16_t color, uint8_t flag);
+ void drawFastLine(int16_t x0, int16_t y0, int16_t l, uint16_t color, uint8_t flag);
uint8_t read8(void);
uint8_t _cs, _cd, _reset, _wr, _rd;
@@ -1,5 +1,5 @@
-#include "Adafruit_TFTLCD.h"
-#include <Adafruit_GFX.h>
+#include <Adafruit_GFX.h> // Core graphics library
+#include <Adafruit_TFTLCD.h> // Hardware-specific library
// The control pins can connect to any pins but we'll use the
// analog lines since that means we can double up the pins
@@ -109,22 +109,22 @@ void loop(void) {
void testFillRoundRect() {
tft.fillScreen(BLACK);
- for (uint16_t x=tft.width(); x > 20 ; x-=6) {
+ for (int16_t x=tft.width(); x > 20 ; x-=6) {
tft.fillRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.Color565(0, x, 0));
}
}
void testRoundRect() {
tft.fillScreen(BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.Color565(x, 0, 0));
}
}
void testtriangles() {
tft.fillScreen(BLACK);
- for (uint16_t i=0; i<tft.width()/2; i+=5) {
+ for (int16_t i=0; i<tft.width()/2; i+=5) {
tft.drawTriangle(tft.width()/2, tft.height()/2-i,
tft.width()/2-i, tft.height()/2+i,
tft.width()/2+i, tft.height()/2+i, tft.Color565(0, 0, i));
@@ -134,7 +134,7 @@ void testtriangles() {
void testfilltriangles() {
tft.fillScreen(BLACK);
- for (uint16_t i=tft.width()/2; i>10; i-=5) {
+ for (int16_t i=tft.width()/2; i>10; i-=5) {
tft.fillTriangle(tft.width()/2, tft.height()/2-i,
tft.width()/2-i, tft.height()/2+i,
tft.width()/2+i, tft.height()/2+i,
@@ -157,16 +157,16 @@ void testtext(uint16_t color) {
}
void testfillcircles(uint8_t radius, uint16_t color) {
- for (uint16_t x=radius; x < tft.width(); x+=radius*2) {
- for (uint16_t y=radius; y < tft.height(); y+=radius*2) {
+ for (int16_t x=radius; x < tft.width(); x+=radius*2) {
+ for (int16_t y=radius; y < tft.height(); y+=radius*2) {
tft.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
- for (uint16_t x=0; x < tft.width()+radius; x+=radius*2) {
- for (uint16_t y=0; y < tft.height()+radius; y+=radius*2) {
+ for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
+ for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
tft.drawCircle(x, y, radius, color);
}
}
@@ -175,7 +175,7 @@ void testdrawcircles(uint8_t radius, uint16_t color) {
void testfillrects(uint16_t color1, uint16_t color2) {
tft.fillScreen(BLACK);
- for (uint16_t x=tft.width()-1; x > 6; x-=6) {
+ for (int16_t x=tft.width()-1; x > 6; x-=6) {
//Serial.println(x, DEC);
tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
@@ -184,59 +184,59 @@ void testfillrects(uint16_t color1, uint16_t color2) {
void testdrawrects(uint16_t color) {
tft.fillScreen(BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
}
}
void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(BLACK);
- for (uint16_t y=0; y < tft.height(); y+=5) {
+ for (int16_t y=0; y < tft.height(); y+=5) {
tft.drawFastHLine(0, y, tft.width(), color1);
}
- for (uint16_t x=0; x < tft.width(); x+=5) {
+ for (int16_t x=0; x < tft.width(); x+=5) {
tft.drawFastVLine(x, 0, tft.height(), color2);
}
}
void testlines(uint16_t color) {
tft.fillScreen(BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, 0, x, tft.height()-1, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, 0, tft.width()-1, y, color);
}
tft.fillScreen(BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, 0, 0, y, color);
}
tft.fillScreen(BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, tft.height()-1, x, 0, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
}
tft.fillScreen(BLACK);
- for (uint16_t x=0; x < tft.width(); x+=6) {
+ for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
}
- for (uint16_t y=0; y < tft.height(); y+=6) {
+ for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
}
}
void testBars() {
- uint16_t i,j;
+ int16_t i,j;
for(i=0; i < tft.height(); i++)
{
for(j=0; j < tft.width(); j++)
@@ -251,4 +251,4 @@ void testBars() {
else tft.writeData(BLACK);
}
}
-}
+}
@@ -1,3 +1,6 @@
+#include <Adafruit_GFX.h> // Core graphics library
+#include <Adafruit_TFTLCD.h> // Hardware-specific library
+
// 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)
@@ -33,9 +36,6 @@ For Mega's use pins 22 thru 29 (on the double header at the end)
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
-#include "Adafruit_TFTLCD.h"
-#include "Adafruit_GFX.h"
-
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup(void) {
@@ -199,4 +199,4 @@ void rotatePixel(void) {
tft.setRotation(tft.getRotation()+1);
}
-}
+}
@@ -1,4 +1,7 @@
+#include <Adafruit_GFX.h> // Core graphics library
+#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <SD.h>
+
// 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)
@@ -28,9 +31,6 @@ For Mega's use pins 22 thru 29 (on the double header at the end)
// In the SD card, place 24 bit color BMP files (be sure they are 24-bit!)
// There are examples in the sketch folder
-#include "Adafruit_GFX.h"
-#include "Adafruit_TFTLCD.h"
-
// our TFT wiring
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, 0);
@@ -1,7 +1,7 @@
+#include <Adafruit_GFX.h> // Core graphics library
+#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <SD.h>
#include <SPI.h>
-#include "Adafruit_GFX.h"
-#include "Adafruit_TFTLCD.h"
#if not defined USE_ADAFRUIT_SHIELD_PINOUT
#error "For use with the shield, make sure to #define USE_ADAFRUIT_SHIELD_PINOUT in the TFTLCD.h library file"
@@ -1,6 +1,6 @@
-#include "Adafruit_GFX.h"
-#include "Adafruit_TFTLCD.h"
-#include "TouchScreen.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <Adafruit_TFTLCD.h> // Hardware-specific library
+#include <TouchScreen.h>
/* For the 8 data pins:
Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
@@ -175,4 +175,4 @@ void loop()
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
}
}
-}
+}
@@ -1,6 +1,6 @@
-#include "Adafruit_GFX.h"
-#include "Adafruit_TFTLCD.h"
-#include "TouchScreen.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <Adafruit_TFTLCD.h> // Hardware-specific library
+#include <TouchScreen.h>
#if not defined USE_ADAFRUIT_SHIELD_PINOUT
#error "For use with the shield, make sure to #define USE_ADAFRUIT_SHIELD_PINOUT in the TFTLCD.h library file"
@@ -159,4 +159,4 @@ void loop()
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
}
}
-}
+}

0 comments on commit ca4b16a

Please sign in to comment.