From 058b564a16483b77efee591c344a2566b7d595fb Mon Sep 17 00:00:00 2001 From: lexus2k Date: Fri, 17 Jun 2022 09:10:51 +1000 Subject: [PATCH] ST7789 240x240 support initial commit #86 --- src/v2/lcd/st7789/lcd_st7789.cpp | 11 +++ src/v2/lcd/st7789/lcd_st7789.h | 106 +++++++++++++++++++++++++ src/v2/lcd/st7789/lcd_st7789.inl | 47 +++++++++++ tools/templates/lcd/st7789/st7789.json | 39 +++++++++ 4 files changed, 203 insertions(+) diff --git a/src/v2/lcd/st7789/lcd_st7789.cpp b/src/v2/lcd/st7789/lcd_st7789.cpp index f83fcf6..b2fe015 100644 --- a/src/v2/lcd/st7789/lcd_st7789.cpp +++ b/src/v2/lcd/st7789/lcd_st7789.cpp @@ -38,3 +38,14 @@ void DisplayST7789_135x240x16_SPI::end() DisplayST7789_135x240x16::end(); m_spi.end(); } +void DisplayST7789_240x240x16_SPI::begin() +{ + m_spi.begin(); + DisplayST7789_240x240x16::begin(); +} + +void DisplayST7789_240x240x16_SPI::end() +{ + DisplayST7789_240x240x16::end(); + m_spi.end(); +} diff --git a/src/v2/lcd/st7789/lcd_st7789.h b/src/v2/lcd/st7789/lcd_st7789.h index 807029a..a8e2f17 100644 --- a/src/v2/lcd/st7789/lcd_st7789.h +++ b/src/v2/lcd/st7789/lcd_st7789.h @@ -263,6 +263,112 @@ template class DisplayST7789_135x240x16_CustomSPI: public DisplayST778 m_spi.end(); } +private: + InterfaceST7789 m_spi; +}; +/** + * Class implements basic functions for 16-bit mode of ST7789-based displays + */ +template class DisplayST7789_240x240x16: public DisplayST7789x16 +{ +public: + /** + * Creates instance of ST7789 240x240x16 controller class for 16-bit mode + * + * @param intf interface to use + * @param rstPin pin to use as HW reset pin for LCD display + */ + DisplayST7789_240x240x16(I &intf, int8_t rstPin) + : DisplayST7789x16(intf, rstPin) + { + } + +protected: + /** + * Basic ST7789 240x240x16 initialization + */ + void begin() override; + + /** + * Basic ST7789 deinitialization + */ + void end() override; +}; +/** + * Class implements ST7789 240x240x16 lcd display in 16 bit mode over SPI + */ +class DisplayST7789_240x240x16_SPI: public DisplayST7789_240x240x16> +{ +public: + /** + * @brief Inits 240x240x16 lcd display over spi (based on ST7789 controller): 16-bit mode. + * + * Inits 240x240x16 lcd display over spi (based on ST7789 controller): 16-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform spi configuration. Please refer to SPlatformSpiConfig. + */ + explicit DisplayST7789_240x240x16_SPI(int8_t rstPin, const SPlatformSpiConfig &config = {-1, {-1}, -1, 0, -1, -1}) + : DisplayST7789_240x240x16(m_spi, rstPin) + , m_spi(*this, config.dc, + SPlatformSpiConfig{ + config.busId, {config.cs}, config.dc, config.frequency ?: 40000000, config.scl, config.sda}) + { + } + + /** + * Initializes ST7789 lcd in 16-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceST7789 m_spi; +}; + +/** + * Template class implements ST7789 240x240x16 lcd display in 16 bit mode over custom SPI implementation + * (user-defined spi implementation). I - user custom spi class + */ +template class DisplayST7789_240x240x16_CustomSPI: public DisplayST7789_240x240x16> +{ +public: + /** + * @brief Inits 240x240x16 lcd display over spi (based on ST7789 controller): 16-bit mode. + * + * Inits 240x240x16 lcd display over spi (based on ST7789 controller): 16-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin + * @param data variable argument list for custom user spi interface. + */ + template + DisplayST7789_240x240x16_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data) + : DisplayST7789_240x240x16>(m_spi, rstPin) + , m_spi(*this, dcPin, data...) + { + } + + /** + * Initializes ST7789 lcd in 16-bit mode + */ + void begin() override + { + m_spi.begin(); + DisplayST7789_240x240x16>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplayST7789_240x240x16>::end(); + m_spi.end(); + } + private: InterfaceST7789 m_spi; }; diff --git a/src/v2/lcd/st7789/lcd_st7789.inl b/src/v2/lcd/st7789/lcd_st7789.inl index 12e4fc6..abc781b 100644 --- a/src/v2/lcd/st7789/lcd_st7789.inl +++ b/src/v2/lcd/st7789/lcd_st7789.inl @@ -217,3 +217,50 @@ template void DisplayST7789_135x240x16::begin() template void DisplayST7789_135x240x16::end() { } + +static const PROGMEM uint8_t s_ST7789_lcd240x240x16_initData[] = { +#ifdef SDL_EMULATION + SDL_LCD_ST7789, 0x00, 0b00010000, 0x00, +#endif + 0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset + 0x11, CMD_DELAY, 20, // SLPOUT exit sleep mode + 0x13, CMD_DELAY, 10, // NORON + 0x3A, 0x01, 0x55, // COLMOD set 16-bit pixel format 0x55 + 0x36, 0x01, 0b00001000, // MADCTL 08 Adafruit + 0xB6, 0x02, 0x0A, 0x82, // DISSET5 + 0xB2, 0x05, 0x0C, 0x0C, 0x00, 0x33, 0x33, // FRMCTR2 / PORCTL, Frame Rate Control (In Idle mode/ 8-colors) + 0xB7, 0x01, 0x35, // VGH / VGL + 0xBB, 0x01, 0x28, // VCOM + 0xC0, 0x01, 0x0C, // LCM / PWCTR1 power control 1 + 0xC2, 0x02, 0x01, 0xFF, // VDV PWCTR3 power control 3 + 0xC3, 0x01, 0x10, // VRH + 0xC4, 0x01, 0x20, // VDV + 0xC6, 0x01, 0x0F, // FRCTR2 + 0xD0, 0x02, 0xA4, 0xA1, // PWCTRL1 + 0xE0, 0x0E, // GMCTRP1 positive gamma correction + 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17, 0xE1, + 0x0E, // GMCTRN1 negative gamma correction + 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E, + // 0x2A, 0x04, 0x00, 0x00, 0x00, 0x7F, // set column address, not needed. set by direct API + // 0x2B, 0x04, 0x00, 0x00, 0x00, 0x9F, // set page address, not needed. set by direct API + 0x21, CMD_DELAY, 10, // INVON (21h): Display Inversion On + 0x29, CMD_DELAY, 120, // DISPON display on +}; + +//////////////////////////////////////////////////////////////////////////////// +// ST7789 basic 16-bit implementation +//////////////////////////////////////////////////////////////////////////////// + +template void DisplayST7789_240x240x16::begin() +{ + ssd1306_resetController2(this->m_rstPin, 20); + this->m_w = 240; + this->m_h = 240; + // Give LCD some time to initialize. Refer to ST7789 datasheet + lcd_delay(120); + _configureSpiDisplay(this->m_intf, s_ST7789_lcd240x240x16_initData, sizeof(s_ST7789_lcd240x240x16_initData)); +} + +template void DisplayST7789_240x240x16::end() +{ +} diff --git a/tools/templates/lcd/st7789/st7789.json b/tools/templates/lcd/st7789/st7789.json index 9a5da68..6f850a0 100644 --- a/tools/templates/lcd/st7789/st7789.json +++ b/tools/templates/lcd/st7789/st7789.json @@ -31,6 +31,45 @@ "16": { "135x240": + { + "init": + [ + "#ifdef SDL_EMULATION", + " SDL_LCD_ST7789, 0x00,", + " 0b00010000, 0x00,", + "#endif", + " 0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset", + " 0x11, CMD_DELAY, 20, // SLPOUT exit sleep mode", + " 0x13, CMD_DELAY, 10, // NORON", + " 0x3A, 0x01, 0x55, // COLMOD set 16-bit pixel format 0x55", + " 0x36, 0x01, 0b00001000, // MADCTL 08 Adafruit", + " 0xB6, 0x02, 0x0A, 0x82, // DISSET5", + " 0xB2, 0x05, 0x0C, 0x0C, 0x00, 0x33, 0x33, // FRMCTR2 / PORCTL, Frame Rate Control (In Idle mode/ 8-colors)", + " 0xB7, 0x01, 0x35, // VGH / VGL", + " 0xBB, 0x01, 0x28, // VCOM", + " 0xC0, 0x01, 0x0C, // LCM / PWCTR1 power control 1", + " 0xC2, 0x02, 0x01, 0xFF, // VDV PWCTR3 power control 3", + " 0xC3, 0x01, 0x10, // VRH", + " 0xC4, 0x01, 0x20, // VDV", + " 0xC6, 0x01, 0x0F, // FRCTR2", + " 0xD0, 0x02, 0xA4, 0xA1, // PWCTRL1", + " 0xE0, 0x0E, // GMCTRP1 positive gamma correction", + " 0xD0, 0x00, 0x02, 0x07,", + " 0x0A, 0x28, 0x32, 0x44,", + " 0x42, 0x06, 0x0E, 0x12,", + " 0x14, 0x17,", + " 0xE1, 0x0E, // GMCTRN1 negative gamma correction", + " 0xD0, 0x00, 0x02, 0x07,", + " 0x0A, 0x28, 0x31, 0x54,", + " 0x47, 0x0E, 0x1C, 0x17,", + " 0x1B, 0x1E,", + "// 0x2A, 0x04, 0x00, 0x00, 0x00, 0x7F, // set column address, not needed. set by direct API", + "// 0x2B, 0x04, 0x00, 0x00, 0x00, 0x9F, // set page address, not needed. set by direct API", + " 0x21, CMD_DELAY, 10, // INVON (21h): Display Inversion On", + " 0x29, CMD_DELAY, 120, // DISPON display on" + ] + }, + "240x240": { "init": [