Restore official Waveshare display register init sequence and LEDC backlight driver to fix blank display screen
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
SPIClass LCDspi(FSPI);
|
||||
#define SPI_WRITE(_dat) LCDspi.transfer(_dat)
|
||||
#define SPI_WRITE_Word(_dat) LCDspi.transfer16(_dat)
|
||||
|
||||
void SPI_Init()
|
||||
{
|
||||
LCDspi.begin(EXAMPLE_PIN_NUM_SCLK,EXAMPLE_PIN_NUM_MISO,EXAMPLE_PIN_NUM_MOSI);
|
||||
LCDspi.begin(EXAMPLE_PIN_NUM_SCLK, EXAMPLE_PIN_NUM_MISO, EXAMPLE_PIN_NUM_MOSI);
|
||||
}
|
||||
|
||||
void LCD_WriteCommand(uint8_t Cmd)
|
||||
@@ -17,6 +18,7 @@ void LCD_WriteCommand(uint8_t Cmd)
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
LCDspi.endTransaction();
|
||||
}
|
||||
|
||||
void LCD_WriteData(uint8_t Data)
|
||||
{
|
||||
LCDspi.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
@@ -26,6 +28,7 @@ void LCD_WriteData(uint8_t Data)
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
LCDspi.endTransaction();
|
||||
}
|
||||
|
||||
void LCD_WriteData_Word(uint16_t Data)
|
||||
{
|
||||
LCDspi.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
@@ -35,7 +38,8 @@ void LCD_WriteData_Word(uint16_t Data)
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
LCDspi.endTransaction();
|
||||
}
|
||||
void LCD_WriteData_nbyte(uint8_t* SetData,uint8_t* ReadData,uint32_t Size)
|
||||
|
||||
void LCD_WriteData_nbyte(uint8_t* SetData, uint8_t* ReadData, uint32_t Size)
|
||||
{
|
||||
LCDspi.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);
|
||||
@@ -54,6 +58,7 @@ void LCD_Reset(void)
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_RST, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
|
||||
void LCD_Init(void)
|
||||
{
|
||||
pinMode(EXAMPLE_PIN_NUM_LCD_CS, OUTPUT);
|
||||
@@ -62,192 +67,107 @@ void LCD_Init(void)
|
||||
Backlight_Init();
|
||||
SPI_Init();
|
||||
|
||||
// Reset LCD
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_RST, LOW);
|
||||
delay(10);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_RST, HIGH);
|
||||
delay(50);
|
||||
|
||||
//************* JD9853 Start Initial Sequence **********//
|
||||
LCD_WriteCommand(0x11); // Sleep Out
|
||||
LCD_Reset();
|
||||
|
||||
//************* Start Initial Sequence **********//
|
||||
LCD_WriteCommand(0x11);
|
||||
delay(120);
|
||||
|
||||
LCD_WriteCommand(0xDF);
|
||||
LCD_WriteData(0x98);
|
||||
LCD_WriteData(0x53);
|
||||
|
||||
LCD_WriteCommand(0xB2);
|
||||
LCD_WriteData(0x23);
|
||||
|
||||
LCD_WriteCommand(0xB7);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x47);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x6F);
|
||||
|
||||
LCD_WriteCommand(0xBB);
|
||||
LCD_WriteData(0x1C);
|
||||
LCD_WriteData(0x1A);
|
||||
LCD_WriteData(0x55);
|
||||
LCD_WriteData(0x73);
|
||||
LCD_WriteData(0x63);
|
||||
LCD_WriteData(0xF0);
|
||||
|
||||
LCD_WriteCommand(0xC0);
|
||||
LCD_WriteData(0x44);
|
||||
LCD_WriteData(0xA4);
|
||||
|
||||
LCD_WriteCommand(0xC1);
|
||||
LCD_WriteData(0x16);
|
||||
|
||||
LCD_WriteCommand(0xC3);
|
||||
LCD_WriteData(0x7D);
|
||||
LCD_WriteData(0x07);
|
||||
LCD_WriteData(0x14);
|
||||
LCD_WriteData(0x06);
|
||||
LCD_WriteData(0xCF);
|
||||
LCD_WriteData(0x71);
|
||||
LCD_WriteData(0x72);
|
||||
LCD_WriteData(0x77);
|
||||
|
||||
LCD_WriteCommand(0xC4);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0xA0);
|
||||
LCD_WriteData(0x79);
|
||||
LCD_WriteData(0x0B);
|
||||
LCD_WriteData(0x0A);
|
||||
LCD_WriteData(0x16);
|
||||
LCD_WriteData(0x79);
|
||||
LCD_WriteData(0x0B);
|
||||
LCD_WriteData(0x0A);
|
||||
LCD_WriteData(0x16);
|
||||
LCD_WriteData(0x82);
|
||||
|
||||
LCD_WriteCommand(0xC8);
|
||||
const uint8_t c8_data[] = {
|
||||
0x3F, 0x32, 0x29, 0x29, 0x27, 0x2B, 0x27, 0x28, 0x28, 0x26, 0x25, 0x17, 0x12, 0x0D, 0x04, 0x00,
|
||||
0x3F, 0x32, 0x29, 0x29, 0x27, 0x2B, 0x27, 0x28, 0x28, 0x26, 0x25, 0x17, 0x12, 0x0D, 0x04, 0x00
|
||||
};
|
||||
for (int i = 0; i < 32; i++) {
|
||||
LCD_WriteData(c8_data[i]);
|
||||
}
|
||||
|
||||
LCD_WriteCommand(0xD0);
|
||||
LCD_WriteData(0x04);
|
||||
LCD_WriteData(0x06);
|
||||
LCD_WriteData(0x6B);
|
||||
LCD_WriteData(0x0F);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0xD7);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x30);
|
||||
|
||||
LCD_WriteCommand(0xE6);
|
||||
LCD_WriteData(0x14);
|
||||
|
||||
LCD_WriteCommand(0xDE);
|
||||
LCD_WriteData(0x01);
|
||||
|
||||
LCD_WriteCommand(0xB7);
|
||||
LCD_WriteData(0x03);
|
||||
LCD_WriteData(0x13);
|
||||
LCD_WriteData(0xEF);
|
||||
LCD_WriteData(0x35);
|
||||
LCD_WriteData(0x35);
|
||||
|
||||
LCD_WriteCommand(0xC1);
|
||||
LCD_WriteData(0x14);
|
||||
LCD_WriteData(0x15);
|
||||
LCD_WriteData(0xC0);
|
||||
|
||||
LCD_WriteCommand(0xC2);
|
||||
LCD_WriteData(0x06);
|
||||
LCD_WriteData(0x3A);
|
||||
|
||||
LCD_WriteCommand(0xC4);
|
||||
LCD_WriteData(0x72);
|
||||
LCD_WriteData(0x12);
|
||||
|
||||
LCD_WriteCommand(0xBE);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0xDE);
|
||||
LCD_WriteData(0x02);
|
||||
|
||||
LCD_WriteCommand(0xE5);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x02);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0xE5);
|
||||
LCD_WriteData(0x01);
|
||||
LCD_WriteData(0x02);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0xDE);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0x35);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0x3A);
|
||||
LCD_WriteData(0x05);
|
||||
|
||||
LCD_WriteCommand(0x2A);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x22);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0xCD);
|
||||
|
||||
LCD_WriteCommand(0x2B);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x01);
|
||||
LCD_WriteData(0x3F);
|
||||
|
||||
LCD_WriteCommand(0xDE);
|
||||
LCD_WriteData(0x02);
|
||||
|
||||
LCD_WriteCommand(0xE5);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x02);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0xDE);
|
||||
LCD_WriteData(0x00);
|
||||
|
||||
LCD_WriteCommand(0x36); // Rotation control
|
||||
LCD_WriteCommand(0x36);
|
||||
if (HORIZONTAL)
|
||||
LCD_WriteData(0x00);
|
||||
else
|
||||
LCD_WriteData(0x70);
|
||||
|
||||
LCD_WriteCommand(0x21); // Display Inversion On
|
||||
LCD_WriteCommand(0x3A);
|
||||
LCD_WriteData(0x05);
|
||||
|
||||
delay(10);
|
||||
LCD_WriteCommand(0x29); // Display On
|
||||
LCD_WriteCommand(0xB0);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0xE8);
|
||||
|
||||
LCD_WriteCommand(0xB2);
|
||||
LCD_WriteData(0x0C);
|
||||
LCD_WriteData(0x0C);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x33);
|
||||
LCD_WriteData(0x33);
|
||||
|
||||
LCD_WriteCommand(0xB7);
|
||||
LCD_WriteData(0x35);
|
||||
|
||||
LCD_WriteCommand(0xBB);
|
||||
LCD_WriteData(0x35);
|
||||
|
||||
LCD_WriteCommand(0xC0);
|
||||
LCD_WriteData(0x2C);
|
||||
|
||||
LCD_WriteCommand(0xC2);
|
||||
LCD_WriteData(0x01);
|
||||
|
||||
LCD_WriteCommand(0xC3);
|
||||
LCD_WriteData(0x13);
|
||||
|
||||
LCD_WriteCommand(0xC4);
|
||||
LCD_WriteData(0x20);
|
||||
|
||||
LCD_WriteCommand(0xC6);
|
||||
LCD_WriteData(0x0F);
|
||||
|
||||
LCD_WriteCommand(0xD0);
|
||||
LCD_WriteData(0xA4);
|
||||
LCD_WriteData(0xA1);
|
||||
|
||||
LCD_WriteCommand(0xD6);
|
||||
LCD_WriteData(0xA1);
|
||||
|
||||
LCD_WriteCommand(0xE0);
|
||||
LCD_WriteData(0xF0);
|
||||
LCD_WriteData(0x00);
|
||||
LCD_WriteData(0x04);
|
||||
LCD_WriteData(0x04);
|
||||
LCD_WriteData(0x04);
|
||||
LCD_WriteData(0x05);
|
||||
LCD_WriteData(0x29);
|
||||
LCD_WriteData(0x33);
|
||||
LCD_WriteData(0x3E);
|
||||
LCD_WriteData(0x38);
|
||||
LCD_WriteData(0x12);
|
||||
LCD_WriteData(0x12);
|
||||
LCD_WriteData(0x28);
|
||||
LCD_WriteData(0x30);
|
||||
|
||||
LCD_WriteCommand(0xE1);
|
||||
LCD_WriteData(0xF0);
|
||||
LCD_WriteData(0x07);
|
||||
LCD_WriteData(0x0A);
|
||||
LCD_WriteData(0x0D);
|
||||
LCD_WriteData(0x0B);
|
||||
LCD_WriteData(0x07);
|
||||
LCD_WriteData(0x28);
|
||||
LCD_WriteData(0x33);
|
||||
LCD_WriteData(0x3E);
|
||||
LCD_WriteData(0x36);
|
||||
LCD_WriteData(0x14);
|
||||
LCD_WriteData(0x14);
|
||||
LCD_WriteData(0x29);
|
||||
LCD_WriteData(0x32);
|
||||
|
||||
LCD_WriteCommand(0x21);
|
||||
|
||||
LCD_WriteCommand(0x11);
|
||||
delay(120);
|
||||
LCD_WriteCommand(0x29);
|
||||
}
|
||||
/******************************************************************************
|
||||
function: Set the cursor position
|
||||
parameter :
|
||||
Xstart: Start uint16_t x coordinate
|
||||
Ystart: Start uint16_t y coordinate
|
||||
Xend : End uint16_t coordinates
|
||||
Yend : End uint16_t coordinatesen
|
||||
******************************************************************************/
|
||||
void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend)
|
||||
|
||||
void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend)
|
||||
{
|
||||
if (HORIZONTAL) {
|
||||
// set the X coordinates
|
||||
LCD_WriteCommand(0x2A);
|
||||
LCD_WriteData(Xstart >> 8);
|
||||
LCD_WriteData(Xstart + Offset_X);
|
||||
LCD_WriteData(Xend >> 8);
|
||||
LCD_WriteData(Xend + Offset_X);
|
||||
|
||||
// set the Y coordinates
|
||||
LCD_WriteCommand(0x2B);
|
||||
LCD_WriteData(Ystart >> 8);
|
||||
LCD_WriteData(Ystart + Offset_Y);
|
||||
@@ -255,13 +175,12 @@ void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Ye
|
||||
LCD_WriteData(Yend + Offset_Y);
|
||||
}
|
||||
else {
|
||||
// set the X coordinates
|
||||
LCD_WriteCommand(0x2A);
|
||||
LCD_WriteData(Ystart >> 8);
|
||||
LCD_WriteData(Ystart + Offset_Y);
|
||||
LCD_WriteData(Yend >> 8);
|
||||
LCD_WriteData(Yend + Offset_Y);
|
||||
// set the Y coordinates
|
||||
|
||||
LCD_WriteCommand(0x2B);
|
||||
LCD_WriteData(Xstart >> 8);
|
||||
LCD_WriteData(Xstart + Offset_X);
|
||||
@@ -270,15 +189,7 @@ void LCD_SetCursor(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Ye
|
||||
}
|
||||
LCD_WriteCommand(0x2C);
|
||||
}
|
||||
/******************************************************************************
|
||||
function: Refresh the image in an area
|
||||
parameter :
|
||||
Xstart: Start uint16_t x coordinate
|
||||
Ystart: Start uint16_t y coordinate
|
||||
Xend : End uint16_t coordinates
|
||||
Yend : End uint16_t coordinates
|
||||
color : Set the color
|
||||
******************************************************************************/
|
||||
|
||||
void LCD_addWindow(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend, uint16_t* color)
|
||||
{
|
||||
uint16_t Show_Width = Xend - Xstart + 1;
|
||||
@@ -293,19 +204,16 @@ void LCD_addWindow(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yen
|
||||
digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);
|
||||
LCDspi.endTransaction();
|
||||
}
|
||||
// backlight
|
||||
|
||||
void Backlight_Init(void)
|
||||
{
|
||||
pinMode(EXAMPLE_PIN_NUM_BK_LIGHT, OUTPUT);
|
||||
digitalWrite(EXAMPLE_PIN_NUM_BK_LIGHT, HIGH); // Set backlight to full brightness
|
||||
ledcAttach(EXAMPLE_PIN_NUM_BK_LIGHT, Frequency, Resolution);
|
||||
ledcWrite(EXAMPLE_PIN_NUM_BK_LIGHT, 100);
|
||||
}
|
||||
|
||||
void Set_Backlight(uint8_t Light) //
|
||||
void Set_Backlight(uint8_t Light)
|
||||
{
|
||||
pinMode(EXAMPLE_PIN_NUM_BK_LIGHT, OUTPUT);
|
||||
if (Light > 0) {
|
||||
digitalWrite(EXAMPLE_PIN_NUM_BK_LIGHT, HIGH);
|
||||
} else {
|
||||
digitalWrite(EXAMPLE_PIN_NUM_BK_LIGHT, LOW);
|
||||
}
|
||||
if (Light > 100) Light = 100;
|
||||
uint32_t duty = Light * 10;
|
||||
ledcWrite(EXAMPLE_PIN_NUM_BK_LIGHT, duty);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user