BMP drawing working with HX chipset

This commit is contained in:
ladyada
2012-07-04 13:11:27 -04:00
parent 2938be3d5a
commit d44a453e17
3 changed files with 90 additions and 17 deletions
+50
View File
@@ -86,6 +86,22 @@ void Adafruit_TFTLCD::goTo(int x, int y) {
writeCommand(0x0022); // Write Data to GRAM (R22h)
}
}
void Adafruit_TFTLCD::setWindow(int x1, int y1, int x2, int y2) {
if (driver == 0x7575) {
writeRegister8(HX8347G_COLADDRSTART2, x1>>8);
writeRegister8(HX8347G_COLADDRSTART1, x1);
writeRegister8(HX8347G_ROWADDRSTART2, y1>>8);
writeRegister8(HX8347G_ROWADDRSTART1, y1);
writeRegister8(HX8347G_COLADDREND2, x2>>8);
writeRegister8(HX8347G_COLADDREND1, x2);
writeRegister8(HX8347G_ROWADDREND2, y2>>8);
writeRegister8(HX8347G_ROWADDREND1, y2);
writeCommand(0x0022); // Write Data to GRAM (R22h)
}
}
uint16_t Adafruit_TFTLCD::Color565(uint8_t r, uint8_t g, uint8_t b) {
@@ -292,6 +308,40 @@ void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color)
writeData(color);
}
uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y)
{
if ((x >= _width) || (y >= _height)) return 0;
// check rotation, move pixel around if necessary
switch (rotation) {
case 1:
swap(x, y);
x = TFTWIDTH - x - 1;
break;
case 2:
x = TFTWIDTH - x - 1;
y = TFTHEIGHT - y - 1;
break;
case 3:
swap(x, y);
y = TFTHEIGHT - y - 1;
break;
}
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)
writeCommand(ILI932X_RW_GRAM); // Read Data to GRAM
} else if (driver == 0x7575) {
writeRegister8(HX8347G_COLADDRSTART2, x >> 8);
writeRegister8(HX8347G_COLADDRSTART1, x & 0xFF);
writeRegister8(HX8347G_ROWADDRSTART2, y >> 8);
writeRegister8(HX8347G_ROWADDRSTART1, y & 0xFF);
writeCommand8(0x0022); // Read Data from GRAM (R22h)
}
return readData();
}
static const uint16_t HX8347G_regValues[] PROGMEM = {
0x2E, 0x89,
+4
View File
@@ -78,6 +78,8 @@
#define HX8347G_ROWADDREND2 0x08
#define HX8347G_ROWADDREND1 0x09
#define HX8347G_MEMACCESS 0x16
#define TFTLCD_DELAYCMD 0xFF
@@ -91,6 +93,7 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
// drawing primitives!
void drawPixel(int16_t x, int16_t y, uint16_t color);
uint16_t readPixel(int16_t x, int16_t y);
void fillScreen(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);
@@ -100,6 +103,7 @@ class Adafruit_TFTLCD : public Adafruit_GFX {
// commands
void begin(uint16_t id = 0x9325);
void goTo(int x, int y);
void setWindow(int x1, int y1, int x2, int y2);
void reset(void);
/* low level */
+36 -17
View File
@@ -43,6 +43,7 @@ void enableSPI(void) {
}
/******************************************/
uint16_t identifier;
void setup()
{
@@ -51,7 +52,7 @@ void setup()
tft.reset();
// find the TFT display
uint16_t identifier = tft.readRegister(0x0);
identifier = tft.readRegister(0x0);
if (identifier == 0x9325) {
Serial.println("Found ILI9325");
} else if (identifier == 0x9328) {
@@ -67,7 +68,7 @@ void setup()
tft.begin(identifier);
// the image is a landscape, so get into landscape mode
tft.setRotation(1);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
@@ -133,19 +134,36 @@ void bmpdraw(File f, int x, int y) {
for (i=0; i< bmpHeight; i++) {
// bitmaps are stored with the BOTTOM line first so we have to move 'up'
if (tft.getRotation() == 3) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1028);
tft.goTo(x+i, y);
} else if (tft.getRotation() == 2) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1020);
tft.goTo(x+bmpWidth, y+i);
} else if (tft.getRotation() == 1) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1018);
tft.goTo(x+bmpHeight-1-i, y);
} else if (tft.getRotation() == 0) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1030);
tft.goTo(x, y+bmpHeight-i);
if ((identifier == 0x9325) || (identifier == 0x9328)) {
if (tft.getRotation() == 3) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1028);
tft.goTo(x+i, y);
} else if (tft.getRotation() == 2) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1020);
tft.goTo(x+bmpWidth, y+i);
} else if (tft.getRotation() == 1) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1018);
tft.goTo(x+bmpHeight-1-i, y);
} else if (tft.getRotation() == 0) {
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1030);
tft.goTo(x, y+bmpHeight-i);
}
} else if (identifier == 0x7575) {
if (tft.getRotation() == 3) {
tft.writeRegister8(HX8347G_MEMACCESS, 0x20);
tft.setWindow(x, y+i, 319, y+i);
} else if (tft.getRotation() == 2) {
tft.writeRegister8(HX8347G_MEMACCESS, 0x40);
tft.goTo(x, y+i);
} else if (tft.getRotation() == 1) {
tft.writeRegister8(HX8347G_MEMACCESS, 0xA0);
tft.setWindow(x, y+bmpHeight-1-i, 319, y+bmpHeight-i);
} else if (tft.getRotation() == 0) {
tft.writeRegister8(HX8347G_MEMACCESS, 0x0);
tft.goTo(x, y+bmpHeight-i-1);
}
}
for (j=0; j<bmpWidth; j++) {
// read more pixels
@@ -171,11 +189,12 @@ void bmpdraw(File f, int x, int y) {
b >>= 3;
p |= b;
// write out the 16 bits of color
// write out the 16 bits of color
tft.writeData(p);
}
}
tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1030);
if (identifier == 0x7575) tft.writeRegister8(HX8347G_MEMACCESS, 0x0);
else tft.writeRegister16(ILI932X_ENTRY_MOD, 0x1030);
Serial.print(millis() - time, DEC);
Serial.println(" ms");
}
@@ -249,4 +268,4 @@ uint32_t read32(File f) {
d <<= 16;
d |= b;
return d;
}
}