Skip to content

Commit

Permalink
ST7789 240x240 support initial commit #86
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Jun 16, 2022
1 parent 27d059b commit 058b564
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/v2/lcd/st7789/lcd_st7789.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
106 changes: 106 additions & 0 deletions src/v2/lcd/st7789/lcd_st7789.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,112 @@ template <class I> class DisplayST7789_135x240x16_CustomSPI: public DisplayST778
m_spi.end();
}

private:
InterfaceST7789<I> m_spi;
};
/**
* Class implements basic functions for 16-bit mode of ST7789-based displays
*/
template <class I> class DisplayST7789_240x240x16: public DisplayST7789x16<I>
{
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<I>(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<InterfaceST7789<PlatformSpi>>
{
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<PlatformSpi> 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 I> class DisplayST7789_240x240x16_CustomSPI: public DisplayST7789_240x240x16<InterfaceST7789<I>>
{
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 <typename... Args>
DisplayST7789_240x240x16_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data)
: DisplayST7789_240x240x16<InterfaceST7789<I>>(m_spi, rstPin)
, m_spi(*this, dcPin, data...)
{
}

/**
* Initializes ST7789 lcd in 16-bit mode
*/
void begin() override
{
m_spi.begin();
DisplayST7789_240x240x16<InterfaceST7789<I>>::begin();
}

/**
* Closes connection to display
*/
void end() override
{
DisplayST7789_240x240x16<InterfaceST7789<I>>::end();
m_spi.end();
}

private:
InterfaceST7789<I> m_spi;
};
Expand Down
47 changes: 47 additions & 0 deletions src/v2/lcd/st7789/lcd_st7789.inl
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,50 @@ template <class I> void DisplayST7789_135x240x16<I>::begin()
template <class I> void DisplayST7789_135x240x16<I>::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 <class I> void DisplayST7789_240x240x16<I>::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<I>(this->m_intf, s_ST7789_lcd240x240x16_initData, sizeof(s_ST7789_lcd240x240x16_initData));
}

template <class I> void DisplayST7789_240x240x16<I>::end()
{
}
39 changes: 39 additions & 0 deletions tools/templates/lcd/st7789/st7789.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":
[
Expand Down

0 comments on commit 058b564

Please sign in to comment.