From 466451583e5646a0ac2f9e2e78fe1b9a2e3218ac Mon Sep 17 00:00:00 2001 From: Bla Date: Sun, 24 Jul 2016 10:56:39 +0200 Subject: [PATCH 1/5] Examples projects changed from .pde to .ino. --- examples/graphicstest/{graphicstest.pde => graphicstest.ino} | 0 examples/rotationtest/{rotationtest.pde => rotationtest.ino} | 0 examples/tftbmp/{tftbmp.pde => tftbmp.ino} | 0 examples/tftbmp_shield/{tftbmp_shield.pde => tftbmp_shield.ino} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename examples/graphicstest/{graphicstest.pde => graphicstest.ino} (100%) rename examples/rotationtest/{rotationtest.pde => rotationtest.ino} (100%) rename examples/tftbmp/{tftbmp.pde => tftbmp.ino} (100%) rename examples/tftbmp_shield/{tftbmp_shield.pde => tftbmp_shield.ino} (100%) diff --git a/examples/graphicstest/graphicstest.pde b/examples/graphicstest/graphicstest.ino similarity index 100% rename from examples/graphicstest/graphicstest.pde rename to examples/graphicstest/graphicstest.ino diff --git a/examples/rotationtest/rotationtest.pde b/examples/rotationtest/rotationtest.ino similarity index 100% rename from examples/rotationtest/rotationtest.pde rename to examples/rotationtest/rotationtest.ino diff --git a/examples/tftbmp/tftbmp.pde b/examples/tftbmp/tftbmp.ino similarity index 100% rename from examples/tftbmp/tftbmp.pde rename to examples/tftbmp/tftbmp.ino diff --git a/examples/tftbmp_shield/tftbmp_shield.pde b/examples/tftbmp_shield/tftbmp_shield.ino similarity index 100% rename from examples/tftbmp_shield/tftbmp_shield.pde rename to examples/tftbmp_shield/tftbmp_shield.ino From b34bafb849119842738b346cdf974cf3ce14ce59 Mon Sep 17 00:00:00 2001 From: Bla Date: Sun, 24 Jul 2016 11:42:38 +0200 Subject: [PATCH 2/5] Bugfix reset signal. According to the ILI9341 datasheet, a delay of at least 5ms is required after releasing the RESET signal before sending commands. Some displays won't start after power-on without this delay. --- Adafruit_TFTLCD.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index 69f6a83..6ce9024 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -360,6 +360,12 @@ void Adafruit_TFTLCD::reset(void) { delay(2); digitalWrite(_reset, HIGH); } + + // According to the ILI9341 datasheet, a delay of at least 5ms is + // required after releasing the RESET signal before sending + // commands. Some displays won't start after power-on without this + // delay. + delay(5); #endif // Data transfer sync From 1b38cba621cd5cfa80a562dcaae0bc16e5ed1fc2 Mon Sep 17 00:00:00 2001 From: Erriez Date: Sun, 24 Jul 2016 13:56:16 +0200 Subject: [PATCH 3/5] ILI9341 display intialization comments added. --- Adafruit_TFTLCD.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index 6ce9024..ee2ff97 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -274,25 +274,102 @@ void Adafruit_TFTLCD::begin(uint16_t id) { uint16_t a, d; driver = ID_9341; CS_ACTIVE; + + /* Software Reset (01h) + * TODO: This register does not accept parameters + */ writeRegister8(ILI9341_SOFTRESET, 0); + /* Worst case delay after soft reset */ delay(50); + + /* Display OFF (28h) + * TODO: This register does not accept parameters + */ writeRegister8(ILI9341_DISPLAYOFF, 0); + /* Power Control 1 (C0h) + * Reset value: 21h + * - D[5:0]: VRH[5:0] = 6'b100011: 4.60 V + * Set the GVDD level, which is a reference level for the VCOM + * level and the grayscale voltage level. + */ writeRegister8(ILI9341_POWERCONTROL1, 0x23); + + /* Power Control 2 (C1h) + * Reset value: 10h: + * - D[4]: = 1'b1 + * - D[2:0]: BT[2:0] = 3'b000: + * - Sets the factor used in the step-up circuits. + * - AVDD: VCIx2 + * - VGH: VCHx7 + * - VGL: -VCIx4 + */ writeRegister8(ILI9341_POWERCONTROL2, 0x10); + + /* VCOM Control 1 (C5h) + * Reset value: 313Ch + * - D[7:0]: VMH[6:0] = 7'b00101011: VCOMH = 3.775V + * - D[15:8]: VML[6:0] = 7'b00101011: VCOML = -1.425V + */ writeRegister16(ILI9341_VCOMCONTROL1, 0x2B2B); + + /* VCOM Control 2 (C7h) + * Reset value: C0h + * - D[7]: nVM = 1'b1 VMF [6:0] becomes valid + * - D[6:0]: VMF[6:0] = 7'b1000000 VCOMH = VMH; VCOML = VML + */ writeRegister8(ILI9341_VCOMCONTROL2, 0xC0); + + /* Memory Access Control (36h) + * Reset value: 00h + * - D[7]: MY = 1'b1 Row Address Order + * - D[6]: MX = 1'b0 Column Address Order + * - D[5]: MV = 1'b0 Row / Column Exchange + * - D[4]: ML = 1'b0 Vertical Refresh Order + * - D[3]: BGR = 1'b1 RGB-BGR Order: BGR color filter panel + * - D[2]: MH = 1'b0 Horizontal Refresh ORDER + */ writeRegister8(ILI9341_MEMCONTROL, ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR); + + /* COLMOD: Pixel Format Set (3Ah) + * Reset value: 66h + * - D[6:4]: DPI[2:0] = 3'b101 16 bits / pixel + * - D[2:0]: DBI[2:0] = 3'b101 16 bits / pixel + */ writeRegister8(ILI9341_PIXELFORMAT, 0x55); + + /* Frame Rate Control (In Normal Mode/Full Colors) (B1h) + * Reset value: 001Bh + * D[1:0]: DIVA[1:0] = 2'b00 Division Ratio = fosc + * D[12:8]: RTNA[4:0] = 5'b11011 Frame Rate: 70Hz (default) + */ writeRegister16(ILI9341_FRAMECONTROL, 0x001B); + /* Entry Mode Set (B7h) + * Reset value: 06h + * D[3]: DSTB = 1'b0 Deep Standby Mode: Disable + * D[2]: GON = 1'b1 G1~G320 Gate Output: Normal display + * D[1]: DTE = 1'b1 G1~G320 Gate Output: Normal display + * D[0]: GAS = 1'b1 Low voltage detection: Disable + */ writeRegister8(ILI9341_ENTRYMODE, 0x07); + + /* Display Function Control (B6h) */ /* writeRegister32(ILI9341_DISPLAYFUNC, 0x0A822700);*/ + /* Enter Sleep Mode (10h) + * TODO: This register does not accept parameters + */ writeRegister8(ILI9341_SLEEPOUT, 0); delay(150); + + /* Display ON (29h) + * TODO: This register does not accept parameters + */ writeRegister8(ILI9341_DISPLAYON, 0); delay(500); + + /* Configure Column Address Set (2Ah) and Page Address Set (2Bh) */ setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1); return; From 48936eaa93017083f7635a282e3810bc384ba686 Mon Sep 17 00:00:00 2001 From: Erriez Date: Sun, 24 Jul 2016 16:51:17 +0200 Subject: [PATCH 4/5] Fixed Arduino pin numbers in examples when macro USE_ADAFRUIT_SHIELD_PINOUT enabled. Pin number comments added. --- examples/graphicstest/graphicstest.ino | 6 +- examples/rotationtest/rotationtest.ino | 6 +- examples/tftbmp/tftbmp.ino | 6 +- examples/tftpaint/tftpaint.ino | 6 +- pin_magic.h | 116 +++++++++++++++++++++---- 5 files changed, 112 insertions(+), 28 deletions(-) diff --git a/examples/graphicstest/graphicstest.ino b/examples/graphicstest/graphicstest.ino index 14701c7..05f1d48 100755 --- a/examples/graphicstest/graphicstest.ino +++ b/examples/graphicstest/graphicstest.ino @@ -19,10 +19,10 @@ // 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 +// D2 connects to digital pin 10 +// D3 connects to digital pin 11 // D4 connects to digital pin 4 -// D5 connects to digital pin 5 +// D5 connects to digital pin 13 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 diff --git a/examples/rotationtest/rotationtest.ino b/examples/rotationtest/rotationtest.ino index 7b83622..a222496 100644 --- a/examples/rotationtest/rotationtest.ino +++ b/examples/rotationtest/rotationtest.ino @@ -19,10 +19,10 @@ // 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 +// D2 connects to digital pin 10 +// D3 connects to digital pin 11 // D4 connects to digital pin 4 -// D5 connects to digital pin 5 +// D5 connects to digital pin 13 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 diff --git a/examples/tftbmp/tftbmp.ino b/examples/tftbmp/tftbmp.ino index 8979ed1..3e471dc 100755 --- a/examples/tftbmp/tftbmp.ino +++ b/examples/tftbmp/tftbmp.ino @@ -20,10 +20,10 @@ // 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 +// D2 connects to digital pin 10 +// D3 connects to digital pin 11 // D4 connects to digital pin 4 -// D5 connects to digital pin 5 +// D5 connects to digital pin 13 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 diff --git a/examples/tftpaint/tftpaint.ino b/examples/tftpaint/tftpaint.ino index 0380b2c..e4dad03 100644 --- a/examples/tftpaint/tftpaint.ino +++ b/examples/tftpaint/tftpaint.ino @@ -15,10 +15,10 @@ // 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 +// D2 connects to digital pin 10 +// D3 connects to digital pin 11 // D4 connects to digital pin 4 -// D5 connects to digital pin 5 +// D5 connects to digital pin 13 // D6 connects to digital pin 6 // D7 connects to digital pin 7 diff --git a/pin_magic.h b/pin_magic.h index 443dc91..82baf64 100644 --- a/pin_magic.h +++ b/pin_magic.h @@ -68,12 +68,33 @@ #ifdef USE_ADAFRUIT_SHIELD_PINOUT + // Display - Arduino port/pins: + // +---------+--------+---------+------+ + // | Display | Analog | Arduino | IC | + // | | Touch | pin | pin | + // +---------+--------+---------+------+ + // | RD | - | A0 | PC0 | + // | WR | - | A1 | PC1 | + // | RS | XM | A2 | PC2 | + // | CS | YP | A3 | PC3 | + // | RESET | - | A4 | PC4 | + // | | | | | + // | D0 | XP | 8 | PB0 | + // | D1 | YM | 9 | PB1 | + // | D2 | | 10 | PB2 | + // | D3 | | 11 | PB3 | + // | D4 | | 4 | PD4 | + // | D5 | | 13 | PB5 | + // | D6 | | 6 | PD6 | + // | D7 | | 7 | PD7 | + // +---------+--------+---------+------+ + // LCD control lines: // RD (read), WR (write), CD (command/data), CS (chip select) - #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_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 @@ -107,6 +128,27 @@ #else // Uno w/Breakout board + // Display - Arduino port/pins: + // +---------+--------+---------+------+ + // | Display | Analog | Arduino | IC | + // | | Touch | pin | pin | + // +---------+--------+---------+------+ + // | RD | - | A0 | PC0 | + // | WR | - | A1 | PC1 | + // | RS | XM | A2 | PC2 | + // | CS | YP | A3 | PC3 | + // | RESET | - | A4 | PC4 | + // | | | | | + // | D0 | XP | 8 | PB0 | + // | D1 | YM | 9 | PB1 | + // | D2 | | 2 | PD2 | + // | D3 | | 3 | PD3 | + // | D4 | | 4 | PD4 | + // | D5 | | 5 | PD5 | + // | D6 | | 6 | PD6 | + // | D7 | | 7 | PD7 | + // +---------+--------+---------+------+ + #define write8inline(d) { \ PORTD = (PORTD & B00000011) | ((d) & B11111100); \ PORTB = (PORTB & B11111100) | ((d) & B00000011); \ @@ -135,10 +177,31 @@ #ifdef USE_ADAFRUIT_SHIELD_PINOUT - #define RD_PORT PORTF - #define WR_PORT PORTF - #define CD_PORT PORTF - #define CS_PORT PORTF + // Display - Arduino port/pins: + // +---------+--------+---------+------+ + // | Display | Analog | Arduino | IC | + // | | Touch | pin | pin | + // +---------+--------+---------+------+ + // | RD | - | A0 | PC0 | + // | WR | - | A1 | PC1 | + // | RS | XM | A2 | PC2 | + // | CS | YP | A3 | PC3 | + // | RESET | - | A4 | PC4 | + // | | | | | + // | D0 | XP | 8 | PH5 | + // | D1 | YM | 9 | PH6 | + // | D2 | | 10 | PB4 | + // | D3 | | 11 | PB5 | + // | D4 | | 4 | PG5 | + // | D5 | | 13 | PB7 | + // | D6 | | 6 | PH3 | + // | D7 | | 7 | PH4 | + // +---------+--------+---------+------+ + + #define RD_PORT PORTF /* pin A0 */ + #define WR_PORT PORTF /* pin A1 */ + #define CD_PORT PORTF /* pin A2 */ + #define CS_PORT PORTF /* pin A3 */ #define RD_MASK B00000001 #define WR_MASK B00000010 #define CD_MASK B00000100 @@ -162,6 +225,27 @@ #else // Mega w/Breakout board + // Display - Arduino port/pins: + // +---------+--------+---------+------+ + // | Display | Analog | Arduino | IC | + // | | Touch | pin | pin | + // +---------+--------+---------+------+ + // | RD | - | A0 | PC0 | + // | WR | - | A1 | PC1 | + // | RS | XM | A2 | PC2 | + // | CS | YP | A3 | PC3 | + // | RESET | - | A4 | PC4 | + // | | | | | + // | D0 | XP | 22 | PA0 | + // | D1 | YM | 23 | PA1 | + // | D2 | | 24 | PA2 | + // | D3 | | 25 | PA3 | + // | D4 | | 26 | PA4 | + // | D5 | | 27 | PA5 | + // | D6 | | 28 | PA6 | + // | D7 | | 29 | PA7 | + // +---------+--------+---------+------+ + #define write8inline(d) { PORTA = (d); WR_STROBE; } #define read8inline(result) { \ RD_ACTIVE; \ @@ -193,10 +277,10 @@ #ifdef USE_ADAFRUIT_SHIELD_PINOUT - #define RD_PORT PORTF - #define WR_PORT PORTF - #define CD_PORT PORTF - #define CS_PORT PORTF + #define RD_PORT PORTF /* pin A0 */ + #define WR_PORT PORTF /* pin A1 */ + #define CD_PORT PORTF /* pin A2 */ + #define CS_PORT PORTF /* pin A3 */ #define RD_MASK B10000000 #define WR_MASK B01000000 #define CD_MASK B00100000 @@ -261,10 +345,10 @@ #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_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 From e959ea5f37e0fd4eea88c4e9acdb7afea8cb900c Mon Sep 17 00:00:00 2001 From: Erriez Date: Tue, 26 Jul 2016 21:44:17 +0200 Subject: [PATCH 5/5] ILI9341 read support added. --- Adafruit_TFTLCD.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Adafruit_TFTLCD.cpp b/Adafruit_TFTLCD.cpp index ee2ff97..323bc0c 100644 --- a/Adafruit_TFTLCD.cpp +++ b/Adafruit_TFTLCD.cpp @@ -950,6 +950,23 @@ uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) { return (((uint16_t)r & B11111000) << 8) | (((uint16_t)g & B11111100) << 3) | ( b >> 3); + } else if(driver == ID_9341) { + uint8_t r, g, b; + + setAddrWindow(x, y, _width-1, _height-1); + CS_ACTIVE; + CD_COMMAND; + write8(0x2E); + setReadDir(); // Set up LCD data port(s) for READ operations + CD_DATA; + read8(r); // First byte back is a dummy read + read8(r); + read8(g); + read8(b); + setWriteDir(); // Restore LCD data port(s) to WRITE configuration + return (((uint16_t)r & B11111000) << 8) | + (((uint16_t)g & B11111100) << 3) | + ( b >> 3); } else return 0; }