Skip to content

Bugfix reset signal and .pde projects renamed to .ino #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Adafruit_TFTLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -360,6 +437,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
Expand Down Expand Up @@ -867,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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/tftbmp/tftbmp.pde → examples/tftbmp/tftbmp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/tftpaint/tftpaint.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
116 changes: 100 additions & 16 deletions pin_magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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
Expand All @@ -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; \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down