Skip to content

Commit

Permalink
- Added Panel ST7701 base initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
FigueiredoStable committed May 1, 2024
1 parent 3438208 commit 670ccf8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 124 deletions.
180 changes: 60 additions & 120 deletions src/lgfx/v1/platforms/esp32s3/Panel_RGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Original Source:
[mongonta0716](https://github.com/mongonta0716)
[tobozo](https://github.com/tobozo)
/----------------------------------------------------------------------------*/

#if defined (ESP_PLATFORM)
#include <sdkconfig.h>
#if defined (CONFIG_IDF_TARGET_ESP32S3)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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[] =
Expand Down Expand Up @@ -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
{
Expand Down
11 changes: 7 additions & 4 deletions src/lgfx/v1/platforms/esp32s3/Panel_RGB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 670ccf8

Please sign in to comment.