From 34382082ac98d530379d3194f1b7e08e2a2c3e06 Mon Sep 17 00:00:00 2001 From: Gilson Figueiredo Date: Mon, 29 Apr 2024 12:47:37 -0300 Subject: [PATCH 1/2] - Added GUITION ST7701 panel instructions. --- src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp | 140 ++++++++++++++++++++ src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp | 6 + 2 files changed, 146 insertions(+) diff --git a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp index b09a0857..4e0200b6 100644 --- a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp +++ b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp @@ -317,6 +317,146 @@ namespace lgfx //---------------------------------------------------------------------------- + const uint8_t* Panel_ST7701_guition_esp32_4848S040::getInitCommands(uint8_t listno) const + { + static constexpr const uint8_t list0[] = + { + // Command2 BK0 SEL + 0xFF, 5, 0x77, 0x01, 0x00, 0x00, 0x10, + + 0xC0, 2, 0x3B, 0x00, // added by manufacture + 0xC1, 2, 0x0D, 0x02, + 0xC2, 2, 0x31, 0x05, + 0xCD, 1, 0x00, // changed by manufacture + + // Positive Voltage Gamma Control + 0xB0, 16, 0x00, 0x11, 0x18, 0x0E, 0x11, 0x06, 0x07, 0x08, + 0x07, 0x22, 0x04, 0x12, 0x0F, 0xAA, 0x31, 0x18, + + // Negative Voltage Gamma Control + 0xB1, 16, 0x00, 0x11, 0x19, 0x0E, 0x12, 0x07, 0x08, 0x08, + 0x08, 0x22, 0x04, 0x11, 0x11, 0xA9, 0x32, 0x18, + + // Command2 BK1 SEL + 0xFF, 5, 0x77, 0x01, 0x00, 0x00, 0x11, + + 0xB0, 1, 0x60, // Vop=4.7375v + 0xB1, 1, 0x32, // VCOM=32 + 0xB2, 1, 0x07, // VGH=15v + 0xB3, 1, 0x80, + 0xB5, 1, 0x49, // VGL=-10.17v + 0xB7, 1, 0x85, + 0xB8, 1, 0x21, // AVDD=6.6 & AVCL=-4.6 + 0xC1, 1, 0x78, + 0xC2, 1, 0x78, + + 0xE0, 3, 0x00, 0x1B, 0x02, + + 0xE1, 11, 0x08, 0xA0, 0x00, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x44, 0x44, + 0xE2, 12, 0x11, 0x11, 0x44, 0x44, 0xED, 0xA0, 0x00, 0x00, 0xEC, 0xA0, 0x00, 0x00, + + 0xE3, 4, 0x00, 0x00, 0x11, 0x11, + 0xE4, 2, 0x44, 0x44, + + 0xE5, 16, 0x0A, 0xE9, 0xD8, 0xA0, 0x0C, 0xEB, 0xD8, 0xA0, + 0x0E, 0xED, 0xD8, 0xA0, 0x10, 0xEF, 0xD8, 0xA0, + + 0xE6, 4, 0x00, 0x00, 0x11, 0x11, + + 0xE7, 2, 0x44, 0x44, + + 0xE8, 16, 0x09, 0xE8, 0xD8, 0xA0, 0x0B, 0xEA, 0xD8, 0xA0, + 0x0D, 0xEC, 0xD8, 0xA0, 0x0F, 0xEE, 0xD8, 0xA0, + + 0xEB, 7, 0x02, 0x00, 0xE4, 0xE4, 0x88, 0x00, 0x40, + 0xEC, 2, 0x3C, 0x00, + 0xED, 16, 0xAB, 0x89, 0x76, 0x54, 0x02, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0x20, 0x45, 0x67, 0x98, 0xBA, + + //-----------VAP & VAN--------------- + // Command2 BK3 SEL + 0xFF, 5, 0x77, 0x01, 0x00, 0x00, 0x13, + + 0xE5, 1, 0xE4, + + // Command2 BK0 SEL + 0xFF, 5, 0x77, 0x01, 0x00, 0x00, 0x00, + + //0x21, 0, // 0x20 normal, 0x21 IPS // commented by manufacture + 0x3A, 1, 0x60, // 0x70 RGB888, 0x60 RGB666, 0x50 RGB565 + + 0x11, CMD_INIT_DELAY, 120, // Sleep Out + + 0x29, 0, // Display On + + 0xFF, 0xFF, + }; + switch (listno) + { + case 0: return list0; + default: return nullptr; + } + } + + bool Panel_ST7701_guition_esp32_4848S040::init(bool use_reset) + { + if (!Panel_RGB::init(use_reset)) + { + return false; + } + + int32_t pin_mosi = _config_detail.pin_mosi; + int32_t pin_sclk = _config_detail.pin_sclk; + if (pin_mosi >= 0 && pin_sclk >= 0) + { + lgfx::gpio::pin_backup_t backup_pins[] = { (gpio_num_t)pin_mosi, (gpio_num_t)pin_sclk }; + + lgfx::gpio_lo(pin_mosi); + lgfx::pinMode(pin_mosi, pin_mode_t::output); + lgfx::gpio_lo(pin_sclk); + lgfx::pinMode(pin_sclk, pin_mode_t::output); + + + int32_t pin_cs = _config_detail.pin_cs; + lgfx::gpio_lo(pin_cs); + + writeCommand(0xFF, 1); + writeData(0x77, 1); + writeData(0x01, 1); + writeData(0x00, 2); + writeData(0x10, 1); + + // 0xC0 : LNSET : Display Line Setting + writeCommand(0xC0, 1); + uint32_t line1 = (_cfg.panel_height >> 3) + 1; + uint32_t line2 = (_cfg.panel_height >> 1) & 3; + writeData(line1 + (line2 ? 0x80 : 0x00), 1); + writeData(line2, 1); + + // 0xC3 : RGBCTRL + auto cfg = ((Bus_RGB*)_bus)->config(); + writeCommand(0xC3, 1); + uint32_t rgbctrl = 0; + if ( cfg.de_idle_high ) rgbctrl += 0x01; + if ( cfg.pclk_idle_high) rgbctrl += 0x02; + if (!cfg.hsync_polarity) rgbctrl += 0x04; + if (!cfg.vsync_polarity) rgbctrl += 0x08; + writeData(rgbctrl, 1); + writeData(0x10, 1); + writeData(0x08, 1); + + for (uint8_t i = 0; auto cmds = getInitCommands(i); i++) + { + command_list(cmds); + } + + lgfx::gpio_hi(pin_cs); + for (auto &bup : backup_pins) { bup.restore(); } + } + + return true; + } + const uint8_t* Panel_GC9503::getInitCommands(uint8_t listno) const { static constexpr const uint8_t list0[] = diff --git a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp index 84527282..6118ff67 100644 --- a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp +++ b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp @@ -100,6 +100,12 @@ namespace lgfx const uint8_t* getInitCommands(uint8_t listno) const override; }; + struct Panel_ST7701_guition_esp32_4848S040: public Panel_RGB + { + bool init(bool) override; + protected: + const uint8_t* getInitCommands(uint8_t listno) const override; + }; struct Panel_GC9503 : public Panel_RGB { From 670ccf8c081f968e87f2b7330cec2f7394e8174a Mon Sep 17 00:00:00 2001 From: Gilson Figueiredo Date: Wed, 1 May 2024 13:51:36 -0300 Subject: [PATCH 2/2] - Added Panel ST7701 base initialization. --- src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp | 180 +++++++------------- src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp | 11 +- 2 files changed, 67 insertions(+), 124 deletions(-) diff --git a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp index 4e0200b6..d0d2ecbc 100644 --- a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp +++ b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp @@ -15,7 +15,6 @@ Original Source: [mongonta0716](https://github.com/mongonta0716) [tobozo](https://github.com/tobozo) /----------------------------------------------------------------------------*/ - #if defined (ESP_PLATFORM) #include #if defined (CONFIG_IDF_TARGET_ESP32S3) @@ -175,6 +174,65 @@ namespace lgfx } //---------------------------------------------------------------------------- + /* Panel ST7701 base initialization */ + bool Panel_ST7701_Base::init(bool use_reset) + { + if (!Panel_RGB::init(use_reset)) + { + return false; + } + + int32_t pin_mosi = _config_detail.pin_mosi; + int32_t pin_sclk = _config_detail.pin_sclk; + if (pin_mosi >= 0 && pin_sclk >= 0) + { + lgfx::gpio::pin_backup_t backup_pins[] = { (gpio_num_t)pin_mosi, (gpio_num_t)pin_sclk }; + + lgfx::gpio_lo(pin_mosi); + lgfx::pinMode(pin_mosi, pin_mode_t::output); + lgfx::gpio_lo(pin_sclk); + lgfx::pinMode(pin_sclk, pin_mode_t::output); + + + int32_t pin_cs = _config_detail.pin_cs; + lgfx::gpio_lo(pin_cs); + + writeCommand(0xFF, 1); + writeData(0x77, 1); + writeData(0x01, 1); + writeData(0x00, 2); + writeData(0x10, 1); + + // 0xC0 : LNSET : Display Line Setting + writeCommand(0xC0, 1); + uint32_t line1 = (_cfg.panel_height >> 3) + 1; + uint32_t line2 = (_cfg.panel_height >> 1) & 3; + writeData(line1 + (line2 ? 0x80 : 0x00), 1); + writeData(line2, 1); + + // 0xC3 : RGBCTRL + auto cfg = ((Bus_RGB*)_bus)->config(); + writeCommand(0xC3, 1); + uint32_t rgbctrl = 0; + if ( cfg.de_idle_high ) rgbctrl += 0x01; + if ( cfg.pclk_idle_high) rgbctrl += 0x02; + if (!cfg.hsync_polarity) rgbctrl += 0x04; + if (!cfg.vsync_polarity) rgbctrl += 0x08; + writeData(rgbctrl, 1); + writeData(0x10, 1); + writeData(0x08, 1); + + for (uint8_t i = 0; auto cmds = getInitCommands(i); i++) + { + command_list(cmds); + } + + lgfx::gpio_hi(pin_cs); + for (auto &bup : backup_pins) { bup.restore(); } + } + + return true; + } const uint8_t* Panel_ST7701::getInitCommands(uint8_t listno) const { @@ -256,67 +314,6 @@ namespace lgfx } } - bool Panel_ST7701::init(bool use_reset) - { - if (!Panel_RGB::init(use_reset)) - { - return false; - } - - int32_t pin_mosi = _config_detail.pin_mosi; - int32_t pin_sclk = _config_detail.pin_sclk; - if (pin_mosi >= 0 && pin_sclk >= 0) - { - lgfx::gpio::pin_backup_t backup_pins[] = { (gpio_num_t)pin_mosi, (gpio_num_t)pin_sclk }; - - lgfx::gpio_lo(pin_mosi); - lgfx::pinMode(pin_mosi, pin_mode_t::output); - lgfx::gpio_lo(pin_sclk); - lgfx::pinMode(pin_sclk, pin_mode_t::output); - - - int32_t pin_cs = _config_detail.pin_cs; - lgfx::gpio_lo(pin_cs); - - writeCommand(0xFF, 1); - writeData(0x77, 1); - writeData(0x01, 1); - writeData(0x00, 2); - writeData(0x10, 1); - - // 0xC0 : LNSET : Display Line Setting - writeCommand(0xC0, 1); - uint32_t line1 = (_cfg.panel_height >> 3) + 1; - uint32_t line2 = (_cfg.panel_height >> 1) & 3; - writeData(line1 + (line2 ? 0x80 : 0x00), 1); - writeData(line2, 1); - - // 0xC3 : RGBCTRL - auto cfg = ((Bus_RGB*)_bus)->config(); - writeCommand(0xC3, 1); - uint32_t rgbctrl = 0; - if ( cfg.de_idle_high ) rgbctrl += 0x01; - if ( cfg.pclk_idle_high) rgbctrl += 0x02; - if (!cfg.hsync_polarity) rgbctrl += 0x04; - if (!cfg.vsync_polarity) rgbctrl += 0x08; - writeData(rgbctrl, 1); - writeData(0x10, 1); - writeData(0x08, 1); - - for (uint8_t i = 0; auto cmds = getInitCommands(i); i++) - { - command_list(cmds); - } - - lgfx::gpio_hi(pin_cs); - for (auto &bup : backup_pins) { bup.restore(); } - } - - return true; - } - -//---------------------------------------------------------------------------- - const uint8_t* Panel_ST7701_guition_esp32_4848S040::getInitCommands(uint8_t listno) const { static constexpr const uint8_t list0[] = @@ -398,64 +395,7 @@ namespace lgfx } } - bool Panel_ST7701_guition_esp32_4848S040::init(bool use_reset) - { - if (!Panel_RGB::init(use_reset)) - { - return false; - } - - int32_t pin_mosi = _config_detail.pin_mosi; - int32_t pin_sclk = _config_detail.pin_sclk; - if (pin_mosi >= 0 && pin_sclk >= 0) - { - lgfx::gpio::pin_backup_t backup_pins[] = { (gpio_num_t)pin_mosi, (gpio_num_t)pin_sclk }; - - lgfx::gpio_lo(pin_mosi); - lgfx::pinMode(pin_mosi, pin_mode_t::output); - lgfx::gpio_lo(pin_sclk); - lgfx::pinMode(pin_sclk, pin_mode_t::output); - - - int32_t pin_cs = _config_detail.pin_cs; - lgfx::gpio_lo(pin_cs); - - writeCommand(0xFF, 1); - writeData(0x77, 1); - writeData(0x01, 1); - writeData(0x00, 2); - writeData(0x10, 1); - - // 0xC0 : LNSET : Display Line Setting - writeCommand(0xC0, 1); - uint32_t line1 = (_cfg.panel_height >> 3) + 1; - uint32_t line2 = (_cfg.panel_height >> 1) & 3; - writeData(line1 + (line2 ? 0x80 : 0x00), 1); - writeData(line2, 1); - - // 0xC3 : RGBCTRL - auto cfg = ((Bus_RGB*)_bus)->config(); - writeCommand(0xC3, 1); - uint32_t rgbctrl = 0; - if ( cfg.de_idle_high ) rgbctrl += 0x01; - if ( cfg.pclk_idle_high) rgbctrl += 0x02; - if (!cfg.hsync_polarity) rgbctrl += 0x04; - if (!cfg.vsync_polarity) rgbctrl += 0x08; - writeData(rgbctrl, 1); - writeData(0x10, 1); - writeData(0x08, 1); - - for (uint8_t i = 0; auto cmds = getInitCommands(i); i++) - { - command_list(cmds); - } - - lgfx::gpio_hi(pin_cs); - for (auto &bup : backup_pins) { bup.restore(); } - } - - return true; - } +//---------------------------------------------------------------------------- const uint8_t* Panel_GC9503::getInitCommands(uint8_t listno) const { diff --git a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp index 6118ff67..220ef267 100644 --- a/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp +++ b/src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp @@ -93,16 +93,19 @@ namespace lgfx }; - struct Panel_ST7701 : public Panel_RGB + struct Panel_ST7701_Base : public Panel_RGB + { + bool init(bool) override; + }; + + struct Panel_ST7701 : public Panel_ST7701_Base { - bool init(bool) override; protected: const uint8_t* getInitCommands(uint8_t listno) const override; }; - struct Panel_ST7701_guition_esp32_4848S040: public Panel_RGB + struct Panel_ST7701_guition_esp32_4848S040: public Panel_ST7701_Base { - bool init(bool) override; protected: const uint8_t* getInitCommands(uint8_t listno) const override; };