/*
/Newhaven Display invests time and resources providing this open source code,
/Please support Newhaven Display by purchasing products from Newhaven Display!
*
* This code is provided as an example only and without any warranty by Newhaven Display.
* Newhaven Display accepts no responsibility for any issues resulting from its use.
* The developer on the final application incorporating any parts of this
* sample code is responsible for ensuring its safe and correct operation
* and for any consequences resulting from its use.
* See the GNU General Public License for more details.
* ST7789VI Controller
* 8-bit Parallel Interface
*/
/****************************************************
* PINOUT: Arduino Due -> 2.4" TFT *
*****************************************************/
#define RS 2 // D/C
#define WR 11
// RD tied HIGH
// DB0-DB7 NC
// DB8 -> Pin 33
// DB9 -> Pin 34
// DB10 -> Pin 35
// DB11 -> Pin 36
// DB12 -> Pin 37
// DB13 -> Pin 38
// DB14 -> Pin 39
// DB15 -> Pin 40
// RES tied HIGH
// IM0 tied HIGH
/****************************************************
* Function Commands *
******************************************************/
void comm_out(unsigned char c)
{
PIOB -> PIO_CODR = 1 << 25; //RS LOW
REG_PIOC_ODSR = c << 1;
PIOD -> PIO_CODR = 1 << 7; //WR LOW
PIOD -> PIO_SODR = 1 << 7; //WR HIGH
}
void data_out(unsigned char d)
{
PIOB -> PIO_SODR = 1 << 25; //RS HIGH
REG_PIOC_ODSR = d << 1;
PIOD -> PIO_CODR = 1 << 7; //WR LOW
PIOD -> PIO_SODR = 1 << 7; //WR HIGH
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Window Set Function
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void window_set(unsigned s_x, unsigned e_x, unsigned s_y, unsigned e_y)
{
comm_out(0x2a); //SET column address
data_out((s_x)>>8); //SET start column address
data_out(s_x);
data_out((e_x)>>8); //SET end column address
data_out(e_x);
comm_out(0x2b); //SET page address
data_out((s_y)>>8); //SET start page address
data_out(s_y);
data_out((e_y)>>8); //SET end page address
data_out(e_y);
}
/****************************************************
* Initialization and Setup Routine *
*****************************************************/
void setup()
{
delay(100);
pinMode(RS,OUTPUT);
pinMode(WR,OUTPUT);
PIOC->PIO_OER = 0xFFFFFFFF;
digitalWrite(WR, LOW);
comm_out(0x28); //display off
comm_out(0x11); //exit SLEEP mode
delay(100);
comm_out(0x36); //MADCTL: memory data access control
data_out(0x10); //changing from 0x88
comm_out(0x20); //display inversion OFF
comm_out(0x3A); //COLMOD: Interface Pixel format *** 65K-colors in 16bit/pixel (5-6-5) format when using 16-bit interface to allow 1-byte per pixel
data_out(0x55); //0x55 = 65k //0x65 = 262k
comm_out(0xB2); //PORCTRK: Porch setting
data_out(0x0C);
data_out(0x0C);
data_out(0x00);
data_out(0x33);
data_out(0x33);
comm_out(0xB7); //GCTRL: Gate Control
data_out(0x35);
comm_out(0xBB); //VCOMS: VCOM setting
data_out(0x2B);
comm_out(0xC0); //LCMCTRL: LCM Control
data_out(0x2C);
comm_out(0xC2); //VDVVRHEN: VDV and VRH Command Enable
data_out(0x01);
data_out(0xFF);
comm_out(0xC3); //VRHS: VRH Set
data_out(0x11);
comm_out(0xC4); //VDVS: VDV Set
data_out(0x20);
comm_out(0xC6); //FRCTRL2: Frame Rate control in normal mode
data_out(0x0F);
comm_out(0xD0); //PWCTRL1: Power Control 1
data_out(0xA4);
data_out(0xA1);
comm_out(0xE0); //PVGAMCTRL: Positive Voltage Gamma control
data_out(0xD0);
data_out(0x00);
data_out(0x05);
data_out(0x0E);
data_out(0x15);
data_out(0x0D);
data_out(0x37);
data_out(0x43);
data_out(0x47);
data_out(0x09);
data_out(0x15);
data_out(0x12);
data_out(0x16);
data_out(0x19);
comm_out(0xE1); //NVGAMCTRL: Negative Voltage Gamma control
data_out(0xD0);
data_out(0x00);
data_out(0x05);
data_out(0x0D);
data_out(0x0C);
data_out(0x06);
data_out(0x2D);
data_out(0x44);
data_out(0x40);
data_out(0x0E);
data_out(0x1C);
data_out(0x18);
data_out(0x16);
data_out(0x19);
comm_out(0x2A); //X address set
data_out(0x00);
data_out(0x00);
data_out(0x00);
data_out(0xEF);
comm_out(0x2B); //Y address set
data_out(0x00);
data_out(0x00);
data_out(0x01);
data_out(0x3F);
delay(10);
comm_out(0x29); //display ON
delay(10);
}
/*****************************************************
* Loop Function, to run repeatedly *
*****************************************************/
void loop()
{
disp();
delay(1000);
}
void disp()
{
unsigned int i;
comm_out(0x2C); //command to begin writing to frame memory
for(i=0;i<38400;i++) //fill screen with blue pixels
{
data_out(0x00);
data_out(0x1F);
data_out(0x00);
data_out(0x1F);
delayMicroseconds(50);
}
for(i=0;i<38400;i++) //fill screen with green pixels
{
data_out(0x07);
data_out(0xE0);
data_out(0x07);
data_out(0xE0);
delayMicroseconds(50);
}
for(i=0;i<38400;i++) //fill screen with red pixels
{
data_out(0xF8);
data_out(0x00);
data_out(0xF8);
data_out(0x00);
delayMicroseconds(50);
}
for(i=0;i<38400;i++) //fill screen with black pixels
{
data_out(0x00);
data_out(0x00);
data_out(0x00);
data_out(0x00);
delayMicroseconds(50);
}
for(i=0;i<38400;i++) //fill screen with white pixels
{
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
data_out(0xFF);
delayMicroseconds(50);
}
}