diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index 7ee270f..50f028e 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -1000,8 +1000,25 @@ uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) { CS_IDLE; return (((uint16_t)r & B11111000) << 8) | (((uint16_t)g & B11111100) << 3) | (b >> 3); - } else - return 0; + } else if(driver == ID_9341) { + uint8_t r, g, b; + setAddrWindow(x, y, width()-1, height()-1); + CS_ACTIVE; + CD_COMMAND; + write8(ILI9341_MEMORYREAD); + setReadDir(); + CD_DATA; + delayMicroseconds(50); + read8(r); + read8(r); + read8(g); + read8(b); + setWriteDir(); + CS_IDLE; + return (((uint16_t)r & B11111000) << 8) | (((uint16_t)g & B11111100) << 3) | + (b >> 3); + + } else return 0; } // Ditto with the read/write port directions, as above. diff --git a/pin_magic.h b/pin_magic.h index a6e9f11..dcfd322 100644 --- a/pin_magic.h +++ b/pin_magic.h @@ -202,21 +202,17 @@ } #else // Mega w/Breakout board - -#define write8inline(d) \ - { \ - PORTA = (d); \ - WR_STROBE; \ - } -#define read8inline(result) \ - { \ - RD_ACTIVE; \ - DELAY7; \ - result = PINA; \ - RD_IDLE; \ - } -#define setWriteDirInline() DDRA = 0xff -#define setReadDirInline() DDRA = 0 + #define write8inline(d) {\ + PORTH &= ~(0x78);\ + PORTH |= ((d&0xC0) >> 3) | ((d&0x3) << 5);\ + PORTE &= ~(0x38);\ + PORTE |= ((d & 0xC) << 2) | ((d & 0x20) >> 2);\ + PORTG &= ~(0x20);\ + PORTG |= (d & 0x10) << 1; \ + WR_STROBE; } + #define read8inline(result) { RD_ACTIVE; DELAY7; result = (PINH & 0x60) >> 5;result |= (PINH & 0x18) << 3;result |= (PINE & 0x8) << 2;result |= (PINE & 0x30) >> 2;result |= (PING & 0x20) >> 1;RD_IDLE;} + #define setWriteDirInline() { DDRH |= 0x78;DDRE |= 0x38;DDRG |= 0x20; } + #define setReadDirInline() { DDRH &= ~0x78;DDRE &= ~0x38;DDRG &= ~(0x20); } #endif diff --git a/registers.h b/registers.h index c8bb816..436285f 100644 --- a/registers.h +++ b/registers.h @@ -72,6 +72,7 @@ #define ILI9341_COLADDRSET 0x2A #define ILI9341_PAGEADDRSET 0x2B #define ILI9341_MEMORYWRITE 0x2C +#define ILI9341_MEMORYREAD 0x2E #define ILI9341_PIXELFORMAT 0x3A #define ILI9341_FRAMECONTROL 0xB1 #define ILI9341_DISPLAYFUNC 0xB6